summaryrefslogtreecommitdiff
path: root/sapi
diff options
context:
space:
mode:
Diffstat (limited to 'sapi')
-rw-r--r--sapi/activescript/CREDITS2
-rw-r--r--sapi/activescript/EXPERIMENTAL5
-rw-r--r--sapi/activescript/README56
-rw-r--r--sapi/activescript/classfactory.cpp361
-rw-r--r--sapi/activescript/php4activescript.c154
-rw-r--r--sapi/activescript/php4activescript.def5
-rw-r--r--sapi/activescript/php4activescript.dsp185
-rw-r--r--sapi/activescript/php4activescript.h25
-rw-r--r--sapi/activescript/php4as_classfactory.h52
-rw-r--r--sapi/activescript/php4as_scriptengine.h235
-rw-r--r--sapi/activescript/scriptengine.cpp1873
-rw-r--r--sapi/aolserver/CREDITS2
-rw-r--r--sapi/aolserver/README69
-rw-r--r--sapi/aolserver/aolserver.c616
-rw-r--r--sapi/aolserver/config.m433
-rw-r--r--sapi/aolserver/php.sym2
-rw-r--r--sapi/aolserver/php4aolserver.dsp135
-rw-r--r--sapi/apache/CREDITS3
-rw-r--r--sapi/apache/apMakefile.libdir4
-rw-r--r--sapi/apache/apMakefile.tmpl77
-rw-r--r--sapi/apache/config.m4268
-rw-r--r--sapi/apache/libphp4.module.in11
-rw-r--r--sapi/apache/libpre.c55
-rw-r--r--sapi/apache/mod_php4.c966
-rw-r--r--sapi/apache/mod_php4.exp1
-rw-r--r--sapi/apache/mod_php4.h54
-rw-r--r--sapi/apache/php.sym1
-rw-r--r--sapi/apache/php4apache.dsp151
-rw-r--r--sapi/apache/php_apache.c543
-rw-r--r--sapi/apache/php_apache_http.h66
-rw-r--r--sapi/apache/sapi_apache.c75
-rw-r--r--sapi/apache2filter/CREDITS2
-rw-r--r--sapi/apache2filter/EXPERIMENTAL5
-rw-r--r--sapi/apache2filter/README71
-rw-r--r--sapi/apache2filter/apache_config.c230
-rw-r--r--sapi/apache2filter/config.m4118
-rw-r--r--sapi/apache2filter/php.sym1
-rw-r--r--sapi/apache2filter/php4apache2.dsp142
-rw-r--r--sapi/apache2filter/php_apache.h72
-rw-r--r--sapi/apache2filter/php_functions.c393
-rw-r--r--sapi/apache2filter/sapi_apache2.c688
-rw-r--r--sapi/apache2handler/CREDITS3
-rw-r--r--sapi/apache2handler/EXPERIMENTAL5
-rw-r--r--sapi/apache2handler/README76
-rw-r--r--sapi/apache2handler/apache_config.c228
-rw-r--r--sapi/apache2handler/config.m4118
-rw-r--r--sapi/apache2handler/php.sym1
-rw-r--r--sapi/apache2handler/php4apache2.dsp142
-rw-r--r--sapi/apache2handler/php_apache.h66
-rw-r--r--sapi/apache2handler/php_functions.c404
-rw-r--r--sapi/apache2handler/sapi_apache2.c613
-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.m4242
-rw-r--r--sapi/apache_hooks/libphp4.module.in11
-rw-r--r--sapi/apache_hooks/mod_php4.c1474
-rw-r--r--sapi/apache_hooks/mod_php4.exp1
-rw-r--r--sapi/apache_hooks/mod_php4.h81
-rw-r--r--sapi/apache_hooks/php.sym1
-rwxr-xr-xsapi/apache_hooks/php4apache_hooks.dsp151
-rw-r--r--sapi/apache_hooks/php_apache.c1954
-rw-r--r--sapi/apache_hooks/php_apache_http.h44
-rw-r--r--sapi/apache_hooks/sapi_apache.c136
-rw-r--r--sapi/caudium/CREDITS2
-rw-r--r--sapi/caudium/README16
-rw-r--r--sapi/caudium/TODO30
-rw-r--r--sapi/caudium/caudium.c791
-rw-r--r--sapi/caudium/config.m499
-rw-r--r--sapi/cgi/CREDITS2
-rw-r--r--sapi/cgi/Makefile.frag2
-rw-r--r--sapi/cgi/README.FastCGI137
-rw-r--r--sapi/cgi/cgi_main.c1593
-rw-r--r--sapi/cgi/config9.m4171
-rw-r--r--sapi/cgi/getopt.c154
-rw-r--r--sapi/cgi/libfcgi/LICENSE.TERMS28
-rw-r--r--sapi/cgi/libfcgi/acinclude.m4389
-rw-r--r--sapi/cgi/libfcgi/fcgi_stdio.c801
-rw-r--r--sapi/cgi/libfcgi/fcgiapp.c2323
-rw-r--r--sapi/cgi/libfcgi/include/fastcgi.h136
-rw-r--r--sapi/cgi/libfcgi/include/fcgi_config.h7
-rw-r--r--sapi/cgi/libfcgi/include/fcgi_config_win32.h111
-rw-r--r--sapi/cgi/libfcgi/include/fcgi_config_x86.h103
-rw-r--r--sapi/cgi/libfcgi/include/fcgi_stdio.h249
-rw-r--r--sapi/cgi/libfcgi/include/fcgiapp.h640
-rw-r--r--sapi/cgi/libfcgi/include/fcgiappmisc.h50
-rw-r--r--sapi/cgi/libfcgi/include/fcgimisc.h38
-rw-r--r--sapi/cgi/libfcgi/include/fcgio.h147
-rw-r--r--sapi/cgi/libfcgi/include/fcgios.h140
-rw-r--r--sapi/cgi/libfcgi/libfcgi.m477
-rw-r--r--sapi/cgi/libfcgi/os_unix.c1268
-rw-r--r--sapi/cgi/libfcgi/os_win32.c2067
-rw-r--r--sapi/cgi/libfcgi/strerror.c91
-rw-r--r--sapi/cgi/php.sym0
-rw-r--r--sapi/cgi/php_getopt.h30
-rw-r--r--sapi/cli/CREDITS2
-rw-r--r--sapi/cli/Makefile.frag9
-rw-r--r--sapi/cli/README19
-rw-r--r--sapi/cli/TODO6
-rw-r--r--sapi/cli/config.m440
-rw-r--r--sapi/cli/getopt.c154
-rw-r--r--sapi/cli/php.1.in387
-rw-r--r--sapi/cli/php_cli.c1020
-rw-r--r--sapi/cli/php_getopt.h30
-rw-r--r--sapi/embed/CREDITS2
-rw-r--r--sapi/embed/EXPERIMENTAL5
-rw-r--r--sapi/embed/config.m432
-rw-r--r--sapi/embed/php4embed.dsp100
-rw-r--r--sapi/embed/php_embed.c225
-rw-r--r--sapi/embed/php_embed.h61
-rw-r--r--sapi/isapi/CREDITS2
-rw-r--r--sapi/isapi/config.m427
-rw-r--r--sapi/isapi/php.sym5
-rw-r--r--sapi/isapi/php4isapi.c925
-rw-r--r--sapi/isapi/php4isapi.def5
-rw-r--r--sapi/isapi/php4isapi.dsp165
-rw-r--r--sapi/isapi/stresstest/getopt.c175
-rw-r--r--sapi/isapi/stresstest/getopt.h12
-rw-r--r--sapi/isapi/stresstest/notes.txt56
-rw-r--r--sapi/isapi/stresstest/stresstest.cpp936
-rw-r--r--sapi/isapi/stresstest/stresstest.dsp108
-rw-r--r--sapi/milter/CREDITS2
-rw-r--r--sapi/milter/EXPERIMENTAL5
-rw-r--r--sapi/milter/Makefile.frag2
-rw-r--r--sapi/milter/TODO5
-rw-r--r--sapi/milter/config.m439
-rw-r--r--sapi/milter/getopt.c173
-rw-r--r--sapi/milter/milter.php132
-rw-r--r--sapi/milter/php_getopt.h7
-rw-r--r--sapi/milter/php_milter.c1139
-rw-r--r--sapi/milter/php_milter.h31
-rw-r--r--sapi/nsapi/CREDITS2
-rw-r--r--sapi/nsapi/config.m445
-rw-r--r--sapi/nsapi/nsapi-readme.txt76
-rw-r--r--sapi/nsapi/nsapi.c599
-rw-r--r--sapi/nsapi/php4nsapi.dsp135
-rw-r--r--sapi/phttpd/CREDITS2
-rw-r--r--sapi/phttpd/README5
-rw-r--r--sapi/phttpd/config.m425
-rw-r--r--sapi/phttpd/php.sym4
-rw-r--r--sapi/phttpd/php_phttpd.h24
-rw-r--r--sapi/phttpd/phttpd.c305
-rw-r--r--sapi/pi3web/CREDITS2
-rw-r--r--sapi/pi3web/README50
-rw-r--r--sapi/pi3web/config.m435
-rw-r--r--sapi/pi3web/php.sym0
-rw-r--r--sapi/pi3web/php4pi3web.dsp136
-rw-r--r--sapi/pi3web/pi3web_sapi.c482
-rw-r--r--sapi/pi3web/pi3web_sapi.h95
-rw-r--r--sapi/roxen/README18
-rw-r--r--sapi/roxen/TODO33
-rw-r--r--sapi/roxen/config.m460
-rw-r--r--sapi/roxen/roxen.c725
-rw-r--r--sapi/servlet/CREDITS2
-rw-r--r--sapi/servlet/EXPERIMENTAL5
-rw-r--r--sapi/servlet/Makefile.frag19
-rw-r--r--sapi/servlet/README113
-rw-r--r--sapi/servlet/config.m454
-rw-r--r--sapi/servlet/cookies.php41
-rw-r--r--sapi/servlet/date.php28
-rw-r--r--sapi/servlet/formatter.java31
-rw-r--r--sapi/servlet/jinfo.php5
-rw-r--r--sapi/servlet/jver.php17
-rw-r--r--sapi/servlet/reqheaders.php24
-rw-r--r--sapi/servlet/reqinfo.php29
-rw-r--r--sapi/servlet/reqparams.php35
-rw-r--r--sapi/servlet/servlet.c397
-rw-r--r--sapi/servlet/servlet.dsp286
-rw-r--r--sapi/servlet/servlet.java221
-rw-r--r--sapi/servlet/sessions.php60
-rw-r--r--sapi/servlet/web.xml40
-rw-r--r--sapi/thttpd/CREDITS2
-rw-r--r--sapi/thttpd/README85
-rw-r--r--sapi/thttpd/config.m433
-rw-r--r--sapi/thttpd/php.sym3
-rw-r--r--sapi/thttpd/php_thttpd.h35
-rw-r--r--sapi/thttpd/stub.c0
-rw-r--r--sapi/thttpd/thttpd.c747
-rw-r--r--sapi/thttpd/thttpd_patch1881
-rw-r--r--sapi/tux/CREDITS2
-rw-r--r--sapi/tux/README86
-rw-r--r--sapi/tux/config.m418
-rw-r--r--sapi/tux/php.sym2
-rw-r--r--sapi/tux/php_tux.c453
-rw-r--r--sapi/webjames/CREDITS2
-rw-r--r--sapi/webjames/README28
-rw-r--r--sapi/webjames/config.m420
-rw-r--r--sapi/webjames/php_webjames.h28
-rw-r--r--sapi/webjames/webjames.c305
190 files changed, 0 insertions, 39577 deletions
diff --git a/sapi/activescript/CREDITS b/sapi/activescript/CREDITS
deleted file mode 100644
index ef347bac0d..0000000000
--- a/sapi/activescript/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-ActiveScript
-Wez Furlong
diff --git a/sapi/activescript/EXPERIMENTAL b/sapi/activescript/EXPERIMENTAL
deleted file mode 100644
index 293159a693..0000000000
--- a/sapi/activescript/EXPERIMENTAL
+++ /dev/null
@@ -1,5 +0,0 @@
-this module is experimental,
-its functions may change their names
-or move to extension all together
-so do not rely to much on them
-you have been warned!
diff --git a/sapi/activescript/README b/sapi/activescript/README
deleted file mode 100644
index b033110332..0000000000
--- a/sapi/activescript/README
+++ /dev/null
@@ -1,56 +0,0 @@
-This is the ActiveScript SAPI for PHP.
-======================================
-
-Once registered on your system (using regsvr32), you will be able to use
-PHP script in any ActiveScript compliant host. The list includes:
-
-o. Client-side script in Internet Explorer
-o. Windows Script Host
-o. ASP and ASP.NET
-o. Windows Script Components / Behaviours
-o. MS Scriptlet control
-
-Probably the most useful of these will be using it with the scriptlet
-control, or in your own activescript host, so that you can very easily
-embed PHP into your win32 application.
-
-Installation.
-=============
-
-Build and install it somewhere; then register the engine like this:
-
- regsvr32 php4activescript.dll
-
-Usage.
-======
-
-o. Client-side script in Internet Explorer
-
- <script language="ActivePHP">
- $window->alert("Hello");
- </script>
-
-o. Windows Script Host
-
- Create a .wsf file like this:
-
- <job id="test">
- <script language="ActivePHP">
- $WScript->Echo("Hello");
- </script>
- </script>
-
-o. ASP and ASP.NET
-
- <%@language=ActivePHP %>
- <% $Response->Write("Hello"); %>
-
-o. Windows Script Components / Behaviours
-
- Use language="ActivePHP" on your <script> tags
-
-o. MS Scriptlet control
-
- Set the language property to "ActivePHP"
-
-
diff --git a/sapi/activescript/classfactory.cpp b/sapi/activescript/classfactory.cpp
deleted file mode 100644
index 7dd37424c7..0000000000
--- a/sapi/activescript/classfactory.cpp
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2002 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-/* IClassFactory Implementation, and DllXXX function implementation */
-
-#define INITGUID
-#define DEBUG_CLASS_FACTORY 0
-
-#include <windows.h>
-#include <initguid.h>
-
-extern "C" {
-HINSTANCE module_handle;
-}
-
-#include <comcat.h>
-#include "TSRM.h"
-#include "php4as_classfactory.h"
-#include "php4as_scriptengine.h"
-
-volatile LONG TPHPClassFactory::factory_count = 0;
-volatile LONG TPHPClassFactory::object_count = 0;
-
-/* {{{ Class Factory Implementation */
-TPHPClassFactory::TPHPClassFactory()
-{
- m_refcount = 1;
- InterlockedIncrement(const_cast<long*> (&factory_count));
-}
-
-TPHPClassFactory::~TPHPClassFactory()
-{
- InterlockedDecrement(const_cast<long*> (&factory_count));
-}
-
-void TPHPClassFactory::AddToObjectCount(void)
-{
- InterlockedIncrement(const_cast<long*> (&object_count));
-}
-
-void TPHPClassFactory::RemoveFromObjectCount(void)
-{
- InterlockedDecrement(const_cast<long*> (&object_count));
-}
-
-STDMETHODIMP_(DWORD) TPHPClassFactory::AddRef(void)
-{
- return InterlockedIncrement(const_cast<long*> (&m_refcount));
-}
-
-STDMETHODIMP_(DWORD) TPHPClassFactory::Release(void)
-{
- DWORD ret = InterlockedDecrement(const_cast<long*> (&m_refcount));
- if (ret == 0)
- delete this;
- return ret;
-}
-
-STDMETHODIMP TPHPClassFactory::QueryInterface(REFIID iid, void **ppvObject)
-{
- *ppvObject = NULL;
-
- if (IsEqualGUID(IID_IClassFactory, iid)) {
- *ppvObject = (IClassFactory*)this;
- } else if (IsEqualGUID(IID_IUnknown, iid)) {
- *ppvObject = this;
- }
- if (*ppvObject) {
- AddRef();
- return S_OK;
- }
-
- return E_NOINTERFACE;
-}
-
-STDMETHODIMP TPHPClassFactory::LockServer(BOOL fLock)
-{
- return E_NOTIMPL;
-}
-
-STDMETHODIMP TPHPClassFactory::CreateInstance(IUnknown *pUnkOuter, REFIID iid, void **ppvObject)
-{
- TPHPScriptingEngine *engine = new TPHPScriptingEngine;
-
- HRESULT ret = engine->QueryInterface(iid, ppvObject);
-
- engine->Release();
-
- return ret;
-}
-
-int TPHPClassFactory::CanUnload(void)
-{
- return (object_count + factory_count) == 0 ? 1 : 0;
-}
-
-/* }}} */
-
-/* {{{ Registration structures */
-struct reg_entry {
- HKEY root_key;
- char *sub_key;
- char *value_name;
- char *data;
-};
-
-struct reg_class {
- /* REFIID here causes compilation errors */
- const GUID *class_id;
- char *class_name;
- char *threading;
- const struct reg_entry *reg;
- const GUID **cats;
-};
-
-#define MAX_REG_SUBST 8
-struct reg_subst {
- int count;
- char *names[MAX_REG_SUBST];
- char *values[MAX_REG_SUBST];
-};
-/* }}} */
-
-/* {{{ Registration information */
-/* This registers the sapi as a scripting engine that can be instantiated using it's progid */
-static const struct reg_entry engine_entries[] = {
- { HKEY_CLASSES_ROOT, "CLSID\\[CLSID]", NULL, "[CLASSNAME]" },
- { HKEY_CLASSES_ROOT, "CLSID\\[CLSID]\\InprocServer32", NULL, "[MODULENAME]" },
- { HKEY_CLASSES_ROOT, "CLSID\\[CLSID]\\InprocServer32", "ThreadingModel", "[THREADING]" },
- { HKEY_CLASSES_ROOT, "CLSID\\[CLSID]\\OLEScript", NULL, NULL },
- { HKEY_CLASSES_ROOT, "CLSID\\[CLSID]\\ProgID", NULL, "ActivePHP" },
- { HKEY_CLASSES_ROOT, "ActivePHP", NULL, "ActivePHP" },
- { HKEY_CLASSES_ROOT, "ActivePHP\\CLSID", NULL, "[CLSID]"},
- { HKEY_CLASSES_ROOT, "ActivePHP\\OLEScript", NULL, NULL},
-
- { 0, NULL, NULL, NULL }
-};
-
-static const GUID *script_engine_categories[] = {
- &CATID_ActiveScript,
- &CATID_ActiveScriptParse,
- NULL
-};
-
-static const struct reg_class classes_to_register[] = {
- { &CLSID_PHPActiveScriptEngine, "PHP Active Script Engine", "Both", engine_entries, script_engine_categories },
- { NULL, NULL, NULL, 0, NULL }
-};
-/* }}} */
-
-/* {{{ Registration code */
-static void substitute(struct reg_subst *subst, char *srcstring, char *deststring)
-{
- int i;
- char *srcpos = srcstring;
- char *destpos = deststring;
-
- while(1) {
- char *repstart = strchr(srcpos, '[');
-
- if (repstart == NULL) {
- strcpy(destpos, srcpos);
- break;
- }
-
- /* copy everything up until that character to the dest */
- strncpy(destpos, srcpos, repstart - srcpos);
- destpos += repstart - srcpos;
- *destpos = 0;
-
- /* search for replacement strings in the table */
- for (i = 0; i < subst->count; i++) {
- int len = strlen(subst->names[i]);
- if (strncmp(subst->names[i], repstart + 1, len) == 0) {
- /* append the replacement value to the buffer */
- strcpy(destpos, subst->values[i]);
- destpos += strlen(subst->values[i]);
- srcpos = repstart + len + 2;
-
- break;
- }
- }
- }
-#if DEBUG_CLASS_FACTORY
- MessageBox(0, deststring, srcstring, MB_ICONHAND);
-#endif
-}
-
-static int reg_string(BOOL do_reg, struct reg_subst *subst, const struct reg_entry *entry)
-{
- char subbuf[MAX_PATH], valuebuf[MAX_PATH], databuf[MAX_PATH];
- char *sub = NULL, *value = NULL, *data = NULL;
- LRESULT res;
- HKEY hkey;
- DWORD disp;
-
- if (entry->sub_key) {
- substitute(subst, entry->sub_key, subbuf);
- sub = subbuf;
- }
-
- if (entry->value_name) {
- substitute(subst, entry->value_name, valuebuf);
- value = valuebuf;
- }
-
- if (entry->data) {
- substitute(subst, entry->data, databuf);
- data = databuf;
- }
-
- if (do_reg) {
- res = RegCreateKeyEx(entry->root_key, sub, 0, NULL, REG_OPTION_NON_VOLATILE,
- KEY_WRITE, NULL, &hkey, &disp);
- if (res == NOERROR) {
- if (data)
- res = RegSetValueEx(hkey, value, 0, REG_SZ, (LPBYTE)data, strlen(data) + 1);
- RegCloseKey(hkey);
- }
- } else {
- res = RegDeleteKey(entry->root_key, sub);
- }
- return res == NOERROR ? 1 : 0;
-}
-
-static int perform_registration(BOOL do_reg)
-{
- char module_name[MAX_PATH];
- char classid[40];
- int ret = 0;
- int i, j;
- struct reg_subst subst = {0};
- LPOLESTR classidw;
- ICatRegister *catreg = NULL;
- CATID cats[8];
- int ncats;
-
- CoInitialize(NULL);
- CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (LPVOID*)&catreg);
-
- GetModuleFileName(module_handle, module_name, sizeof(module_name));
-
- subst.names[0] = "CLSID";
- subst.values[0] = classid;
-
- subst.names[1] = "MODULENAME";
- subst.values[1] = module_name;
-
- subst.names[2] = "CLASSNAME";
- subst.names[3] = "THREADING";
-
- subst.count = 4;
-
- for (i = 0; classes_to_register[i].class_id; i++) {
- StringFromCLSID(*classes_to_register[i].class_id, &classidw);
- WideCharToMultiByte(CP_ACP, 0, classidw, -1, classid, sizeof(classid), NULL, NULL);
- classid[39] = 0;
- CoTaskMemFree(classidw);
-
- subst.values[2] = classes_to_register[i].class_name;
- subst.values[3] = classes_to_register[i].threading;
-
- if (catreg && classes_to_register[i].cats) {
- ncats = 0;
- while(classes_to_register[i].cats[ncats]) {
- CopyMemory(&cats[ncats], classes_to_register[i].cats[ncats], sizeof(CATID));
- ncats++;
- }
- }
-
- if (do_reg) {
- for (j = 0; classes_to_register[i].reg[j].root_key; j++) {
- if (!reg_string(do_reg, &subst, &classes_to_register[i].reg[j])) {
- ret = 0;
- break;
- }
- }
-
- if (catreg && ncats) {
- catreg->RegisterClassImplCategories(*classes_to_register[i].class_id, ncats, cats);
- }
-
- } else {
-
- if (catreg && ncats) {
- catreg->UnRegisterClassImplCategories(*classes_to_register[i].class_id, ncats, cats);
- }
-
- /* do it in reverse order, so count the number of entries first */
- for (j = 0; classes_to_register[i].reg[j].root_key; j++)
- ;
- while(j-- > 0) {
- if (!reg_string(do_reg, &subst, &classes_to_register[i].reg[j])) {
- ret = 0;
- break;
- }
- }
- }
- }
-
- if (catreg)
- catreg->Release();
- CoUninitialize();
-
- return ret;
-}
-/* }}} */
-
-/* {{{ Standard COM server DllXXX entry points */
-
-STDAPI DllCanUnloadNow(void)
-{
- if (TPHPClassFactory::CanUnload())
- return S_OK;
- return S_FALSE;
-}
-
-STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
-{
- HRESULT ret = E_FAIL;
-
- if (IsEqualCLSID(CLSID_PHPActiveScriptEngine, rclsid)) {
- TPHPClassFactory *factory = new TPHPClassFactory();
-
- if (factory) {
- ret = factory->QueryInterface(riid, ppv);
- factory->Release();
- }
- }
- return ret;
-}
-
-
-
-STDAPI DllRegisterServer(void)
-{
- return perform_registration(TRUE) ? S_OK : S_FALSE;
-}
-
-STDAPI DllUnregisterServer(void)
-{
- return perform_registration(FALSE) ? S_OK : S_FALSE;
-}
-
-/* }}} */
diff --git a/sapi/activescript/php4activescript.c b/sapi/activescript/php4activescript.c
deleted file mode 100644
index 0dc6bd7e46..0000000000
--- a/sapi/activescript/php4activescript.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
-
-#include "php.h"
-#include "php_main.h"
-#include "SAPI.h"
-#include "php_globals.h"
-#include "ext/standard/info.h"
-#include "php_variables.h"
-#include "php_ini.h"
-#include "php4activescript.h"
-
-/* SAPI definitions and DllMain */
-
-static int php_activescript_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, &php_activescript_module, 1) == FAILURE) {
- return FAILURE;
- } else {
- return SUCCESS;
- }
-}
-
-static int sapi_activescript_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- /* In theory, this is a blackhole. In practice, I wan't to see the output
- * in the debugger! */
-
- char buf[1024];
- uint l, a = str_length;
-
- while(a) {
- l = a;
- if (l > sizeof(buf) - 1)
- l = sizeof(buf) - 1;
- memcpy(buf, str, l);
- buf[l] = 0;
- OutputDebugString(buf);
- a -= l;
- }
-
- return str_length;
-}
-
-static void sapi_activescript_register_server_variables(zval *track_vars_array TSRMLS_DC)
-{
-}
-
-static char *sapi_activescript_read_cookies(TSRMLS_D)
-{
- return NULL;
-}
-
-static int sapi_activescript_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- return SAPI_HEADER_ADD;
-}
-
-static int sapi_activescript_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-zend_module_entry php_activescript_module = {
- STANDARD_MODULE_HEADER,
- "ActiveScript",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- STANDARD_MODULE_PROPERTIES
-};
-
-
-sapi_module_struct activescript_sapi_module = {
- "activescript", /* name */
- "Active Script", /* pretty name */
-
- php_activescript_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- sapi_activescript_ub_write, /* unbuffered write */
- NULL, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
-
- zend_error, /* error handler */
-
- sapi_activescript_header_handler, /* header handler */
- sapi_activescript_send_headers, /* send headers handler */
- NULL, /* send header handler */
-
- NULL, /* read POST data */
- sapi_activescript_read_cookies, /* read Cookies */
-
- sapi_activescript_register_server_variables, /* register server variables */
- NULL, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
-{
- switch (fdwReason) {
- case DLL_PROCESS_ATTACH:
- module_handle = hinstDLL;
-
- tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "C:\\TSRM.log");
-
- sapi_startup(&activescript_sapi_module);
- if (activescript_sapi_module.startup) {
- activescript_sapi_module.startup(&sapi_module);
- }
- break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- ts_free_thread();
- break;
- case DLL_PROCESS_DETACH:
- if (activescript_sapi_module.shutdown) {
- activescript_sapi_module.shutdown(&sapi_module);
- }
- tsrm_shutdown();
- break;
- }
- return TRUE;
-}
-
-
diff --git a/sapi/activescript/php4activescript.def b/sapi/activescript/php4activescript.def
deleted file mode 100644
index 1f8e945838..0000000000
--- a/sapi/activescript/php4activescript.def
+++ /dev/null
@@ -1,5 +0,0 @@
-EXPORTS
-DllCanUnloadNow @1 PRIVATE
-DllGetClassObject @2 PRIVATE
-DllRegisterServer @3 PRIVATE
-DllUnregisterServer @4 PRIVATE
diff --git a/sapi/activescript/php4activescript.dsp b/sapi/activescript/php4activescript.dsp
deleted file mode 100644
index cbfafa1272..0000000000
--- a/sapi/activescript/php4activescript.dsp
+++ /dev/null
@@ -1,185 +0,0 @@
-# Microsoft Developer Studio Project File - Name="php4activescript" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php4activescript - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "php4activescript.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 "php4activescript.mak" CFG="php4activescript - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php4activescript - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4activescript - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4activescript - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4activescript - Win32 Release_TSDbg" (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)" == "php4activescript - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /Ze /W3 /Gm /GX /ZI /Od /Ob0 /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "_DEBUG" /D "COMPILE_LIBZEND" /D ZEND_DEBUG=1 /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "_DEBUG"
-# ADD RSC /l 0x40d /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 wsock32.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 php4ts_debug.lib /nologo /version:4.0 /dll /debug /machine:I386 /nodefaultlib:"libcmt" /pdbtype:sept /libpath:"..\..\Debug_TS"
-
-!ELSEIF "$(CFG)" == "php4activescript - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS"
-# PROP BASE Intermediate_Dir "Release_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"..\..\Release_TS"
-
-!ELSEIF "$(CFG)" == "php4activescript - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php4activescript___Win32_Release_TS_inline"
-# PROP BASE Intermediate_Dir "php4activescript___Win32_Release_TS_inline"
-# PROP BASE Ignore_Export_Lib 0
-# 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 /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "WIN32" /D "_MBCS" /D ZEND_DEBUG=0 /FR /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386 /libpath:"..\..\Release_TS"
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"..\..\Release_TS_inline"
-
-!ELSEIF "$(CFG)" == "php4activescript - Win32 Release_TSDbg"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php4activescript___Win32_Release_TSDbg"
-# PROP BASE Intermediate_Dir "php4activescript___Win32_Release_TSDbg"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Release_TSDbg"
-# PROP Intermediate_Dir "Release_TSDbg"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /Zi /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"..\..\Release_TS"
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /version:4.0 /dll /debug /machine:I386 /libpath:"..\..\Release_TSDbg"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php4activescript - Win32 Debug_TS"
-# Name "php4activescript - Win32 Release_TS"
-# Name "php4activescript - Win32 Release_TS_inline"
-# Name "php4activescript - Win32 Release_TSDbg"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\classfactory.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\php4activescript.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\php4activescript.def
-# End Source File
-# Begin Source File
-
-SOURCE=.\scriptengine.cpp
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php4activescript.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php4as_classfactory.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php4as_scriptengine.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/sapi/activescript/php4activescript.h b/sapi/activescript/php4activescript.h
deleted file mode 100644
index b007289616..0000000000
--- a/sapi/activescript/php4activescript.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-extern zend_module_entry php_activescript_module;
-extern sapi_module_struct activescript_sapi_module;
-extern HINSTANCE module_handle;
-extern void activescript_error_func(int type, const char *error_msg, ...);
-extern void activescript_error_handler(int type, const char *error_filename,
- const uint error_lineno, const char *format, va_list args);
diff --git a/sapi/activescript/php4as_classfactory.h b/sapi/activescript/php4as_classfactory.h
deleted file mode 100644
index 883a1a3ce3..0000000000
--- a/sapi/activescript/php4as_classfactory.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-/* IClassFactory Implementation */
-
-#include <unknwn.h>
-
-// {A0AD8E7A-95EC-4819-986F-78D93895F2AE}
-DEFINE_GUID(CLSID_PHPActiveScriptEngine,
-0xa0ad8e7a, 0x95ec, 0x4819, 0x98, 0x6f, 0x78, 0xd9, 0x38, 0x95, 0xf2, 0xae);
-
-class TPHPClassFactory:
- public IClassFactory
-{
-protected:
- volatile LONG m_refcount;
-
- static volatile LONG factory_count;
- static volatile LONG object_count;
-
-public: /* IUnknown */
- STDMETHODIMP QueryInterface(REFIID iid, void **ppvObject);
- STDMETHODIMP_(DWORD) AddRef(void);
- STDMETHODIMP_(DWORD) Release(void);
-public: /* IClassFactory */
- STDMETHODIMP CreateInstance(IUnknown *pUnkOuter, REFIID iid, void **ppvObject);
- STDMETHODIMP LockServer(BOOL fLock);
-
- TPHPClassFactory();
- ~TPHPClassFactory();
-
- static void AddToObjectCount(void);
- static void RemoveFromObjectCount(void);
- static int CanUnload(void);
-};
-
diff --git a/sapi/activescript/php4as_scriptengine.h b/sapi/activescript/php4as_scriptengine.h
deleted file mode 100644
index c34d0e850f..0000000000
--- a/sapi/activescript/php4as_scriptengine.h
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include <activscp.h>
-#include "zend.h"
-#include <setjmp.h>
-
-/* Definitions for thread messages */
-enum {
- PHPSE_STATE_CHANGE = WM_USER + 20,
- PHPSE_INIT_NEW,
- PHPSE_PARSE_SCRIPT,
- PHPSE_ADD_SCRIPTLET,
- PHPSE_CLOSE,
- PHPSE_CLONE,
- PHPSE_ENTER,
- PHPSE_LEAVE,
- PHPSE_TERMINATE,
- PHPSE_PARSE_PROC,
- PHPSE_EXEC_PROC,
- PHPSE_ADD_NAMED_ITEM,
- PHPSE_SET_SITE,
- PHPSE_ADD_TYPELIB,
- PHPSE_TRIGGER_ERROR,
- PHPSE_GET_DISPATCH,
- PHPSE_DUMMY_TICK,
-};
-
-struct php_active_script_get_dispatch_info {
- LPCOLESTR pstrItemName;
- DWORD dispatch;
-};
-
-struct php_active_script_add_named_item_info {
- LPCOLESTR pstrName;
- DWORD dwFlags;
- IUnknown *punk;
- ITypeInfo *ptyp;
- IDispatch *pdisp;
- DWORD marshal;
-};
-
-struct php_active_script_add_scriptlet_info {
- /* [in] */ LPCOLESTR pstrDefaultName;
- /* [in] */ LPCOLESTR pstrCode;
- /* [in] */ LPCOLESTR pstrItemName;
- /* [in] */ LPCOLESTR pstrSubItemName;
- /* [in] */ LPCOLESTR pstrEventName;
- /* [in] */ LPCOLESTR pstrDelimiter;
- /* [in] */ DWORD dwSourceContextCookie;
- /* [in] */ ULONG ulStartingLineNumber;
- /* [in] */ DWORD dwFlags;
- /* [out] */ BSTR *pbstrName;
- /* [out] */ EXCEPINFO *pexcepinfo;
-};
-
-struct php_active_script_parse_info {
- /* [in] */ LPCOLESTR pstrCode;
- /* [in] */ LPCOLESTR pstrItemName;
- /* [in] */ IUnknown *punkContext;
- /* [in] */ LPCOLESTR pstrDelimiter;
- /* [in] */ DWORD dwSourceContextCookie;
- /* [in] */ ULONG ulStartingLineNumber;
- /* [in] */ DWORD dwFlags;
- /* [out] */ VARIANT *pvarResult;
- /* [out] */ EXCEPINFO *pexcepinfo;
-};
-
-struct php_active_script_parse_proc_info {
- /* [in] */ LPCOLESTR pstrCode;
- /* [in] */ LPCOLESTR pstrFormalParams;
- /* [in] */ LPCOLESTR pstrProcedureName;
- /* [in] */ LPCOLESTR pstrItemName;
- /* [in] */ IUnknown *punkContext;
- /* [in] */ LPCOLESTR pstrDelimiter;
- /* [in] */ DWORD dwSourceContextCookie;
- /* [in] */ ULONG ulStartingLineNumber;
- /* [in] */ DWORD dwFlags;
- DWORD dispcookie;
-};
-
-struct php_active_script_add_tlb_info {
- /* [in] */ const GUID * rguidTypeLib;
- /* [in] */ DWORD dwMajor;
- /* [in] */ DWORD dwMinor;
- /* [in] */ DWORD dwFlags;
-};
-
-class TPHPScriptingEngine:
- public IActiveScript,
- public IActiveScriptParse,
- public IActiveScriptParseProcedure
-{
-public:
- volatile LONG m_refcount;
- IActiveScriptSite *m_pass;
- SCRIPTSTATE m_scriptstate;
- MUTEX_T m_mutex;
- HashTable m_script_dispatchers;
- HANDLE m_engine_thread_handle;
-
- HANDLE m_sync_thread_msg;
- HRESULT m_sync_thread_ret;
-
- /* This is hacky, but only used when the host queries us for a script dispatch */
- void *** m_tsrm_hack;
-
- void add_to_global_namespace(IDispatch *disp, DWORD flags, char *name TSRMLS_DC);
-
- THREAD_T m_enginethread, m_basethread;
- HashTable m_frags;
- ULONG m_lambda_count;
- IActiveScriptSite *m_pass_eng;
-
- jmp_buf *m_err_trap;
- int m_in_main, m_stop_main;
-
- HRESULT SendThreadMessage(LONG msg, WPARAM wparam, LPARAM lparam);
-
- void engine_thread_func(void);
- HRESULT engine_thread_handler(LONG msg, WPARAM wParam, LPARAM lParam, int *handled TSRMLS_DC);
-
-public: /* IUnknown */
- STDMETHODIMP QueryInterface(REFIID iid, void **ppvObject);
- STDMETHODIMP_(DWORD) AddRef(void);
- STDMETHODIMP_(DWORD) Release(void);
-public: /* IActiveScript */
- STDMETHODIMP SetScriptSite(
- /* [in] */ IActiveScriptSite *pass);
-
- STDMETHODIMP GetScriptSite(
- /* [in] */ REFIID riid,
- /* [iid_is][out] */ void **ppvObject);
-
- STDMETHODIMP SetScriptState(
- /* [in] */ SCRIPTSTATE ss);
-
- STDMETHODIMP GetScriptState(
- /* [out] */ SCRIPTSTATE *pssState);
-
- STDMETHODIMP Close( void);
-
- STDMETHODIMP AddNamedItem(
- /* [in] */ LPCOLESTR pstrName,
- /* [in] */ DWORD dwFlags);
-
- STDMETHODIMP AddTypeLib(
- /* [in] */ REFGUID rguidTypeLib,
- /* [in] */ DWORD dwMajor,
- /* [in] */ DWORD dwMinor,
- /* [in] */ DWORD dwFlags);
-
- STDMETHODIMP GetScriptDispatch(
- /* [in] */ LPCOLESTR pstrItemName,
- /* [out] */ IDispatch **ppdisp);
-
- STDMETHODIMP GetCurrentScriptThreadID(
- /* [out] */ SCRIPTTHREADID *pstidThread);
-
- STDMETHODIMP GetScriptThreadID(
- /* [in] */ DWORD dwWin32ThreadId,
- /* [out] */ SCRIPTTHREADID *pstidThread);
-
- STDMETHODIMP GetScriptThreadState(
- /* [in] */ SCRIPTTHREADID stidThread,
- /* [out] */ SCRIPTTHREADSTATE *pstsState);
-
- STDMETHODIMP InterruptScriptThread(
- /* [in] */ SCRIPTTHREADID stidThread,
- /* [in] */ const EXCEPINFO *pexcepinfo,
- /* [in] */ DWORD dwFlags);
-
- STDMETHODIMP Clone(
- /* [out] */ IActiveScript **ppscript);
-
-public: /* IActiveScriptParse */
- STDMETHODIMP InitNew( void);
-
- STDMETHODIMP AddScriptlet(
- /* [in] */ LPCOLESTR pstrDefaultName,
- /* [in] */ LPCOLESTR pstrCode,
- /* [in] */ LPCOLESTR pstrItemName,
- /* [in] */ LPCOLESTR pstrSubItemName,
- /* [in] */ LPCOLESTR pstrEventName,
- /* [in] */ LPCOLESTR pstrDelimiter,
- /* [in] */ DWORD dwSourceContextCookie,
- /* [in] */ ULONG ulStartingLineNumber,
- /* [in] */ DWORD dwFlags,
- /* [out] */ BSTR *pbstrName,
- /* [out] */ EXCEPINFO *pexcepinfo);
-
- STDMETHODIMP ParseScriptText(
- /* [in] */ LPCOLESTR pstrCode,
- /* [in] */ LPCOLESTR pstrItemName,
- /* [in] */ IUnknown *punkContext,
- /* [in] */ LPCOLESTR pstrDelimiter,
- /* [in] */ DWORD dwSourceContextCookie,
- /* [in] */ ULONG ulStartingLineNumber,
- /* [in] */ DWORD dwFlags,
- /* [out] */ VARIANT *pvarResult,
- /* [out] */ EXCEPINFO *pexcepinfo);
-public: /* IActiveScriptParseProcedure */
- STDMETHODIMP ParseProcedureText(
- /* [in] */ LPCOLESTR pstrCode,
- /* [in] */ LPCOLESTR pstrFormalParams,
- /* [in] */ LPCOLESTR pstrProcedureName,
- /* [in] */ LPCOLESTR pstrItemName,
- /* [in] */ IUnknown *punkContext,
- /* [in] */ LPCOLESTR pstrDelimiter,
- /* [in] */ DWORD dwSourceContextCookie,
- /* [in] */ ULONG ulStartingLineNumber,
- /* [in] */ DWORD dwFlags,
- /* [out] */ IDispatch **ppdisp);
-public:
- TPHPScriptingEngine();
- ~TPHPScriptingEngine();
-
-};
-
diff --git a/sapi/activescript/scriptengine.cpp b/sapi/activescript/scriptengine.cpp
deleted file mode 100644
index e21e6afec4..0000000000
--- a/sapi/activescript/scriptengine.cpp
+++ /dev/null
@@ -1,1873 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2002 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-/* Implementation Notes:
- *
- * PHP stores scripting engine state in thread-local storage. That means
- * that we need to create a dedicated thread per-engine so that a host can
- * use more than one engine object per thread.
- *
- * There are some interesting synchronization issues: Anything to do with
- * running script in the PHP/Zend engine must take place on the engine
- * thread. Likewise, calling back to the host must take place on the base
- * thread - the thread that set the script site.
- * */
-
-#define _WIN32_DCOM
-#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
-
-#include "php.h"
-extern "C" {
-#include "php_main.h"
-#include "SAPI.h"
-#include "zend.h"
-#include "zend_execute.h"
-#include "zend_compile.h"
-#include "php_globals.h"
-#include "php_variables.h"
-#include "php_ini.h"
-#include "php4activescript.h"
-#include "ext/rpc/com/com.h"
-#include "ext/rpc/com/php_COM.h"
-#include "ext/rpc/com/conversion.h"
-}
-#include "php_ticks.h"
-#include "php4as_scriptengine.h"
-#include "php4as_classfactory.h"
-#include <objbase.h>
-
-/* {{{ trace */
-static inline void trace(char *fmt, ...)
-{
- va_list ap;
- char buf[4096];
-
- sprintf(buf, "T=%08x ", tsrm_thread_id());
- OutputDebugString(buf);
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
-
- OutputDebugString(buf);
-
- va_end(ap);
-}
-/* }}} */
-/* {{{ scriptstate_to_string */
-static const char *scriptstate_to_string(SCRIPTSTATE ss)
-{
- switch(ss) {
- case SCRIPTSTATE_UNINITIALIZED: return "SCRIPTSTATE_UNINITIALIZED";
- case SCRIPTSTATE_INITIALIZED: return "SCRIPTSTATE_INITIALIZED";
- case SCRIPTSTATE_STARTED: return "SCRIPTSTATE_STARTED";
- case SCRIPTSTATE_CONNECTED: return "SCRIPTSTATE_CONNECTED";
- case SCRIPTSTATE_DISCONNECTED: return "SCRIPTSTATE_DISCONNECTED";
- case SCRIPTSTATE_CLOSED: return "SCRIPTSTATE_CLOSED";
- default:
- return "unknown";
- }
-}
-/* }}} */
-/* {{{ TWideString */
-/* This class helps manipulate strings from OLE.
- * It does not use emalloc, so it is better suited for passing pointers
- * between threads. */
-class TWideString {
- public:
- LPOLESTR m_ole;
- char *m_ansi;
- int m_ansi_strlen;
-
- TWideString(LPOLESTR olestr) {
- m_ole = olestr;
- m_ansi = NULL;
- }
- TWideString(LPCOLESTR olestr) {
- m_ole = (LPOLESTR)olestr;
- m_ansi = NULL;
- }
-
- ~TWideString() {
- if (m_ansi) {
- CoTaskMemFree(m_ansi);
- }
- m_ansi = NULL;
- }
-
- char *safe_ansi_string() {
- char *ret = ansi_string();
- if (ret == NULL)
- return "<NULL>";
- return ret;
- }
-
- int ansi_len(void) {
- /* force conversion if it has not already occurred */
- if (m_ansi == NULL)
- ansi_string();
- return m_ansi_strlen;
- }
-
- static BSTR bstr_from_ansi(char *ansi) {
- OLECHAR *ole = NULL;
- BSTR bstr = NULL;
-
- int req = MultiByteToWideChar(CP_ACP, 0, ansi, -1, NULL, 0);
- if (req) {
- ole = (OLECHAR*)CoTaskMemAlloc((req + 1) * sizeof(OLECHAR));
- if (ole) {
- req = MultiByteToWideChar(CP_ACP, 0, ansi, -1, ole, req);
- req--;
- ole[req] = 0;
-
- bstr = SysAllocString(ole);
- CoTaskMemFree(ole);
- }
- }
- return bstr;
- }
-
- char *ansi_string(void)
- {
- if (m_ansi)
- return m_ansi;
-
- if (m_ole == NULL)
- return NULL;
-
- int bufrequired = WideCharToMultiByte(CP_ACP, 0, m_ole, -1, NULL, 0, NULL, NULL);
- if (bufrequired) {
-
- m_ansi = (char*)CoTaskMemAlloc(bufrequired + 1);
- if (m_ansi) {
- m_ansi_strlen = WideCharToMultiByte(CP_ACP, 0, m_ole, -1, m_ansi, bufrequired + 1, NULL, NULL);
-
- if (m_ansi_strlen) {
- m_ansi_strlen--;
- m_ansi[m_ansi_strlen] = 0;
-
- } else {
- trace("conversion failed with return code %08x\n", GetLastError());
- }
- }
- }
- return m_ansi;
- }
-};
-/* }}} */
-
-/* {{{ code fragment structures */
-enum fragtype {
- FRAG_MAIN,
- FRAG_SCRIPTLET,
- FRAG_PROCEDURE
-};
-
-typedef struct {
- enum fragtype fragtype;
- zend_op_array *opcodes;
- char *code;
- int persistent; /* should be retained for Clone */
- int executed; /* for "main" */
- char *functionname;
- unsigned int codelen;
- unsigned int starting_line;
- TPHPScriptingEngine *engine;
- void *ptr;
-} code_frag;
-
-#define FRAG_CREATE_FUNC (char*)-1
-static code_frag *compile_code_fragment(
- enum fragtype fragtype,
- char *functionname,
- LPCOLESTR code,
- ULONG starting_line,
- EXCEPINFO *excepinfo,
- TPHPScriptingEngine *engine
- TSRMLS_DC);
-
-static int execute_code_fragment(code_frag *frag,
- VARIANT *varResult,
- EXCEPINFO *excepinfo
- TSRMLS_DC);
-static void free_code_fragment(code_frag *frag);
-static code_frag *clone_code_fragment(code_frag *frag, TPHPScriptingEngine *engine TSRMLS_DC);
-
-/* }}} */
-
-/* Magic for handling threading correctly */
-static inline HRESULT SEND_THREAD_MESSAGE(TPHPScriptingEngine *engine, LONG msg, WPARAM wparam, LPARAM lparam TSRMLS_DC)
-{
- if (engine->m_enginethread == 0)
- return E_UNEXPECTED;
- if (tsrm_thread_id() == (engine)->m_enginethread)
- return (engine)->engine_thread_handler((msg), (wparam), (lparam), NULL TSRMLS_CC);
- return (engine)->SendThreadMessage((msg), (wparam), (lparam));
-}
-
-/* These functions do some magic so that interfaces can be
- * used across threads without worrying about marshalling
- * or not marshalling, as appropriate.
- * Win95 without DCOM 1.1, and NT SP 2 or lower do not have
- * the GIT; so we emulate the GIT using other means.
- * If you trace problems back to this code, installing the relevant
- * SP should solve them.
- * */
-static inline HRESULT GIT_get(DWORD cookie, REFIID riid, void **obj)
-{
- IGlobalInterfaceTable *git;
- HRESULT ret;
-
- if (SUCCEEDED(CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL,
- CLSCTX_INPROC_SERVER, IID_IGlobalInterfaceTable,
- (void**)&git))) {
-
- ret = git->GetInterfaceFromGlobal(cookie, riid, obj);
- git->Release();
- return ret;
- }
- return CoGetInterfaceAndReleaseStream((LPSTREAM)cookie, riid, obj);
-}
-
-static inline HRESULT GIT_put(IUnknown *unk, REFIID riid, DWORD *cookie)
-{
- IGlobalInterfaceTable *git;
- HRESULT ret;
-
- if (SUCCEEDED(CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL,
- CLSCTX_INPROC_SERVER, IID_IGlobalInterfaceTable,
- (void**)&git))) {
-
- ret = git->RegisterInterfaceInGlobal(unk, riid, cookie);
- git->Release();
- return ret;
- }
- return CoMarshalInterThreadInterfaceInStream(riid, unk, (LPSTREAM*)cookie);
-}
-
-static inline HRESULT GIT_revoke(DWORD cookie, IUnknown *unk)
-{
- IGlobalInterfaceTable *git;
- HRESULT ret;
-
- if (SUCCEEDED(CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL,
- CLSCTX_INPROC_SERVER, IID_IGlobalInterfaceTable,
- (void**)&git))) {
-
- ret = git->RevokeInterfaceFromGlobal(cookie);
- git->Release();
- }
- /* Kill remote clients */
- return CoDisconnectObject(unk, 0);
-}
-
-
-
-/* {{{ A generic stupid IDispatch implementation */
-class IDispatchImpl:
- public IDispatch
-{
-protected:
- volatile LONG m_refcount;
-public:
- /* IUnknown */
- STDMETHODIMP QueryInterface(REFIID iid, void **ppvObject) {
- *ppvObject = NULL;
-
- if (IsEqualGUID(IID_IDispatch, iid)) {
- *ppvObject = (IDispatch*)this;
- } else if (IsEqualGUID(IID_IUnknown, iid)) {
- *ppvObject = this;
- }
- if (*ppvObject) {
- AddRef();
- return S_OK;
- }
- return E_NOINTERFACE;
- }
-
- STDMETHODIMP_(DWORD) AddRef(void) {
- return InterlockedIncrement(const_cast<long*> (&m_refcount));
- }
-
- STDMETHODIMP_(DWORD) Release(void) {
- DWORD ret = InterlockedDecrement(const_cast<long*> (&m_refcount));
- trace("%08x: IDispatchImpl: release ref count is now %d\n", this, ret);
- if (ret == 0)
- delete this;
- return ret;
- }
- /* IDispatch */
- STDMETHODIMP GetTypeInfoCount(unsigned int * pctinfo) {
- *pctinfo = 0;
- trace("%08x: IDispatchImpl: GetTypeInfoCount\n", this);
- return S_OK;
- }
- STDMETHODIMP GetTypeInfo( unsigned int iTInfo, LCID lcid, ITypeInfo **ppTInfo) {
- trace("%08x: IDispatchImpl: GetTypeInfo\n", this);
- return DISP_E_BADINDEX;
- }
- STDMETHODIMP GetIDsOfNames( REFIID riid, OLECHAR **rgszNames, unsigned int cNames, LCID lcid, DISPID *rgDispId)
- {
- unsigned int i;
- trace("%08x: IDispatchImpl: GetIDsOfNames: \n", this);
- for (i = 0; i < cNames; i++) {
- TWideString name(rgszNames[i]);
- trace(" %s\n", name.ansi_string());
- }
- trace("----\n");
- return DISP_E_UNKNOWNNAME;
- }
- STDMETHODIMP Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
- DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, EXCEPINFO FAR* pExcepInfo,
- unsigned int FAR* puArgErr)
- {
- trace("%08x: IDispatchImpl: Invoke dispid %08x\n", this, dispIdMember);
- return S_OK;
- }
-
-
- IDispatchImpl() {
- m_refcount = 1;
- }
-
- virtual ~IDispatchImpl() {
- }
-};
-/* }}} */
-
-/* {{{ This object represents the PHP engine to the scripting host.
- * Although the docs say it's implementation is optional, I found that
- * the Windows Script host would crash if we did not provide it. */
-class ScriptDispatch:
- public IDispatchImpl
-{
-public:
- ScriptDispatch() {
- m_refcount = 1;
- }
-};
-/* }}} */
-
-/* {{{ This object is used in conjunction with IActiveScriptParseProcedure to
- * allow scriptlets to be bound to events. IE uses this for declaring
- * event handlers such as onclick="...".
- * The compiled code is stored in this object; IE will call
- * IDispatch::Invoke when the element is clicked.
- * */
-class ScriptProcedureDispatch:
- public IDispatchImpl
-{
-public:
- code_frag *m_frag;
- DWORD m_procflags;
- TPHPScriptingEngine *m_engine;
- DWORD m_gitcookie;
-
- STDMETHODIMP Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
- DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, EXCEPINFO FAR* pExcepInfo,
- unsigned int FAR* puArgErr)
- {
- TSRMLS_FETCH();
-
- if (m_frag) {
- trace("%08x: Procedure Dispatch: Invoke dispid %08x\n", this, dispIdMember);
- SEND_THREAD_MESSAGE(m_engine, PHPSE_EXEC_PROC, 0, (LPARAM)this TSRMLS_CC);
- }
- return S_OK;
- }
- ScriptProcedureDispatch() {
- m_refcount = 1;
- GIT_put((IDispatch*)this, IID_IDispatch, &m_gitcookie);
- }
-};
-/* }}} */
-
-/* {{{ code fragment management */
-static code_frag *compile_code_fragment(
- enum fragtype fragtype,
- char *functionname,
- LPCOLESTR code,
- ULONG starting_line,
- EXCEPINFO *excepinfo,
- TPHPScriptingEngine *engine
- TSRMLS_DC)
-{
- zval pv;
- int code_offs = 0;
- char namebuf[256];
-
- code_frag *frag = (code_frag*)CoTaskMemAlloc(sizeof(code_frag));
- memset(frag, 0, sizeof(code_frag));
-
- frag->engine = engine;
-
- /* handle the function name */
- if (functionname) {
- int namelen;
- if (functionname == FRAG_CREATE_FUNC) {
- ULONG n = ++engine->m_lambda_count;
-
- sprintf(namebuf, "__frag_%08x_%u", engine, n);
- functionname = namebuf;
- }
-
- namelen = strlen(functionname);
- code_offs = namelen + sizeof("function (){");
-
- frag->functionname = (char*)CoTaskMemAlloc((namelen + 1) * sizeof(char));
- memcpy(frag->functionname, functionname, namelen+1);
- }
-
- frag->functionname = functionname;
-
-trace("%08x: COMPILED FRAG\n", frag);
-
- frag->codelen = WideCharToMultiByte(CP_ACP, 0, code, -1, NULL, 0, NULL, NULL);
- frag->code = (char*)CoTaskMemAlloc(sizeof(char) * (frag->codelen + code_offs + 1));
-
- if (functionname) {
- sprintf(frag->code, "function %s(){ ", functionname);
- }
-
- frag->codelen = WideCharToMultiByte(CP_ACP, 0, code, -1, frag->code + code_offs, frag->codelen, NULL, NULL) - 1;
-
- if (functionname) {
- frag->codelen += code_offs + 1;
- frag->code[frag->codelen-1] = '}';
- frag->code[frag->codelen] = 0;
- }
-
-trace("code to compile is:\ncode_offs=%d func=%s\n%s\n", code_offs, functionname, frag->code);
-
- frag->fragtype = fragtype;
- frag->starting_line = starting_line;
-
- pv.type = IS_STRING;
- pv.value.str.val = frag->code;
- pv.value.str.len = frag->codelen;
-
- frag->opcodes = compile_string(&pv, "fragment" TSRMLS_CC);
-
- if (frag->opcodes == NULL) {
- free_code_fragment(frag);
-
- if (excepinfo) {
- memset(excepinfo, 0, sizeof(EXCEPINFO));
- excepinfo->wCode = 1000;
- excepinfo->bstrSource = TWideString::bstr_from_ansi("fragment");
- excepinfo->bstrDescription = TWideString::bstr_from_ansi("Problem while parsing/compiling");
- }
-
- return NULL;
- }
-
- return frag;
-}
-
-static void free_code_fragment(code_frag *frag)
-{
- switch(frag->fragtype) {
- case FRAG_PROCEDURE:
- if (frag->ptr) {
- ScriptProcedureDispatch *disp = (ScriptProcedureDispatch*)frag->ptr;
- disp->Release();
- GIT_revoke(disp->m_gitcookie, (IDispatch*)disp);
- frag->ptr = NULL;
- }
- break;
- }
-
- if (frag->opcodes)
- destroy_op_array(frag->opcodes);
- if (frag->functionname)
- CoTaskMemFree(frag->functionname);
- CoTaskMemFree(frag->code);
- CoTaskMemFree(frag);
-}
-
-static code_frag *clone_code_fragment(code_frag *frag, TPHPScriptingEngine *engine TSRMLS_DC)
-{
- zval pv;
- code_frag *newfrag = (code_frag*)CoTaskMemAlloc(sizeof(code_frag));
- memset(newfrag, 0, sizeof(code_frag));
-
- newfrag->engine = engine;
-trace("%08x: CLONED FRAG\n", newfrag);
-
- newfrag->persistent = frag->persistent;
- newfrag->codelen = frag->codelen;
- newfrag->code = (char*)CoTaskMemAlloc(sizeof(char) * frag->codelen + 1);
- memcpy(newfrag->code, frag->code, frag->codelen + 1);
-
- if (frag->functionname) {
- int namelen = strlen(frag->functionname);
- newfrag->functionname = (char*)CoTaskMemAlloc(sizeof(char) * (namelen + 1));
- memcpy(newfrag->functionname, frag->functionname, namelen+1);
- } else {
- newfrag->functionname = NULL;
- }
-
- newfrag->fragtype = frag->fragtype;
- newfrag->starting_line = frag->starting_line;
-
- pv.type = IS_STRING;
- pv.value.str.val = newfrag->code;
- pv.value.str.len = newfrag->codelen;
-
- newfrag->opcodes = compile_string(&pv, "fragment" TSRMLS_CC);
-
- if (newfrag->opcodes == NULL) {
- free_code_fragment(newfrag);
-/*
- if (excepinfo) {
- memset(excepinfo, 0, sizeof(EXCEPINFO));
- excepinfo->wCode = 1000;
- excepinfo->bstrSource = TWideString::bstr_from_ansi("fragment");
- excepinfo->bstrDescription = TWideString::bstr_from_ansi("Problem while parsing/compiling");
- }
-*/
- return NULL;
- }
-
- return newfrag;
-
-}
-
-static int execute_code_fragment(code_frag *frag,
- VARIANT *varResult,
- EXCEPINFO *excepinfo
- TSRMLS_DC)
-{
- zval *retval_ptr = NULL;
- jmp_buf *orig_jmpbuf;
- jmp_buf err_trap;
-
- if (frag->fragtype == FRAG_MAIN && frag->executed)
- return 1;
-
- orig_jmpbuf = frag->engine->m_err_trap;
- frag->engine->m_err_trap = &err_trap;
-
- if (setjmp(err_trap) == 0) {
- trace("*** Executing code in thread %08x\n", tsrm_thread_id());
-
- if (frag->functionname) {
-
- zval fname;
-
- fname.type = IS_STRING;
- fname.value.str.val = frag->functionname;
- fname.value.str.len = strlen(frag->functionname);
-
- call_user_function_ex(CG(function_table), NULL, &fname, &retval_ptr, 0, NULL, 1, NULL TSRMLS_CC);
-
- } else {
- zend_op_array *active_op_array = EG(active_op_array);
- zend_function_state *function_state_ptr = EG(function_state_ptr);
- zval **return_value_ptr_ptr = EG(return_value_ptr_ptr);
- zend_op **opline_ptr = EG(opline_ptr);
-
- EG(return_value_ptr_ptr) = &retval_ptr;
- EG(active_op_array) = frag->opcodes;
- EG(no_extensions) = 1;
-
- zend_execute(frag->opcodes TSRMLS_CC);
-
- EG(no_extensions) = 0;
- EG(opline_ptr) = opline_ptr;
- EG(active_op_array) = active_op_array;
- EG(function_state_ptr) = function_state_ptr;
- EG(return_value_ptr_ptr) = return_value_ptr_ptr;
- }
- } else {
- trace("*** --> caught error while executing\n");
- if (frag->engine->m_in_main)
- frag->engine->m_stop_main = 1;
- }
-
- frag->engine->m_err_trap = orig_jmpbuf;
-
- if (frag->fragtype == FRAG_MAIN)
- frag->executed = 1;
-
- if (varResult)
- VariantInit(varResult);
-
- if (retval_ptr) {
- if (varResult)
- php_pval_to_variant(retval_ptr, varResult, CP_ACP TSRMLS_CC);
- zval_ptr_dtor(&retval_ptr);
- }
-
- return 1;
-}
-
-static void frag_dtor(void *pDest)
-{
- code_frag *frag = *(code_frag**)pDest;
- free_code_fragment(frag);
-}
-/* }}} */
-
-/* glue for getting back into the OO land */
-static DWORD WINAPI begin_engine_thread(LPVOID param)
-{
- TPHPScriptingEngine *engine = (TPHPScriptingEngine*)param;
- engine->engine_thread_func();
- trace("engine thread has really gone away!\n");
- return 0;
-}
-
-TPHPScriptingEngine::TPHPScriptingEngine()
-{
- m_scriptstate = SCRIPTSTATE_UNINITIALIZED;
- m_pass = NULL;
- m_in_main = 0;
- m_stop_main = 0;
- m_err_trap = NULL;
- m_lambda_count = 0;
- m_pass_eng = NULL;
- m_refcount = 1;
- m_basethread = tsrm_thread_id();
- m_mutex = tsrm_mutex_alloc();
- m_sync_thread_msg = CreateEvent(NULL, TRUE, FALSE, NULL);
- TPHPClassFactory::AddToObjectCount();
-
- m_engine_thread_handle = CreateThread(NULL, 0, begin_engine_thread, this, 0, &m_enginethread);
- CloseHandle(m_engine_thread_handle);
-}
-
-void activescript_run_ticks(int count)
-{
- MSG msg;
- TSRMLS_FETCH();
- TPHPScriptingEngine *engine;
-
- trace("ticking %d\n", count);
-
- engine = (TPHPScriptingEngine*)SG(server_context);
-
-/* PostThreadMessage(engine->m_enginethread, PHPSE_DUMMY_TICK, 0, 0); */
-
- while(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
- if (msg.hwnd) {
- PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- } else {
- break;
- }
- }
-}
-
-/* Synchronize with the engine thread */
-HRESULT TPHPScriptingEngine::SendThreadMessage(LONG msg, WPARAM wparam, LPARAM lparam)
-{
- HRESULT ret;
-
- if (m_enginethread == 0)
- return E_UNEXPECTED;
-
- trace("I'm waiting for a mutex in SendThreadMessage\n this=%08x ethread=%08x msg=%08x\n",
- this, m_enginethread, msg);
-
- tsrm_mutex_lock(m_mutex);
- ResetEvent(m_sync_thread_msg);
-
- /* If we call PostThreadMessage before the thread has created the queue, the message
- * posting fails. MSDN docs recommend the following course of action */
- while (!PostThreadMessage(m_enginethread, msg, wparam, lparam)) {
- Sleep(50);
- if (m_enginethread == 0) {
- tsrm_mutex_unlock(m_mutex);
- trace("breaking out of dodgy busy wait\n");
- return E_UNEXPECTED;
- }
- }
-
- /* Wait for the event object to be signalled.
- * This is a nice "blocking without blocking" wait; window messages are dispatched
- * and everything works out quite nicely */
- while(1) {
- DWORD result = MsgWaitForMultipleObjects(1, &m_sync_thread_msg, FALSE, 4000, QS_ALLINPUT);
-
- if (result == WAIT_OBJECT_0 + 1) {
- /* Dispatch some messages */
- MSG msg;
- while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- //trace("dispatching message while waiting\n");
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- } else if (result == WAIT_TIMEOUT) {
- trace("timeout while waiting for thread reply\n");
-
- } else {
- /* the event was signalled */
- break;
- }
- }
- ret = m_sync_thread_ret;
- ResetEvent(m_sync_thread_msg);
- tsrm_mutex_unlock(m_mutex);
- return ret;
-}
-
-TPHPScriptingEngine::~TPHPScriptingEngine()
-{
- trace("\n\n *** Engine Destructor Called\n\n");
- if (m_scriptstate != SCRIPTSTATE_UNINITIALIZED && m_scriptstate != SCRIPTSTATE_CLOSED && m_enginethread)
- Close();
-
- PostThreadMessage(m_enginethread, WM_QUIT, 0, 0);
-
- TPHPClassFactory::RemoveFromObjectCount();
- tsrm_mutex_free(m_mutex);
-}
-
-/* Set some executor globals and execute a zend_op_array.
- * The declaration looks wierd because this can be invoked from
- * zend_hash_apply_with_argument */
-static int execute_main(void *pDest, void *arg TSRMLS_DC)
-{
- code_frag *frag = *(code_frag**)pDest;
-
- if (frag->fragtype == FRAG_MAIN && !(frag->engine->m_in_main && frag->engine->m_stop_main))
- execute_code_fragment(frag, NULL, NULL TSRMLS_CC);
-
- return ZEND_HASH_APPLY_KEEP;
-}
-
-static int clone_frags(void *pDest, void *arg TSRMLS_DC)
-{
- code_frag *frag, *src = *(code_frag**)pDest;
- TPHPScriptingEngine *engine = (TPHPScriptingEngine*)arg;
-
- if (src->persistent) {
- frag = clone_code_fragment(src, engine TSRMLS_CC);
- if (frag)
- zend_hash_next_index_insert(&engine->m_frags, &frag, sizeof(code_frag*), NULL);
- else
- trace("WARNING: clone failed!\n");
- }
-
- return ZEND_HASH_APPLY_KEEP;
-}
-
-HRESULT TPHPScriptingEngine::engine_thread_handler(LONG msg, WPARAM wparam, LPARAM lParam, int *handled TSRMLS_DC)
-{
- HRESULT ret = S_OK;
-
- trace("engine_thread_handler: running in thread %08x, should be %08x msg=%08x this=%08x\n",
- tsrm_thread_id(), m_enginethread, msg, this);
-
- if (handled)
- *handled = 1;
-
- if (m_enginethread == 0)
- return E_UNEXPECTED;
-
- switch(msg) {
- case PHPSE_ADD_TYPELIB:
- {
- struct php_active_script_add_tlb_info *info = (struct php_active_script_add_tlb_info*)lParam;
- ITypeLib *TypeLib;
-
- if (SUCCEEDED(LoadRegTypeLib(*info->rguidTypeLib, (USHORT)info->dwMajor,
- (USHORT)info->dwMinor, LANG_NEUTRAL, &TypeLib))) {
- php_COM_load_typelib(TypeLib, CONST_CS TSRMLS_CC);
- TypeLib->Release();
- }
- }
- break;
- case PHPSE_STATE_CHANGE:
- {
- /* handle the state change here */
- SCRIPTSTATE ss = (SCRIPTSTATE)lParam;
- int start_running = 0;
- trace("%08x: DoSetScriptState(current=%s, new=%s)\n",
- this,
- scriptstate_to_string(m_scriptstate),
- scriptstate_to_string(ss));
-
- if (m_scriptstate == SCRIPTSTATE_INITIALIZED && (ss == SCRIPTSTATE_STARTED || ss == SCRIPTSTATE_CONNECTED))
- start_running = 1;
-
- m_scriptstate = ss;
-
- /* inform host/site of the change */
- if (m_pass_eng)
- m_pass_eng->OnStateChange(m_scriptstate);
-
- if (start_running) {
- /* run "main()", as described in the docs */
- if (m_pass_eng)
- m_pass_eng->OnEnterScript();
- trace("%08x: apply execute main to m_frags\n", this);
- m_in_main = 1;
- m_stop_main = 0;
- zend_hash_apply_with_argument(&m_frags, execute_main, this TSRMLS_CC);
- m_in_main = 0;
- trace("%08x: --- done execute main\n", this);
- if (m_pass_eng)
- m_pass_eng->OnLeaveScript();
-
- /* docs are a bit ambiguous here, but it appears that we should
- * inform the host that the main script execution has completed,
- * and also what the return value is */
- VARIANT varRes;
-
- VariantInit(&varRes);
- if (m_pass_eng)
- m_pass_eng->OnScriptTerminate(&varRes, NULL);
-
- /*
- m_scriptstate = SCRIPTSTATE_INITIALIZED;
- if (m_pass_eng)
- m_pass_eng->OnStateChange(m_scriptstate);
- */
- }
- }
- break;
- case PHPSE_INIT_NEW:
- {
- /* Prepare PHP/ZE for use */
-
- trace("%08x: m_frags : INIT NEW\n", this);
- zend_hash_init(&m_frags, 0, NULL, frag_dtor, TRUE);
-
- SG(options) |= SAPI_OPTION_NO_CHDIR;
- SG(server_context) = this;
- /* override the default PHP error callback */
- zend_error_cb = activescript_error_handler;
-
- zend_alter_ini_entry("register_argc_argv", 19, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("implicit_flush", 15, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
-
- php_request_startup(TSRMLS_C);
- PG(during_request_startup) = 0;
- trace("\n\n *** ticks func at %08x %08x ***\n\n\n", activescript_run_ticks, &activescript_run_ticks);
-// php_add_tick_function(activescript_run_ticks);
-
- }
- break;
- case PHPSE_CLOSE:
- {
- /* Close things down */
- trace("%08x: m_frags : CLOSE/DESTROY\n", this);
- m_scriptstate = SCRIPTSTATE_CLOSED;
- if (m_pass_eng) {
- m_pass_eng->OnStateChange(m_scriptstate);
- trace("%08x: release site from this side\n", this);
- m_pass_eng->Release();
- m_pass_eng = NULL;
- }
- zend_hash_destroy(&m_frags);
- php_request_shutdown(NULL);
-
- break;
- }
- break;
- case PHPSE_CLONE:
- {
- /* Clone the engine state. This is semantically equal to serializing all
- * the parsed code from the source and unserializing it in the dest (this).
- * IE doesn't appear to use it, but Windows Script Host does. I'd expect
- * ASP/ASP.NET to do so also.
- *
- * FIXME: Probably won't work with IActiveScriptParseProcedure scriplets
- * */
-
- TPHPScriptingEngine *src = (TPHPScriptingEngine*)lParam;
-
- trace("%08x: m_frags : CLONE\n", this);
- zend_hash_apply_with_argument(&src->m_frags, clone_frags, this TSRMLS_CC);
-
- }
- break;
- case PHPSE_ADD_SCRIPTLET:
- {
- /* Parse/compile a chunk of script that will act as an event handler.
- * If the host supports IActiveScriptParseProcedure, this code will
- * not be called.
- * The docs are (typically) vague: AFAICT, once the code has been
- * compiled, we are supposed to arrange for an IConnectionPoint
- * advisory connection to the item/subitem, once the script
- * moves into SCRIPTSTATE_CONNECTED.
- * That's a lot of work!
- *
- * FIXME: this is currently almost useless
- * */
-
- struct php_active_script_add_scriptlet_info *info = (struct php_active_script_add_scriptlet_info*)lParam;
-
- TWideString
- default_name(info->pstrDefaultName),
- code(info->pstrCode),
- item_name(info->pstrItemName),
- sub_item_name(info->pstrSubItemName),
- event_name(info->pstrEventName),
- delimiter(info->pstrDelimiter);
-
- /* lets invent a function name for the scriptlet */
- char sname[256];
-
- /* should check if the name is already used! */
- if (info->pstrDefaultName)
- strcpy(sname, default_name.ansi_string());
- else {
- sname[0] = 0;
- strcat(sname, "__");
- if (info->pstrItemName) {
- strcat(sname, item_name.ansi_string());
- strcat(sname, "_");
- }
- if (info->pstrSubItemName) {
- strcat(sname, sub_item_name.ansi_string());
- strcat(sname, "_");
- }
- if (info->pstrEventName)
- strcat(sname, event_name.ansi_string());
- }
-
-
- trace("%08x: AddScriptlet:\n state=%s\n name=%s\n code=%s\n item=%s\n subitem=%s\n event=%s\n delim=%s\n line=%d\n",
- this, scriptstate_to_string(m_scriptstate),
- default_name.safe_ansi_string(), code.safe_ansi_string(), item_name.safe_ansi_string(),
- sub_item_name.safe_ansi_string(), event_name.safe_ansi_string(), delimiter.safe_ansi_string(),
- info->ulStartingLineNumber);
-
-
- code_frag *frag = compile_code_fragment(
- FRAG_SCRIPTLET,
- sname,
- info->pstrCode,
- info->ulStartingLineNumber,
- info->pexcepinfo,
- this
- TSRMLS_CC);
-
- if (frag) {
-
- frag->persistent = (info->dwFlags & SCRIPTTEXT_ISPERSISTENT);
-
- zend_hash_next_index_insert(&m_frags, &frag, sizeof(code_frag*), NULL);
-
- /*
- ScriptProcedureDispatch *disp = new ScriptProcedureDispatch;
-
- disp->AddRef();
- disp->m_frag = frag;
- disp->m_procflags = info->dwFlags;
- disp->m_engine = this;
- frag->ptr = disp;
-
- *info->ppdisp = disp;
- */
- ret = S_OK;
- } else {
- ret = DISP_E_EXCEPTION;
- }
-
- *info->pbstrName = TWideString::bstr_from_ansi(sname);
-
- trace("%08x: done with scriptlet %s\n", this, sname);
-
- }
- break;
- case PHPSE_GET_DISPATCH:
- {
- struct php_active_script_get_dispatch_info *info = (struct php_active_script_get_dispatch_info *)lParam;
- IDispatch *disp = NULL;
-
- if (info->pstrItemName != NULL) {
- zval **tmp;
- /* use this rather than php_OLECHAR_to_char because we want to avoid emalloc here */
- TWideString itemname(info->pstrItemName);
-
- /* Get that item from the global namespace.
- * If it is an object, export it as a dispatchable object.
- * */
-
- if (zend_hash_find(&EG(symbol_table), itemname.ansi_string(),
- itemname.ansi_len() + 1, (void**)&tmp) == SUCCESS) {
- if (Z_TYPE_PP(tmp) == IS_OBJECT) {
- /* FIXME: if this causes an allocation (emalloc) and we are
- * not in the engine thread, things could get ugly!!! */
- disp = php_COM_export_object(*tmp TSRMLS_CC);
- }
- }
-
- } else {
- /* This object represents PHP global namespace */
- disp = (IDispatch*) new ScriptDispatch;
- }
-
- if (disp) {
- ret = GIT_put(disp, IID_IDispatch, &info->dispatch);
- disp->Release();
- } else {
- ret = S_FALSE;
- }
- }
- break;
- case PHPSE_ADD_NAMED_ITEM:
- {
- /* The Host uses this to add objects to the global namespace.
- * Some objects are intended to have their child properties
- * globally visible, so we add those to the global namespace too.
- * */
- struct php_active_script_add_named_item_info *info = (struct php_active_script_add_named_item_info *)lParam;
-
- TWideString name(info->pstrName);
- IDispatch *disp;
-
- if (SUCCEEDED(GIT_get(info->marshal, IID_IDispatch, (void**)&disp)))
- add_to_global_namespace(disp, info->dwFlags, name.ansi_string() TSRMLS_CC);
-
- }
- break;
- case PHPSE_SET_SITE:
- {
- if (m_pass_eng) {
- m_pass_eng->Release();
- m_pass_eng = NULL;
- }
-
- if (lParam)
- GIT_get(lParam, IID_IActiveScriptSite, (void**)&m_pass_eng);
-
- trace("%08x: site (engine-side) is now %08x (base=%08x)\n", this, m_pass_eng, m_pass);
-
- }
- break;
- case PHPSE_EXEC_PROC:
- {
- ScriptProcedureDispatch *disp = (ScriptProcedureDispatch *)lParam;
- execute_code_fragment(disp->m_frag, NULL, NULL TSRMLS_CC);
- }
- break;
- case PHPSE_PARSE_PROC:
- {
- /* This is the IActiveScriptParseProcedure implementation.
- * IE uses this to request for an IDispatch that it will invoke in
- * response to some event, and tells us the code that it wants to
- * run.
- * We compile the code and pass it back a dispatch object.
- * The object will then serialize access to the engine thread and
- * execute the opcodes */
- struct php_active_script_parse_proc_info *info = (struct php_active_script_parse_proc_info*)lParam;
- TWideString
- formal_params(info->pstrFormalParams),
- procedure_name(info->pstrProcedureName),
- item_name(info->pstrItemName),
- delimiter(info->pstrDelimiter);
-
- trace("%08x: ParseProc:\n state=%s\nparams=%s\nproc=%s\nitem=%s\n delim=%s\n line=%d\n",
- this, scriptstate_to_string(m_scriptstate),
- formal_params.ansi_string(), procedure_name.ansi_string(),
- item_name.safe_ansi_string(), delimiter.safe_ansi_string(),
- info->ulStartingLineNumber);
-
-
- code_frag *frag = compile_code_fragment(
- FRAG_PROCEDURE,
- NULL,
- info->pstrCode,
- info->ulStartingLineNumber,
- NULL,
- this
- TSRMLS_CC);
-
- if (frag) {
-
- frag->persistent = (info->dwFlags & SCRIPTTEXT_ISPERSISTENT);
- zend_hash_next_index_insert(&m_frags, &frag, sizeof(code_frag*), NULL);
-
- ScriptProcedureDispatch *disp = new ScriptProcedureDispatch;
-
- disp->m_frag = frag;
- disp->m_procflags = info->dwFlags;
- disp->m_engine = this;
- frag->ptr = disp;
- info->dispcookie = disp->m_gitcookie;
-
- } else {
- ret = DISP_E_EXCEPTION;
- }
-
- }
- break;
-
- case PHPSE_PARSE_SCRIPT:
- {
- struct php_active_script_parse_info *info = (struct php_active_script_parse_info*)lParam;
- int doexec;
-
- TWideString
- code(info->pstrCode),
- item_name(info->pstrItemName),
- delimiter(info->pstrDelimiter);
-
- trace("%08x: ParseScriptText:\n state=%s\ncode=%s\n item=%s\n delim=%s\n line=%d\n",
- this, scriptstate_to_string(m_scriptstate),
- code.safe_ansi_string(), item_name.safe_ansi_string(), delimiter.safe_ansi_string(),
- info->ulStartingLineNumber);
-
- code_frag *frag = compile_code_fragment(
- FRAG_MAIN,
- info->dwFlags & SCRIPTTEXT_ISEXPRESSION ? FRAG_CREATE_FUNC : NULL,
- info->pstrCode,
- info->ulStartingLineNumber,
- info->pexcepinfo,
- this
- TSRMLS_CC);
-
- doexec = (info->dwFlags & SCRIPTTEXT_ISEXPRESSION) ||
- m_scriptstate == SCRIPTSTATE_STARTED ||
- m_scriptstate == SCRIPTSTATE_CONNECTED ||
- m_scriptstate == SCRIPTSTATE_DISCONNECTED;
-
- if (frag) {
- frag->persistent = (info->dwFlags & SCRIPTTEXT_ISPERSISTENT);
- ret = S_OK;
-
- if (info->dwFlags & SCRIPTTEXT_ISEXPRESSION) {
- if (m_scriptstate == SCRIPTSTATE_INITIALIZED) {
- /* not allowed to execute code in this state */
- ret = E_UNEXPECTED;
- doexec = 0;
- }
- }
-
- if (doexec) {
- /* execute the code as an expression */
- if (!execute_code_fragment(frag, info->pvarResult, info->pexcepinfo TSRMLS_CC))
- ret = DISP_E_EXCEPTION;
- }
-
- zend_hash_next_index_insert(&m_frags, &frag, sizeof(code_frag*), NULL);
- } else {
- ret = DISP_E_EXCEPTION;
- }
-
- if (info->pvarResult) {
- VariantInit(info->pvarResult);
- }
-
-
- }
- break;
- default:
- trace("unhandled message type %08x\n", msg);
- if (handled)
- *handled = 0;
- }
- return ret;
-}
-
-/* The PHP/Zend state actually lives in this thread */
-void TPHPScriptingEngine::engine_thread_func(void)
-{
- TSRMLS_FETCH();
- int handled;
- int terminated = 0;
- MSG msg;
-
- trace("%08x: engine thread started up!\n", this);
-
- CoInitializeEx(0, COINIT_MULTITHREADED);
-
- m_tsrm_hack = tsrm_ls;
-
- while(!terminated) {
- DWORD result = MsgWaitForMultipleObjects(0, NULL, FALSE, 4000, QS_ALLINPUT);
-
- switch(result) {
- case WAIT_OBJECT_0:
- while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
-
- if (msg.message == WM_QUIT) {
- terminated = 1;
- } else if (msg.hwnd) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
-
- } else {
- handled = 1;
- m_sync_thread_ret = engine_thread_handler(msg.message, msg.wParam, msg.lParam, &handled TSRMLS_CC);
- if (handled)
- SetEvent(m_sync_thread_msg);
- }
-
- }
- break;
- case WAIT_TIMEOUT:
- trace("thread wait timed out\n");
- break;
- default:
- trace("some strange value\n");
- }
- }
-
-#if 0
- while(GetMessage(&msg, NULL, 0, 0)) {
-
- if (msg.message == WM_QUIT)
- break;
-
- handled = 1;
- m_sync_thread_ret = engine_thread_handler(msg.message, msg.wParam, msg.lParam, &handled TSRMLS_CC);
- if (handled)
- SetEvent(m_sync_thread_msg);
- }
- trace("%08x: engine thread exiting!!!!!\n", this);
-#endif
- m_enginethread = 0;
-
- CoUninitialize();
-}
-
-/* Only call this in the context of the engine thread, or you'll be sorry.
- *
- * When SCRIPTITEM_GLOBALMEMBERS is set, we're only adding COM objects to the namespace.
- * We could add *all* properties, but I don't like this idea; what if the value changes
- * while the page is running? We'd be left with stale data.
- * */
-void TPHPScriptingEngine::add_to_global_namespace(IDispatch *disp, DWORD flags, char *name TSRMLS_DC)
-{
- zval *val;
- ITypeInfo *typ;
- int i;
- unsigned int namelen;
- FUNCDESC *func;
- BSTR funcname;
- TYPEATTR *attr;
- DISPPARAMS dispparams;
- VARIANT vres;
- ITypeInfo *rettyp;
- TYPEATTR *retattr;
-
-trace("Add %s to global namespace\n", name);
-
- val = php_COM_object_from_dispatch(disp, NULL TSRMLS_CC);
-
- if (val == NULL) {
- disp->Release();
- return;
- }
-
- ZEND_SET_SYMBOL(&EG(symbol_table), name, val);
-
- if (flags & SCRIPTITEM_GLOBALMEMBERS == 0) {
- disp->Release();
- return;
- }
-
- /* Enumerate properties and add those too */
- if (FAILED(disp->GetTypeInfo(0, 0, &typ))) {
- disp->Release();
- return;
- }
-
- if (SUCCEEDED(typ->GetTypeAttr(&attr))) {
- for (i = 0; i < attr->cFuncs; i++) {
- if (FAILED(typ->GetFuncDesc(i, &func)))
- continue;
-
- /* Look at it's type */
- if (func->invkind == INVOKE_PROPERTYGET
- && VT_PTR == func->elemdescFunc.tdesc.vt
- && VT_USERDEFINED == func->elemdescFunc.tdesc.lptdesc->vt
- && SUCCEEDED(typ->GetRefTypeInfo(func->elemdescFunc.tdesc.lptdesc->hreftype, &rettyp)))
- {
- if (SUCCEEDED(rettyp->GetTypeAttr(&retattr))) {
- if (retattr->typekind == TKIND_DISPATCH) {
- /* It's dispatchable */
-
- /* get the value */
- dispparams.cArgs = 0;
- dispparams.cNamedArgs = 0;
- VariantInit(&vres);
-
- if (SUCCEEDED(disp->Invoke(func->memid, IID_NULL, 0, func->invkind,
- &dispparams, &vres, NULL, NULL))) {
-
- /* Get it's dispatch */
- IDispatch *sub = NULL;
-
- if (V_VT(&vres) == VT_UNKNOWN)
- V_UNKNOWN(&vres)->QueryInterface(IID_IDispatch, (void**)&sub);
- else if (V_VT(&vres) == VT_DISPATCH)
- sub = V_DISPATCH(&vres);
-
- if (sub) {
- /* find out it's name */
- typ->GetDocumentation(func->memid, &funcname, NULL, NULL, NULL);
- name = php_OLECHAR_to_char(funcname, &namelen, CP_ACP TSRMLS_CC);
-
- /* add to namespace */
- zval *subval = php_COM_object_from_dispatch(sub, NULL TSRMLS_CC);
- if (subval) {
- ZEND_SET_SYMBOL(&EG(symbol_table), name, subval);
- }
-
- efree(name);
- SysFreeString(funcname);
- }
- VariantClear(&vres);
- }
- }
- rettyp->ReleaseTypeAttr(retattr);
- }
- rettyp->Release();
- }
- typ->ReleaseFuncDesc(func);
- }
- typ->ReleaseTypeAttr(attr);
- }
- disp->Release();
-}
-
-STDMETHODIMP_(DWORD) TPHPScriptingEngine::AddRef(void)
-{
- return InterlockedIncrement(const_cast<long*> (&m_refcount));
-}
-
-STDMETHODIMP_(DWORD) TPHPScriptingEngine::Release(void)
-{
- DWORD ret = InterlockedDecrement(const_cast<long*> (&m_refcount));
- if (ret == 0) {
- trace("%08x: Release: zero refcount, destroy the engine!\n", this);
- delete this;
- }
- return ret;
-}
-
-STDMETHODIMP TPHPScriptingEngine::QueryInterface(REFIID iid, void **ppvObject)
-{
- *ppvObject = NULL;
-
- if (IsEqualGUID(IID_IActiveScript, iid)) {
- *ppvObject = (IActiveScript*)this;
- } else if (IsEqualGUID(IID_IActiveScriptParse, iid)) {
- *ppvObject = (IActiveScriptParse*)this;
- } else if (IsEqualGUID(IID_IActiveScriptParseProcedure, iid)) {
- *ppvObject = (IActiveScriptParseProcedure*)this;
- } else if (IsEqualGUID(IID_IUnknown, iid)) {
- *ppvObject = this;
- } else {
- LPOLESTR guidw;
- StringFromCLSID(iid, &guidw);
- {
- TWideString guid(guidw);
- trace("%08x: QueryInterface for unsupported %s\n", this, guid.ansi_string());
- }
- CoTaskMemFree(guidw);
- }
- if (*ppvObject) {
- AddRef();
- return S_OK;
- }
-
- return E_NOINTERFACE;
-}
-
-/* This is called by the host to set the scrite site.
- * It also defines the base thread. */
-STDMETHODIMP TPHPScriptingEngine::SetScriptSite(IActiveScriptSite *pass)
-{
- TSRMLS_FETCH();
-
- tsrm_mutex_lock(m_mutex);
-
- trace("%08x: -----> Base thread is %08x\n", this, tsrm_thread_id());
-
- if (m_pass) {
- m_pass->Release();
- m_pass = NULL;
- SEND_THREAD_MESSAGE(this, PHPSE_SET_SITE, 0, 0 TSRMLS_CC);
- }
-
- if (pass == NULL) {
- trace("Closing down site; we should have no references to objects from the host\n"
- " m_pass=%08x\n m_pass_eng=%08x\n What about named items??\n",
- m_pass, m_pass_eng);
- }
-
- m_pass = pass;
- if (m_pass) {
- m_pass->AddRef();
-
- DWORD cookie;
- if (SUCCEEDED(GIT_put(m_pass, IID_IActiveScriptSite, &cookie)))
- SEND_THREAD_MESSAGE(this, PHPSE_SET_SITE, 0, cookie TSRMLS_CC);
-
- if (m_scriptstate == SCRIPTSTATE_UNINITIALIZED)
- SEND_THREAD_MESSAGE(this, PHPSE_STATE_CHANGE, 0, SCRIPTSTATE_INITIALIZED TSRMLS_CC);
- }
-
- tsrm_mutex_unlock(m_mutex);
- return S_OK;
-}
-
-STDMETHODIMP TPHPScriptingEngine::GetScriptSite(REFIID riid, void **ppvObject)
-{
- HRESULT ret = S_FALSE;
-
- trace("%08x: GetScriptSite()\n", this);
- tsrm_mutex_lock(m_mutex);
-
-
- if (m_pass)
- ret = m_pass->QueryInterface(riid, ppvObject);
-
- tsrm_mutex_unlock(m_mutex);
- return ret;
-}
-
-STDMETHODIMP TPHPScriptingEngine::SetScriptState(SCRIPTSTATE ss)
-{
- TSRMLS_FETCH();
- trace("%08x: SetScriptState(%s)\n", this, scriptstate_to_string(ss));
- return SEND_THREAD_MESSAGE(this, PHPSE_STATE_CHANGE, 0, ss TSRMLS_CC);
-}
-
-STDMETHODIMP TPHPScriptingEngine::GetScriptState(SCRIPTSTATE *pssState)
-{
- trace("%08x: GetScriptState(current=%s)\n", this, scriptstate_to_string(m_scriptstate));
- tsrm_mutex_lock(m_mutex);
- *pssState = m_scriptstate;
- tsrm_mutex_unlock(m_mutex);
- return S_OK;
-}
-
-STDMETHODIMP TPHPScriptingEngine::Close(void)
-{
- TSRMLS_FETCH();
-
- if (m_pass) {
- m_pass->Release();
- m_pass = NULL;
- }
- SEND_THREAD_MESSAGE(this, PHPSE_CLOSE, 0, 0 TSRMLS_CC);
- return S_OK;
-}
-
-/* Add an item to global namespace.
- * This is called in the context of the base thread (or perhaps some other thread).
- * We want to be able to work with the object in the engine thread, so we marshal
- * it into a stream and let the engine thread deal with it.
- * This works quite nicely when PHP scripts call into the object; threading is
- * handled correctly. */
-STDMETHODIMP TPHPScriptingEngine::AddNamedItem(LPCOLESTR pstrName, DWORD dwFlags)
-{
- struct php_active_script_add_named_item_info info;
- TSRMLS_FETCH();
-
- info.pstrName = pstrName;
- info.dwFlags = dwFlags;
-
- m_pass->GetItemInfo(pstrName, SCRIPTINFO_IUNKNOWN, &info.punk, NULL);
- if (SUCCEEDED(GIT_put(info.punk, IID_IDispatch, &info.marshal))) {
- SEND_THREAD_MESSAGE(this, PHPSE_ADD_NAMED_ITEM, 0, (LPARAM)&info TSRMLS_CC);
- }
- info.punk->Release();
-
- return S_OK;
-}
-
-/* Bind to a type library */
-STDMETHODIMP TPHPScriptingEngine::AddTypeLib(
- /* [in] */ REFGUID rguidTypeLib,
- /* [in] */ DWORD dwMajor,
- /* [in] */ DWORD dwMinor,
- /* [in] */ DWORD dwFlags)
-{
- struct php_active_script_add_tlb_info info;
- TSRMLS_FETCH();
-
- info.rguidTypeLib = &rguidTypeLib;
- info.dwMajor = dwMajor;
- info.dwMinor = dwMinor;
- info.dwFlags = dwFlags;
-
- SEND_THREAD_MESSAGE(this, PHPSE_ADD_TYPELIB, 0, (LPARAM)&info TSRMLS_CC);
-
- return S_OK;
-}
-
-/* Returns an object representing the PHP Scripting Engine.
- * Optionally, a client can request a particular item directly.
- * For the moment, we only do the bare minimum amount of work
- * for the engine to work correctly; we can flesh out this part
- * a little later. */
-STDMETHODIMP TPHPScriptingEngine::GetScriptDispatch(
- /* [in] */ LPCOLESTR pstrItemName,
- /* [out] */ IDispatch **ppdisp)
-{
- TSRMLS_FETCH();
- *ppdisp = NULL;
- struct php_active_script_get_dispatch_info info;
-
- info.pstrItemName = pstrItemName;
- info.dispatch = NULL;
-
- /* This hack is required because the host is likely to query us
- * for a dispatch if we use any of it's objects from PHP script.
- * Since the engine thread will be waiting for the return from
- * a COM call, we need to deliberately poke a hole in thread
- * safety so that it is possible to read the symbol table from
- * outside the engine thread and give it a valid return value.
- * This is "safe" only in this instance, since we are not modifying
- * the engine state by looking up the dispatch (I hope).
- * The scripting engine rules pretty much guarantee that this
- * method is only called in the base thread. */
-
- if (tsrm_thread_id() != m_enginethread) {
- tsrm_ls = m_tsrm_hack;
- trace("HEY: hacking thread safety!\n");
- }
-
- if (S_OK == engine_thread_handler(PHPSE_GET_DISPATCH, 0, (LPARAM)&info, NULL TSRMLS_CC)) {
- GIT_get(info.dispatch, IID_IDispatch, (void**)ppdisp);
- }
-
- if (*ppdisp) {
- return S_OK;
- }
- return S_FALSE;
-}
-
-STDMETHODIMP TPHPScriptingEngine::GetCurrentScriptThreadID(
- /* [out] */ SCRIPTTHREADID *pstidThread)
-{
-// tsrm_mutex_lock(m_mutex);
- trace("%08x: GetCurrentScriptThreadID()\n", this);
- *pstidThread = m_enginethread;
-// tsrm_mutex_unlock(m_mutex);
- return S_OK;
-}
-
-STDMETHODIMP TPHPScriptingEngine::GetScriptThreadID(
- /* [in] */ DWORD dwWin32ThreadId,
- /* [out] */ SCRIPTTHREADID *pstidThread)
-{
-// tsrm_mutex_lock(m_mutex);
- trace("%08x: GetScriptThreadID()\n", this);
- *pstidThread = dwWin32ThreadId;
-// tsrm_mutex_unlock(m_mutex);
- return S_OK;
-}
-
-STDMETHODIMP TPHPScriptingEngine::GetScriptThreadState(
- /* [in] */ SCRIPTTHREADID stidThread,
- /* [out] */ SCRIPTTHREADSTATE *pstsState)
-{
-// tsrm_mutex_lock(m_mutex);
-
- trace("%08x: GetScriptThreadState()\n", this);
- *pstsState = SCRIPTTHREADSTATE_NOTINSCRIPT;
-
- switch(stidThread) {
- case SCRIPTTHREADID_BASE:
- stidThread = m_basethread;
- break;
- case SCRIPTTHREADID_CURRENT:
- stidThread = m_enginethread;
- break;
- };
- if (stidThread == m_basethread) {
- *pstsState = SCRIPTTHREADSTATE_NOTINSCRIPT;
- } else if (stidThread == m_enginethread) {
- *pstsState = SCRIPTTHREADSTATE_NOTINSCRIPT;
- }
-// tsrm_mutex_unlock(m_mutex);
- return S_OK;
-}
-
-STDMETHODIMP TPHPScriptingEngine::InterruptScriptThread(
- /* [in] */ SCRIPTTHREADID stidThread,
- /* [in] */ const EXCEPINFO *pexcepinfo,
- /* [in] */ DWORD dwFlags)
-{
- /* do not serialize this method, or call into the script site */
- trace("%08x: InterruptScriptThread()\n", this);
- return S_OK;
-}
-
-/* Clone is essential when running under Windows Script Host.
- * It creates an engine to parse the code. Once it is parsed,
- * the host clones other engines from the original and runs those.
- * It is intended to be a fast method of running the same script
- * multiple times in multiple threads. */
-STDMETHODIMP TPHPScriptingEngine::Clone(
- /* [out] */ IActiveScript **ppscript)
-{
- TPHPScriptingEngine *cloned = new TPHPScriptingEngine;
- TSRMLS_FETCH();
-
- trace("%08x: Clone()\n", this);
-
- if (ppscript)
- *ppscript = NULL;
-
- if (cloned) {
- cloned->InitNew();
- SEND_THREAD_MESSAGE(cloned, PHPSE_CLONE, 0, (LPARAM)this TSRMLS_CC);
- trace("%08x: Cloned OK, returning cloned object ptr %08x\n", this, cloned);
- *ppscript = (IActiveScript*)cloned;
- return S_OK;
-
- }
-
- return E_FAIL;
-}
-
-
-STDMETHODIMP TPHPScriptingEngine::InitNew( void)
-{
- TSRMLS_FETCH();
- SEND_THREAD_MESSAGE(this, PHPSE_INIT_NEW, 0, 0 TSRMLS_CC);
- return S_OK;
-}
-
-STDMETHODIMP TPHPScriptingEngine::AddScriptlet(
- /* [in] */ LPCOLESTR pstrDefaultName,
- /* [in] */ LPCOLESTR pstrCode,
- /* [in] */ LPCOLESTR pstrItemName,
- /* [in] */ LPCOLESTR pstrSubItemName,
- /* [in] */ LPCOLESTR pstrEventName,
- /* [in] */ LPCOLESTR pstrDelimiter,
- /* [in] */ DWORD dwSourceContextCookie,
- /* [in] */ ULONG ulStartingLineNumber,
- /* [in] */ DWORD dwFlags,
- /* [out] */ BSTR *pbstrName,
- /* [out] */ EXCEPINFO *pexcepinfo)
-{
- struct php_active_script_add_scriptlet_info info;
- TSRMLS_FETCH();
-
- info.pstrDefaultName = pstrDefaultName;
- info.pstrCode = pstrCode;
- info.pstrItemName = pstrItemName;
- info.pstrSubItemName = pstrSubItemName;
- info.pstrEventName = pstrEventName;
- info.pstrDelimiter = pstrDelimiter;
- info.dwSourceContextCookie = dwSourceContextCookie;
- info.ulStartingLineNumber = ulStartingLineNumber;
- info.dwFlags = dwFlags;
- info.pbstrName = pbstrName;
- info.pexcepinfo = pexcepinfo;
-
- return SEND_THREAD_MESSAGE(this, PHPSE_ADD_SCRIPTLET, 0, (LPARAM)&info TSRMLS_CC);
-}
-
-STDMETHODIMP TPHPScriptingEngine::ParseScriptText(
- /* [in] */ LPCOLESTR pstrCode,
- /* [in] */ LPCOLESTR pstrItemName,
- /* [in] */ IUnknown *punkContext,
- /* [in] */ LPCOLESTR pstrDelimiter,
- /* [in] */ DWORD dwSourceContextCookie,
- /* [in] */ ULONG ulStartingLineNumber,
- /* [in] */ DWORD dwFlags,
- /* [out] */ VARIANT *pvarResult,
- /* [out] */ EXCEPINFO *pexcepinfo)
-{
- struct php_active_script_parse_info info;
- TSRMLS_FETCH();
-
- info.pstrCode = pstrCode;
- info.pstrItemName = pstrItemName;
- info.punkContext = punkContext;
- info.pstrDelimiter = pstrDelimiter;
- info.dwSourceContextCookie = dwSourceContextCookie;
- info.ulStartingLineNumber = ulStartingLineNumber;
- info.dwFlags = dwFlags;
- info.pvarResult = pvarResult;
- info.pexcepinfo = pexcepinfo;
-
- return SEND_THREAD_MESSAGE(this, PHPSE_PARSE_SCRIPT, 0, (LPARAM)&info TSRMLS_CC);
-}
-
-STDMETHODIMP TPHPScriptingEngine::ParseProcedureText(
- /* [in] */ LPCOLESTR pstrCode,
- /* [in] */ LPCOLESTR pstrFormalParams,
- /* [in] */ LPCOLESTR pstrProcedureName,
- /* [in] */ LPCOLESTR pstrItemName,
- /* [in] */ IUnknown *punkContext,
- /* [in] */ LPCOLESTR pstrDelimiter,
- /* [in] */ DWORD dwSourceContextCookie,
- /* [in] */ ULONG ulStartingLineNumber,
- /* [in] */ DWORD dwFlags,
- /* [out] */ IDispatch **ppdisp)
-{
- struct php_active_script_parse_proc_info info;
- HRESULT ret;
- TSRMLS_FETCH();
-
- info.pstrCode = pstrCode;
- info.pstrFormalParams = pstrFormalParams;
- info.pstrProcedureName = pstrProcedureName;
- info.pstrItemName = pstrItemName;
- info.punkContext = punkContext;
- info.pstrDelimiter = pstrDelimiter;
- info.dwSourceContextCookie = dwSourceContextCookie;
- info.ulStartingLineNumber = ulStartingLineNumber;
- info.dwFlags = dwFlags;
-
- ret = SEND_THREAD_MESSAGE(this, PHPSE_PARSE_PROC, 0, (LPARAM)&info TSRMLS_CC);
-
- if (ret == S_OK)
- ret = GIT_get(info.dispcookie, IID_IDispatch, (void**)ppdisp);
-
- trace("ParseProc: ret=%08x disp=%08x\n", ret, *ppdisp);
- return ret;
-}
-
-extern "C"
-void activescript_error_func(int type, const char *error_msg, ...)
-{
- TSRMLS_FETCH();
-
- TPHPScriptingEngine *engine = (TPHPScriptingEngine*)SG(server_context);
-
-
-}
-
-class TActiveScriptError:
- public IActiveScriptError
-{
-protected:
- volatile LONG m_refcount;
-public:
- /* IUnknown */
- STDMETHODIMP QueryInterface(REFIID iid, void **ppvObject) {
- *ppvObject = NULL;
-
- if (IsEqualGUID(IID_IActiveScriptError, iid)) {
- *ppvObject = (IActiveScriptError*)this;
- } else if (IsEqualGUID(IID_IUnknown, iid)) {
- *ppvObject = this;
- }
- if (*ppvObject) {
- AddRef();
- return S_OK;
- }
- return E_NOINTERFACE;
- }
-
- STDMETHODIMP_(DWORD) AddRef(void) {
- return InterlockedIncrement(const_cast<long*> (&m_refcount));
- }
-
- STDMETHODIMP_(DWORD) Release(void) {
- DWORD ret = InterlockedDecrement(const_cast<long*> (&m_refcount));
- trace("Release: errobj refcount=%d\n", ret);
- if (ret == 0)
- delete this;
- return ret;
- }
-
- HRESULT STDMETHODCALLTYPE GetExceptionInfo(
- /* [out] */ EXCEPINFO *pexcepinfo)
- {
- memset(pexcepinfo, 0, sizeof(EXCEPINFO));
- pexcepinfo->bstrDescription = SysAllocString(m_message);
- pexcepinfo->bstrSource = SysAllocString(m_filename);
- pexcepinfo->wCode = 1000;
- return S_OK;
- }
-
- HRESULT STDMETHODCALLTYPE GetSourcePosition(
- /* [out] */ DWORD *pdwSourceContext,
- /* [out] */ ULONG *pulLineNumber,
- /* [out] */ LONG *plCharacterPosition)
- {
- *pdwSourceContext = 0;
- *pulLineNumber = m_lineno;
- *plCharacterPosition = 0;
- return S_OK;
- }
-
- HRESULT STDMETHODCALLTYPE GetSourceLineText(
- /* [out] */ BSTR *pbstrSourceLine)
- {
- *pbstrSourceLine = NULL;
- return E_FAIL;
- }
-
- BSTR m_filename, m_message;
- UINT m_lineno;
-
- TActiveScriptError(const char *filename, const uint lineno, const char *message)
- {
- m_refcount = 0; /* start with zero refcount because this object is passed
- * directly to the script site; it will call addref */
- m_filename = TWideString::bstr_from_ansi((char*)filename);
- m_message = TWideString::bstr_from_ansi((char*)message);
- m_lineno = lineno;
- }
-
- ~TActiveScriptError()
- {
- trace("%08x: cleaning up error object\n", this);
- SysFreeString(m_filename);
- SysFreeString(m_message);
- }
-};
-
-extern "C"
-void activescript_error_handler(int type, const char *error_filename,
- const uint error_lineno, const char *format, va_list args)
-{
- TSRMLS_FETCH();
- char *buf;
- int buflen;
- TPHPScriptingEngine *engine = (TPHPScriptingEngine*)SG(server_context);
-
- buflen = vspprintf(&buf, PG(log_errors_max_len), format, args);
- trace("%08x: Error: %s\n", engine, buf);
-
- /* if it's a fatal error, report it using IActiveScriptError. */
-
- switch(type) {
- case E_ERROR:
- case E_CORE_ERROR:
- case E_COMPILE_ERROR:
- case E_USER_ERROR:
- case E_PARSE:
- /* trigger an error in the host */
- TActiveScriptError *eobj = new TActiveScriptError(error_filename, error_lineno, buf);
- trace("raising error object!\n");
- if (engine->m_pass_eng)
- engine->m_pass_eng->OnScriptError(eobj);
-
- /* now throw the exception to abort execution */
- if (engine->m_err_trap)
- longjmp(*engine->m_err_trap, 1);
-
- break;
- }
- efree(buf);
-}
-
diff --git a/sapi/aolserver/CREDITS b/sapi/aolserver/CREDITS
deleted file mode 100644
index 8f9a4af950..0000000000
--- a/sapi/aolserver/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-AOLserver
-Sascha Schumann
diff --git a/sapi/aolserver/README b/sapi/aolserver/README
deleted file mode 100644
index 0a725a10bc..0000000000
--- a/sapi/aolserver/README
+++ /dev/null
@@ -1,69 +0,0 @@
-AOLserver README ($Id$)
-
-To compile PHP 4.0 as a module for AOLserver, you need:
-
-- installed AOLserver 3.1 or later
- (see the note below for AOLserver 3.0)
-
-NOTE: You should not use this module in production. PHP is not 100% stable
- yet in threaded mode. To increase reliability enable the Global Lock
- by removing #define NO_GLOBAL_LOCK in main/main.c. Also don't use
- php_value as it will lead to races in a sub-system (use an ini file
- instead).
-
-
-1.) Configuring AOLserver
-
-Read doc/install.txt in the source distribution
-
-It usually boils down to changing the INST/PREFIX variable in
-include/Makefile.global and running make all install.
-
-2.) Configuring PHP
-
-$ ./configure \
- --with-aolserver=/path/to/installed/aolserver \
- <other options>
-
-NOTE: If you are still using AOLserver 3.0, you need to retain the
- AOLserver source code and pass another option to PHP:
-
- --with-aolserver-src=/path/to/source/distribution
-
-3.) Compiling and Installing PHP
-
-$ make install
-
-4.) Changing nsd.tcl
-
-a) New section
-
-Add a new section to pass options to PHP (required):
-
-ns_section "ns/server/${servername}/module/php"
-
-You can use the following commands in this section:
-
-The 'map' command will cause AOLserver to pass all requests to *.php to
-the PHP module (can be specified multiple times). Example:
-
-ns_param map *.php
-
-The 'php_value "name val"' command assigns the configuration option name
-the value val (can be used multiple times). Example:
-
-ns_param php_value "session.auto_start 1"
-
-b) Enabling PHP
-
-Then enable the PHP module:
-
-ns_section "ns/server/${servername}/modules"
-...
-ns_param php ${bindir}/libphp4.so
-
-
-=============================================================================
-This has been tested with AOLserver release 3.0.
-
-AOLserver support has been written by Sascha Schumann <sascha@schumann.cx>.
diff --git a/sapi/aolserver/aolserver.c b/sapi/aolserver/aolserver.c
deleted file mode 100644
index 3f414b5ec7..0000000000
--- a/sapi/aolserver/aolserver.c
+++ /dev/null
@@ -1,616 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-/*
- * TODO:
- * - write documentation
- * - CGI/1.1 conformance
- */
-
-/* $Id$ */
-
-/* conflict between PHP and AOLserver headers */
-#define Debug php_Debug
-#include "php.h"
-#undef Debug
-
-#ifdef HAVE_AOLSERVER
-
-#ifndef ZTS
-#error AOLserver module is only useable in thread-safe mode
-#endif
-
-#include "ext/standard/info.h"
-#define SECTION(name) PUTS("<h2>" name "</h2>\n")
-
-#define NS_BUF_SIZE 511
-
-#include "php_ini.h"
-#include "php_globals.h"
-#include "SAPI.h"
-#include "php_main.h"
-#include "php_variables.h"
-
-#include "ns.h"
-
-#include "php_version.h"
-
-/* This symbol is used by AOLserver to tell the API version we expect */
-
-int Ns_ModuleVersion = 1;
-
-#define NSG(v) TSRMG(ns_globals_id, ns_globals_struct *, v)
-
-/* php_ns_context is per-server (thus only once at all) */
-
-typedef struct {
- sapi_module_struct *sapi_module;
- char *ns_server;
- char *ns_module;
-} php_ns_context;
-
-/* ns_globals_struct is per-thread */
-
-typedef struct {
- Ns_Conn *conn;
- size_t data_avail;
-} ns_globals_struct;
-
-/* TSRM id */
-
-static int ns_globals_id;
-
-/* global context */
-
-static php_ns_context *global_context;
-
-static void php_ns_config(php_ns_context *ctx, char global);
-
-/*
- * php_ns_sapi_ub_write() writes data to the client connection.
- */
-
-static int
-php_ns_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- int n;
- uint sent = 0;
-
- while (str_length > 0) {
- n = Ns_ConnWrite(NSG(conn), (void *) str, str_length);
-
- if (n == -1)
- php_handle_aborted_connection();
-
- str += n;
- sent += n;
- str_length -= n;
- }
-
- return sent;
-}
-
-/*
- * php_ns_sapi_header_handler() sets a HTTP reply header to be
- * sent to the client.
- */
-
-static int
-php_ns_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- char *header_name, *header_content;
- char *p;
-
- header_name = sapi_header->header;
- header_content = p = strchr(header_name, ':');
-
- if (p) {
- *p = '\0';
- do {
- header_content++;
- } while (*header_content == ' ');
-
- if (!strcasecmp(header_name, "Content-type")) {
- Ns_ConnSetTypeHeader(NSG(conn), header_content);
- } else {
- Ns_ConnSetHeaders(NSG(conn), header_name, header_content);
- }
-
- *p = ':';
- }
-
- sapi_free_header(sapi_header);
-
- return 0;
-}
-
-/*
- * php_ns_sapi_send_headers() flushes the headers to the client.
- * Called before real content is sent by PHP.
- */
-
-static int
-php_ns_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- if(SG(sapi_headers).send_default_content_type) {
- Ns_ConnSetRequiredHeaders(NSG(conn), "text/html", 0);
- }
-
- Ns_ConnFlushHeaders(NSG(conn), SG(sapi_headers).http_response_code);
-
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-/*
- * php_ns_sapi_read_post() reads a specified number of bytes from
- * the client. Used for POST/PUT requests.
- */
-
-static int
-php_ns_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC)
-{
- uint max_read;
- uint total_read = 0;
-
- max_read = MIN(NSG(data_avail), count_bytes);
-
- total_read = Ns_ConnRead(NSG(conn), buf, max_read);
-
- if(total_read == NS_ERROR) {
- total_read = -1;
- } else {
- NSG(data_avail) -= total_read;
- }
-
- return total_read;
-}
-
-/*
- * php_ns_sapi_read_cookies() returns the Cookie header from
- * the HTTP request header
- */
-
-static char *php_ns_sapi_read_cookies(TSRMLS_D)
-{
- int i;
- char *http_cookie = NULL;
-
- i = Ns_SetIFind(NSG(conn->headers), "cookie");
- if(i != -1) {
- http_cookie = Ns_SetValue(NSG(conn->headers), i);
- }
-
- return http_cookie;
-}
-
-static void php_info_aolserver(ZEND_MODULE_INFO_FUNC_ARGS)
-{
- char buf[512];
- int uptime = Ns_InfoUptime();
- int i;
-
- php_info_print_table_start();
- php_info_print_table_row(2, "SAPI module version", "$Id$");
- php_info_print_table_row(2, "Build date", Ns_InfoBuildDate());
- php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile());
- php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog());
- php_info_print_table_row(2, "Installation path", Ns_InfoHomePath());
- php_info_print_table_row(2, "Hostname of server", Ns_InfoHostname());
- php_info_print_table_row(2, "Source code label", Ns_InfoLabel());
- php_info_print_table_row(2, "Server platform", Ns_InfoPlatform());
- snprintf(buf, 511, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion());
- php_info_print_table_row(2, "Server version", buf);
- snprintf(buf, 511, "%d day(s), %02d:%02d:%02d",
- uptime / 86400,
- (uptime / 3600) % 24,
- (uptime / 60) % 60,
- uptime % 60);
- php_info_print_table_row(2, "Server uptime", buf);
- php_info_print_table_end();
-
- 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", NSG(conn)->request->line);
- for (i = 0; i < Ns_SetSize(NSG(conn)->headers); i++) {
- php_info_print_table_row(2, Ns_SetKey(NSG(conn)->headers, i), Ns_SetValue(NSG(conn)->headers, i));
- }
-
- php_info_print_table_colspan_header(2, "HTTP Response Headers");
- for (i = 0; i < Ns_SetSize(NSG(conn)->outputheaders); i++) {
- php_info_print_table_row(2, Ns_SetKey(NSG(conn)->outputheaders, i), Ns_SetValue(NSG(conn)->outputheaders, i));
- }
- php_info_print_table_end();
-}
-
-PHP_FUNCTION(getallheaders);
-
-static function_entry aolserver_functions[] = {
- PHP_FE(getallheaders, NULL)
- {NULL, NULL, NULL}
-};
-
-static zend_module_entry php_aolserver_module = {
- STANDARD_MODULE_HEADER,
- "AOLserver",
- aolserver_functions,
- NULL,
- NULL,
- NULL,
- NULL,
- php_info_aolserver,
- NULL,
- STANDARD_MODULE_PROPERTIES
-};
-
-PHP_FUNCTION(getallheaders)
-{
- int i;
-
- array_init(return_value);
-
- for (i = 0; i < Ns_SetSize(NSG(conn->headers)); i++) {
- char *key = Ns_SetKey(NSG(conn->headers), i);
- char *value = Ns_SetValue(NSG(conn->headers), i);
-
- add_assoc_string(return_value, key, value, 1);
- }
-}
-
-static int
-php_ns_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, &php_aolserver_module, 1) == FAILURE) {
- return FAILURE;
- } else {
- return SUCCESS;
- }
-}
-
-
-/*
- * php_ns_sapi_register_variables() populates the php script environment
- * with a number of variables. HTTP_* variables are created for
- * the HTTP header data, so that a script can access these.
- */
-
-#define ADD_STRINGX(name, buf) \
- php_register_variable(name, buf, track_vars_array TSRMLS_CC)
-
-#define ADD_STRING(name) \
- ADD_STRINGX(name, buf)
-
-static void
-php_ns_sapi_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- int i;
- char buf[NS_BUF_SIZE + 1];
- char *tmp;
-
- for(i = 0; i < Ns_SetSize(NSG(conn->headers)); i++) {
- char *key = Ns_SetKey(NSG(conn->headers), i);
- char *value = Ns_SetValue(NSG(conn->headers), i);
- char *p;
- char c;
-
- snprintf(buf, NS_BUF_SIZE, "HTTP_%s", key);
-
- for(p = buf + 5; (c = *p); p++) {
- c = toupper(c);
- if(c < 'A' || c > 'Z') {
- c = '_';
- }
- *p = c;
- }
-
- ADD_STRINGX(buf, value);
- }
-
- snprintf(buf, NS_BUF_SIZE, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion());
- ADD_STRING("SERVER_SOFTWARE");
- snprintf(buf, NS_BUF_SIZE, "HTTP/%1.1f", NSG(conn)->request->version);
- ADD_STRING("SERVER_PROTOCOL");
-
- ADD_STRINGX("REQUEST_METHOD", NSG(conn)->request->method);
-
- if(NSG(conn)->request->query)
- ADD_STRINGX("QUERY_STRING", NSG(conn)->request->query);
-
- ADD_STRINGX("SERVER_BUILDDATE", Ns_InfoBuildDate());
-
- ADD_STRINGX("REMOTE_ADDR", Ns_ConnPeer(NSG(conn)));
-
- snprintf(buf, NS_BUF_SIZE, "%d", Ns_ConnPeerPort(NSG(conn)));
- ADD_STRING("REMOTE_PORT");
-
- snprintf(buf, NS_BUF_SIZE, "%d", Ns_ConnPort(NSG(conn)));
- ADD_STRING("SERVER_PORT");
-
- tmp = Ns_ConnHost(NSG(conn));
- if (tmp)
- ADD_STRINGX("SERVER_NAME", tmp);
-
- ADD_STRINGX("PATH_TRANSLATED", SG(request_info).path_translated);
- ADD_STRINGX("REQUEST_URI", SG(request_info).request_uri);
- ADD_STRINGX("PHP_SELF", SG(request_info).request_uri);
-
- ADD_STRINGX("GATEWAY_INTERFACE", "CGI/1.1");
-
- snprintf(buf, NS_BUF_SIZE, "%d", Ns_InfoBootTime());
- ADD_STRING("SERVER_BOOTTIME");
-}
-
-
-
-/* this structure is static (as in "it does not change") */
-
-static sapi_module_struct aolserver_sapi_module = {
- "aolserver",
- "AOLserver",
-
- php_ns_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- php_ns_sapi_ub_write, /* unbuffered write */
- NULL, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error, /* error handler */
-
- php_ns_sapi_header_handler, /* header handler */
- php_ns_sapi_send_headers, /* send headers handler */
- NULL, /* send header handler */
-
- php_ns_sapi_read_post, /* read POST data */
- php_ns_sapi_read_cookies, /* read Cookies */
-
- php_ns_sapi_register_variables,
- NULL, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-/*
- * php_ns_module_main() is called by the per-request handler and
- * "executes" the script
- */
-
-static int
-php_ns_module_main(TSRMLS_D)
-{
- zend_file_handle file_handle;
-
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = SG(request_info).path_translated;
- file_handle.free_filename = 0;
- file_handle.opened_path = NULL;
-
- php_ns_config(global_context, 0);
- if (php_request_startup(TSRMLS_C) == FAILURE) {
- return NS_ERROR;
- }
-
- php_execute_script(&file_handle TSRMLS_CC);
- php_request_shutdown(NULL);
-
- return NS_OK;
-}
-
-/*
- * php_ns_request_ctor() initializes the per-request data structure
- * and fills it with data provided by the web server
- */
-
-static void
-php_ns_request_ctor(TSRMLS_D)
-{
- char *server;
- Ns_DString ds;
- char *root;
- int index;
- char *tmp;
-
- server = Ns_ConnServer(NSG(conn));
-
-#define safe_strdup(x) ((x)?strdup((x)):NULL)
- SG(request_info).query_string = safe_strdup(NSG(conn->request->query));
-
- Ns_DStringInit(&ds);
- Ns_UrlToFile(&ds, server, NSG(conn->request->url));
-
- /* path_translated is the absolute path to the file */
- SG(request_info).path_translated = safe_strdup(Ns_DStringValue(&ds));
- Ns_DStringFree(&ds);
- root = Ns_PageRoot(server);
- SG(request_info).request_uri = strdup(SG(request_info).path_translated + strlen(root));
- SG(request_info).request_method = NSG(conn)->request->method;
- SG(request_info).content_length = Ns_ConnContentLength(NSG(conn));
- index = Ns_SetIFind(NSG(conn)->headers, "content-type");
- SG(request_info).content_type = index == -1 ? NULL :
- Ns_SetValue(NSG(conn)->headers, index);
- SG(sapi_headers).http_response_code = 200;
-
- tmp = Ns_ConnAuthUser(NSG(conn));
- if (tmp)
- tmp = estrdup(tmp);
- SG(request_info).auth_user = tmp;
-
- tmp = Ns_ConnAuthPasswd(NSG(conn));
- if (tmp)
- tmp = estrdup(tmp);
- SG(request_info).auth_password = tmp;
-
- NSG(data_avail) = SG(request_info).content_length;
-}
-
-/*
- * php_ns_request_dtor() destroys all data associated with
- * the per-request structure
- */
-
-static void
-php_ns_request_dtor(TSRMLS_D)
-{
- free(SG(request_info).path_translated);
- if (SG(request_info).query_string)
- free(SG(request_info).query_string);
- free(SG(request_info).request_uri);
-}
-
-/*
- * The php_ns_request_handler() is called per request and handles
- * everything for one request.
- */
-
-static int
-php_ns_request_handler(void *context, Ns_Conn *conn)
-{
- int status = NS_OK;
- TSRMLS_FETCH();
-
- NSG(conn) = conn;
-
- SG(server_context) = global_context;
-
- php_ns_request_ctor(TSRMLS_C);
-
- status = php_ns_module_main(TSRMLS_C);
-
- php_ns_request_dtor(TSRMLS_C);
-
- return status;
-}
-
-/*
- * php_ns_config() fetches the configuration data.
- *
- * It understands the "map" and "php_value" command.
- */
-
-static void
-php_ns_config(php_ns_context *ctx, char global)
-{
- int i;
- char *path;
- Ns_Set *set;
-
- path = Ns_ConfigGetPath(ctx->ns_server, ctx->ns_module, NULL);
- set = Ns_ConfigGetSection(path);
-
- for (i = 0; set && i < Ns_SetSize(set); i++) {
- char *key = Ns_SetKey(set, i);
- char *value = Ns_SetValue(set, i);
-
- if (global && !strcasecmp(key, "map")) {
- Ns_Log(Notice, "Registering PHP for \"%s\"", value);
- Ns_RegisterRequest(ctx->ns_server, "GET", value, php_ns_request_handler, NULL, ctx, 0);
- Ns_RegisterRequest(ctx->ns_server, "POST", value, php_ns_request_handler, NULL, ctx, 0);
- Ns_RegisterRequest(ctx->ns_server, "HEAD", value, php_ns_request_handler, NULL, ctx, 0);
-
- /*
- * Deactivated for now. The ini system will cause random crashes when
- * accessed from here (since there are no locks to protect the global
- * known_directives)
- */
-
- } else if (!global && !strcasecmp(key, "php_value")) {
- Ns_Log(Notice, "php_value has been deactivated temporarily. Please use a php.ini file to pass directives to PHP. Thanks.");
-#if 0
- char *val;
-
- val = strchr(value, ' ');
- if (val) {
- char *new_key;
-
- new_key = estrndup(value, val - value);
-
- do {
- val++;
- } while(*val == ' ');
-
- Ns_Log(Debug, "PHP configuration option '%s=%s'", new_key, val);
- zend_alter_ini_entry(new_key, strlen(new_key) + 1, val,
- strlen(val) + 1, PHP_INI_SYSTEM, PHP_INI_STAGE_RUNTIME);
-
- efree(new_key);
- }
-#endif
- }
-
- }
-}
-
-/*
- * php_ns_server_shutdown() performs the last steps before the
- * server exits. Shutdowns basic services and frees memory
- */
-
-static void
-php_ns_server_shutdown(void *context)
-{
- php_ns_context *ctx = (php_ns_context *) context;
-
- ctx->sapi_module->shutdown(ctx->sapi_module);
- sapi_shutdown();
- tsrm_shutdown();
-
- free(ctx->ns_module);
- free(ctx->ns_server);
- free(ctx);
-}
-
-/*
- * Ns_ModuleInit() is called by AOLserver once at startup
- *
- * This functions allocates basic structures and initializes
- * basic services.
- */
-
-int Ns_ModuleInit(char *server, char *module)
-{
- php_ns_context *ctx;
-
- tsrm_startup(1, 1, 0, NULL);
- sapi_startup(&aolserver_sapi_module);
- sapi_module.startup(&aolserver_sapi_module);
-
- /* TSRM is used to allocate a per-thread structure */
- ts_allocate_id(&ns_globals_id, sizeof(ns_globals_struct), NULL, NULL);
-
- /* the context contains data valid for all threads */
- ctx = malloc(sizeof *ctx);
- ctx->sapi_module = &aolserver_sapi_module;
- ctx->ns_server = strdup(server);
- ctx->ns_module = strdup(module);
-
- /* read the configuration */
- php_ns_config(ctx, 1);
-
- global_context = ctx;
-
- /* register shutdown handler */
- Ns_RegisterServerShutdown(server, php_ns_server_shutdown, ctx);
-
- return NS_OK;
-}
-
-#endif
diff --git a/sapi/aolserver/config.m4 b/sapi/aolserver/config.m4
deleted file mode 100644
index 2c905af2cc..0000000000
--- a/sapi/aolserver/config.m4
+++ /dev/null
@@ -1,33 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for AOLserver support)
-AC_ARG_WITH(aolserver,
-[ --with-aolserver=DIR Specify path to the installed AOLserver],[
- PHP_AOLSERVER=$withval
-],[
- PHP_AOLSERVER=no
-])
-AC_MSG_RESULT($PHP_AOLSERVER)
-
-if test "$PHP_AOLSERVER" != "no"; then
- if test -d "$PHP_AOLSERVER/include"; then
- PHP_AOLSERVER_SRC=$PHP_AOLSERVER
- fi
- if test -z "$PHP_AOLSERVER_SRC" || test ! -d $PHP_AOLSERVER_SRC/include; then
- AC_MSG_ERROR(Please specify the path to the source distribution of AOLserver using --with-aolserver-src=DIR)
- fi
- if test ! -d $PHP_AOLSERVER/bin ; then
- AC_MSG_ERROR(Please specify the path to the root of AOLserver using --with-aolserver=DIR)
- fi
- PHP_BUILD_THREAD_SAFE
- PHP_ADD_INCLUDE($PHP_AOLSERVER_SRC/include)
- AC_DEFINE(HAVE_AOLSERVER,1,[Whether you have AOLserver])
- PHP_SELECT_SAPI(aolserver, shared, aolserver.c)
- INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PHP_AOLSERVER/bin/"
-fi
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
diff --git a/sapi/aolserver/php.sym b/sapi/aolserver/php.sym
deleted file mode 100644
index b401ffd2b3..0000000000
--- a/sapi/aolserver/php.sym
+++ /dev/null
@@ -1,2 +0,0 @@
-Ns_ModuleVersion
-Ns_ModuleInit
diff --git a/sapi/aolserver/php4aolserver.dsp b/sapi/aolserver/php4aolserver.dsp
deleted file mode 100644
index 1d5a79598c..0000000000
--- a/sapi/aolserver/php4aolserver.dsp
+++ /dev/null
@@ -1,135 +0,0 @@
-# Microsoft Developer Studio Project File - Name="php4aolserver" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php4aolserver - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "php4aolserver.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 "php4aolserver.mak" CFG="php4aolserver - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php4aolserver - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4aolserver - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4aolserver - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "php4aolserver - 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 "PHP4AOLSERVER_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /I "..\..\..\php_build\nsapi30\include\\" /I "..\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\tsrm" /D ZEND_DEBUG=0 /D "NDEBUG" /D "PHP4AOLSERVER_EXPORTS" /D "PHP_WIN32" /D "ZTS" /D "ZEND_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "WIN32" /D "_MBCS" /D "HAVE_AOLSERVER" /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 nsd.lib php4ts.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:"0x62000000" /version:4.0 /dll /machine:I386 /out:"../../Release_TS/php4aolserver.so" /libpath:"..\..\..\php_build\nsapi30\lib\\" /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS"
-
-!ELSEIF "$(CFG)" == "php4aolserver - 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 "PHP4AOLSERVER_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /I "..\..\..\php_build\nsapi30\include\\" /I "..\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\tsrm" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "NDEBUG" /D "PHPAOLSERVER_EXPORTS" /D "PHP_WIN32" /D "ZTS" /D "ZEND_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "WIN32" /D "_MBCS" /D "HAVE_AOLSERVER" /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 nsd.lib php4ts.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:"0x62000000" /version:4.0 /dll /machine:I386 /out:"../../Release_TS_inline/php4aolserver.so" /libpath:"..\..\..\php_build\nsapi30\lib\\" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"
-
-!ELSEIF "$(CFG)" == "php4aolserver - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4AOLSERVER_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /I "..\..\..\php_build\nsapi30\include\\" /I "..\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\tsrm" /D "_DEBUG" /D ZEND_DEBUG=1 /D "PHP4AOLSERVER_EXPORTS" /D "PHP_WIN32" /D "ZTS" /D "ZEND_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "WIN32" /D "_MBCS" /D "HAVE_AOLSERVER" /FR /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 nsd.lib php4ts_debug.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:"0x62000000" /version:4.0 /dll /debug /machine:I386 /out:"..\..\Debug_TS/php4aolserver.so" /pdbtype:sept /libpath:"..\..\..\php_build\nsapi30\lib\\" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php4aolserver - Win32 Release_TS"
-# Name "php4aolserver - Win32 Release_TS_inline"
-# Name "php4aolserver - Win32 Debug_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\aolserver.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# 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/CREDITS b/sapi/apache/CREDITS
deleted file mode 100644
index 991deb5633..0000000000
--- a/sapi/apache/CREDITS
+++ /dev/null
@@ -1,3 +0,0 @@
-Apache 1.3
-Rasmus Lerdorf, Zeev Suraski, Stig Bakken, David Sklar
-
diff --git a/sapi/apache/apMakefile.libdir b/sapi/apache/apMakefile.libdir
deleted file mode 100644
index 7b5254013a..0000000000
--- a/sapi/apache/apMakefile.libdir
+++ /dev/null
@@ -1,4 +0,0 @@
-This is a place-holder which indicates to Configure that it shouldn't
-provide the default targets when building the Makefile in this directory.
-Instead it'll just prepend all the important variable definitions, and
-copy the Makefile.tmpl onto the end.
diff --git a/sapi/apache/apMakefile.tmpl b/sapi/apache/apMakefile.tmpl
deleted file mode 100644
index 80fe346561..0000000000
--- a/sapi/apache/apMakefile.tmpl
+++ /dev/null
@@ -1,77 +0,0 @@
-##
-## Apache 1.3 Makefile template for PHP 4.0 Module
-## [src/modules/php4/Makefile.tmpl]
-##
-
-# the parametrized target
-LIB=libphp4.$(LIBEXT)
-
-# objects for building the static library
-OBJS=mod_php4.o
-OBJS_LIB=libmodphp4.a
-
-# objects for building the shared object library
-SHLIB_OBJS=mod_php4.so-o
-SHLIB_OBJS_LIB=libmodphp4.a
-
-# the general targets
-all: lib
-lib: $(LIB)
-
-# build the static library by merging the object files
-libphp4.a: $(OBJS) $(OBJS_LIB)
- cp $(OBJS_LIB) $@
- ar r $@ $(OBJS)
- $(RANLIB) $@
-
-# ugly hack to support older Apache-1.3 betas that don't set $LIBEXT
-libphp4.: $(OBJS) $(OBJS_LIB)
- cp $(OBJS_LIB) $@
- ar r $@ $(OBJS)
- $(RANLIB) $@
- cp libphp4. libphp4.a
-
-# build the shared object library by linking the object files
-libphp4.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB)
- rm -f $@
- $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) $(LIBS) $(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_php4.o: mod_php4.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \
- $(INCDIR)/buff.h \
- $(INCDIR)/http_config.h \
- $(INCDIR)/http_core.h $(INCDIR)/http_main.h \
- $(INCDIR)/http_protocol.h $(INCDIR)/http_request.h \
- $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php4.h
diff --git a/sapi/apache/config.m4 b/sapi/apache/config.m4
deleted file mode 100644
index 9fb54cf033..0000000000
--- a/sapi/apache/config.m4
+++ /dev/null
@@ -1,268 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for Apache 1.x module support via DSO through APXS)
-AC_ARG_WITH(apxs,
-[ --with-apxs[=FILE] Build shared Apache 1.x module. FILE is the optional
- pathname to the Apache apxs tool; defaults to "apxs".],[
- if test "$withval" = "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($withval, 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
- 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/libphp4.so
- build_type=bundle
- ;;
- *)
- build_type=shared
- ;;
- esac
-
- PHP_SELECT_SAPI(apache, $build_type, sapi_apache.c mod_php4.c php_apache.c, $APACHE_CPPFLAGS -I$APXS_INCLUDEDIR)
-
- # Test whether apxs support -S option
- $APXS -q -S CFLAGS="$APXS_CFLAGS" CFLAGS >/dev/null 2>&1
-
- if test "$?" != "0"; then
- APACHE_INSTALL="$APXS -i -a -n php4 $SAPI_SHARED" # Old apxs does not have -S option
- else
- APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR`
- if test -z `$APXS -q SYSCONFDIR`; then
- APACHE_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \
- $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \
- -i -n php4 $SAPI_SHARED"
- else
- APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR`
- APACHE_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \
- \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \
- $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \
- -S SYSCONFDIR='$APXS_SYSCONFDIR' \
- -i -a -n php4 $SAPI_SHARED"
- fi
- fi
-
- if test -z "`$APXS -q LD_SHLIB`" || test "`$APXS -q LIBEXECDIR`" = "modules"; then
- PHP_APXS_BROKEN=yes
- fi
- STRONGHOLD=
- AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
- AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
- AC_DEFINE(HAVE_APACHE,1,[ ])
- AC_MSG_RESULT(yes)
-],[
- AC_MSG_RESULT(no)
-])
-
-if test "$PHP_SAPI" != "apache"; then
-AC_MSG_CHECKING(for Apache 1.x module support)
-AC_ARG_WITH(apache,
-[ --with-apache[=DIR] Build Apache 1.x module. DIR is the top-level Apache
- build directory, defaults to /usr/local/apache.],[
-
- APACHE_INSTALL_FILES="\$(srcdir)/sapi/apache/mod_php4.* sapi/apache/libphp4.module"
-
- if test "$withval" = "yes"; then
- # Apache's default directory
- withval=/usr/local/apache
- fi
- if test "$withval" != "no"; then
- AC_DEFINE(HAVE_APACHE,1,[ ])
- APACHE_MODULE=yes
- PHP_EXPAND_PATH($withval, withval)
- # For Apache 1.2.x
- if test -f $withval/src/httpd.h; then
- APACHE_INCLUDE=-I$withval/src
- APACHE_TARGET=$withval/src
- PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php4.c php_apache.c, $APACHE_INCLUDE)
- APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_INSTALL_FILES $APACHE_TARGET"
- PHP_LIBS="-L. -lphp3"
- AC_MSG_RESULT(yes - Apache 1.2.x)
- STRONGHOLD=
- if test -f $withval/src/ap_config.h; then
- AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
- fi
- # For Apache 2.0.x
- elif test -f $withval/include/httpd.h &&
- test -f $withval/srclib/apr/include/apr_general.h ; then
- AC_MSG_ERROR([Use --with-apache2 with Apache 2.x!])
- # For Apache 1.3.x
- elif test -f $withval/src/main/httpd.h; then
- APACHE_HAS_REGEX=1
- APACHE_INCLUDE="-I$withval/src/main -I$withval/src/os/unix -I$withval/src/ap"
- APACHE_TARGET=$withval/src/modules/php4
- if test ! -d $APACHE_TARGET; then
- mkdir $APACHE_TARGET
- fi
- PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php4.c php_apache.c, $APACHE_INCLUDE)
- APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp4.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache/apMakefile.libdir $APACHE_TARGET/Makefile.libdir"
- PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4"
- AC_MSG_RESULT(yes - Apache 1.3.x)
- STRONGHOLD=
- if test -f $withval/src/include/ap_config.h; then
- AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
- fi
- if test -f $withval/src/include/ap_compat.h; then
- AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
- if test ! -f $withval/src/include/ap_config_auto.h; then
- AC_MSG_ERROR(Please run Apache\'s configure or src/Configure program once and try again)
- fi
- else
- if test -f $withval/src/include/compat.h; then
- AC_DEFINE(HAVE_OLD_COMPAT_H,1,[ ])
- fi
- fi
- # Also for Apache 1.3.x
- elif test -f $withval/src/include/httpd.h; then
- APACHE_HAS_REGEX=1
- APACHE_INCLUDE="-I$withval/src/include -I$withval/src/os/unix"
- APACHE_TARGET=$withval/src/modules/php4
- if test ! -d $APACHE_TARGET; then
- mkdir $APACHE_TARGET
- fi
- PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php4.c php_apache.c, $APACHE_INCLUDE)
- PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4"
- APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp4.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache/apMakefile.libdir $APACHE_TARGET/Makefile.libdir"
- AC_MSG_RESULT(yes - Apache 1.3.x)
- STRONGHOLD=
- if test -f $withval/src/include/ap_config.h; then
- AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
- fi
- if test -f $withval/src/include/ap_compat.h; then
- AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
- if test ! -f $withval/src/include/ap_config_auto.h; then
- AC_MSG_ERROR(Please run Apache\'s configure or src/Configure program once and try again)
- fi
- else
- if test -f $withval/src/include/compat.h; then
- AC_DEFINE(HAVE_OLD_COMPAT_H,1,[ ])
- fi
- fi
- # For StrongHold 2.2
- elif test -f $withval/apache/httpd.h; then
- APACHE_INCLUDE=-"I$withval/apache -I$withval/ssl/include"
- APACHE_TARGET=$withval/apache
- PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php4.c php_apache.c, $APACHE_INCLUDE)
- PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4"
- APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp4.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET"
- STRONGHOLD=-DSTRONGHOLD=1
- AC_MSG_RESULT(yes - StrongHold)
- if test -f $withval/apache/ap_config.h; then
- AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
- fi
- if test -f $withval/src/ap_compat.h; then
- AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
- if test ! -f $withval/src/include/ap_config_auto.h; then
- AC_MSG_ERROR(Please run Apache\'s configure or src/Configure program once and try again)
- fi
- else
- if test -f $withval/src/compat.h; then
- AC_DEFINE(HAVE_OLD_COMPAT_H,1,[ ])
- fi
- fi
- else
- AC_MSG_RESULT(no)
- AC_MSG_ERROR(Invalid Apache directory - unable to find httpd.h under $withval)
- fi
- else
- AC_MSG_RESULT(no)
- fi
-],[
- AC_MSG_RESULT(no)
-])
-
-fi
-
-if test "x$APXS" != "x" -a "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then
- APXS_EXP=-bE:sapi/apache/mod_php4.exp
-fi
-
-PHP_SUBST(APXS_EXP)
-PHP_SUBST(APACHE_INCLUDE)
-PHP_SUBST(APACHE_TARGET)
-PHP_SUBST(APXS)
-PHP_SUBST(APXS_LDFLAGS)
-PHP_SUBST(APACHE_INSTALL)
-PHP_SUBST(STRONGHOLD)
-
-AC_CACHE_CHECK([for member fd in BUFF *],ac_cv_php_fd_in_buff,[
- save=$CPPFLAGS
- CPPFLAGS="$CPPFLAGS $APACHE_INCLUDE"
- 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
-
-AC_MSG_CHECKING(for mod_charset compatibility option)
-AC_ARG_WITH(mod_charset,
-[ --with-mod_charset Enable transfer tables for mod_charset (Rus Apache).],
-[
- AC_MSG_RESULT(yes)
- AC_DEFINE(USE_TRANSFER_TABLES,1,[ ])
-],[
- AC_MSG_RESULT(no)
-])
-
-if test -n "$APACHE_MODULE"; then
- PHP_TARGET_RDYNAMIC
- $php_shtool mkdir -p sapi/apache
- PHP_OUTPUT(sapi/apache/libphp4.module)
-fi
-
-if test -n "$APACHE_INSTALL"; then
- INSTALL_IT=$APACHE_INSTALL
-fi
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
diff --git a/sapi/apache/libphp4.module.in b/sapi/apache/libphp4.module.in
deleted file mode 100644
index 429c566fad..0000000000
--- a/sapi/apache/libphp4.module.in
+++ /dev/null
@@ -1,11 +0,0 @@
-Name: php4_module
-ConfigStart
- RULE_WANTHSREGEX=no
- RULE_HIDE=yes
- PHP_LIBS="@NATIVE_RPATHS@ @PHP_LDFLAGS@ @PHP_LIBS@ @EXTRA_LDFLAGS@ @EXTRA_LIBS@ $LIBS"
- PHP_CFLAGS="$CFLAGS @OPENSSL_INCDIR_OPT@ -I@php_abs_top_builddir@/main -I@php_abs_top_builddir@/Zend -I@php_abs_top_builddir@/TSRM -I@php_abs_top_srcdir@ -I@php_abs_top_srcdir@/sapi/apache -I@php_abs_top_srcdir@/main -I@php_abs_top_srcdir@/Zend -I@php_abs_top_srcdir@/TSRM"
- my_outfile="Makefile.config"
- echo "PHP_CFLAGS=$PHP_CFLAGS" >>$my_outfile
- echo "PHP_LIBS=$PHP_LIBS" >>$my_outfile
- LIBS=$PHP_LIBS
-ConfigEnd
diff --git a/sapi/apache/libpre.c b/sapi/apache/libpre.c
deleted file mode 100644
index 0692cb5410..0000000000
--- a/sapi/apache/libpre.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifdef NETWARE
-
-/* ------------------------------------------------------------------
- * These functions are to be called when the shared NLM starts and
- * stops. By using these functions instead of defining a main()
- * and calling ExitThread(TSR_THREAD, 0), the load time of the
- * shared NLM is faster and memory size reduced.
- *
- * You may also want to override these in your own Apache module
- * to do any cleanup other than the mechanism Apache modules provide.
- * ------------------------------------------------------------------
- */
-
-
-#ifdef __GNUC__
-#include <string.h> /* memset */
-extern char _edata, _end ; /* end of DATA (start of BSS), end of BSS */
-#endif
-
-int _lib_start()
-{
-/* printf("Inside _lib_start\n");*/
-#ifdef __GNUC__
- memset (&_edata, 0, &_end - &_edata);
-#endif
- return 0;
-}
-
-int _lib_stop()
-{
-/* printf("Inside _lib_stop\n");*/
- return 0;
-}
-
-#endif /* NETWARE */
diff --git a/sapi/apache/mod_php4.c b/sapi/apache/mod_php4.c
deleted file mode 100644
index 64e19b4d32..0000000000
--- a/sapi/apache/mod_php4.c
+++ /dev/null
@@ -1,966 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@php.net> |
- | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> |
- | PHP 4.0 patches by Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include "php_apache_http.h"
-#include "http_conf_globals.h"
-
-#ifdef NETWARE
-#define SIGPIPE SIGINT
-#endif
-
-#if defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING)
-#include "ext/mbstring/mbstring.h"
-#endif /* defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) */
-
-#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_headers_struct *sapi_headers TSRMLS_DC);
-static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC);
-static int send_php(request_rec *r, int display_source_mode, char *filename);
-static int send_parsed_php(request_rec * r);
-static int send_parsed_php_source(request_rec * r);
-static int php_xbithack_handler(request_rec * r);
-static void php_init_handler(server_rec *s, pool *p);
-/* }}} */
-
-#if MODULE_MAGIC_NUMBER >= 19970728
-static void php_child_exit_handler(server_rec *s, pool *p);
-#endif
-
-#if MODULE_MAGIC_NUMBER > 19961007
-#define CONST_PREFIX const
-#else
-#define CONST_PREFIX
-#endif
-static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
-static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
-static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
-static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
-static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
-static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
-
-/* ### these should be defined in mod_php4.h or somewhere else */
-#define USE_PATH 1
-#define IGNORE_URL 2
-
-module MODULE_VAR_EXPORT php4_module;
-
-int saved_umask;
-static unsigned char apache_php_initialized;
-
-typedef struct _php_per_dir_entry {
- char *key;
- char *value;
- uint key_length;
- uint value_length;
- int type;
-} php_per_dir_entry;
-
-/* some systems are missing these from their header files */
-
-/* {{{ php_save_umask
- */
-static void php_save_umask(void)
-{
- saved_umask = umask(077);
- umask(saved_umask);
-}
-/* }}} */
-
-/* {{{ sapi_apache_ub_write
- */
-static int sapi_apache_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- int ret=0;
-
- if (SG(server_context)) {
- ret = rwrite(str, str_length, (request_rec *) SG(server_context));
- }
- if (ret != str_length) {
- php_handle_aborted_connection();
- }
- return ret;
-}
-/* }}} */
-
-/* {{{ sapi_apache_flush
- */
-static void sapi_apache_flush(void *server_context)
-{
- if (server_context) {
-#if MODULE_MAGIC_NUMBER > 19970110
- rflush((request_rec *) server_context);
-#else
- bflush((request_rec *) server_context->connection->client);
-#endif
- }
-}
-/* }}} */
-
-/* {{{ sapi_apache_read_post
- */
-static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
- 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_headers_struct *sapi_headers TSRMLS_DC)
-{
- char *header_name, *header_content, *p;
- request_rec *r = (request_rec *) SG(server_context);
- if(!r) {
- efree(sapi_header->header);
- return 0;
- }
-
- header_name = sapi_header->header;
-
- header_content = p = strchr(header_name, ':');
- if (!p) {
- efree(sapi_header->header);
- 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 (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 */
-
- efree(sapi_header->header);
-
- return 0; /* don't use the default SAPI mechanism, Apache duplicates this functionality */
-}
-/* }}} */
-
-/* {{{ 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;
- send_http_header((request_rec *) SG(server_context));
- 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 = empty_string;
- }
- 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 if (PG(register_globals)) {
- /* should never happen nowadays */
- symbol_table = EG(active_symbol_table);
- } 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_FETCH();
-
- if (SG(server_context)) {
-#if MODULE_MAGIC_NUMBER >= 19970831
- aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, "%s", message);
-#else
- log_error(message, ((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();
-
- php_output_set_status(0 TSRMLS_CC);
- if (AP(in_request)) {
- AP(in_request) = 0;
- php_request_shutdown(dummy);
- }
- SG(server_context) = NULL;
- /*
- * The server context (request) is NOT invalid by the time
- * run_cleanups() is called
- */
-}
-/* }}} */
-
-/* {{{ php_apache_sapi_activate
- */
-static int php_apache_sapi_activate(TSRMLS_D)
-{
- request_rec *r = (request_rec *) SG(server_context);
-
- /*
- * For the Apache module version, this bit of code registers a cleanup
- * function that gets triggered when our request pool is destroyed.
- * We need this because at any point in our code we can be interrupted
- * and that may happen before we have had time to free our memory.
- * The php_request_shutdown function needs to free all outstanding allocated
- * memory.
- */
- block_alarms();
- register_cleanup(r->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec);
- AP(in_request)=1;
- unblock_alarms();
-
- /* Override the default headers_only value - sometimes "GET" requests should actually only
- * send headers.
- */
- SG(request_info).headers_only = r->header_only;
- return SUCCESS;
-}
-/* }}} */
-
-/* {{{ php_apache_get_stat
- */
-static struct stat *php_apache_get_stat(TSRMLS_D)
-{
- return &((request_rec *) SG(server_context))->finfo;
-}
-/* }}} */
-
-/* {{{ php_apache_getenv
- */
-static char *php_apache_getenv(char *name, size_t name_len TSRMLS_DC)
-{
- return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, name);
-}
-/* }}} */
-
-/* {{{ sapi_apache_get_fd
- */
-static int sapi_apache_get_fd(int *nfd TSRMLS_DC)
-{
-#if PHP_APACHE_HAVE_CLIENT_FD
- request_rec *r = SG(server_context);
- int fd;
-
- fd = r->connection->client->fd;
-
- if (fd >= 0) {
- if (nfd) *nfd = fd;
- return SUCCESS;
- }
-#endif
- return FAILURE;
-}
-/* }}} */
-
-/* {{{ sapi_apache_force_http_10
- */
-static int sapi_apache_force_http_10(TSRMLS_D)
-{
- request_rec *r = SG(server_context);
-
- r->proto_num = HTTP_VERSION(1,0);
-
- return SUCCESS;
-}
-
-/* {{{ sapi_apache_get_target_uid
- */
-static int sapi_apache_get_target_uid(uid_t *obj TSRMLS_DC)
-{
- *obj = ap_user_id;
- return SUCCESS;
-}
-
-/* {{{ sapi_apache_get_target_gid
- */
-static int sapi_apache_get_target_gid(gid_t *obj TSRMLS_DC)
-{
- *obj = ap_group_id;
- return SUCCESS;
-}
-
-/* {{{ 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, /* 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 */
- sapi_apache_get_fd,
- sapi_apache_force_http_10,
- sapi_apache_get_target_uid,
- sapi_apache_get_target_gid
-};
-/* }}} */
-
-/* {{{ php_restore_umask
- */
-static void php_restore_umask(void)
-{
- umask(saved_umask);
-}
-/* }}} */
-
-/* {{{ init_request_info
- */
-static void init_request_info(TSRMLS_D)
-{
- request_rec *r = ((request_rec *) SG(server_context));
- char *content_length = (char *) table_get(r->subprocess_env, "CONTENT_LENGTH");
- const char *authorization=NULL;
- char *tmp;
-
- SG(request_info).query_string = r->args;
- SG(request_info).path_translated = r->filename;
- SG(request_info).request_uri = r->uri;
- SG(request_info).request_method = (char *)r->method;
- SG(request_info).content_type = (char *) table_get(r->subprocess_env, "CONTENT_TYPE");
- SG(request_info).content_length = (content_length ? atoi(content_length) : 0);
- SG(sapi_headers).http_response_code = r->status;
-
- if (r->headers_in) {
- authorization = table_get(r->headers_in, "Authorization");
- }
- if (authorization
- && (!PG(safe_mode) || (PG(safe_mode) && !auth_type(r)))
- && !strcasecmp(getword(r->pool, &authorization, ' '), "Basic")) {
- tmp = uudecode(r->pool, authorization);
- SG(request_info).auth_user = getword_nulls_nc(r->pool, &tmp, ':');
- if (SG(request_info).auth_user) {
- r->connection->user = pstrdup(r->connection->pool, SG(request_info).auth_user);
- r->connection->ap_auth_type = "Basic";
- SG(request_info).auth_user = estrdup(SG(request_info).auth_user);
- }
- SG(request_info).auth_password = tmp;
- if (SG(request_info).auth_password) {
- SG(request_info).auth_password = estrdup(SG(request_info).auth_password);
- }
- } else {
- SG(request_info).auth_user = NULL;
- SG(request_info).auth_password = NULL;
- }
-}
-/* }}} */
-
-/* {{{ 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;
- HashTable *per_dir_conf;
- TSRMLS_FETCH();
-
- if (AP(in_request)) {
- zend_file_handle fh;
-
- fh.filename = r->filename;
- fh.opened_path = NULL;
- fh.free_filename = 0;
- fh.type = ZEND_HANDLE_FILENAME;
-
-#if defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING)
- php_mb_set_zend_encoding(TSRMLS_C);
-#endif /* defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) */
-
- 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 = (HashTable *) get_module_config(r->per_dir_config, &php4_module);
- if (per_dir_conf) {
- zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC);
- }
-
- /* If PHP parser engine has been turned off with an "engine off"
- * directive, then decline to handle this request
- */
- if (!AP(engine)) {
- r->content_type = php_apache_get_default_mimetype(r TSRMLS_CC);
- 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();
- 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);
-
-#if MEMORY_LIMIT
- {
- char *mem_usage;
- TSRMLS_FETCH();
-
- mem_usage = ap_psprintf(r->pool, "%u", AG(allocated_memory_peak));
- AG(allocated_memory_peak) = 0;
- ap_table_setn(r->notes, "mod_php_memory_usage", mem_usage);
- }
-#endif
-
- 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_dir_info
- */
-static void php_destroy_per_dir_info(HashTable *per_dir_info)
-{
- zend_hash_destroy(per_dir_info);
- free(per_dir_info);
-}
-/* }}} */
-
-/* {{{ php_create_dir
- */
-static void *php_create_dir(pool *p, char *dummy)
-{
- HashTable *per_dir_info;
-
- per_dir_info = (HashTable *) malloc(sizeof(HashTable));
- zend_hash_init_ex(per_dir_info, 5, NULL, (void (*)(void *)) destroy_per_dir_entry, 1, 0);
- register_cleanup(p, (void *) per_dir_info, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) zend_hash_destroy);
-
- return per_dir_info;
-}
-/* }}} */
-
-/* {{{ php_merge_dir
- */
-static void *php_merge_dir(pool *p, void *basev, void *addv)
-{
- /* This function *must* return addv, and not modify basev */
- zend_hash_merge_ex((HashTable *) addv, (HashTable *) basev, (copy_ctor_func_t) copy_per_dir_entry, sizeof(php_per_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL);
- return addv;
-}
-/* }}} */
-
-/* {{{ 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;
-}
-/* }}} */
-
-/* {{{ php_apache_value_handler
- */
-static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2)
-{
- return php_apache_value_handler_ex(cmd, conf, arg1, arg2, PHP_INI_PERDIR);
-}
-/* }}} */
-
-/* {{{ php_apache_admin_value_handler
- */
-static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2)
-{
- return php_apache_value_handler_ex(cmd, conf, arg1, arg2, PHP_INI_SYSTEM);
-}
-/* }}} */
-
-/* {{{ php_apache_flag_handler_ex
- */
-static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode)
-{
- char bool_val[2];
-
- if (!strcasecmp(arg2, "On") || (arg2[0] == '1' && arg2[1] == '\0')) {
- bool_val[0] = '1';
- } else {
- bool_val[0] = '0';
- }
- bool_val[1] = 0;
-
- return php_apache_value_handler_ex(cmd, conf, arg1, bool_val, mode);
-}
-/* }}} */
-
-/* {{{ php_apache_flag_handler
- */
-static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2)
-{
- return php_apache_flag_handler_ex(cmd, conf, arg1, arg2, PHP_INI_PERDIR);
-}
-/* }}} */
-
-/* {{{ php_apache_admin_flag_handler
- */
-static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2)
-{
- return php_apache_flag_handler_ex(cmd, conf, arg1, arg2, PHP_INI_SYSTEM);
-}
-/* }}} */
-
-/* {{{ int php_xbithack_handler(request_rec * r)
- */
-static int php_xbithack_handler(request_rec * r)
-{
- HashTable *per_dir_conf;
- TSRMLS_FETCH();
-
- if (!(r->finfo.st_mode & S_IXUSR)) {
- r->allowed |= (1 << METHODS) - 1;
- return DECLINED;
- }
- per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php4_module);
- if (per_dir_conf) {
- zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC);
- }
- if(!AP(xbithack)) {
- r->allowed |= (1 << METHODS) - 1;
- return DECLINED;
- }
- return send_parsed_php(r);
-}
-/* }}} */
-
-/* {{{ apache_php_module_shutdown_wrapper
- */
-static void apache_php_module_shutdown_wrapper(void)
-{
- apache_php_initialized = 0;
- apache_sapi_module.shutdown(&apache_sapi_module);
-
-#if MODULE_MAGIC_NUMBER >= 19970728
- /* This function is only called on server exit if the apache API
- * child_exit handler exists, so shutdown globally
- */
- sapi_shutdown();
-#endif
-
-#ifdef ZTS
- tsrm_shutdown();
-#endif
-}
-/* }}} */
-
-#if MODULE_MAGIC_NUMBER >= 19970728
-/* {{{ php_child_exit_handler
- */
-static void php_child_exit_handler(server_rec *s, pool *p)
-{
-/* apache_php_initialized = 0; */
- apache_sapi_module.shutdown(&apache_sapi_module);
-
-#ifdef ZTS
- tsrm_shutdown();
-#endif
-}
-/* }}} */
-#endif
-
-/* {{{ void php_init_handler(server_rec *s, pool *p)
- */
-static void php_init_handler(server_rec *s, pool *p)
-{
- register_cleanup(p, NULL, (void (*)(void *))apache_php_module_shutdown_wrapper, (void (*)(void *))php_module_shutdown_for_exec);
- if (!apache_php_initialized) {
- apache_php_initialized = 1;
-#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
-#endif
- sapi_startup(&apache_sapi_module);
- php_apache_startup(&apache_sapi_module);
- }
-#if MODULE_MAGIC_NUMBER >= 19980527
- {
- TSRMLS_FETCH();
- if (PG(expose_php)) {
- ap_add_version_component("PHP/" PHP_VERSION);
- }
- }
-#endif
-}
-/* }}} */
-
-/* {{{ handler_rec php_handlers[]
- */
-handler_rec php_handlers[] =
-{
- {"application/x-httpd-php", send_parsed_php},
- {"application/x-httpd-php-source", send_parsed_php_source},
- {"text/html", php_xbithack_handler},
- {NULL}
-};
-/* }}} */
-
-/* {{{ command_rec php_commands[]
- */
-command_rec php_commands[] =
-{
- {"php_value", php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"},
- {"php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, TAKE2, "PHP Flag Modifier"},
- {"php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Value Modifier (Admin)"},
- {"php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Flag Modifier (Admin)"},
- {NULL}
-};
-/* }}} */
-
-/* {{{ odule MODULE_VAR_EXPORT php4_module
- */
-module MODULE_VAR_EXPORT php4_module =
-{
- STANDARD_MODULE_STUFF,
- php_init_handler, /* initializer */
- php_create_dir, /* per-directory config creator */
- php_merge_dir, /* dir merger */
- NULL, /* per-server config creator */
- NULL, /* merge server config */
- php_commands, /* command table */
- php_handlers, /* handlers */
- NULL, /* filename translation */
- NULL, /* check_user_id */
- NULL, /* check auth */
- NULL, /* check access */
- NULL, /* type_checker */
- NULL, /* fixups */
- NULL /* logger */
-#if MODULE_MAGIC_NUMBER >= 19970103
- , NULL /* header parser */
-#endif
-#if MODULE_MAGIC_NUMBER >= 19970719
- , NULL /* child_init */
-#endif
-#if MODULE_MAGIC_NUMBER >= 19970728
- , php_child_exit_handler /* child_exit */
-#endif
-#if MODULE_MAGIC_NUMBER >= 19970902
- , NULL /* post read-request */
-#endif
-};
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/sapi/apache/mod_php4.exp b/sapi/apache/mod_php4.exp
deleted file mode 100644
index 2dca1256c2..0000000000
--- a/sapi/apache/mod_php4.exp
+++ /dev/null
@@ -1 +0,0 @@
-php4_module
diff --git a/sapi/apache/mod_php4.h b/sapi/apache/mod_php4.h
deleted file mode 100644
index 6d030ecb3c..0000000000
--- a/sapi/apache/mod_php4.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Rasmus Lerdorf <rasmus@php.net> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#ifndef MOD_PHP4_H
-#define MOD_PHP4_H
-
-#if !defined(WIN32) && !defined(WINNT)
-#ifndef MODULE_VAR_EXPORT
-#define MODULE_VAR_EXPORT
-#endif
-#endif
-
-typedef struct {
- long engine;
- long last_modified;
- long xbithack;
- long terminate_child;
- zend_bool in_request;
-} php_apache_info_struct;
-
-extern zend_module_entry apache_module_entry;
-
-#ifdef ZTS
-extern int php_apache_info_id;
-#define AP(v) TSRMG(php_apache_info_id, php_apache_info_struct *, v)
-#else
-extern php_apache_info_struct php_apache_info;
-#define AP(v) (php_apache_info.v)
-#endif
-
-#endif /* MOD_PHP4_H */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/sapi/apache/php.sym b/sapi/apache/php.sym
deleted file mode 100644
index 2dca1256c2..0000000000
--- a/sapi/apache/php.sym
+++ /dev/null
@@ -1 +0,0 @@
-php4_module
diff --git a/sapi/apache/php4apache.dsp b/sapi/apache/php4apache.dsp
deleted file mode 100644
index 6197d3da9b..0000000000
--- a/sapi/apache/php4apache.dsp
+++ /dev/null
@@ -1,151 +0,0 @@
-# Microsoft Developer Studio Project File - Name="php4apache" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php4apache - 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 "php4apache.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 "php4apache.mak" CFG="php4apache - Win32 Release_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php4apache - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4apache - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4apache - 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)" == "php4apache - 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 "APACHEPHP4_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\includes" /I "..\..\main" /I "..\..\TSRM" /I "..\..\regex" /I "C:\Program Files\Apache Group\Apache\include" /D ZEND_DEBUG=0 /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP4_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 php4ts.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x60000000" /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\release" /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS" /libpath:"C:\Program Files\Apache Group\Apache\libexec"
-
-!ELSEIF "$(CFG)" == "php4apache - 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 "APACHEPHP4_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\includes" /I "..\..\main" /I "..\..\TSRM" /I "..\..\regex" /I "C:\Program Files\Apache Group\Apache\include" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP4_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 php4ts_debug.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x60000000" /version:4.0 /dll /incremental:yes /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\php_build\release" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS" /libpath:"C:\Program Files\Apache Group\Apache\libexec"
-
-!ELSEIF "$(CFG)" == "php4apache - 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 "APACHEPHP4_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\includes" /I "..\..\main" /I "..\..\TSRM" /I "..\..\regex" /I "C:\Program Files\Apache Group\Apache\include" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP4_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 php4ts.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\release" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline" /libpath:"C:\Program Files\Apache Group\Apache\libexec"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php4apache - Win32 Release_TS"
-# Name "php4apache - Win32 Debug_TS"
-# Name "php4apache - 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_php4.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_php4.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_apache_http.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
diff --git a/sapi/apache/php_apache.c b/sapi/apache/php_apache.c
deleted file mode 100644
index fd3405dfa3..0000000000
--- a/sapi/apache/php_apache.c
+++ /dev/null
@@ -1,543 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Stig Sæther Bakken <ssb@fast.no> |
- | David Sklar <sklar@student.net> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include "php_apache_http.h"
-
-#if defined(PHP_WIN32) || defined(NETWARE)
-#include "zend.h"
-#include "ap_compat.h"
-#endif
-
-#ifdef ZTS
-int php_apache_info_id;
-#else
-php_apache_info_struct php_apache_info;
-#endif
-
-#define SECTION(name) PUTS("<h2>" name "</h2>\n")
-
-extern module *top_module;
-extern module **ap_loaded_modules;
-
-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);
-
-function_entry apache_functions[] = {
- PHP_FE(virtual, NULL)
- PHP_FE(apache_request_headers, NULL)
- PHP_FE(apache_note, NULL)
- PHP_FE(apache_lookup_uri, NULL)
- PHP_FE(apache_child_terminate, NULL)
- PHP_FE(apache_setenv, NULL)
- PHP_FE(apache_response_headers, NULL)
- PHP_FE(apache_get_version, NULL)
- PHP_FE(apache_get_modules, NULL)
- PHP_FALIAS(getallheaders, apache_request_headers, NULL)
- {NULL, NULL, NULL}
-};
-
-
-PHP_INI_BEGIN()
- STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateInt, xbithack, php_apache_info_struct, php_apache_info)
- STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateInt, engine, php_apache_info_struct, php_apache_info)
- STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateInt, last_modified, php_apache_info_struct, php_apache_info)
- STD_PHP_INI_ENTRY("child_terminate", "0", PHP_INI_ALL, OnUpdateInt, terminate_child, php_apache_info_struct, php_apache_info)
-PHP_INI_END()
-
-
-
-static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRMLS_DC)
-{
- apache_globals->in_request = 0;
-}
-
-
-static PHP_MINIT_FUNCTION(apache)
-{
-#ifdef ZTS
- ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL);
-#else
- php_apache_globals_ctor(&php_apache_info TSRMLS_CC);
-#endif
- REGISTER_INI_ENTRIES();
- return SUCCESS;
-}
-
-
-static PHP_MSHUTDOWN_FUNCTION(apache)
-{
- UNREGISTER_INI_ENTRIES();
- return SUCCESS;
-}
-
-zend_module_entry apache_module_entry = {
- STANDARD_MODULE_HEADER,
- "apache",
- apache_functions,
- PHP_MINIT(apache),
- PHP_MSHUTDOWN(apache),
- NULL,
- NULL,
- PHP_MINFO(apache),
- NO_VERSION_YET,
- STANDARD_MODULE_PROPERTIES
-};
-
-/* {{{ proto bool apache_child_terminate(void)
- Terminate apache process after this request */
-PHP_FUNCTION(apache_child_terminate)
-{
-#ifndef MULTITHREAD
- if (AP(terminate_child)) {
- ap_child_terminate( ((request_rec *)SG(server_context)) );
- RETURN_TRUE;
- } else { /* tell them to get lost! */
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is disabled");
- RETURN_FALSE;
- }
-#else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is not supported in this build");
- RETURN_FALSE;
-#endif
-}
-/* }}} */
-
-/* {{{ proto string apache_note(string note_name [, string note_value])
- Get and set Apache request notes */
-PHP_FUNCTION(apache_note)
-{
- pval **arg_name, **arg_val;
- char *note_val;
- int arg_count = ZEND_NUM_ARGS();
-
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &arg_name, &arg_val) ==FAILURE ) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(arg_name);
- note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val);
-
- if (arg_count == 2) {
- convert_to_string_ex(arg_val);
- table_set(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val, (*arg_val)->value.str.val);
- }
-
- if (note_val) {
- RETURN_STRING(note_val, 1);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ PHP_MINFO_FUNCTION
- */
-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
- sprintf(output_buf, "%d", APACHE_RELEASE);
- php_info_print_table_row(2, "Apache Release", output_buf);
-#endif
- sprintf(output_buf, "%d", MODULE_MAGIC_NUMBER);
- php_info_print_table_row(2, "Apache API Version", output_buf);
- sprintf(output_buf, "%s:%u", serv->server_hostname, serv->port);
- php_info_print_table_row(2, "Hostname:Port", output_buf);
-#if !defined(WIN32) && !defined(WINNT)
- sprintf(output_buf, "%s(%d)/%d", user_name, (int)user_id, (int)group_id);
- php_info_print_table_row(2, "User/Group", output_buf);
- sprintf(output_buf, "Per Child: %d - 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
- sprintf(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 */
- }
- strcat(modulenames, name);
- if (modp->next) {
- strcat(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 && (!PG(safe_mode) || (PG(safe_mode) && strncasecmp(env[i].key, "authorization", 13)))) {
- 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)
-{
- pval **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 = sub_req_lookup_uri ((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
- RETURN_FALSE;
- }
-
- if (rr->status != 200) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
- RETURN_FALSE;
- }
-
- php_end_ob_buffers(1 TSRMLS_CC);
- php_header();
-
- if (run_sub_req(rr)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
- RETURN_FALSE;
- } else {
- if (rr) destroy_sub_req (rr);
- RETURN_TRUE;
- }
-}
-/* }}} */
-
-/* {{{ proto array getallheaders(void)
- Alias for apache_request_headers() */
-/* }}} */
-/* {{{ proto array apache_request_headers(void)
- Fetch all HTTP request headers */
-PHP_FUNCTION(apache_request_headers)
-{
- array_header *env_arr;
- table_entry *tenv;
- int i;
-
- array_init(return_value);
- env_arr = table_elts(((request_rec *) SG(server_context))->headers_in);
- tenv = (table_entry *)env_arr->elts;
- for (i = 0; i < env_arr->nelts; ++i) {
- if (!tenv[i].key ||
- (PG(safe_mode) &&
- !strncasecmp(tenv[i].key, "authorization", 13))) {
- continue;
- }
- if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
- RETURN_FALSE;
- }
- }
-}
-/* }}} */
-
-/* {{{ proto array apache_response_headers(void)
- Fetch all HTTP response headers */
-PHP_FUNCTION(apache_response_headers)
-{
- array_header *env_arr;
- table_entry *tenv;
- int i;
-
- array_init(return_value);
- env_arr = table_elts(((request_rec *) SG(server_context))->headers_out);
- tenv = (table_entry *)env_arr->elts;
- for (i = 0; i < env_arr->nelts; ++i) {
- if (!tenv[i].key) continue;
- if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
- RETURN_FALSE;
- }
- }
-}
-/* }}} */
-
-/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top])
- Set an Apache subprocess_env variable */
-PHP_FUNCTION(apache_setenv)
-{
- int var_len, val_len, 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)
-{
- pval **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 = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed", (*filename)->value.str.val);
- RETURN_FALSE;
- }
- object_init(return_value);
- add_property_long(return_value,"status", rr->status);
- if (rr->the_request) {
- add_property_string(return_value,"the_request", rr->the_request, 1);
- }
- if (rr->status_line) {
- add_property_string(return_value,"status_line", (char *)rr->status_line, 1);
- }
- if (rr->method) {
- add_property_string(return_value,"method", (char *)rr->method, 1);
- }
- if (rr->content_type) {
- add_property_string(return_value,"content_type", (char *)rr->content_type, 1);
- }
- if (rr->handler) {
- add_property_string(return_value,"handler", (char *)rr->handler, 1);
- }
- if (rr->uri) {
- add_property_string(return_value,"uri", rr->uri, 1);
- }
- if (rr->filename) {
- add_property_string(return_value,"filename", rr->filename, 1);
- }
- if (rr->path_info) {
- add_property_string(return_value,"path_info", rr->path_info, 1);
- }
- if (rr->args) {
- add_property_string(return_value,"args", rr->args, 1);
- }
- if (rr->boundary) {
- add_property_string(return_value,"boundary", rr->boundary, 1);
- }
- add_property_long(return_value,"no_cache", rr->no_cache);
- add_property_long(return_value,"no_local_copy", rr->no_local_copy);
- add_property_long(return_value,"allowed", rr->allowed);
- add_property_long(return_value,"sent_bodyct", rr->sent_bodyct);
- add_property_long(return_value,"bytes_sent", rr->bytes_sent);
- add_property_long(return_value,"byterange", rr->byterange);
- add_property_long(return_value,"clength", rr->clength);
-
-#if MODULE_MAGIC_NUMBER >= 19980324
- if (rr->unparsed_uri) {
- add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1);
- }
- if(rr->mtime) {
- add_property_long(return_value,"mtime", rr->mtime);
- }
-#endif
- if(rr->request_time) {
- add_property_long(return_value,"request_time", rr->request_time);
- }
-
- destroy_sub_req(rr);
-}
-/* }}} */
-
-
-#if 0
-This function is most likely a bad idea. Just playing with it for now.
-
-PHP_FUNCTION(apache_exec_uri)
-{
- pval **filename;
- request_rec *rr=NULL;
- TSRMLS_FETCH();
-
- 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_docref(NULL TSRMLS_CC, 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/php_apache_http.h b/sapi/apache/php_apache_http.h
deleted file mode 100644
index a4eedf4983..0000000000
--- a/sapi/apache/php_apache_http.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Stig Sæther Bakken <ssb@fast.no> |
- | David Sklar <sklar@student.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#define NO_REGEX_EXTRA_H
-
-#ifdef WIN32
-#include <stddef.h>
-#endif
-
-#ifdef NETWARE
-#include <netinet/in.h>
-#endif
-
-#include "zend.h"
-#include "php_regex.h"
-#include "php_compat.h"
-
-#if HAVE_OPENSSL_EXT
-/* zlib typedefs free_func which causes problems if the SSL includes happen
- * after zlib.h is included */
-# include <openssl/ssl.h>
-#endif
-
-#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_php4.h"
diff --git a/sapi/apache/sapi_apache.c b/sapi/apache/sapi_apache.c
deleted file mode 100644
index 69d9dc2f73..0000000000
--- a/sapi/apache/sapi_apache.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@php.net> |
- | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> |
- | PHP 4.0 patches by: |
- | Zeev Suraski <zeev@zend.com> |
- | Stig Bakken <ssb@fast.no> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#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;
-
- zend_try {
- php_request_shutdown(NULL);
- } zend_end_try();
-
- 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
- */
diff --git a/sapi/apache2filter/CREDITS b/sapi/apache2filter/CREDITS
deleted file mode 100644
index 54e39b46f0..0000000000
--- a/sapi/apache2filter/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-Apache 2.0
-Sascha Schumann, Aaron Bannert
diff --git a/sapi/apache2filter/EXPERIMENTAL b/sapi/apache2filter/EXPERIMENTAL
deleted file mode 100644
index 293159a693..0000000000
--- a/sapi/apache2filter/EXPERIMENTAL
+++ /dev/null
@@ -1,5 +0,0 @@
-this module is experimental,
-its functions may change their names
-or move to extension all together
-so do not rely to much on them
-you have been warned!
diff --git a/sapi/apache2filter/README b/sapi/apache2filter/README
deleted file mode 100644
index 3054e208d3..0000000000
--- a/sapi/apache2filter/README
+++ /dev/null
@@ -1,71 +0,0 @@
-WHAT IS THIS?
-
- This module exploits the layered I/O support in Apache 2.0.
-
-HOW DOES IT WORK?
-
- In Apache 2.0, you have handlers which generate content (like
- reading a script from disk). The content goes then through
- a chain of filters. PHP can be such a filter, so that it processes
- your script and hands the output to the next filter (which will
- usually cause a write to the network).
-
-DOES IT WORK?
-
- It is experimental as interfaces in Apache 2.0 might change in the
- future.
-
-HOW TO INSTALL
-
- This SAPI module is known to work with Apache 2.0.40.
-
- $ cd apache-2.x
- $ cd src
- $ ./configure --enable-so
- $ make install
-
- For testing purposes, you might want to use --with-mpm=prefork.
- (Albeit PHP also works with threaded MPMs.)
-
- Configure PHP 4:
-
- $ cd php-4.x
- $ ./configure --with-apxs2=/path/to/apache-2.0/bin/apxs
- $ make install
-
- At the end of conf/httpd.conf, add:
-
- AddType application/x-httpd-php .php
-
- If you would like to enable source code highlighting functionality add:
-
- AddType application/x-httpd-php-source .phps
-
- That's it. Now start bin/httpd.
-
-HOW TO CONFIGURE
-
- The Apache 2.0 PHP module supports a new configuration directive that
- allows an admin to override the php.ini search path. For example,
- place your php.ini file in Apache's ServerRoot/conf directory and
- add this to your httpd.conf file:
-
- PHPINIDir "conf"
-
-DEBUGGING APACHE AND PHP
-
- To debug Apache, we recommened:
-
- 1. Use the Prefork MPM (Apache 1.3-like process model) by
- configuring Apache with '--with-mpm=prefork'.
- 2. Start httpd using -DONE_PROCESS (e.g. (gdb) r -DONE_PROCESS).
-
- If you want to debug a part of the PHP startup procedure, set a
- breakpoint on 'load_module'. Step through it until apr_dso_load() is
- done. Then you can set a breakpoint on any PHP-related symbol.
-
-TODO
-
- PHP functions like apache_sub_req (see php_functions.c)
- Protocol handlers
- Passing script data to engine without temporary file
diff --git a/sapi/apache2filter/apache_config.c b/sapi/apache2filter/apache_config.c
deleted file mode 100644
index 0631a5e30a..0000000000
--- a/sapi/apache2filter/apache_config.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
-
-#include "php.h"
-#include "php_ini.h"
-#include "php_apache.h"
-
-#include "apr_strings.h"
-#include "ap_config.h"
-#include "util_filter.h"
-#include "httpd.h"
-#include "http_config.h"
-#include "http_request.h"
-#include "http_core.h"
-#include "http_protocol.h"
-#include "http_log.h"
-#include "http_main.h"
-#include "util_script.h"
-#include "http_core.h"
-
-#ifdef PHP_AP_DEBUG
-#define phpapdebug(a) fprintf a
-#else
-#define phpapdebug(a)
-#endif
-
-typedef struct {
- HashTable config;
-} php_conf_rec;
-
-typedef struct {
- char *value;
- size_t value_len;
- char status;
-} php_dir_entry;
-
-static const char *real_value_hnd(cmd_parms *cmd, void *dummy,
- const char *name, const char *value, int status)
-{
- php_conf_rec *d = dummy;
- php_dir_entry e;
-
- phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy,
- zend_hash_num_elements(&d->config)));
-
- if (!strncasecmp(value, "none", sizeof("none"))) {
- value = "";
- }
-
- e.value = apr_pstrdup(cmd->pool, value);
- e.value_len = strlen(value);
- e.status = status;
-
- zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e,
- sizeof(e), NULL);
- return NULL;
-}
-
-static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy,
- const char *name, const char *value)
-{
- return real_value_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
-}
-
-static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy,
- const char *name, const char *value)
-{
- return real_value_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
-}
-
-static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1,
- const char *arg2, int status)
-{
- char bool_val[2];
-
- if (!strcasecmp(arg2, "On") || (arg2[0] == '1' && arg2[1] == '\0')) {
- bool_val[0] = '1';
- } else {
- bool_val[0] = '0';
- }
- bool_val[1] = 0;
-
- return real_value_hnd(cmd, dummy, arg1, bool_val, status);
-}
-
-static const char *php_apache_flag_handler(cmd_parms *cmd, void *dummy,
- const char *name, const char *value)
-{
- return real_flag_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
-}
-
-static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy,
- const char *name, const char *value)
-{
- return real_flag_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
-}
-
-static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig,
- const char *arg)
-{
- if (apache2_php_ini_path_override) {
- return "Only first PHPINIDir directive honored per configuration tree "
- "- subsequent ones ignored";
- }
- apache2_php_ini_path_override = ap_server_root_relative(cmd->pool, arg);
- return NULL;
-}
-
-
-void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
-{
- php_conf_rec *d = base_conf, *e = new_conf;
- php_dir_entry *pe;
- php_dir_entry *data;
- char *str;
- uint str_len;
- ulong num_index;
-
- phpapdebug((stderr, "Merge dir (%p) (%p)\n", base_conf, new_conf));
- for (zend_hash_internal_pointer_reset(&d->config);
- zend_hash_get_current_key_ex(&d->config, &str, &str_len,
- &num_index, 0, NULL) == HASH_KEY_IS_STRING;
- zend_hash_move_forward(&d->config)) {
- pe = NULL;
- zend_hash_get_current_data(&d->config, (void **) &data);
- if (zend_hash_find(&e->config, str, str_len, (void **) &pe) == SUCCESS) {
- if (pe->status >= data->status) continue;
- }
- zend_hash_update(&e->config, str, str_len, data, sizeof(*data), NULL);
- phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str,
- data->status, pe?pe->status:-1));
- }
- return new_conf;
-}
-
-char *get_php_config(void *conf, char *name, size_t name_len)
-{
- php_conf_rec *d = conf;
- php_dir_entry *pe;
-
- if (zend_hash_find(&d->config, name, name_len, (void **) &pe) == SUCCESS) {
- return pe->value;
- }
-
- return "";
-}
-
-void apply_config(void *dummy)
-{
- php_conf_rec *d = dummy;
- char *str;
- uint str_len;
- php_dir_entry *data;
-
- for (zend_hash_internal_pointer_reset(&d->config);
- zend_hash_get_current_key_ex(&d->config, &str, &str_len, NULL, 0,
- NULL) == HASH_KEY_IS_STRING;
- zend_hash_move_forward(&d->config)) {
- zend_hash_get_current_data(&d->config, (void **) &data);
- phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value));
- if (zend_alter_ini_entry(str, str_len, data->value, data->value_len,
- data->status, PHP_INI_STAGE_RUNTIME) == FAILURE) {
- phpapdebug((stderr, "..FAILED\n"));
- }
- }
-}
-
-const command_rec php_dir_cmds[] =
-{
- AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS,
- "PHP Value Modifier"),
- AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS,
- "PHP Flag Modifier"),
- AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL,
- ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"),
- AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL,
- ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"),
- AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF,
- "Directory containing the php.ini file"),
- {NULL}
-};
-
-static apr_status_t destroy_php_config(void *data)
-{
- php_conf_rec *d = data;
-
- phpapdebug((stderr, "Destroying config %p\n", data));
- zend_hash_destroy(&d->config);
-
- return APR_SUCCESS;
-}
-
-void *create_php_config(apr_pool_t *p, char *dummy)
-{
- php_conf_rec *newx =
- (php_conf_rec *) apr_pcalloc(p, sizeof(*newx));
-
- phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy));
- zend_hash_init(&newx->config, 0, NULL, NULL, 1);
- apr_pool_cleanup_register(p, newx, destroy_php_config, apr_pool_cleanup_null);
- return (void *) newx;
-}
-
-/*
- * 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/apache2filter/config.m4 b/sapi/apache2filter/config.m4
deleted file mode 100644
index 770c3eabd7..0000000000
--- a/sapi/apache2filter/config.m4
+++ /dev/null
@@ -1,118 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for Apache 2.0 module support via DSO through APXS)
-AC_ARG_WITH(apxs2,
-[ --with-apxs2[=FILE] EXPERIMENTAL: Build shared Apache 2.0 module. FILE is the optional
- pathname to the Apache apxs tool; defaults to "apxs".],[
- if test "$withval" = "yes"; then
- APXS=apxs
- $APXS -q CFLAGS >/dev/null 2>&1
- if test "$?" != "0" && test -x /usr/sbin/apxs; then
- APXS=/usr/sbin/apxs
- fi
- else
- PHP_EXPAND_PATH($withval, APXS)
- fi
-
- $APXS -q CFLAGS >/dev/null 2>&1
- if test "$?" != "0"; then
- AC_MSG_RESULT()
- AC_MSG_RESULT()
- AC_MSG_RESULT([Sorry, I cannot run apxs. Possible reasons follow:])
- AC_MSG_RESULT()
- AC_MSG_RESULT([1. Perl is not installed])
- AC_MSG_RESULT([2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs])
- AC_MSG_RESULT([3. Apache was not built using --enable-so (the apxs usage page is displayed)])
- AC_MSG_RESULT()
- AC_MSG_RESULT([The output of $APXS follows:])
- $APXS
- AC_MSG_ERROR([Aborting])
- fi
-
- APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR`
- APXS_HTTPD=`$APXS -q SBINDIR`/`$APXS -q TARGET`
- APXS_CFLAGS=`$APXS -q CFLAGS`
- APXS_MPM=`$APXS -q MPM_NAME`
-
- for flag in $APXS_CFLAGS; do
- case $flag in
- -D*) CPPFLAGS="$CPPFLAGS $flag";;
- esac
- done
-
- # Test that we're trying to configure with apache 2.x
- PHP_AP_EXTRACT_VERSION($APXS_HTTPD)
- if test "$APACHE_VERSION" -le 2000000; then
- AC_MSG_ERROR([You have enabled Apache 2 support while your server is Apache 1.3. Please use the appropiate switch --with-apxs (without the 2)])
- elif test "$APACHE_VERSION" -lt 2000040; then
- AC_MSG_ERROR([Please note that Apache version >= 2.0.40 is required.])
- fi
-
- APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR`
- if test -z `$APXS -q SYSCONFDIR`; then
- INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \
- $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \
- -i -n php4"
- else
- APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR`
- INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \
- \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \
- $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \
- -S SYSCONFDIR='$APXS_SYSCONFDIR' \
- -i -a -n php4"
- fi
-
- case $host_alias in
- *aix*)
- EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-brtl -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp"
- PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c)
- INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL"
- ;;
- *darwin*)
- dnl When using bundles on Darwin, we must resolve all symbols. However,
- dnl the linker does not recursively look at the bundle loader and
- dnl pull in its dependencies. Therefore, we must pull in the APR
- dnl and APR-util libraries.
- APXS_BINDIR=`$APXS -q BINDIR`
- if test -f $APXS_BINDIR/apr-config; then
- MH_BUNDLE_FLAGS="`$APXS_BINDIR/apr-config --ldflags --link-ld --libs`"
- fi
- if test -f $APXS_BINDIR/apu-config; then
- MH_BUNDLE_FLAGS="`$APXS_BINDIR/apu-config --ldflags --link-ld --libs` $MH_BUNDLE_FLAGS"
- fi
- MH_BUNDLE_FLAGS="-bundle -bundle_loader $APXS_HTTPD $MH_BUNDLE_FLAGS"
- PHP_SUBST(MH_BUNDLE_FLAGS)
- PHP_SELECT_SAPI(apache2filter, bundle, sapi_apache2.c apache_config.c php_functions.c)
- SAPI_SHARED=libs/libphp4.so
- INSTALL_IT="$INSTALL_IT $SAPI_SHARED"
- ;;
- *beos*)
- APXS_BINDIR=`$APXS -q BINDIR`
- if test -f _APP_; then `rm _APP_`; fi
- `ln -s $APXS_BINDIR/httpd _APP_`
- EXTRA_LIBS="$EXTRA_LIBS _APP_"
- PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c)
- INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL"
- ;;
- *)
- PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c)
- INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL"
- ;;
- esac
-
- PHP_ADD_INCLUDE($APXS_INCLUDEDIR)
- if test "$APXS_MPM" != "prefork"; then
- PHP_BUILD_THREAD_SAFE
- fi
- AC_MSG_RESULT(yes)
-],[
- AC_MSG_RESULT(no)
-])
-
-PHP_SUBST(APXS)
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
diff --git a/sapi/apache2filter/php.sym b/sapi/apache2filter/php.sym
deleted file mode 100644
index 2dca1256c2..0000000000
--- a/sapi/apache2filter/php.sym
+++ /dev/null
@@ -1 +0,0 @@
-php4_module
diff --git a/sapi/apache2filter/php4apache2.dsp b/sapi/apache2filter/php4apache2.dsp
deleted file mode 100644
index 2c93b3cc74..0000000000
--- a/sapi/apache2filter/php4apache2.dsp
+++ /dev/null
@@ -1,142 +0,0 @@
-# Microsoft Developer Studio Project File - Name="php4apache2" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php4apache2 - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "php4apache2.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 "php4apache2.mak" CFG="php4apache2 - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php4apache2 - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4apache2 - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4apache2 - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "php4apache2 - 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 "PHP4APACHE2_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "WIN32" /D "_MBCS" /D "_WINSOCK2API_" /D "_MSWSOCK_" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "NDEBUG"
-# ADD RSC /l 0x407 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php4ts.lib libhttpd.lib libapr.lib libaprutil.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS"
-
-!ELSEIF "$(CFG)" == "php4apache2 - 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 "PHP4APACHE2_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /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 "WIN32" /D "_MBCS" /D "_WINSOCK2API_" /D "_MSWSOCK_" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "NDEBUG"
-# ADD RSC /l 0x407 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php4ts.lib libhttpd.lib libapr.lib libaprutil.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS_inline/php4apache2.dll" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"
-
-!ELSEIF "$(CFG)" == "php4apache2 - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4APACHE2_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "WIN32" /D "_MBCS" /D "_WINSOCK2API_" /D "_MSWSOCK_" /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "_DEBUG"
-# ADD RSC /l 0x407 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 php4ts_debug.lib libhttpd.lib libapr.lib libaprutil.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php4apache2 - Win32 Release_TS"
-# Name "php4apache2 - Win32 Release_TS_inline"
-# Name "php4apache2 - Win32 Debug_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\apache_config.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_functions.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\sapi_apache2.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php_apache.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/sapi/apache2filter/php_apache.h b/sapi/apache2filter/php_apache.h
deleted file mode 100644
index 1e3c5695a0..0000000000
--- a/sapi/apache2filter/php_apache.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#ifndef PHP_APACHE_H
-#define PHP_APACHE_H
-
-#include "httpd.h"
-#include "http_config.h"
-#include "http_core.h"
-
-/* Declare this so we can get to it from outside the sapi_apache2.c file */
-extern module AP_MODULE_DECLARE_DATA php4_module;
-
-/* A way to specify the location of the php.ini dir in an apache directive */
-extern char *apache2_php_ini_path_override;
-
-/* The server_context used by PHP */
-typedef struct php_struct {
- int state;
- request_rec *r;
- ap_filter_t *f; /* downstream output filters after the PHP filter. */
- /* Length of post_data buffer */
- int post_len;
- /* Index for reading from buffer */
- int post_idx;
- /* stat structure of the current file */
-#if defined(NETWARE) && defined(CLIB_STAT_PATCH)
- struct stat_libc finfo;
-#else
- struct stat finfo;
-#endif
- /* Buffer for request body filter */
- char *post_data;
- /* Whether or not we've processed PHP in the output filters yet. */
- int request_processed;
-} php_struct;
-
-void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf);
-void *create_php_config(apr_pool_t *p, char *dummy);
-char *get_php_config(void *conf, char *name, size_t name_len);
-void apply_config(void *);
-extern const command_rec php_dir_cmds[];
-
-#define APR_ARRAY_FOREACH_OPEN(arr, key, val) \
-{ \
- apr_table_entry_t *elts; \
- int i; \
- elts = (apr_table_entry_t *) arr->elts; \
- for (i = 0; i < arr->nelts; i++) { \
- key = elts[i].key; \
- val = elts[i].val;
-
-#define APR_ARRAY_FOREACH_CLOSE() }}
-
-#endif /* PHP_APACHE_H */
diff --git a/sapi/apache2filter/php_functions.c b/sapi/apache2filter/php_functions.c
deleted file mode 100644
index fe7bf41353..0000000000
--- a/sapi/apache2filter/php_functions.c
+++ /dev/null
@@ -1,393 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-
-#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
-
-#include "php.h"
-#include "ext/standard/php_smart_str.h"
-#include "ext/standard/info.h"
-#include "SAPI.h"
-
-#define CORE_PRIVATE
-#include "apr_strings.h"
-#include "apr_time.h"
-#include "ap_config.h"
-#include "util_filter.h"
-#include "httpd.h"
-#include "http_config.h"
-#include "http_request.h"
-#include "http_core.h"
-#include "http_protocol.h"
-#include "http_log.h"
-#include "http_main.h"
-#include "util_script.h"
-#include "http_core.h"
-
-#include "php_apache.h"
-
-static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC)
-{
- php_struct *ctx;
-
- if (!filename) {
- return NULL;
- }
-
- ctx = SG(server_context);
- return ap_sub_req_lookup_uri(filename, ctx->f->r, ctx->f->next);
-}
-
-/* {{{ proto bool virtual(string uri)
- Perform an apache sub-request */
-PHP_FUNCTION(virtual)
-{
- zval **filename;
- request_rec *rr;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(filename);
-
- if (!(rr = php_apache_lookup_uri(Z_STRVAL_PP(filename) TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", Z_STRVAL_PP(filename));
- RETURN_FALSE;
- }
-
- if (rr->status == HTTP_OK) {
- if (ap_run_sub_req(rr)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", Z_STRVAL_PP(filename));
- ap_destroy_sub_req(rr);
- RETURN_FALSE;
- }
- ap_destroy_sub_req(rr);
- RETURN_TRUE;
- }
-
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", Z_STRVAL_PP(filename));
- ap_destroy_sub_req(rr);
- RETURN_FALSE;
-}
-/* }}} */
-
-#define ADD_LONG(name) \
- add_property_long(return_value, #name, rr->name)
-#define ADD_TIME(name) \
- add_property_long(return_value, #name, rr->name / APR_USEC_PER_SEC);
-#define ADD_STRING(name) \
- if (rr->name) add_property_string(return_value, #name, (char *) rr->name, 1)
-
-PHP_FUNCTION(apache_lookup_uri)
-{
- request_rec *rr;
- zval **filename;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(filename);
-
- if (!(rr = php_apache_lookup_uri(Z_STRVAL_PP(filename) TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", Z_STRVAL_PP(filename));
- RETURN_FALSE;
- }
-
- if (rr->status == HTTP_OK) {
- object_init(return_value);
-
- ADD_LONG(status);
- ADD_STRING(the_request);
- ADD_STRING(status_line);
- ADD_STRING(method);
- ADD_TIME(mtime);
- ADD_LONG(clength);
-#if MODULE_MAGIC_NUMBER < 20020506
- ADD_STRING(boundary);
-#endif
- ADD_STRING(range);
- ADD_LONG(chunked);
- ADD_STRING(content_type);
- ADD_STRING(handler);
- ADD_LONG(no_cache);
- ADD_LONG(no_local_copy);
- ADD_STRING(unparsed_uri);
- ADD_STRING(uri);
- ADD_STRING(filename);
- ADD_STRING(path_info);
- ADD_STRING(args);
- ADD_LONG(allowed);
- ADD_LONG(sent_bodyct);
- ADD_LONG(bytes_sent);
- ADD_LONG(request_time);
- ADD_LONG(mtime);
- ADD_TIME(request_time);
-
- ap_destroy_sub_req(rr);
- return;
- }
-
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", Z_STRVAL_PP(filename));
- ap_destroy_sub_req(rr);
- RETURN_FALSE;
-}
-
-/* {{{ proto array getallheaders(void)
- Fetch all HTTP request headers */
-PHP_FUNCTION(apache_request_headers)
-{
- php_struct *ctx;
- const apr_array_header_t *arr;
- char *key, *val;
-
- array_init(return_value);
-
- ctx = SG(server_context);
- arr = apr_table_elts(ctx->f->r->headers_in);
-
- APR_ARRAY_FOREACH_OPEN(arr, key, val)
- if (!val) val = empty_string;
- add_assoc_string(return_value, key, val, 1);
- APR_ARRAY_FOREACH_CLOSE()
-}
-/* }}} */
-
-/* {{{ proto array apache_response_headers(void)
- Fetch all HTTP response headers */
-PHP_FUNCTION(apache_response_headers)
-{
- php_struct *ctx;
- const apr_array_header_t *arr;
- char *key, *val;
-
- array_init(return_value);
-
- ctx = SG(server_context);
- arr = apr_table_elts(ctx->f->r->headers_out);
-
- APR_ARRAY_FOREACH_OPEN(arr, key, val)
- if (!val) val = empty_string;
- add_assoc_string(return_value, key, val, 1);
- APR_ARRAY_FOREACH_CLOSE()
-}
-/* }}} */
-
-/* {{{ proto string apache_note(string note_name [, string note_value])
- Get and set Apache request notes */
-PHP_FUNCTION(apache_note)
-{
- php_struct *ctx;
- zval **note_name, **note_val;
- char *old_note_val=NULL;
- int arg_count = ZEND_NUM_ARGS();
-
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &note_name, &note_val) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- ctx = SG(server_context);
-
- convert_to_string_ex(note_name);
-
- old_note_val = (char *) apr_table_get(ctx->r->notes, Z_STRVAL_PP(note_name));
-
- if (arg_count == 2) {
- convert_to_string_ex(note_val);
- apr_table_set(ctx->r->notes, Z_STRVAL_PP(note_name), Z_STRVAL_PP(note_val));
- }
-
- if (old_note_val) {
- RETURN_STRING(old_note_val, 1);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-
-/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top])
- Set an Apache subprocess_env variable */
-PHP_FUNCTION(apache_setenv)
-{
- php_struct *ctx;
- zval **variable=NULL, **string_val=NULL, **walk_to_top=NULL;
- int arg_count = ZEND_NUM_ARGS();
-
- if (arg_count<1 || arg_count>3 ||
- zend_get_parameters_ex(arg_count, &variable, &string_val, &walk_to_top) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- ctx = SG(server_context);
-
- if (arg_count == 3 && Z_STRVAL_PP(walk_to_top)) {
- while(ctx->f->r->prev) {
- ctx->f->r = ctx->f->r->prev;
- }
- }
-
- convert_to_string_ex(variable);
- convert_to_string_ex(string_val);
-
- apr_table_set(ctx->r->subprocess_env, Z_STRVAL_PP(variable), Z_STRVAL_PP(string_val));
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto bool apache_getenv(string variable [, bool walk_to_top])
- Get an Apache subprocess_env variable */
-PHP_FUNCTION(apache_getenv)
-{
- php_struct *ctx;
- zval **variable=NULL, **walk_to_top=NULL;
- int arg_count = ZEND_NUM_ARGS();
- char *env_val=NULL;
-
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &variable, &walk_to_top) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- ctx = SG(server_context);
-
- if (arg_count == 2 && Z_STRVAL_PP(walk_to_top)) {
- while(ctx->f->r->prev) {
- ctx->f->r = ctx->f->r->prev;
- }
- }
-
- convert_to_string_ex(variable);
-
- env_val = (char*) apr_table_get(ctx->r->subprocess_env, Z_STRVAL_PP(variable));
- if (env_val != NULL) {
- RETURN_STRING(env_val, 1);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-static char *php_apache_get_version()
-{
- return (char *) ap_get_server_version();
-}
-
-/* {{{ proto string apache_get_version(void)
- Fetch Apache version */
-PHP_FUNCTION(apache_get_version)
-{
- char *apv = php_apache_get_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);
- }
- }
-}
-/* }}} */
-
-PHP_MINFO_FUNCTION(apache)
-{
- char *apv = php_apache_get_version();
- smart_str tmp1 = {0};
- int n;
- char *p;
-
- for (n = 0; ap_loaded_modules[n]; ++n) {
- char *s = (char *) ap_loaded_modules[n]->name;
- if ((p = strchr(s, '.'))) {
- smart_str_appendl(&tmp1, s, (p - s));
- } else {
- smart_str_appends(&tmp1, s);
- }
- smart_str_appendc(&tmp1, ' ');
- }
- if ((tmp1.len - 1) >= 0) {
- tmp1.c[tmp1.len - 1] = '\0';
- }
-
- php_info_print_table_start();
- if (apv && *apv) {
- php_info_print_table_row(2, "Apache Version", apv);
- }
- php_info_print_table_row(2, "Loaded Modules", tmp1.c);
- smart_str_free(&tmp1);
- php_info_print_table_end();
-}
-
-static function_entry apache_functions[] = {
- PHP_FE(apache_lookup_uri, NULL)
- PHP_FE(virtual, NULL)
- PHP_FE(apache_request_headers, NULL)
- PHP_FE(apache_response_headers, NULL)
- PHP_FE(apache_setenv, NULL)
- PHP_FE(apache_getenv, NULL)
- PHP_FE(apache_note, NULL)
- PHP_FE(apache_get_version, NULL)
- PHP_FE(apache_get_modules, NULL)
- PHP_FALIAS(getallheaders, apache_request_headers, NULL)
- {NULL, NULL, NULL}
-};
-
-zend_module_entry php_apache_module = {
- STANDARD_MODULE_HEADER,
- "Apache 2.0",
- apache_functions,
- NULL,
- NULL,
- NULL,
- NULL,
- PHP_MINFO(apache),
- NULL,
- STANDARD_MODULE_PROPERTIES
-};
-
-/*
- * 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/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c
deleted file mode 100644
index 792b01b734..0000000000
--- a/sapi/apache2filter/sapi_apache2.c
+++ /dev/null
@@ -1,688 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- | Parts based on Apache 1.3 SAPI module by |
- | Rasmus Lerdorf and Zeev Suraski |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include <fcntl.h>
-
-#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
-
-#include "php.h"
-#include "php_main.h"
-#include "php_ini.h"
-#include "php_variables.h"
-#include "SAPI.h"
-
-#include "ext/standard/php_smart_str.h"
-#ifndef NETWARE
-#include "ext/standard/php_standard.h"
-#else
-#include "ext/standard/basic_functions.h"
-#endif
-
-#include "apr_strings.h"
-#include "ap_config.h"
-#include "util_filter.h"
-#include "httpd.h"
-#include "http_config.h"
-#include "http_request.h"
-#include "http_core.h"
-#include "http_protocol.h"
-#include "http_log.h"
-#include "http_main.h"
-#include "util_script.h"
-#include "http_core.h"
-#include "ap_mpm.h"
-
-#include "php_apache.h"
-
-#ifdef NETWARE
-#undef shutdown /* To avoid Winsock confusion */
-#endif
-
-/* A way to specify the location of the php.ini dir in an apache directive */
-char *apache2_php_ini_path_override = NULL;
-
-static int
-php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- apr_bucket *b;
- apr_bucket_brigade *bb;
- apr_bucket_alloc_t *ba;
- ap_filter_t *f; /* remaining output filters */
- php_struct *ctx;
-
- ctx = SG(server_context);
- f = ctx->f;
-
- if (str_length == 0) return 0;
-
- ba = f->c->bucket_alloc;
- bb = apr_brigade_create(ctx->r->pool, ba);
-
- b = apr_bucket_transient_create(str, str_length, ba);
- APR_BRIGADE_INSERT_TAIL(bb, b);
-
-#if 0
- /* Add a Flush bucket to the end of this brigade, so that
- * the transient buckets above are more likely to make it out
- * the end of the filter instead of having to be copied into
- * someone's setaside. */
- b = apr_bucket_flush_create(ba);
- APR_BRIGADE_INSERT_TAIL(bb, b);
-#endif
-
- if (ap_pass_brigade(f->next, bb) != APR_SUCCESS) {
- php_handle_aborted_connection();
- }
-
- return str_length; /* we always consume all the data passed to us. */
-}
-
-static int
-php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- php_struct *ctx;
- ap_filter_t *f;
- char *val;
-
- ctx = SG(server_context);
- f = ctx->r->output_filters;
-
- val = strchr(sapi_header->header, ':');
-
- if (!val) {
- sapi_free_header(sapi_header);
- return 0;
- }
-
- *val = '\0';
-
- do {
- val++;
- } while (*val == ' ');
-
- if (!strcasecmp(sapi_header->header, "content-type"))
- ctx->r->content_type = apr_pstrdup(ctx->r->pool, val);
- else if (sapi_header->replace)
- apr_table_set(ctx->r->headers_out, sapi_header->header, val);
- else
- apr_table_add(ctx->r->headers_out, sapi_header->header, val);
-
- sapi_free_header(sapi_header);
-
- return 0;
-}
-
-static int
-php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- php_struct *ctx = SG(server_context);
-
- ctx->r->status = SG(sapi_headers).http_response_code;
-
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-static int
-php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC)
-{
- int n;
- int to_read;
- php_struct *ctx = SG(server_context);
-
- to_read = ctx->post_len - ctx->post_idx;
- n = MIN(to_read, count_bytes);
-
- if (n > 0) {
- memcpy(buf, ctx->post_data + ctx->post_idx, n);
- ctx->post_idx += n;
- } else {
- if (ctx->post_data) free(ctx->post_data);
- ctx->post_data = NULL;
- }
-
- return n;
-}
-
-static struct stat*
-php_apache_sapi_get_stat(TSRMLS_D)
-{
- php_struct *ctx = SG(server_context);
-
- ctx->finfo.st_uid = ctx->r->finfo.user;
- ctx->finfo.st_gid = ctx->r->finfo.group;
- ctx->finfo.st_ino = ctx->r->finfo.inode;
-#if defined(NETWARE) && defined(CLIB_STAT_PATCH)
- ctx->finfo.st_atime.tv_sec = ctx->r->finfo.atime/1000000;
- ctx->finfo.st_mtime.tv_sec = ctx->r->finfo.mtime/1000000;
- ctx->finfo.st_ctime.tv_sec = ctx->r->finfo.ctime/1000000;
-#else
- ctx->finfo.st_atime = ctx->r->finfo.atime/1000000;
- ctx->finfo.st_mtime = ctx->r->finfo.mtime/1000000;
- ctx->finfo.st_ctime = ctx->r->finfo.ctime/1000000;
-#endif
-
- ctx->finfo.st_size = ctx->r->finfo.size;
- ctx->finfo.st_nlink = ctx->r->finfo.nlink;
-
- return &ctx->finfo;
-}
-
-static char *
-php_apache_sapi_read_cookies(TSRMLS_D)
-{
- php_struct *ctx = SG(server_context);
- const char *http_cookie;
-
- http_cookie = apr_table_get(ctx->r->headers_in, "cookie");
-
- /* The SAPI interface should use 'const char *' */
- return (char *) http_cookie;
-}
-
-static char *
-php_apache_sapi_getenv(char *name, size_t name_len TSRMLS_DC)
-{
- php_struct *ctx = SG(server_context);
- const char *env_var;
-
- env_var = apr_table_get(ctx->r->subprocess_env, name);
-
- return (char *) env_var;
-}
-
-static void
-php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- php_struct *ctx = SG(server_context);
- const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env);
- char *key, *val;
-
- APR_ARRAY_FOREACH_OPEN(arr, key, val)
- if (!val) val = empty_string;
- php_register_variable(key, val, track_vars_array TSRMLS_CC);
- APR_ARRAY_FOREACH_CLOSE()
-
- php_register_variable("PHP_SELF", ctx->r->uri, track_vars_array TSRMLS_CC);
-}
-
-static void
-php_apache_sapi_flush(void *server_context)
-{
- php_struct *ctx;
- apr_bucket_brigade *bb;
- apr_bucket_alloc_t *ba;
- apr_bucket *b;
- ap_filter_t *f; /* output filters */
-
- ctx = server_context;
-
- /* If we haven't registered a server_context yet,
- * then don't bother flushing. */
- if (!server_context)
- return;
-
- f = ctx->f;
-
- /* Send a flush bucket down the filter chain. The current default
- * handler seems to act on the first flush bucket, but ignores
- * all further flush buckets.
- */
-
- ba = ctx->r->connection->bucket_alloc;
- bb = apr_brigade_create(ctx->r->pool, ba);
- b = apr_bucket_flush_create(ba);
- APR_BRIGADE_INSERT_TAIL(bb, b);
- if (ap_pass_brigade(f->next, bb) != APR_SUCCESS) {
- php_handle_aborted_connection();
- }
-}
-
-static void php_apache_sapi_log_message(char *msg)
-{
- php_struct *ctx;
- TSRMLS_FETCH();
-
- ctx = SG(server_context);
-
- /* We use APLOG_STARTUP because it keeps us from printing the
- * data and time information at the beginning of the error log
- * line. Not sure if this is correct, but it mirrors what happens
- * with Apache 1.3 -- rbb
- */
- if (ctx == NULL) { /* we haven't initialized our ctx yet, oh well */
- ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO | APLOG_STARTUP,
- 0, NULL, "%s", msg);
- }
- else {
- ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO | APLOG_STARTUP,
- 0, ctx->r->server, "%s", msg);
- }
-}
-
-static int
-php_apache_disable_caching(ap_filter_t *f)
-{
- /* Identify PHP scripts as non-cacheable, thus preventing
- * Apache from sending a 304 status when the browser sends
- * If-Modified-Since header.
- */
- f->r->no_local_copy = 1;
-
- return OK;
-}
-
-extern zend_module_entry php_apache_module;
-
-static int php_apache2_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, &php_apache_module, 1)==FAILURE) {
- return FAILURE;
- }
- return SUCCESS;
-}
-
-static sapi_module_struct apache2_sapi_module = {
- "apache2filter",
- "Apache 2.0 Filter",
-
- php_apache2_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- php_apache_sapi_ub_write, /* unbuffered write */
- php_apache_sapi_flush, /* flush */
- php_apache_sapi_get_stat, /* get uid */
- php_apache_sapi_getenv, /* getenv */
-
- php_error, /* error handler */
-
- php_apache_sapi_header_handler, /* header handler */
- php_apache_sapi_send_headers, /* send headers handler */
- NULL, /* send header handler */
-
- php_apache_sapi_read_post, /* read POST data */
- php_apache_sapi_read_cookies, /* read Cookies */
-
- php_apache_sapi_register_variables,
- php_apache_sapi_log_message, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-static int php_input_filter(ap_filter_t *f, apr_bucket_brigade *bb,
- ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes)
-{
- php_struct *ctx;
- long old_index;
- apr_bucket *b;
- const char *str;
- apr_size_t n;
- apr_status_t rv;
- TSRMLS_FETCH();
-
- if (f->r->proxyreq) {
- return ap_get_brigade(f->next, bb, mode, block, readbytes);
- }
-
- ctx = SG(server_context);
- if (ctx == NULL) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, f->r,
- "php failed to get server context");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
-
- if ((rv = ap_get_brigade(f->next, bb, mode, block, readbytes)) != APR_SUCCESS) {
- return rv;
- }
-
- for (b = APR_BRIGADE_FIRST(bb); b != APR_BRIGADE_SENTINEL(bb); b = APR_BUCKET_NEXT(b)) {
- apr_bucket_read(b, &str, &n, 1);
- if (n > 0) {
- old_index = ctx->post_len;
- ctx->post_len += n;
- ctx->post_data = realloc(ctx->post_data, ctx->post_len + 1);
- memcpy(ctx->post_data + old_index, str, n);
- }
- }
- return APR_SUCCESS;
-}
-
-static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx TSRMLS_DC)
-{
- char *content_type;
- const char *auth;
-
- PG(during_request_startup) = 0;
- SG(sapi_headers).http_response_code = 200;
- SG(request_info).content_type = apr_table_get(f->r->headers_in, "Content-Type");
-#undef safe_strdup
-#define safe_strdup(x) ((x)?strdup((x)):NULL)
- SG(request_info).query_string = safe_strdup(f->r->args);
- SG(request_info).request_method = f->r->method;
- SG(request_info).request_uri = safe_strdup(f->r->uri);
- f->r->no_local_copy = 1;
- content_type = sapi_get_default_content_type(TSRMLS_C);
- f->r->content_type = apr_pstrdup(f->r->pool, content_type);
- SG(request_info).post_data = ctx->post_data;
- SG(request_info).post_data_length = ctx->post_len;
-
- efree(content_type);
- apr_table_unset(f->r->headers_out, "Content-Length");
- apr_table_unset(f->r->headers_out, "Last-Modified");
- apr_table_unset(f->r->headers_out, "Expires");
- apr_table_unset(f->r->headers_out, "ETag");
- apr_table_unset(f->r->headers_in, "Connection");
- if (!PG(safe_mode)) {
- auth = apr_table_get(f->r->headers_in, "Authorization");
- php_handle_auth_data(auth TSRMLS_CC);
- } else {
- SG(request_info).auth_user = NULL;
- SG(request_info).auth_password = NULL;
- }
- php_request_startup(TSRMLS_C);
-}
-
-static void php_apache_request_dtor(ap_filter_t *f TSRMLS_DC)
-{
- php_request_shutdown(NULL);
-
- if (SG(request_info).query_string) {
- free(SG(request_info).query_string);
- }
- if (SG(request_info).request_uri) {
- free(SG(request_info).request_uri);
- }
-}
-
-static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
-{
- php_struct *ctx;
- apr_bucket *b;
- void *conf = ap_get_module_config(f->r->per_dir_config, &php4_module);
- char *p = get_php_config(conf, "engine", sizeof("engine"));
- TSRMLS_FETCH();
-
- if (f->r->proxyreq) {
- return ap_pass_brigade(f->next, bb);
- }
-
- /* handle situations where user turns the engine off */
- if (*p == '0') {
- return ap_pass_brigade(f->next, bb);
- }
-
- /* setup standard CGI variables */
- ap_add_common_vars(f->r);
- ap_add_cgi_vars(f->r);
-
- ctx = SG(server_context);
- if (ctx == NULL) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, f->r,
- "php failed to get server context");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- ctx->f = f; /* save whatever filters are after us in the chain. */
-
- if (ctx->request_processed) {
- return ap_pass_brigade(f->next, bb);
- }
-
- for (b = APR_BRIGADE_FIRST(bb); b != APR_BRIGADE_SENTINEL(bb); b = APR_BUCKET_NEXT(b)) {
- zend_file_handle zfd;
-
- if (!ctx->request_processed && APR_BUCKET_IS_FILE(b)) {
- const char *path;
- apr_bucket_brigade *prebb = bb;
-
- /* Split the brigade into two brigades before and after
- * the file bucket. Leave the "after the FILE" brigade
- * in the original bb, so it gets passed outside of this
- * loop. */
- bb = apr_brigade_split(prebb, b);
-
- /* Pass the "before the FILE" brigade here
- * (if it's non-empty). */
- if (!APR_BRIGADE_EMPTY(prebb)) {
- apr_status_t rv;
- rv = ap_pass_brigade(f->next, prebb);
- /* XXX: destroy the prebb, since we know we're
- * done with it? */
- if (rv != APR_SUCCESS) {
- php_handle_aborted_connection();
- }
- }
-
- apply_config(conf);
- php_apache_request_ctor(f, ctx TSRMLS_CC);
-
- apr_file_name_get(&path, ((apr_bucket_file *) b->data)->fd);
-
- /* Determine if we need to parse the file or show the source */
- if (strncmp(ctx->r->handler, "application/x-httpd-php-source", sizeof("application/x-httpd-php-source"))) {
- zfd.type = ZEND_HANDLE_FILENAME;
- zfd.filename = (char *) path;
- zfd.free_filename = 0;
- zfd.opened_path = NULL;
-
- php_execute_script(&zfd TSRMLS_CC);
-#if MEMORY_LIMIT
- {
- char *mem_usage;
-
- mem_usage = apr_psprintf(ctx->r->pool, "%u", AG(allocated_memory_peak));
- AG(allocated_memory_peak) = 0;
- apr_table_set(ctx->r->notes, "mod_php_memory_usage", mem_usage);
- }
-#endif
- } else {
- zend_syntax_highlighter_ini syntax_highlighter_ini;
-
- php_get_highlight_struct(&syntax_highlighter_ini);
-
- highlight_file((char *)path, &syntax_highlighter_ini TSRMLS_CC);
- }
-
- php_apache_request_dtor(f TSRMLS_CC);
-
- if (!f->r->main) {
- ctx->request_processed = 1;
- }
-
- /* Delete the FILE bucket from the brigade. */
- apr_bucket_delete(b);
-
- /* We won't handle any more buckets in this brigade, so
- * it's ok to break out now. */
- break;
- }
- }
-
- /* Pass whatever is left on the brigade. */
- return ap_pass_brigade(f->next, bb);
-}
-
-static apr_status_t
-php_apache_server_shutdown(void *tmp)
-{
- apache2_sapi_module.shutdown(&apache2_sapi_module);
- sapi_shutdown();
-#ifdef ZTS
- tsrm_shutdown();
-#endif
- return APR_SUCCESS;
-}
-
-static void php_apache_add_version(apr_pool_t *p)
-{
- TSRMLS_FETCH();
- if (PG(expose_php)) {
- ap_add_version_component(p, "PHP/" PHP_VERSION);
- }
-}
-
-static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
-{
-#ifndef ZTS
- int threaded_mpm;
-
- ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm);
- if(threaded_mpm) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, 0, 0, "Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.");
- return DONE;
- }
-#endif
- /* When this is NULL, apache won't override the hard-coded default
- * php.ini path setting. */
- apache2_php_ini_path_override = NULL;
- return OK;
-}
-
-static int
-php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog,
- apr_pool_t *ptemp, server_rec *s)
-{
- void *data = NULL;
- const char *userdata_key = "apache2filter_post_config";
-
- /* Apache will load, unload and then reload a DSO module. This
- * prevents us from starting PHP until the second load. */
- apr_pool_userdata_get(&data, userdata_key, s->process->pool);
- if (data == NULL) {
- /* We must use set() here and *not* setn(), otherwise the
- * static string pointed to by userdata_key will be mapped
- * to a different location when the DSO is reloaded and the
- * pointers won't match, causing get() to return NULL when
- * we expected it to return non-NULL. */
- apr_pool_userdata_set((const void *)1, userdata_key,
- apr_pool_cleanup_null, s->process->pool);
- return OK;
- }
-
- /* Set up our overridden path. */
- if (apache2_php_ini_path_override) {
- apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;
- }
-#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
-#endif
- sapi_startup(&apache2_sapi_module);
- apache2_sapi_module.startup(&apache2_sapi_module);
- apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
- php_apache_add_version(pconf);
-
- return OK;
-}
-
-static void php_add_filter(request_rec *r, ap_filter_t *f)
-{
- int output = (f == r->output_filters);
-
- /* for those who still have Set*Filter PHP configured */
- while (f) {
- if (strcmp(f->frec->name, "PHP") == 0) {
- ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO,
- 0, r->server,
- "\"Set%sFilter PHP\" already configured for %s",
- output ? "Output" : "Input", r->uri);
- return;
- }
- f = f->next;
- }
-
- if (output) {
- ap_add_output_filter("PHP", NULL, r, r->connection);
- } else {
- ap_add_input_filter("PHP", NULL, r, r->connection);
- }
-}
-
-static void php_insert_filter(request_rec *r)
-{
- int content_type_len = strlen("application/x-httpd-php");
-
- if (r->content_type && !strncmp(r->content_type, "application/x-httpd-php", content_type_len-1)) {
- if (r->content_type[content_type_len] == '\0' || !strncmp(r->content_type+content_type_len, "-source", sizeof("-source"))) {
- php_add_filter(r, r->output_filters);
- php_add_filter(r, r->input_filters);
- }
- }
-}
-
-static apr_status_t php_server_context_cleanup(void *data_)
-{
- void **data = data_;
- *data = NULL;
- return APR_SUCCESS;
-}
-
-static int php_post_read_request(request_rec *r)
-{
- php_struct *ctx;
- TSRMLS_FETCH();
-
- /* Initialize filter context */
- SG(server_context) = ctx = apr_pcalloc(r->pool, sizeof(*ctx));
-
- /* register a cleanup so we clear out the SG(server_context)
- * after each request. Note: We pass in the pointer to the
- * server_context in case this is handled by a different thread. */
- apr_pool_cleanup_register(r->pool, (void *)&SG(server_context),
- php_server_context_cleanup,
- apr_pool_cleanup_null);
-
- /* Save the entire request, so we can get the input or output
- * filters if we need them. */
- ctx->r = r;
-
- return OK;
-}
-
-static void php_register_hook(apr_pool_t *p)
-{
- ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_insert_filter(php_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_post_read_request(php_post_read_request, NULL, NULL, APR_HOOK_MIDDLE);
- ap_register_output_filter("PHP", php_output_filter, php_apache_disable_caching, AP_FTYPE_RESOURCE);
- ap_register_input_filter("PHP", php_input_filter, php_apache_disable_caching, AP_FTYPE_RESOURCE);
-}
-
-AP_MODULE_DECLARE_DATA module php4_module = {
- STANDARD20_MODULE_STUFF,
- create_php_config, /* create per-directory config structure */
- merge_php_config, /* merge per-directory config structures */
- NULL, /* create per-server config structure */
- NULL, /* merge per-server config structures */
- php_dir_cmds, /* command apr_table_t */
- php_register_hook /* register hooks */
-};
-
-/*
- * 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/apache2handler/CREDITS b/sapi/apache2handler/CREDITS
deleted file mode 100644
index 5e85cb448e..0000000000
--- a/sapi/apache2handler/CREDITS
+++ /dev/null
@@ -1,3 +0,0 @@
-Apache 2.0
-Sascha Schumann, Aaron Bannert original work
-Ian Holsman & Justin Erenkrantz is for converting this to a handler
diff --git a/sapi/apache2handler/EXPERIMENTAL b/sapi/apache2handler/EXPERIMENTAL
deleted file mode 100644
index 293159a693..0000000000
--- a/sapi/apache2handler/EXPERIMENTAL
+++ /dev/null
@@ -1,5 +0,0 @@
-this module is experimental,
-its functions may change their names
-or move to extension all together
-so do not rely to much on them
-you have been warned!
diff --git a/sapi/apache2handler/README b/sapi/apache2handler/README
deleted file mode 100644
index 5cbd1b95dd..0000000000
--- a/sapi/apache2handler/README
+++ /dev/null
@@ -1,76 +0,0 @@
-WHAT IS THIS?
-
- This module exploits the layered I/O support in Apache 2.0.
-
-HOW DOES IT WORK?
-
- In Apache 2.0, you have handlers which generate content (like
- reading a script from disk). The content goes then through
- a chain of filters. PHP can be such a filter, so that it processes
- your script and hands the output to the next filter (which will
- usually cause a write to the network).
-
-DOES IT WORK?
-
- Currently the issues with the module are:
- * Thread safety of external PHP modules
- * The lack of re-entrancy of PHP. due to this I have disabled the 'virtual'
- function, and tried to stop any method where a php script can run another php
- script while it is being run.
-
-
-HOW TO INSTALL
-
- This SAPI module is known to work with Apache 2.0.44.
-
- $ cd apache-2.x
- $ cd src
- $ ./configure --enable-so
- $ make install
-
- For testing purposes, you might want to use --with-mpm=prefork.
- (Albeit PHP also works with threaded MPMs. See Thread Safety note above)
-
- Configure PHP 4:
-
- $ cd php-4.x
- $ ./configure --with-apxs2=/path/to/apache-2.0/bin/apxs
- $ make install
-
- At the end of conf/httpd.conf, add:
-
- AddType application/x-httpd-php .php
-
- If you would like to enable source code highlighting functionality add:
-
- AddType application/x-httpd-php-source .phps
-
- That's it. Now start bin/httpd.
-
-HOW TO CONFIGURE
-
- The Apache 2.0 PHP module supports a new configuration directive that
- allows an admin to override the php.ini search path. For example,
- place your php.ini file in Apache's ServerRoot/conf directory and
- add this to your httpd.conf file:
-
- PHPINIDir "conf"
-
-DEBUGGING APACHE AND PHP
-
- To debug Apache, we recommened:
-
- 1. Use the Prefork MPM (Apache 1.3-like process model) by
- configuring Apache with '--with-mpm=prefork'.
- 2. Start httpd using -DONE_PROCESS (e.g. (gdb) r -DONE_PROCESS).
-
- If you want to debug a part of the PHP startup procedure, set a
- breakpoint on 'load_module'. Step through it until apr_dso_load() is
- done. Then you can set a breakpoint on any PHP-related symbol.
-
-TODO
-
- PHP functions like apache_sub_req (see php_functions.c)
- Source Code Highlighting
- Protocol handlers
-
diff --git a/sapi/apache2handler/apache_config.c b/sapi/apache2handler/apache_config.c
deleted file mode 100644
index 3859653ce8..0000000000
--- a/sapi/apache2handler/apache_config.c
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-#include "php_ini.h"
-#include "php_apache.h"
-
-#include "apr_strings.h"
-#include "ap_config.h"
-#include "util_filter.h"
-#include "httpd.h"
-#include "http_config.h"
-#include "http_request.h"
-#include "http_core.h"
-#include "http_protocol.h"
-#include "http_log.h"
-#include "http_main.h"
-#include "util_script.h"
-#include "http_core.h"
-
-#ifdef PHP_AP_DEBUG
-#define phpapdebug(a) fprintf a
-#else
-#define phpapdebug(a)
-#endif
-
-typedef struct {
- HashTable config;
-} php_conf_rec;
-
-typedef struct {
- char *value;
- size_t value_len;
- char status;
-} php_dir_entry;
-
-static const char *real_value_hnd(cmd_parms *cmd, void *dummy,
- const char *name, const char *value, int status)
-{
- php_conf_rec *d = dummy;
- php_dir_entry e;
-
- phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy,
- zend_hash_num_elements(&d->config)));
-
- if (!strncasecmp(value, "none", sizeof("none"))) {
- value = "";
- }
-
- e.value = apr_pstrdup(cmd->pool, value);
- e.value_len = strlen(value);
- e.status = status;
-
- zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e,
- sizeof(e), NULL);
- return NULL;
-}
-
-static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy,
- const char *name, const char *value)
-{
- return real_value_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
-}
-
-static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy,
- const char *name, const char *value)
-{
- return real_value_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
-}
-
-static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1,
- const char *arg2, int status)
-{
- char bool_val[2];
-
- if (!strcasecmp(arg2, "On") || (arg2[0] == '1' && arg2[1] == '\0')) {
- bool_val[0] = '1';
- } else {
- bool_val[0] = '0';
- }
- bool_val[1] = 0;
-
- return real_value_hnd(cmd, dummy, arg1, bool_val, status);
-}
-
-static const char *php_apache_flag_handler(cmd_parms *cmd, void *dummy,
- const char *name, const char *value)
-{
- return real_flag_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
-}
-
-static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy,
- const char *name, const char *value)
-{
- return real_flag_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
-}
-
-static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig,
- const char *arg)
-{
- if (apache2_php_ini_path_override) {
- return "Only first PHPINIDir directive honored per configuration tree "
- "- subsequent ones ignored";
- }
- apache2_php_ini_path_override = ap_server_root_relative(cmd->pool, arg);
- return NULL;
-}
-
-
-void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
-{
- php_conf_rec *d = base_conf, *e = new_conf;
- php_dir_entry *pe;
- php_dir_entry *data;
- char *str;
- uint str_len;
- ulong num_index;
-
- phpapdebug((stderr, "Merge dir (%p) (%p)\n", base_conf, new_conf));
- for (zend_hash_internal_pointer_reset(&d->config);
- zend_hash_get_current_key_ex(&d->config, &str, &str_len,
- &num_index, 0, NULL) == HASH_KEY_IS_STRING;
- zend_hash_move_forward(&d->config)) {
- pe = NULL;
- zend_hash_get_current_data(&d->config, (void **) &data);
- if (zend_hash_find(&e->config, str, str_len, (void **) &pe) == SUCCESS) {
- if (pe->status >= data->status) continue;
- }
- zend_hash_update(&e->config, str, str_len, data, sizeof(*data), NULL);
- phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str,
- data->status, pe?pe->status:-1));
- }
- return new_conf;
-}
-
-char *get_php_config(void *conf, char *name, size_t name_len)
-{
- php_conf_rec *d = conf;
- php_dir_entry *pe;
-
- if (zend_hash_find(&d->config, name, name_len, (void **) &pe) == SUCCESS) {
- return pe->value;
- }
-
- return "";
-}
-
-void apply_config(void *dummy)
-{
- php_conf_rec *d = dummy;
- char *str;
- uint str_len;
- php_dir_entry *data;
-
- for (zend_hash_internal_pointer_reset(&d->config);
- zend_hash_get_current_key_ex(&d->config, &str, &str_len, NULL, 0,
- NULL) == HASH_KEY_IS_STRING;
- zend_hash_move_forward(&d->config)) {
- zend_hash_get_current_data(&d->config, (void **) &data);
- phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value));
- if (zend_alter_ini_entry(str, str_len, data->value, data->value_len,
- data->status, PHP_INI_STAGE_RUNTIME) == FAILURE) {
- phpapdebug((stderr, "..FAILED\n"));
- }
- }
-}
-
-const command_rec php_dir_cmds[] =
-{
- AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS,
- "PHP Value Modifier"),
- AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS,
- "PHP Flag Modifier"),
- AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL,
- ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"),
- AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL,
- ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"),
- AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF,
- "Directory containing the php.ini file"),
- {NULL}
-};
-
-static apr_status_t destroy_php_config(void *data)
-{
- php_conf_rec *d = data;
-
- phpapdebug((stderr, "Destroying config %p\n", data));
- zend_hash_destroy(&d->config);
-
- return APR_SUCCESS;
-}
-
-void *create_php_config(apr_pool_t *p, char *dummy)
-{
- php_conf_rec *newx =
- (php_conf_rec *) apr_pcalloc(p, sizeof(*newx));
-
- phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy));
- zend_hash_init(&newx->config, 0, NULL, NULL, 1);
- apr_pool_cleanup_register(p, newx, destroy_php_config, apr_pool_cleanup_null);
- return (void *) newx;
-}
-
-/*
- * 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/apache2handler/config.m4 b/sapi/apache2handler/config.m4
deleted file mode 100644
index 7eb001cfe2..0000000000
--- a/sapi/apache2handler/config.m4
+++ /dev/null
@@ -1,118 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for Apache 2.0 handler-module support via DSO through APXS)
-AC_ARG_WITH(apxs2handler,
-[ --with-apxs2handler[=FILE] EXPERIMENTAL: Build shared Apache 2.0 module. FILE is the optional
- pathname to the Apache apxs tool; defaults to "apxs".],[
- if test "$withval" = "yes"; then
- APXS=apxs
- $APXS -q CFLAGS >/dev/null 2>&1
- if test "$?" != "0" && test -x /usr/sbin/apxs; then
- APXS=/usr/sbin/apxs
- fi
- else
- PHP_EXPAND_PATH($withval, APXS)
- fi
-
- $APXS -q CFLAGS >/dev/null 2>&1
- if test "$?" != "0"; then
- AC_MSG_RESULT()
- AC_MSG_RESULT()
- AC_MSG_RESULT([Sorry, I cannot run apxs. Possible reasons follow:])
- AC_MSG_RESULT()
- AC_MSG_RESULT([1. Perl is not installed])
- AC_MSG_RESULT([2. apxs was not found. Try to pass the path using --with-apxs2handler=/path/to/apxs])
- AC_MSG_RESULT([3. Apache was not built using --enable-so (the apxs usage page is displayed)])
- AC_MSG_RESULT()
- AC_MSG_RESULT([The output of $APXS follows:])
- $APXS
- AC_MSG_ERROR([Aborting])
- fi
-
- APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR`
- APXS_HTTPD=`$APXS -q SBINDIR`/`$APXS -q TARGET`
- APXS_CFLAGS=`$APXS -q CFLAGS`
- APXS_MPM=`$APXS -q MPM_NAME`
-
- for flag in $APXS_CFLAGS; do
- case $flag in
- -D*) CPPFLAGS="$CPPFLAGS $flag";;
- esac
- done
-
- # Test that we're trying to configure with apache 2.x
- PHP_AP_EXTRACT_VERSION($APXS_HTTPD)
- if test "$APACHE_VERSION" -le 2000000; then
- AC_MSG_ERROR([You have enabled Apache 2 support while your server is Apache 1.3. Please use the appropiate switch --with-apxs (without the 2)])
- elif test "$APACHE_VERSION" -lt 2000044; then
- AC_MSG_ERROR([Please note that Apache version >= 2.0.44 is required.])
- fi
-
- APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR`
- if test -z `$APXS -q SYSCONFDIR`; then
- INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \
- $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \
- -i -n php4"
- else
- APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR`
- INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \
- \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \
- $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \
- -S SYSCONFDIR='$APXS_SYSCONFDIR' \
- -i -a -n php4"
- fi
-
- case $host_alias in
- *aix*)
- EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-brtl -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp"
- PHP_SELECT_SAPI(apache2handler, shared, sapi_apache2.c apache_config.c php_functions.c)
- INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL"
- ;;
- *darwin*)
- dnl When using bundles on Darwin, we must resolve all symbols. However,
- dnl the linker does not recursively look at the bundle loader and
- dnl pull in its dependencies. Therefore, we must pull in the APR
- dnl and APR-util libraries.
- APXS_BINDIR=`$APXS -q BINDIR`
- if test -f $APXS_BINDIR/apr-config; then
- MH_BUNDLE_FLAGS="`$APXS_BINDIR/apr-config --ldflags --link-ld --libs`"
- fi
- if test -f $APXS_BINDIR/apu-config; then
- MH_BUNDLE_FLAGS="`$APXS_BINDIR/apu-config --ldflags --link-ld --libs` $MH_BUNDLE_FLAGS"
- fi
- MH_BUNDLE_FLAGS="-bundle -bundle_loader $APXS_HTTPD $MH_BUNDLE_FLAGS"
- PHP_SUBST(MH_BUNDLE_FLAGS)
- PHP_SELECT_SAPI(apache2handler, bundle, sapi_apache2.c apache_config.c php_functions.c)
- SAPI_SHARED=libs/libphp4.so
- INSTALL_IT="$INSTALL_IT $SAPI_SHARED"
- ;;
- *beos*)
- APXS_BINDIR=`$APXS -q BINDIR`
- if test -f _APP_; then `rm _APP_`; fi
- `ln -s $APXS_BINDIR/httpd _APP_`
- EXTRA_LIBS="$EXTRA_LIBS _APP_"
- PHP_SELECT_SAPI(apache2handler, shared, sapi_apache2.c apache_config.c php_functions.c)
- INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL"
- ;;
- *)
- PHP_SELECT_SAPI(apache2handler, shared, sapi_apache2.c apache_config.c php_functions.c)
- INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL"
- ;;
- esac
-
- PHP_ADD_INCLUDE($APXS_INCLUDEDIR)
- if test "$APXS_MPM" != "prefork"; then
- PHP_BUILD_THREAD_SAFE
- fi
- AC_MSG_RESULT(yes)
-],[
- AC_MSG_RESULT(no)
-])
-
-PHP_SUBST(APXS)
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
diff --git a/sapi/apache2handler/php.sym b/sapi/apache2handler/php.sym
deleted file mode 100644
index 2dca1256c2..0000000000
--- a/sapi/apache2handler/php.sym
+++ /dev/null
@@ -1 +0,0 @@
-php4_module
diff --git a/sapi/apache2handler/php4apache2.dsp b/sapi/apache2handler/php4apache2.dsp
deleted file mode 100644
index 6a21ee8de1..0000000000
--- a/sapi/apache2handler/php4apache2.dsp
+++ /dev/null
@@ -1,142 +0,0 @@
-# Microsoft Developer Studio Project File - Name="php4apache2h" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php4apache2h - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "php4apache2h.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 "php4apache2h.mak" CFG="php4apache2h - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php4apache2h - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4apache2h - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4apache2h - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "php4apache2h - 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 "php4apache2h_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "WIN32" /D "_MBCS" /D "_WINSOCK2API_" /D "_MSWSOCK_" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "NDEBUG"
-# ADD RSC /l 0x407 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php4ts.lib libhttpd.lib libapr.lib libaprutil.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS"
-
-!ELSEIF "$(CFG)" == "php4apache2h - 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 "php4apache2h_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /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 "WIN32" /D "_MBCS" /D "_WINSOCK2API_" /D "_MSWSOCK_" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "NDEBUG"
-# ADD RSC /l 0x407 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php4ts.lib libhttpd.lib libapr.lib libaprutil.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS_inline/php4apache2h.dll" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"
-
-!ELSEIF "$(CFG)" == "php4apache2h - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "php4apache2h_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "WIN32" /D "_MBCS" /D "_WINSOCK2API_" /D "_MSWSOCK_" /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "_DEBUG"
-# ADD RSC /l 0x407 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 php4ts_debug.lib libhttpd.lib libapr.lib libaprutil.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php4apache2h - Win32 Release_TS"
-# Name "php4apache2h - Win32 Release_TS_inline"
-# Name "php4apache2h - Win32 Debug_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\apache_config.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_functions.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\sapi_apache2.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php_apache.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/sapi/apache2handler/php_apache.h b/sapi/apache2handler/php_apache.h
deleted file mode 100644
index edd76e6fa3..0000000000
--- a/sapi/apache2handler/php_apache.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#ifndef PHP_APACHE_H
-#define PHP_APACHE_H
-
-#include "httpd.h"
-#include "http_config.h"
-#include "http_core.h"
-
-/* Declare this so we can get to it from outside the sapi_apache2.c file */
-extern module AP_MODULE_DECLARE_DATA php4_module;
-
-/* A way to specify the location of the php.ini dir in an apache directive */
-extern char *apache2_php_ini_path_override;
-
-/* The server_context used by PHP */
-typedef struct php_struct {
- int state;
- request_rec *r;
- apr_bucket_brigade *brigade;
- /* stat structure of the current file */
-#if defined(NETWARE) && defined(CLIB_STAT_PATCH)
- struct stat_libc finfo;
-#else
- struct stat finfo;
-#endif
- /* Whether or not we've processed PHP in the output filters yet. */
- int request_processed;
-} php_struct;
-
-void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf);
-void *create_php_config(apr_pool_t *p, char *dummy);
-char *get_php_config(void *conf, char *name, size_t name_len);
-void apply_config(void *);
-extern const command_rec php_dir_cmds[];
-
-#define APR_ARRAY_FOREACH_OPEN(arr, key, val) \
-{ \
- apr_table_entry_t *elts; \
- int i; \
- elts = (apr_table_entry_t *) arr->elts; \
- for (i = 0; i < arr->nelts; i++) { \
- key = elts[i].key; \
- val = elts[i].val;
-
-#define APR_ARRAY_FOREACH_CLOSE() }}
-
-#endif /* PHP_APACHE_H */
diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c
deleted file mode 100644
index 20547424be..0000000000
--- a/sapi/apache2handler/php_functions.c
+++ /dev/null
@@ -1,404 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-#include "ext/standard/php_smart_str.h"
-#include "ext/standard/info.h"
-#include "SAPI.h"
-
-#define CORE_PRIVATE
-#include "apr_strings.h"
-#include "apr_time.h"
-#include "ap_config.h"
-#include "util_filter.h"
-#include "httpd.h"
-#include "http_config.h"
-#include "http_request.h"
-#include "http_core.h"
-#include "http_protocol.h"
-#include "http_log.h"
-#include "http_main.h"
-#include "util_script.h"
-#include "http_core.h"
-
-#include "php_apache.h"
-
-static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC)
-{
- php_struct *ctx;
-
- if (!filename) {
- return NULL;
- }
-
- ctx = SG(server_context);
- return ap_sub_req_lookup_uri(filename, ctx->r, ctx->r->output_filters);
-}
-
-/* proto bool virtual(string uri)
- Perform an apache sub-request */
-PHP_FUNCTION(virtual)
-{
- zval **filename;
- request_rec *rr;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(filename);
-
-
- if (!(rr = php_apache_lookup_uri(Z_STRVAL_PP(filename) TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", Z_STRVAL_PP(filename));
- RETURN_FALSE;
- }
-
- if (rr->status != HTTP_OK) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", Z_STRVAL_PP(filename));
- ap_destroy_sub_req(rr);
- RETURN_FALSE;
- }
-
- /* Flush everything. */
- php_end_ob_buffers(1 TSRMLS_CC);
- php_header();
-
- if (ap_run_sub_req(rr)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", Z_STRVAL_PP(filename));
- ap_destroy_sub_req(rr);
- RETURN_FALSE;
- }
- ap_destroy_sub_req(rr);
- RETURN_TRUE;
-}
-/* */
-
-#define ADD_LONG(name) \
- add_property_long(return_value, #name, rr->name)
-#define ADD_TIME(name) \
- add_property_long(return_value, #name, rr->name / APR_USEC_PER_SEC);
-#define ADD_STRING(name) \
- if (rr->name) add_property_string(return_value, #name, (char *) rr->name, 1)
-
-PHP_FUNCTION(apache_lookup_uri)
-{
- request_rec *rr;
- zval **filename;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(filename);
-
- if (!(rr = php_apache_lookup_uri(Z_STRVAL_PP(filename) TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", Z_STRVAL_PP(filename));
- RETURN_FALSE;
- }
-
- if (rr->status == HTTP_OK) {
- object_init(return_value);
-
- ADD_LONG(status);
- ADD_STRING(the_request);
- ADD_STRING(status_line);
- ADD_STRING(method);
- ADD_TIME(mtime);
- ADD_LONG(clength);
-#if MODULE_MAGIC_NUMBER < 20020506
- ADD_STRING(boundary);
-#endif
- ADD_STRING(range);
- ADD_LONG(chunked);
- ADD_STRING(content_type);
- ADD_STRING(handler);
- ADD_LONG(no_cache);
- ADD_LONG(no_local_copy);
- ADD_STRING(unparsed_uri);
- ADD_STRING(uri);
- ADD_STRING(filename);
- ADD_STRING(path_info);
- ADD_STRING(args);
- ADD_LONG(allowed);
- ADD_LONG(sent_bodyct);
- ADD_LONG(bytes_sent);
- ADD_LONG(request_time);
- ADD_LONG(mtime);
- ADD_TIME(request_time);
-
- ap_destroy_sub_req(rr);
- return;
- }
-
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", Z_STRVAL_PP(filename));
- ap_destroy_sub_req(rr);
- RETURN_FALSE;
-}
-
-/* proto array getallheaders(void)
- Fetch all HTTP request headers */
-PHP_FUNCTION(apache_request_headers)
-{
- php_struct *ctx;
- const apr_array_header_t *arr;
- char *key, *val;
-
- array_init(return_value);
-
- ctx = SG(server_context);
- arr = apr_table_elts(ctx->r->headers_in);
-
- APR_ARRAY_FOREACH_OPEN(arr, key, val)
- if (!val) val = empty_string;
- add_assoc_string(return_value, key, val, 1);
- APR_ARRAY_FOREACH_CLOSE()
-}
-/* */
-
-/* {{{ proto array apache_response_headers(void)
- Fetch all HTTP response headers */
-PHP_FUNCTION(apache_response_headers)
-{
- php_struct *ctx;
- const apr_array_header_t *arr;
- char *key, *val;
-
- array_init(return_value);
-
- ctx = SG(server_context);
- arr = apr_table_elts(ctx->r->headers_out);
-
- APR_ARRAY_FOREACH_OPEN(arr, key, val)
- if (!val) val = empty_string;
- add_assoc_string(return_value, key, val, 1);
- APR_ARRAY_FOREACH_CLOSE()
-}
-/* }}} */
-
-/* {{{ proto string apache_note(string note_name [, string note_value])
- Get and set Apache request notes */
-PHP_FUNCTION(apache_note)
-{
- php_struct *ctx;
- zval **note_name, **note_val;
- char *old_note_val=NULL;
- int arg_count = ZEND_NUM_ARGS();
-
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &note_name, &note_val) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- ctx = SG(server_context);
-
- convert_to_string_ex(note_name);
-
- old_note_val = (char *) apr_table_get(ctx->r->notes, Z_STRVAL_PP(note_name));
-
- if (arg_count == 2) {
- convert_to_string_ex(note_val);
- apr_table_set(ctx->r->notes, Z_STRVAL_PP(note_name), Z_STRVAL_PP(note_val));
- }
-
- if (old_note_val) {
- RETURN_STRING(old_note_val, 1);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-
-/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top])
- Set an Apache subprocess_env variable */
-/*
- * XXX this doesn't look right. shouldn't it be the parent ?*/
-PHP_FUNCTION(apache_setenv)
-{
- php_struct *ctx;
- zval **variable=NULL, **string_val=NULL, **walk_to_top=NULL;
- int arg_count = ZEND_NUM_ARGS();
- request_rec *r;
-
- if (arg_count<1 || arg_count>3 ||
- zend_get_parameters_ex(arg_count, &variable, &string_val, &walk_to_top) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- ctx = SG(server_context);
-
- if (arg_count == 3 && Z_STRVAL_PP(walk_to_top)) {
- r = ctx->r;
- while(r->prev) {
- r = r->prev;
- }
- }
-
- convert_to_string_ex(variable);
- convert_to_string_ex(string_val);
-
- apr_table_set(r->subprocess_env, Z_STRVAL_PP(variable), Z_STRVAL_PP(string_val));
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto bool apache_getenv(string variable [, bool walk_to_top])
- Get an Apache subprocess_env variable */
-/*
- * XXX: shouldn't this be the parent not the 'prev'
- */
-PHP_FUNCTION(apache_getenv)
-{
- php_struct *ctx;
- zval **variable=NULL, **walk_to_top=NULL;
- int arg_count = ZEND_NUM_ARGS();
- char *env_val=NULL;
- request_rec *r;
-
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &variable, &walk_to_top) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- ctx = SG(server_context);
-
- r = ctx->r;
- if (arg_count == 2 && Z_STRVAL_PP(walk_to_top)) {
- while(r->prev) {
- r = r->prev;
- }
- }
-
- convert_to_string_ex(variable);
-
- env_val = (char*) apr_table_get(r->subprocess_env, Z_STRVAL_PP(variable));
- if (env_val != NULL) {
- RETURN_STRING(env_val, 1);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-static char *php_apache_get_version()
-{
- return (char *) ap_get_server_version();
-}
-
-/* {{{ proto string apache_get_version(void)
- Fetch Apache version */
-PHP_FUNCTION(apache_get_version)
-{
- char *apv = php_apache_get_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);
- }
- }
-}
-/* }}} */
-
-PHP_MINFO_FUNCTION(apache)
-{
- char *apv = php_apache_get_version();
- smart_str tmp1 = {0};
- int n;
- char *p;
-
- for (n = 0; ap_loaded_modules[n]; ++n) {
- char *s = (char *) ap_loaded_modules[n]->name;
- if ((p = strchr(s, '.'))) {
- smart_str_appendl(&tmp1, s, (p - s));
- } else {
- smart_str_appends(&tmp1, s);
- }
- smart_str_appendc(&tmp1, ' ');
- }
- if ((tmp1.len - 1) >= 0) {
- tmp1.c[tmp1.len - 1] = '\0';
- }
-
- php_info_print_table_start();
- if (apv && *apv) {
- php_info_print_table_row(2, "Apache Version", apv);
- }
- php_info_print_table_row(2, "Loaded Modules", tmp1.c);
- smart_str_free(&tmp1);
- php_info_print_table_end();
-}
-
-static function_entry apache_functions[] = {
- PHP_FE(apache_lookup_uri, NULL)
- PHP_FE(virtual, NULL)
- PHP_FE(apache_request_headers, NULL)
- PHP_FE(apache_response_headers, NULL)
- PHP_FE(apache_setenv, NULL)
- PHP_FE(apache_getenv, NULL)
- PHP_FE(apache_note, NULL)
- PHP_FE(apache_get_version, NULL)
- PHP_FE(apache_get_modules, NULL)
- PHP_FALIAS(getallheaders, apache_request_headers, NULL)
- {NULL, NULL, NULL}
-};
-
-zend_module_entry php_apache_module = {
- STANDARD_MODULE_HEADER,
- "Apache 2.0",
- apache_functions,
- NULL,
- NULL,
- NULL,
- NULL,
- PHP_MINFO(apache),
- NULL,
- STANDARD_MODULE_PROPERTIES
-};
-
-/*
- * 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/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c
deleted file mode 100644
index 9918271aa4..0000000000
--- a/sapi/apache2handler/sapi_apache2.c
+++ /dev/null
@@ -1,613 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- | Parts based on Apache 1.3 SAPI module by |
- | Rasmus Lerdorf and Zeev Suraski |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include <fcntl.h>
-
-#include "php.h"
-#include "php_main.h"
-#include "php_ini.h"
-#include "php_variables.h"
-#include "SAPI.h"
-
-#include "ext/standard/php_smart_str.h"
-#ifndef NETWARE
-#include "ext/standard/php_standard.h"
-#else
-#include "ext/standard/basic_functions.h"
-#endif
-
-#include "apr_strings.h"
-#include "ap_config.h"
-#include "util_filter.h"
-#include "httpd.h"
-#include "http_config.h"
-#include "http_request.h"
-#include "http_core.h"
-#include "http_protocol.h"
-#include "http_log.h"
-#include "http_main.h"
-#include "util_script.h"
-#include "http_core.h"
-#include "ap_mpm.h"
-
-#include "php_apache.h"
-
-#ifdef NETWARE
-#undef shutdown /* To avoid Winsock confusion */
-#endif
-
-#define PHP_MAGIC_TYPE "application/x-httpd-php"
-#define PHP_SOURCE_MAGIC_TYPE "application/x-httpd-php-source"
-#define PHP_SCRIPT "php-script"
-
-/* A way to specify the location of the php.ini dir in an apache directive */
-char *apache2_php_ini_path_override = NULL;
-
-static int
-php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- apr_bucket *bucket;
- apr_bucket_brigade *brigade;
- request_rec *r;
- php_struct *ctx;
-
- if (str_length == 0) {
- return 0;
- }
-
- ctx = SG(server_context);
- r = ctx->r;
- brigade = ctx->brigade;
-
- bucket = apr_bucket_transient_create(str, str_length,
- r->connection->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(brigade, bucket);
-
- /* Add a Flush bucket to the end of this brigade, so that
- * the transient buckets above are more likely to make it out
- * the end of the filter instead of having to be copied into
- * someone's setaside.
- */
- bucket = apr_bucket_flush_create(r->connection->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(brigade, bucket);
-
- if (ap_pass_brigade(r->output_filters, brigade) != APR_SUCCESS) {
- php_handle_aborted_connection();
- }
- /* Ensure this brigade is empty for the next usage. */
- apr_brigade_cleanup(brigade);
-
- return str_length; /* we always consume all the data passed to us. */
-}
-
-static int
-php_apache_sapi_header_handler(sapi_header_struct *sapi_header,sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- php_struct *ctx;
- char *val;
-
- ctx = SG(server_context);
-
- val = strchr(sapi_header->header, ':');
-
- if (!val) {
- sapi_free_header(sapi_header);
- return 0;
- }
-
- *val = '\0';
-
- do {
- val++;
- } while (*val == ' ');
-
- if (!strcasecmp(sapi_header->header, "content-type")) {
- val = apr_pstrdup(ctx->r->pool, val);
- ap_set_content_type(ctx->r, val);
- }
- else if (sapi_header->replace) {
- apr_table_set(ctx->r->headers_out, sapi_header->header, val);
- }
- else {
- apr_table_add(ctx->r->headers_out, sapi_header->header, val);
- }
-
- sapi_free_header(sapi_header);
-
- return 0;
-}
-
-static int
-php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- php_struct *ctx = SG(server_context);
-
- ctx->r->status = SG(sapi_headers).http_response_code;
-
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-static int
-php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC)
-{
- apr_size_t len;
- php_struct *ctx = SG(server_context);
- request_rec *r;
- apr_bucket_brigade *brigade;
- apr_status_t rv;
-
- r = ctx->r;
- brigade = ctx->brigade;
- len = count_bytes;
-
- rv = ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES,
- APR_BLOCK_READ, len);
-
- if (rv == APR_SUCCESS) {
- apr_brigade_flatten(brigade, buf, &len);
- }
- else {
- len = 0;
- }
-
- apr_brigade_cleanup(brigade);
-
- /* This is downcast is okay, because len is constrained by
- * count_bytes and we know ap_get_brigade won't return more
- * than that.
- */
- return len;
-}
-
-static struct stat*
-php_apache_sapi_get_stat(TSRMLS_D)
-{
- php_struct *ctx = SG(server_context);
-
- ctx->finfo.st_uid = ctx->r->finfo.user;
- ctx->finfo.st_gid = ctx->r->finfo.group;
- ctx->finfo.st_ino = ctx->r->finfo.inode;
-#if defined(NETWARE) && defined(CLIB_STAT_PATCH)
- ctx->finfo.st_atime.tv_sec = ctx->r->finfo.atime/1000000;
- ctx->finfo.st_mtime.tv_sec = ctx->r->finfo.mtime/1000000;
- ctx->finfo.st_ctime.tv_sec = ctx->r->finfo.ctime/1000000;
-#else
- ctx->finfo.st_atime = ctx->r->finfo.atime/1000000;
- ctx->finfo.st_mtime = ctx->r->finfo.mtime/1000000;
- ctx->finfo.st_ctime = ctx->r->finfo.ctime/1000000;
-#endif
-
- ctx->finfo.st_size = ctx->r->finfo.size;
- ctx->finfo.st_nlink = ctx->r->finfo.nlink;
-
- return &ctx->finfo;
-}
-
-static char *
-php_apache_sapi_read_cookies(TSRMLS_D)
-{
- php_struct *ctx = SG(server_context);
- const char *http_cookie;
-
- http_cookie = apr_table_get(ctx->r->headers_in, "cookie");
-
- /* The SAPI interface should use 'const char *' */
- return (char *) http_cookie;
-}
-
-static char *
-php_apache_sapi_getenv(char *name, size_t name_len TSRMLS_DC)
-{
- php_struct *ctx = SG(server_context);
- const char *env_var;
-
- env_var = apr_table_get(ctx->r->subprocess_env, name);
-
- return (char *) env_var;
-}
-
-static void
-php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- php_struct *ctx = SG(server_context);
- const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env);
- char *key, *val;
-
- APR_ARRAY_FOREACH_OPEN(arr, key, val)
- if (!val) val = empty_string;
- php_register_variable(key, val, track_vars_array TSRMLS_CC);
- APR_ARRAY_FOREACH_CLOSE()
-
- php_register_variable("PHP_SELF", ctx->r->uri, track_vars_array TSRMLS_CC);
-}
-
-static void
-php_apache_sapi_flush(void *server_context)
-{
- php_struct *ctx;
- apr_bucket_brigade *brigade;
- apr_bucket *bucket;
- request_rec *r;
-
- ctx = server_context;
-
- /* If we haven't registered a server_context yet,
- * then don't bother flushing. */
- if (!server_context) {
- return;
- }
-
- r = ctx->r;
- brigade = ctx->brigade;
-
- /* Send a flush bucket down the filter chain. */
- bucket = apr_bucket_flush_create(r->connection->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(brigade, bucket);
- if (ap_pass_brigade(r->output_filters, brigade) != APR_SUCCESS) {
- php_handle_aborted_connection();
- }
- apr_brigade_cleanup(brigade);
-}
-
-static void php_apache_sapi_log_message(char *msg)
-{
- php_struct *ctx;
- TSRMLS_FETCH();
-
- ctx = SG(server_context);
-
- /* We use APLOG_STARTUP because it keeps us from printing the
- * data and time information at the beginning of the error log
- * line. Not sure if this is correct, but it mirrors what happens
- * with Apache 1.3 -- rbb
- */
- if (ctx == NULL) { /* we haven't initialized our ctx yet, oh well */
- ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO | APLOG_STARTUP,
- 0, NULL, "%s", msg);
- }
- else {
- ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO | APLOG_STARTUP,
- 0, ctx->r, "%s", msg);
- }
-}
-
-extern zend_module_entry php_apache_module;
-
-static int php_apache2_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, &php_apache_module, 1)==FAILURE) {
- return FAILURE;
- }
- return SUCCESS;
-}
-
-static sapi_module_struct apache2_sapi_module = {
- "apache2handler",
- "Apache 2.0 Handler",
-
- php_apache2_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- php_apache_sapi_ub_write, /* unbuffered write */
- php_apache_sapi_flush, /* flush */
- php_apache_sapi_get_stat, /* get uid */
- php_apache_sapi_getenv, /* getenv */
-
- php_error, /* error handler */
-
- php_apache_sapi_header_handler, /* header handler */
- php_apache_sapi_send_headers, /* send headers handler */
- NULL, /* send header handler */
-
- php_apache_sapi_read_post, /* read POST data */
- php_apache_sapi_read_cookies, /* read Cookies */
-
- php_apache_sapi_register_variables,
- php_apache_sapi_log_message, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-static apr_status_t
-php_apache_server_shutdown(void *tmp)
-{
- apache2_sapi_module.shutdown(&apache2_sapi_module);
- sapi_shutdown();
-#ifdef ZTS
- tsrm_shutdown();
-#endif
- return APR_SUCCESS;
-}
-
-static void php_apache_add_version(apr_pool_t *p)
-{
- TSRMLS_FETCH();
- if (PG(expose_php)) {
- ap_add_version_component(p, "PHP/" PHP_VERSION);
- }
-}
-
-static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
-{
-#ifndef ZTS
- int threaded_mpm;
-
- ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm);
- if(threaded_mpm) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, 0, 0, "Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.");
- return DONE;
- }
-#endif
- /* When this is NULL, apache won't override the hard-coded default
- * php.ini path setting. */
- apache2_php_ini_path_override = NULL;
- return OK;
-}
-
-static int
-php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog,
- apr_pool_t *ptemp, server_rec *s)
-{
- void *data = NULL;
- const char *userdata_key = "apache2hook_post_config";
-
- /* Apache will load, unload and then reload a DSO module. This
- * prevents us from starting PHP until the second load. */
- apr_pool_userdata_get(&data, userdata_key, s->process->pool);
- if (data == NULL) {
- /* We must use set() here and *not* setn(), otherwise the
- * static string pointed to by userdata_key will be mapped
- * to a different location when the DSO is reloaded and the
- * pointers won't match, causing get() to return NULL when
- * we expected it to return non-NULL. */
- apr_pool_userdata_set((const void *)1, userdata_key,
- apr_pool_cleanup_null, s->process->pool);
- return OK;
- }
-
- /* Set up our overridden path. */
- if (apache2_php_ini_path_override) {
- apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;
- }
-#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
-#endif
- sapi_startup(&apache2_sapi_module);
- apache2_sapi_module.startup(&apache2_sapi_module);
- apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
- php_apache_add_version(pconf);
-
- return OK;
-}
-
-static void php_add_filter(request_rec *r, ap_filter_t *f)
-{
- int output = (f == r->output_filters);
-
- /* for those who still have Set*Filter PHP configured */
- while (f) {
- if (strcmp(f->frec->name, "PHP") == 0) {
- ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO,
- 0, r->server,
- "\"Set%sFilter PHP\" already configured for %s",
- output ? "Output" : "Input", r->uri);
- return;
- }
- f = f->next;
- }
-
- if (output) {
- ap_add_output_filter("PHP", NULL, r, r->connection);
- } else {
- ap_add_input_filter("PHP", NULL, r, r->connection);
- }
-}
-
-static apr_status_t php_server_context_cleanup(void *data_)
-{
- void **data = data_;
- *data = NULL;
- return APR_SUCCESS;
-}
-
-static void php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC)
-{
- char *content_type;
- const char *auth;
-
- SG(sapi_headers).http_response_code = 200;
- SG(request_info).content_type = apr_table_get(r->headers_in,
- "Content-Type");
- SG(request_info).query_string = apr_pstrdup(r->pool, r->args);
- SG(request_info).request_method = r->method;
- SG(request_info).request_uri = apr_pstrdup(r->pool, r->uri);
- r->no_local_copy = 1;
-
- content_type = sapi_get_default_content_type(TSRMLS_C);
- ap_set_content_type(r, apr_pstrdup(r->pool,
- sapi_get_default_content_type(TSRMLS_C)));
- efree(content_type);
-
- apr_table_unset(r->headers_out, "Content-Length");
- apr_table_unset(r->headers_out, "Last-Modified");
- apr_table_unset(r->headers_out, "Expires");
- apr_table_unset(r->headers_out, "ETag");
- apr_table_unset(r->headers_in, "Connection");
- if (!PG(safe_mode)) {
- auth = apr_table_get(r->headers_in, "Authorization");
- php_handle_auth_data(auth TSRMLS_CC);
- } else {
- SG(request_info).auth_user = NULL;
- SG(request_info).auth_password = NULL;
- }
- php_request_startup(TSRMLS_C);
-}
-
-static void php_apache_request_dtor(request_rec *r TSRMLS_DC)
-{
- php_request_shutdown(NULL);
-}
-
-static int php_handler(request_rec *r)
-{
- php_struct *ctx;
- void *conf;
- char *enabled;
- apr_bucket_brigade *brigade;
- apr_bucket *bucket;
- apr_status_t rv;
- request_rec *parent_req = NULL;
- TSRMLS_FETCH();
-
- conf = ap_get_module_config(r->per_dir_config, &php4_module);
- apply_config(conf);
-
- if (strcmp(r->handler, PHP_MAGIC_TYPE) &&
- strcmp(r->handler, PHP_SOURCE_MAGIC_TYPE) &&
- strcmp(r->handler, PHP_SCRIPT)) {
- char *xbithack;
- /* Check for xbithack in this case. */
- if (strcmp(r->handler, "text/html")) {
- return DECLINED;
- }
- xbithack = get_php_config(conf, "xbithack", sizeof("xbithack"));
- if (*xbithack == '\0' || *xbithack == '0'
- || !(r->finfo.protection & APR_UEXECUTE)) {
- return DECLINED;
- }
- }
-
- enabled = get_php_config(conf, "engine", sizeof("engine"));
-
- /* handle situations where user turns the engine off */
- if (*enabled == '0') {
- return DECLINED;
- }
-
- /* setup standard CGI variables */
- ap_add_common_vars(r);
- ap_add_cgi_vars(r);
-
- ctx = SG(server_context);
- if (ctx == NULL) {
- ctx = SG(server_context) = apr_pcalloc(r->pool, sizeof(*ctx));;
- /* register a cleanup so we clear out the SG(server_context)
- * after each request. Note: We pass in the pointer to the
- * server_context in case this is handled by a different thread.
- */
- apr_pool_cleanup_register(r->pool, (void *)&SG(server_context),
- php_server_context_cleanup,
- apr_pool_cleanup_null);
-
- ctx->r = r;
- brigade = apr_brigade_create(r->pool, r->connection->bucket_alloc);
- ctx->brigade = brigade;
-
- php_apache_request_ctor(r, ctx TSRMLS_CC);
- }
- else {
- parent_req = ctx->r;
- ctx->r = r;
- brigade = ctx->brigade;
- }
-
- /* Determine if we need to parse the file or show the source */
- if (strncmp(r->handler, PHP_SOURCE_MAGIC_TYPE,
- sizeof(PHP_SOURCE_MAGIC_TYPE) - 1) == 0) {
- zend_syntax_highlighter_ini syntax_highlighter_ini;
- php_get_highlight_struct(&syntax_highlighter_ini);
- highlight_file((char *)r->filename,
- &syntax_highlighter_ini TSRMLS_CC);
- }
- else {
- zend_file_handle zfd;
-
- zfd.type = ZEND_HANDLE_FILENAME;
- zfd.filename = (char *) r->filename;
- zfd.free_filename = 0;
- zfd.opened_path = NULL;
-
- if (!parent_req) {
- php_execute_script(&zfd TSRMLS_CC);
- }
- else {
- zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &zfd);
- }
-#if MEMORY_LIMIT
- {
- char *mem_usage;
-
- mem_usage = apr_psprintf(ctx->r->pool, "%u",
- AG(allocated_memory_peak));
- AG(allocated_memory_peak) = 0;
- apr_table_set(r->notes, "mod_php_memory_usage", mem_usage);
- }
-#endif
- }
-
- if (!parent_req) {
- php_apache_request_dtor(r TSRMLS_CC);
- ctx->request_processed = 1;
- bucket = apr_bucket_eos_create(r->connection->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(brigade, bucket);
-
- rv = ap_pass_brigade(r->output_filters, brigade);
- if (rv != APR_SUCCESS) {
- php_handle_aborted_connection();
- }
- apr_brigade_cleanup(brigade);
- }
- else {
- ctx->r = parent_req;
- }
-
- return OK;
-}
-
-static void php_register_hook(apr_pool_t *p)
-{
- ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_handler(php_handler, NULL, NULL, APR_HOOK_MIDDLE);
-}
-
-AP_MODULE_DECLARE_DATA module php4_module = {
- STANDARD20_MODULE_STUFF,
- create_php_config, /* create per-directory config structure */
- merge_php_config, /* merge per-directory config structures */
- NULL, /* create per-server config structure */
- NULL, /* merge per-server config structures */
- php_dir_cmds, /* command apr_table_t */
- php_register_hook /* register hooks */
-};
-
-/*
- * 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/CREDITS b/sapi/apache_hooks/CREDITS
deleted file mode 100644
index 86ac27d0b7..0000000000
--- a/sapi/apache_hooks/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-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
deleted file mode 100644
index 9a5a3e2b64..0000000000
--- a/sapi/apache_hooks/README
+++ /dev/null
@@ -1,206 +0,0 @@
-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
deleted file mode 100644
index 7b5254013a..0000000000
--- a/sapi/apache_hooks/apMakefile.libdir
+++ /dev/null
@@ -1,4 +0,0 @@
-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
deleted file mode 100644
index 80fe346561..0000000000
--- a/sapi/apache_hooks/apMakefile.tmpl
+++ /dev/null
@@ -1,77 +0,0 @@
-##
-## Apache 1.3 Makefile template for PHP 4.0 Module
-## [src/modules/php4/Makefile.tmpl]
-##
-
-# the parametrized target
-LIB=libphp4.$(LIBEXT)
-
-# objects for building the static library
-OBJS=mod_php4.o
-OBJS_LIB=libmodphp4.a
-
-# objects for building the shared object library
-SHLIB_OBJS=mod_php4.so-o
-SHLIB_OBJS_LIB=libmodphp4.a
-
-# the general targets
-all: lib
-lib: $(LIB)
-
-# build the static library by merging the object files
-libphp4.a: $(OBJS) $(OBJS_LIB)
- cp $(OBJS_LIB) $@
- ar r $@ $(OBJS)
- $(RANLIB) $@
-
-# ugly hack to support older Apache-1.3 betas that don't set $LIBEXT
-libphp4.: $(OBJS) $(OBJS_LIB)
- cp $(OBJS_LIB) $@
- ar r $@ $(OBJS)
- $(RANLIB) $@
- cp libphp4. libphp4.a
-
-# build the shared object library by linking the object files
-libphp4.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB)
- rm -f $@
- $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) $(LIBS) $(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_php4.o: mod_php4.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \
- $(INCDIR)/buff.h \
- $(INCDIR)/http_config.h \
- $(INCDIR)/http_core.h $(INCDIR)/http_main.h \
- $(INCDIR)/http_protocol.h $(INCDIR)/http_request.h \
- $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php4.h
diff --git a/sapi/apache_hooks/config.m4 b/sapi/apache_hooks/config.m4
deleted file mode 100644
index 558250b6a8..0000000000
--- a/sapi/apache_hooks/config.m4
+++ /dev/null
@@ -1,242 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for Apache 1.x (hooks) module support via DSO through APXS)
-AC_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; defaults to "apxs".],[
- if test "$withval" = "yes"; then
- APXS=apxs
- AC_DEFINE(APACHE_HOOKS,1,[ ])
- $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
- AC_DEFINE(APACHE_HOOKS,1,[ ])
- PHP_EXPAND_PATH($withval, 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
- 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`
-
- # 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*) CPPFLAGS="$CPPFLAGS $flag";;
- esac
- done
- case $host_alias in
- *aix*)
- APXS_LIBEXECDIR=`$APXS -q LIBEXECDIR`
- EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp"
- PHP_SELECT_SAPI(apache_hooks, shared, sapi_apache.c mod_php4.c php_apache.c, -I$APXS_INCLUDEDIR)
- ;;
- *darwin*)
- MH_BUNDLE_FLAGS="-dynamic -twolevel_namespace -bundle -bundle_loader $APXS_HTTPD"
- PHP_SUBST(MH_BUNDLE_FLAGS)
- SAPI_SHARED=libs/libphp4.so
- PHP_SELECT_SAPI(apache_hooks, bundle, sapi_apache.c mod_php4.c php_apache.c, -I$APXS_INCLUDEDIR)
- ;;
- *)
- PHP_SELECT_SAPI(apache_hooks, shared, sapi_apache.c mod_php4.c php_apache.c, -I$APXS_INCLUDEDIR)
- ;;
- esac
-
- # Test whether apxs support -S option
- $APXS -q -S CFLAGS="$APXS_CFLAGS" CFLAGS >/dev/null 2>&1
-
- if test "$?" != "0"; then
- APACHE_INSTALL="$APXS -i -a -n php4 $SAPI_SHARED" # Old apxs does not have -S option
- else
- APACHE_INSTALL="\$(mkinstalldirs) \"\$(INSTALL_ROOT)`$APXS -q LIBEXECDIR`\" && $APXS -S LIBEXECDIR=\"\$(INSTALL_ROOT)`$APXS -q LIBEXECDIR`\" -i -a -n php4 $SAPI_SHARED"
- 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_MSG_RESULT(yes)
-],[
- AC_MSG_RESULT(no)
-])
-
-APACHE_INSTALL_FILES="\$(srcdir)/sapi/apache_hooks/mod_php4.* sapi/apache_hooks/libphp4.module"
-
-if test "$PHP_SAPI" != "apache_hooks"; then
-AC_MSG_CHECKING(for Apache 1.x (hooks) module support)
-AC_ARG_WITH(apache-hooks-static,
-[ --with-apache-hooks-static[=DIR]
- EXPERIMENTAL: Build Apache 1.x module. DIR is the top-level Apache
- build directory, defaults to /usr/local/apache.],[
- AC_DEFINE(APACHE_HOOKS,1,[ ])
- if test "$withval" = "yes"; then
- # Apache's default directory
- withval=/usr/local/apache
- fi
- if test "$withval" != "no"; then
- APACHE_MODULE=yes
- PHP_EXPAND_PATH($withval, withval)
- # For Apache 1.2.x
- if test -f $withval/src/httpd.h; then
- APACHE_INCLUDE=-I$withval/src
- APACHE_TARGET=$withval/src
- PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php4.c php_apache.c, $APACHE_INCLUDE)
- APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_INSTALL_FILES $APACHE_TARGET"
- PHP_LIBS="-L. -lphp3"
- AC_MSG_RESULT(yes - Apache 1.2.x)
- STRONGHOLD=
- if test -f $withval/src/ap_config.h; then
- AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
- fi
- # For Apache 2.0.x
- elif test -f $withval/include/httpd.h &&
- test -f $withval/srclib/apr/include/apr_general.h ; then
- AC_MSG_ERROR([Use --with-apache2 with Apache 2.x!])
- # For Apache 1.3.x
- elif test -f $withval/src/main/httpd.h; then
- APACHE_HAS_REGEX=1
- APACHE_INCLUDE="-I$withval/src/main -I$withval/src/os/unix -I$withval/src/ap"
- APACHE_TARGET=$withval/src/modules/php4
- if test ! -d $APACHE_TARGET; then
- mkdir $APACHE_TARGET
- fi
- PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php4.c php_apache.c, $APACHE_INCLUDE)
- APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp4.a; cp $APACHE_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/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4"
- AC_MSG_RESULT(yes - Apache 1.3.x)
- STRONGHOLD=
- if test -f $withval/src/include/ap_config.h; then
- AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
- fi
- if test -f $withval/src/include/ap_compat.h; then
- AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
- if test ! -f $withval/src/include/ap_config_auto.h; then
- AC_MSG_ERROR(Please run Apache\'s configure or src/Configure program once and try again)
- fi
- else
- if test -f $withval/src/include/compat.h; then
- AC_DEFINE(HAVE_OLD_COMPAT_H,1,[ ])
- fi
- fi
- # Also for Apache 1.3.x
- elif test -f $withval/src/include/httpd.h; then
- APACHE_HAS_REGEX=1
- APACHE_INCLUDE="-I$withval/src/include -I$withval/src/os/unix"
- APACHE_TARGET=$withval/src/modules/php4
- if test ! -d $APACHE_TARGET; then
- mkdir $APACHE_TARGET
- fi
- PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php4.c php_apache.c, $APACHE_INCLUDE)
- PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4"
- APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp4.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_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 $withval/src/include/ap_config.h; then
- AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
- fi
- if test -f $withval/src/include/ap_compat.h; then
- AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
- if test ! -f $withval/src/include/ap_config_auto.h; then
- AC_MSG_ERROR(Please run Apache\'s configure or src/Configure program once and try again)
- fi
- else
- if test -f $withval/src/include/compat.h; then
- AC_DEFINE(HAVE_OLD_COMPAT_H,1,[ ])
- fi
- fi
- # For StrongHold 2.2
- elif test -f $withval/apache/httpd.h; then
- APACHE_INCLUDE=-"I$withval/apache -I$withval/ssl/include"
- APACHE_TARGET=$withval/apache
- PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php4.c php_apache.c, $APACHE_INCLUDE)
- PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4"
- APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp4.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET"
- STRONGHOLD=-DSTRONGHOLD=1
- AC_MSG_RESULT(yes - StrongHold)
- if test -f $withval/apache/ap_config.h; then
- AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
- fi
- if test -f $withval/src/ap_compat.h; then
- AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
- if test ! -f $withval/src/include/ap_config_auto.h; then
- AC_MSG_ERROR(Please run Apache\'s configure or src/Configure program once and try again)
- fi
- else
- if test -f $withval/src/compat.h; then
- AC_DEFINE(HAVE_OLD_COMPAT_H,1,[ ])
- fi
- fi
- else
- AC_MSG_RESULT(no)
- AC_MSG_ERROR(Invalid Apache directory - unable to find httpd.h under $withval)
- fi
- else
- AC_MSG_RESULT(no)
- fi
-],[
- AC_MSG_RESULT(no)
-])
-
-fi
-
-if test "x$APXS" != "x" -a "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then
- APXS_EXP=-bE:sapi/apache_hooks/mod_php4.exp
-fi
-
-PHP_SUBST(APXS_EXP)
-PHP_SUBST(APACHE_INCLUDE)
-PHP_SUBST(APACHE_TARGET)
-PHP_SUBST(APXS)
-PHP_SUBST(APXS_LDFLAGS)
-PHP_SUBST(APACHE_INSTALL)
-PHP_SUBST(STRONGHOLD)
-
-AC_MSG_CHECKING(for mod_charset compatibility option)
-AC_ARG_WITH(mod_charset,
-[ --with-mod_charset Enable transfer tables for mod_charset (Rus Apache).],
-[
- AC_MSG_RESULT(yes)
- AC_DEFINE(USE_TRANSFER_TABLES,1,[ ])
-],[
- AC_MSG_RESULT(no)
-])
-
-if test -n "$APACHE_MODULE"; then
- PHP_TARGET_RDYNAMIC
- $php_shtool mkdir -p sapi/apache_hooks
- PHP_OUTPUT(sapi/apache_hooks/libphp4.module)
-fi
-
-if test -n "$APACHE_INSTALL"; then
- INSTALL_IT=$APACHE_INSTALL
-fi
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
diff --git a/sapi/apache_hooks/libphp4.module.in b/sapi/apache_hooks/libphp4.module.in
deleted file mode 100644
index ccb97493a7..0000000000
--- a/sapi/apache_hooks/libphp4.module.in
+++ /dev/null
@@ -1,11 +0,0 @@
-Name: php4_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_php4.c b/sapi/apache_hooks/mod_php4.c
deleted file mode 100644
index 6175514310..0000000000
--- a/sapi/apache_hooks/mod_php4.c
+++ /dev/null
@@ -1,1474 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@php.net> |
- | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> |
- | PHP 4.0 patches by Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include "php_apache_http.h"
-
-#ifdef NETWARE
-#define SIGPIPE SIGINT
-#endif
-
-#if defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING)
-#include "ext/mbstring/mbstring.h"
-#endif /* defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) */
-
-#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_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_php4.h or somewhere else */
-#define USE_PATH 1
-#define IGNORE_URL 2
-
-module MODULE_VAR_EXPORT php4_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_headers_struct *sapi_headers TSRMLS_DC)
-{
- char *header_name, *header_content, *p;
- request_rec *r = (request_rec *) SG(server_context);
-
- header_name = sapi_header->header;
-
- header_content = p = strchr(header_name, ':');
- if (!p) {
- efree(sapi_header->header);
- return 0;
- }
-
- *p = 0;
- do {
- header_content++;
- } while (*header_content==' ');
-
- if (!strcasecmp(header_name, "Content-Type")) {
- r->content_type = pstrdup(r->pool, header_content);
- } else if (!strcasecmp(header_name, "Set-Cookie")) {
- table_add(r->headers_out, header_name, header_content);
- } else {
- table_set(r->headers_out, header_name, header_content);
- }
-
- *p = ':'; /* a well behaved header handler shouldn't change its original arguments */
-
- efree(sapi_header->header);
-
- return 0; /* don't use the default SAPI mechanism, Apache duplicates this functionality */
-}
-/* }}} */
-
-/* {{{ 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 = empty_string;
- }
- 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 if (PG(register_globals)) {
- /* should never happen nowadays */
- symbol_table = EG(active_symbol_table);
- } 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_FETCH();
-
- if (SG(server_context)) {
-#if MODULE_MAGIC_NUMBER >= 19970831
- aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, "%s", message);
-#else
- log_error(message, ((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(0 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, /* 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;
-
- SG(request_info).query_string = r->args;
- SG(request_info).path_translated = r->filename;
- SG(request_info).request_uri = r->uri;
- SG(request_info).request_method = (char *)r->method;
- SG(request_info).content_type = (char *) table_get(r->subprocess_env, "CONTENT_TYPE");
- SG(request_info).content_length = (content_length ? atoi(content_length) : 0);
- SG(sapi_headers).http_response_code = r->status;
-
- if (r->headers_in) {
- authorization = table_get(r->headers_in, "Authorization");
- }
- if (authorization
- && !auth_type(r)
- && !strcasecmp(getword(r->pool, &authorization, ' '), "Basic")) {
- tmp = uudecode(r->pool, authorization);
- SG(request_info).auth_user = getword_nulls_nc(r->pool, &tmp, ':');
- if (SG(request_info).auth_user) {
- r->connection->user = pstrdup(r->connection->pool, SG(request_info).auth_user);
- r->connection->ap_auth_type = "Basic";
- SG(request_info).auth_user = estrdup(SG(request_info).auth_user);
- }
- SG(request_info).auth_password = tmp;
- if (SG(request_info).auth_password) {
- SG(request_info).auth_password = estrdup(SG(request_info).auth_password);
- }
- } else {
- SG(request_info).auth_user = NULL;
- SG(request_info).auth_password = NULL;
- }
-}
-/* }}} */
-
-/* {{{ 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;
-
-#if defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING)
- php_mbstring_set_zend_encoding(TSRMLS_C);
-#endif /* defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) */
-
- 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, &php4_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);
-
-#if MEMORY_LIMIT
- {
- char *mem_usage;
- TSRMLS_FETCH();
-
- mem_usage = ap_psprintf(r->pool, "%u", AG(allocated_memory_peak));
- AG(allocated_memory_peak) = 0;
- ap_table_setn(r->notes, "mod_php_memory_usage", mem_usage);
- }
-#endif
-
- 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, &php4_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);
-}
-/* }}} */
-
-/* {{{ 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, &php4_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;
- 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, &php4_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, &php4_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, &php4_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, &php4_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, &php4_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, &php4_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, &php4_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, &php4_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, &php4_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, &php4_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, &php4_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)"},
- {NULL}
-};
-/* }}} */
-
-/* {{{ module MODULE_VAR_EXPORT php4_module
- */
-module MODULE_VAR_EXPORT php4_module =
-{
- STANDARD_MODULE_STUFF,
- php_init_handler, /* initializer */
- php_create_dir, /* per-directory config creator */
- php_merge_dir, /* dir merger */
- 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_php4.exp b/sapi/apache_hooks/mod_php4.exp
deleted file mode 100644
index 2dca1256c2..0000000000
--- a/sapi/apache_hooks/mod_php4.exp
+++ /dev/null
@@ -1 +0,0 @@
-php4_module
diff --git a/sapi/apache_hooks/mod_php4.h b/sapi/apache_hooks/mod_php4.h
deleted file mode 100644
index 1adeecc687..0000000000
--- a/sapi/apache_hooks/mod_php4.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Rasmus Lerdorf <rasmus@php.net> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#ifndef MOD_PHP4_H
-#define MOD_PHP4_H
-
-#if !defined(WIN32) && !defined(WINNT)
-#ifndef MODULE_VAR_EXPORT
-#define MODULE_VAR_EXPORT
-#endif
-#endif
-
-typedef struct {
- long engine;
- long last_modified;
- 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
-
-#endif /* MOD_PHP4_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
deleted file mode 100644
index 2dca1256c2..0000000000
--- a/sapi/apache_hooks/php.sym
+++ /dev/null
@@ -1 +0,0 @@
-php4_module
diff --git a/sapi/apache_hooks/php4apache_hooks.dsp b/sapi/apache_hooks/php4apache_hooks.dsp
deleted file mode 100755
index 3a2f347d8a..0000000000
--- a/sapi/apache_hooks/php4apache_hooks.dsp
+++ /dev/null
@@ -1,151 +0,0 @@
-# Microsoft Developer Studio Project File - Name="php4apache_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=php4apache_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 "php4apache_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 "php4apache_hooks.mak" CFG="php4apache_hooks - Win32 Release_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php4apache_hooks - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4apache_hooks - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4apache_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)" == "php4apache_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 "APACHEPHP4_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 "APACHEPHP4_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 php4ts.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x60000000" /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\apache\src\corer" /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS"
-
-!ELSEIF "$(CFG)" == "php4apache_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 "APACHEPHP4_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 "APACHEPHP4_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 php4ts_debug.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x60000000" /version:4.0 /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php4apache_hooks.dll" /pdbtype:sept /libpath:"..\..\..\php_build\apache\src\cored" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"
-
-!ELSEIF "$(CFG)" == "php4apache_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 "APACHEPHP4_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 "APACHEPHP4_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 php4ts.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"\apache\src\corer" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php4apache_hooks - Win32 Release_TS"
-# Name "php4apache_hooks - Win32 Debug_TS"
-# Name "php4apache_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_php4.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_php4.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
deleted file mode 100644
index 5ae3a36f60..0000000000
--- a/sapi/apache_hooks/php_apache.c
+++ /dev/null
@@ -1,1954 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Stig Sæther Bakken <ssb@fast.no> |
- | 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 *, int safe_mode, 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);
-
-
-function_entry apache_functions[] = {
- PHP_FE(virtual, NULL)
- PHP_FE(apache_request_headers, NULL)
- PHP_FE(apache_note, NULL)
- PHP_FE(apache_lookup_uri, NULL)
- PHP_FE(apache_child_terminate, NULL)
- PHP_FE(apache_setenv, NULL)
- PHP_FE(apache_response_headers, NULL)
- PHP_FE(apache_get_version, NULL)
- PHP_FE(apache_get_modules, NULL)
- PHP_FALIAS(getallheaders, apache_request_headers, NULL)
- {NULL, NULL, NULL}
-};
-
-/* {{{ php_apache ini entries
- */
-PHP_INI_BEGIN()
- STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateInt, xbithack, php_apache_info_struct, php_apache_info)
- STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateInt, engine, php_apache_info_struct, php_apache_info)
- STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateInt, last_modified, php_apache_info_struct, php_apache_info)
- STD_PHP_INI_ENTRY("child_terminate", "0", PHP_INI_ALL, OnUpdateInt, 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(pval *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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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, **new_value;
- request_rec *r;
- char *old_value;
- char **target;
-
- APREQ_GET_REQUEST(id, r);
-
- target = (char **)((char*)r + offset);
- old_value = *target;
-
- switch (ZEND_NUM_ARGS()) {
- case 0:
- break;
- case 1:
- if (zend_get_parameters_ex(1, &new_value) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_string_ex(new_value);
- *target = ap_pstrdup(r->pool, Z_STRVAL_PP(new_value));
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
- 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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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, **new_value;
- request_rec *r;
- long old_value;
- long *target;
-
- APREQ_GET_REQUEST(id, r);
-
- target = (long *)((char*)r + offset);
- old_value = *target;
-
- switch (ZEND_NUM_ARGS()) {
- case 0:
- break;
- case 1:
- if (zend_get_parameters_ex(1, &new_value) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(new_value);
- *target = Z_LVAL_PP(new_value);
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
- RETURN_LONG(old_value);
-}
-/* }}} */
-
-
-/* {{{ access string slots of request rec
- */
-
-/* {{{ proto string $request->filename([string new_filename])
- */
-PHP_FUNCTION(apache_request_filename)
-{
- apache_request_string_slot(offsetof(request_rec, filename), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto string $request->uri([string new_uri])
- */
-PHP_FUNCTION(apache_request_uri)
-{
- apache_request_string_slot(offsetof(request_rec, uri), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto string $request->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 $request->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 $request->args([string new_args])
- */
-PHP_FUNCTION(apache_request_args)
-{
- apache_request_string_slot(offsetof(request_rec, args), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto string $request->boundary()
- */
-PHP_FUNCTION(apache_request_boundary)
-{
- apache_request_read_string_slot(offsetof(request_rec, boundary), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-
-/* {{{ proto string $request->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 $request->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 $request->handler([string new_handler])
- */
-PHP_FUNCTION(apache_request_handler)
-{
- apache_request_string_slot(offsetof(request_rec, handler), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto string $request->the_request()
- */
-PHP_FUNCTION(apache_request_the_request)
-{
- apache_request_read_string_slot(offsetof(request_rec, the_request), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto string $request->protocol()
- */
-PHP_FUNCTION(apache_request_protocol)
-{
- apache_request_read_string_slot(offsetof(request_rec, protocol), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto string $request->hostname()
- */
-PHP_FUNCTION(apache_request_hostname)
-{
- apache_request_read_string_slot(offsetof(request_rec, hostname), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto string $request->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 $request->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 $request->proto_num()
- */
-PHP_FUNCTION(apache_request_proto_num)
-{
- apache_request_read_int_slot(offsetof(request_rec, proto_num), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto int $request->assbackwards()
- */
-PHP_FUNCTION(apache_request_assbackwards)
-{
- apache_request_read_int_slot(offsetof(request_rec, assbackwards), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-
-/* {{{ proto int $request->proxyreq([int new_proxyreq])
- */
-PHP_FUNCTION(apache_request_proxyreq)
-{
- apache_request_int_slot(offsetof(request_rec, proxyreq), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto int $request->chunked()
- */
-PHP_FUNCTION(apache_request_chunked)
-{
- apache_request_read_int_slot(offsetof(request_rec, chunked), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-
-/* {{{ proto int $request->header_only()
- */
-PHP_FUNCTION(apache_request_header_only)
-{
- apache_request_read_int_slot(offsetof(request_rec, header_only), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto int $request->request_time()
- */
-PHP_FUNCTION(apache_request_request_time)
-{
- apache_request_read_int_slot(offsetof(request_rec, request_time), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto int $request->status([int new_status])
- */
-PHP_FUNCTION(apache_request_status)
-{
- apache_request_int_slot(offsetof(request_rec, status), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto int $request->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 $request->allowed([int allowed])
- */
-PHP_FUNCTION(apache_request_allowed)
-{
- apache_request_int_slot(offsetof(request_rec, allowed), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto int $request->bytes_sent()
- */
-PHP_FUNCTION(apache_request_bytes_sent)
-{
- apache_request_read_int_slot(offsetof(request_rec, bytes_sent), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto int $request->mtime()
- */
-PHP_FUNCTION(apache_request_mtime)
-{
- apache_request_read_int_slot(offsetof(request_rec, mtime), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto int $request->content_length([int new_content_length])
- */
-PHP_FUNCTION(apache_request_content_length)
-{
- zval *id, **zlen;
- request_rec *r;
-
- if (ZEND_NUM_ARGS() == 0) {
- apache_request_read_int_slot(offsetof(request_rec, clength), INTERNAL_FUNCTION_PARAM_PASSTHRU);
- }
- else if (ZEND_NUM_ARGS() > 1) {
- WRONG_PARAM_COUNT;
- }
- else {
- if (zend_get_parameters_ex(1, &zlen) == FAILURE) {
- RETURN_FALSE;
- }
-
- APREQ_GET_REQUEST(id, r);
-
- convert_to_long_ex(zlen);
- (void)ap_set_content_length(r, Z_LVAL_PP(zlen));
- RETURN_TRUE;
- }
-}
-/* }}} */
-
-/* {{{ proto int $request->remaining()
- */
-PHP_FUNCTION(apache_request_remaining)
-{
- apache_request_read_int_slot(offsetof(request_rec, remaining), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto int $request->no_cache()
- */
-PHP_FUNCTION(apache_request_no_cache)
-{
- apache_request_int_slot(offsetof(request_rec, no_cache), INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-/* }}} */
-
-/* {{{ proto int $request->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 $request->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, 0, 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, 0, 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, 0, 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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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, **ztype;
- request_rec *r;
- char *res;
- int type = REMOTE_NAME;
-
- switch (ZEND_NUM_ARGS()) {
- case 0:
- break;
- case 1:
- if (zend_get_parameters_ex(1, &ztype) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(ztype);
- type = Z_LVAL_PP(ztype);
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
-
- APREQ_GET_REQUEST(id, r);
-
- res = (char *)ap_get_remote_host(r->connection, r->per_dir_config, 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, **zmtime;
- request_rec *r;
- int mtime = 0;
-
- switch (ZEND_NUM_ARGS()) {
- case 0:
- break;
- case 1:
- if (zend_get_parameters_ex(1, &zmtime) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(zmtime);
- mtime = Z_LVAL_PP(zmtime);
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
-
- APREQ_GET_REQUEST(id, r);
-
- RETURN_LONG(ap_update_mtime(r, mtime));
-}
-/* }}} */
-
-
-/* {{{ proto void apache_request_set_etag()
- */
-PHP_FUNCTION(apache_request_set_etag)
-{
- zval *id;
- request_rec *r;
-
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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_NUM_ARGS() != 1) {
- WRONG_PARAM_COUNT;
- }
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zpw) == FAILURE) {
- RETURN_NULL();
- }
-
- 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;
-
- 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;
-
- 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;
-
- 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 **recursive;
- zval *id;
- request_rec *r;
- int rec;
-
- switch(ZEND_NUM_ARGS()) {
- case 0:
- rec = 0;
- break;
- case 1:
- if(zend_get_parameters_ex(1, &recursive) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(recursive);
- rec = Z_LVAL_PP(recursive);
- break;
- default:
- WRONG_PARAM_COUNT;
- }
- APREQ_GET_REQUEST(id, r);
- ap_send_error_response(r, rec);
- RETURN_TRUE;
-}
-
-PHP_FUNCTION(apache_request_set_content_length)
-{
- zval **length;
- zval *id;
- request_rec *r;
-
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &length) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- APREQ_GET_REQUEST(id, r);
-
- convert_to_long_ex(length);
- ap_set_content_length(r, Z_LVAL_PP(length));
- RETURN_TRUE;
-}
-
-PHP_FUNCTION(apache_request_set_keepalive)
-{
- zval *id;
- request_rec *r;
- 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)
-{
- zval **buffer;
- zval *id;
- request_rec *r;
-
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &buffer) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(buffer);
- ap_rwrite(Z_STRVAL_PP(buffer), Z_STRLEN_PP(buffer), (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;
- zval **z_errstr, **z_facility;
- request_rec *r;
- int facility = APLOG_ERR;
-
- switch(ZEND_NUM_ARGS()) {
- case 1:
- if(zend_get_parameters_ex(1, &z_errstr) == FAILURE) {
- RETURN_FALSE;
- }
- break;
- case 2:
- if(zend_get_parameters_ex(1, &z_errstr, &z_facility) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(z_facility);
- facility = Z_LVAL_PP(z_facility);
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
- APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(z_errstr);
- ap_log_error(APLOG_MARK, facility, r->server, "%s", Z_STRVAL_PP(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;
- zval **file;
- request_rec *r, *sub_r;
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(file);
- sub_r = ap_sub_req_lookup_uri(Z_STRVAL_PP(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;
- zval **file;
- request_rec *r, *sub_r;
-
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(file);
- sub_r = ap_sub_req_lookup_file(Z_STRVAL_PP(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;
- zval **file, **method;
- request_rec *r, *sub_r;
-
- if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &method, &file) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(method);
- convert_to_string_ex(file);
- sub_r = ap_sub_req_method_uri(Z_STRVAL_PP(method),Z_STRVAL_PP(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;
-
- 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;
- zval **new_uri;
- request_rec *r;
-
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_uri) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(new_uri);
- ap_internal_redirect(Z_STRVAL_PP(new_uri), r);
-}
-
-PHP_FUNCTION(apache_request_send_header_field)
-{
- zval **fieldname;
- zval **fieldval;
- zval *id;
- request_rec *r;
-
- if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fieldname, &fieldval) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(fieldname);
- convert_to_string_ex(fieldval);
- APREQ_GET_REQUEST(id, r);
-
- ap_send_header_field(r, Z_STRVAL_PP(fieldname), Z_STRVAL_PP(fieldval));
- SG(headers_sent) = 1;
- AP(headers_sent) = 1;
-}
-
-
-
-/* }}} */
-
-/* {{{ php_apache_request_class_functions
- */
-static 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)
- { NULL, NULL, NULL }
-};
-/* }}} */
-
-
-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)
-{
- zval **arg_name, **arg_val;
- char *note_val;
- int arg_count = ZEND_NUM_ARGS();
-
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &arg_name, &arg_val) ==FAILURE ) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(arg_name);
- note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val);
-
- if (arg_count == 2) {
- convert_to_string_ex(arg_val);
- table_set(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val, (*arg_val)->value.str.val);
- }
-
- if (note_val) {
- RETURN_STRING(note_val, 1);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ PHP_MINFO_FUNCTION
- */
-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
- sprintf(output_buf, "%d", APACHE_RELEASE);
- php_info_print_table_row(2, "Apache Release", output_buf);
-#endif
- sprintf(output_buf, "%d", MODULE_MAGIC_NUMBER);
- php_info_print_table_row(2, "Apache API Version", output_buf);
- sprintf(output_buf, "%s:%u", serv->server_hostname, serv->port);
- php_info_print_table_row(2, "Hostname:Port", output_buf);
-#if !defined(WIN32) && !defined(WINNT)
- sprintf(output_buf, "%s(%d)/%d", user_name, (int)user_id, (int)group_id);
- php_info_print_table_row(2, "User/Group", output_buf);
- sprintf(output_buf, "Per Child: %d - 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
- sprintf(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 */
- }
- strcat(modulenames, name);
- if (modp->next) {
- strcat(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 && (!PG(safe_mode) || (PG(safe_mode) && strncasecmp(env[i].key, "authorization", 13)))) {
- 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)
-{
- pval **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 = sub_req_lookup_uri ((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error(E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
- RETURN_FALSE;
- }
-
- if (rr->status != 200) {
- php_error(E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
- RETURN_FALSE;
- }
-
- php_end_ob_buffers(1 TSRMLS_CC);
- php_header();
-
- if (run_sub_req(rr)) {
- php_error(E_WARNING, "Unable to include '%s' - request execution failed", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
- RETURN_FALSE;
- } else {
- if (rr) destroy_sub_req (rr);
- RETURN_TRUE;
- }
-}
-/* }}} */
-
-
-/* {{{ apache_table_to_zval(table *, int safe_mode, zval *return_value)
- Fetch all HTTP request headers */
-static void apache_table_to_zval(table *t, int safe_mode, 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 ||
- (safe_mode && !strncasecmp(tenv[i].key, "authorization", 13))) {
- continue;
- }
- if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
- RETURN_FALSE;
- }
- }
-
-}
-/* }}} */
-
-
-/* {{{ proto array getallheaders(void)
-*/
-/* Alias for apache_request_headers() */
-/* }}} */
-
-/* {{{ proto array apache_request_headers(void)
- Fetch all HTTP request headers */
-PHP_FUNCTION(apache_request_headers)
-{
- apache_table_to_zval(((request_rec *)SG(server_context))->headers_in, PG(safe_mode), return_value);
-}
-/* }}} */
-
-/* {{{ proto array apache_response_headers(void)
- Fetch all HTTP response headers */
-PHP_FUNCTION(apache_response_headers)
-{
- apache_table_to_zval(((request_rec *) SG(server_context))->headers_out, 0, 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, 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)
-{
- pval **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 = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val);
- RETURN_FALSE;
- }
- object_init(return_value);
- add_property_long(return_value,"status", rr->status);
- if (rr->the_request) {
- add_property_string(return_value,"the_request", rr->the_request, 1);
- }
- if (rr->status_line) {
- add_property_string(return_value,"status_line", (char *)rr->status_line, 1);
- }
- if (rr->method) {
- add_property_string(return_value,"method", (char *)rr->method, 1);
- }
- if (rr->content_type) {
- add_property_string(return_value,"content_type", (char *)rr->content_type, 1);
- }
- if (rr->handler) {
- add_property_string(return_value,"handler", (char *)rr->handler, 1);
- }
- if (rr->uri) {
- add_property_string(return_value,"uri", rr->uri, 1);
- }
- if (rr->filename) {
- add_property_string(return_value,"filename", rr->filename, 1);
- }
- if (rr->path_info) {
- add_property_string(return_value,"path_info", rr->path_info, 1);
- }
- if (rr->args) {
- add_property_string(return_value,"args", rr->args, 1);
- }
- if (rr->boundary) {
- add_property_string(return_value,"boundary", rr->boundary, 1);
- }
- add_property_long(return_value,"no_cache", rr->no_cache);
- add_property_long(return_value,"no_local_copy", rr->no_local_copy);
- add_property_long(return_value,"allowed", rr->allowed);
- add_property_long(return_value,"sent_bodyct", rr->sent_bodyct);
- add_property_long(return_value,"bytes_sent", rr->bytes_sent);
- add_property_long(return_value,"byterange", rr->byterange);
- add_property_long(return_value,"clength", rr->clength);
-
-#if MODULE_MAGIC_NUMBER >= 19980324
- if (rr->unparsed_uri) {
- add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1);
- }
- if(rr->mtime) {
- add_property_long(return_value,"mtime", rr->mtime);
- }
-#endif
- if(rr->request_time) {
- add_property_long(return_value,"request_time", rr->request_time);
- }
-
- destroy_sub_req(rr);
-}
-/* }}} */
-
-
-#if 0
-This function is most likely a bad idea. Just playing with it for now.
-
-PHP_FUNCTION(apache_exec_uri)
-{
- pval **filename;
- request_rec *rr=NULL;
- TSRMLS_FETCH();
-
- 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
deleted file mode 100644
index b9b3c63715..0000000000
--- a/sapi/apache_hooks/php_apache_http.h
+++ /dev/null
@@ -1,44 +0,0 @@
-#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 "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_php4.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
deleted file mode 100644
index 49882768e8..0000000000
--- a/sapi/apache_hooks/sapi_apache.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@php.net> |
- | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> |
- | PHP 4.0 patches by: |
- | Zeev Suraski <zeev@zend.com> |
- | Stig Bakken <ssb@fast.no> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#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);
- if(PG(register_globals)) {
- php_register_variable_ex("request", req, NULL TSRMLS_CC);
- }
- else {
- 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
- */
diff --git a/sapi/caudium/CREDITS b/sapi/caudium/CREDITS
deleted file mode 100644
index 45789dbdfe..0000000000
--- a/sapi/caudium/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-Caudium / Roxen
-David Hedbor
diff --git a/sapi/caudium/README b/sapi/caudium/README
deleted file mode 100644
index 86ef65655d..0000000000
--- a/sapi/caudium/README
+++ /dev/null
@@ -1,16 +0,0 @@
-Embedded Caudium PHP support. It seems to work but isn't tested
-much. Due to a design choice it requires _Pike_ threads and a
-thread-safe PHP. It doesn't however require _Caudium_ to run in
-threaded mode. Due to the design, utilization of multiple processors
-should be pretty good.
-
-It requires a new Pike 7.0 and Caudium. It will not work with
-Roxen. Also, with the help of the VIRTUAL_DIR code in PHP, PHP
-execution should be very similar to that of mod_php or the cgi
-script.
-
-If you have any questions, please contact me, David Hedbor
-(neotron@php.net or neotron@caudium.net). For more information on
-Caudium, see http://caudium.net/ and http://caudium.org/.
-
-
diff --git a/sapi/caudium/TODO b/sapi/caudium/TODO
deleted file mode 100644
index b8217c5934..0000000000
--- a/sapi/caudium/TODO
+++ /dev/null
@@ -1,30 +0,0 @@
-TODO:
-
-- per-virtual-server configuration
-- configurable limit of number of concurrent PHP executions
-- fix setting of auth info.
-
-FIXED:
-+ => fixed
-- => not fixed and no fix planned
-? => Maybe fixed, maybe not.
-
-+ Allow multiple headers
- This is now fixed.
-+ fix backtraces
- Uses th_farm, thus problem is fixed
-+ exit in PHP exits Caudium
- Name conflict with do_exit in Pike and PHP. Reported to both teams.
-+ POST newline added?
- Was a Caudium bug.
-+ use th_farm
- Yeppers. Works great.
-- change cwd in single threaded mode
- There will be no single threaded mode support. The Caudium module
- will requite PHP ZTS and Pike threads to run. Single threaded PHP
- is rather uninteresting anyway.
-? Recursive mutex lock problem:
- Dunno if this is fixed. Major rewrite so it would have to be
- retested.
-
-
diff --git a/sapi/caudium/caudium.c b/sapi/caudium/caudium.c
deleted file mode 100644
index 3124f87a12..0000000000
--- a/sapi/caudium/caudium.c
+++ /dev/null
@@ -1,791 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: David Hedbor <neotron@php.net> |
- | Based on aolserver SAPI by Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-#ifdef HAVE_CAUDIUM
-
-#include "php_ini.h"
-#include "php_globals.h"
-#include "SAPI.h"
-#include "php_main.h"
-#include "ext/standard/info.h"
-
-#include "php_version.h"
-
-/* Pike Include Files
- *
- * conflicts with pike avoided by only using long names. Requires a new
- * Pike 0.7 since it was implemented for this interface only.
- *
- */
-#define NO_PIKE_SHORTHAND
-
-/* Ok, we are now using Pike level threads to handle PHP4 since
- * the nice th_farm threads aren't working on Linux with glibc 2.2
- * (why this is I don't know).
- */
-#define USE_PIKE_LEVEL_THREADS
-
-#include <fdlib.h>
-#include <program.h>
-#include <pike_types.h>
-#include <interpret.h>
-#include <module_support.h>
-#include <array.h>
-#include <backend.h>
-#include <stralloc.h>
-#include <mapping.h>
-#include <object.h>
-#include <threads.h>
-#include <builtin_functions.h>
-#include <operators.h>
-#include <version.h>
-
-#if (PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION == 1 && PIKE_BUILD_VERSION >= 12) || PIKE_MAJOR_VERSION > 7 || (PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION > 1)
-# include "pike_error.h"
-#else
-# include "error.h"
-# ifndef Pike_error
-# define Pike_error error
-# endif
-#endif
-
-/* Pike 7.x and newer */
-#define MY_MAPPING_LOOP(md, COUNT, KEY) \
- for(COUNT=0;COUNT < md->data->hashsize; COUNT++ ) \
- for(KEY=md->data->hash[COUNT];KEY;KEY=KEY->next)
-
-#ifndef ZTS
-/* Need thread safety */
-#error You need to compile PHP with threads.
-#endif
-
-#ifndef PIKE_THREADS
-#error The PHP4 module requires that your Pike has thread support.
-#endif
-
-#undef HIDE_GLOBAL_VARIABLES
-#undef REVEAL_GLOBAL_VARIABLES
-#define HIDE_GLOBAL_VARIABLES()
-#define REVEAL_GLOBAL_VARIABLES()
-
-/* php_caudium_request is per-request object storage */
-
-typedef struct
-{
- struct mapping *request_data;
- struct object *my_fd_obj;
- struct svalue done_cb;
- struct pike_string *filename;
- int my_fd;
- int written;
- TSRMLS_D;
-} php_caudium_request;
-
-
-void pike_module_init(void);
-void pike_module_exit(void);
-static void free_struct(TSRMLS_D);
-void f_php_caudium_request_handler(INT32 args);
-
-/* Defines to get to the data supplied when the script is started. */
-
-/* Per thread storage area id... */
-static int caudium_globals_id;
-
-#define GET_THIS() php_caudium_request *_request = ts_resource(caudium_globals_id)
-#define THIS _request
-#define PTHIS ((php_caudium_request *)(Pike_fp->current_storage))
-/* File descriptor integer. Used to write directly to the FD without
- * passing Pike
- */
-#define MY_FD (THIS->my_fd)
-
-/* FD object. Really a PHPScript object from Pike which implements a couple
- * of functions to handle headers, writing and buffering.
- */
-#define MY_FD_OBJ ((struct object *)(THIS->my_fd_obj))
-
-/* Mapping with data supplied from the calling Caudium module. Contains
- * a mapping with headers, an FD object etc.
- */
-#define REQUEST_DATA ((struct mapping *)(THIS->request_data))
-
-extern int fd_from_object(struct object *o);
-static unsigned char caudium_php_initialized;
-
-#ifndef mt_lock_interpreter
-#define mt_lock_interpreter() mt_lock(&interpreter_lock);
-#define mt_unlock_interpreter() mt_unlock(&interpreter_lock);
-#endif
-
-
-/* This allows calling of pike functions from the PHP callbacks,
- * which requires the Pike interpreter to be locked.
- */
-#define THREAD_SAFE_RUN(COMMAND, what) do {\
- struct thread_state *state;\
- if((state = thread_state_for_id(th_self()))!=NULL) {\
- if(!state->swapped) {\
- COMMAND;\
- } else {\
- mt_lock_interpreter();\
- SWAP_IN_THREAD(state);\
- COMMAND;\
- SWAP_OUT_THREAD(state);\
- mt_unlock_interpreter();\
- }\
- }\
-} while(0)
-
-
-
-/* Low level header lookup. Basically looks for the named header in the mapping
- * headers in the supplied options mapping.
- */
-
-INLINE static struct svalue *lookup_header(char *headername)
-{
- struct svalue *headers, *value;
- struct pike_string *sind;
- GET_THIS();
- sind = make_shared_string("env");
- headers = low_mapping_string_lookup(REQUEST_DATA, sind);
- free_string(sind);
- if(!headers || headers->type != PIKE_T_MAPPING) return NULL;
- sind = make_shared_string(headername);
- value = low_mapping_string_lookup(headers->u.mapping, sind);
- free_string(sind);
- if(!value) return NULL;
- return value;
-}
-
-/* Lookup a header in the mapping and return the value as a string, or
- * return the default if it's missing
- */
-INLINE static char *lookup_string_header(char *headername, char *default_value)
-{
- struct svalue *head = NULL;
- THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup");
- if(!head || head->type != PIKE_T_STRING)
- return default_value;
- return head->u.string->str;
-}
-
-/* Lookup a header in the mapping and return the value as if it's an integer
- * and otherwise return the default.
- */
-INLINE static int lookup_integer_header(char *headername, int default_value)
-{
- struct svalue *head = NULL;
- THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup");
- if(!head || head->type != PIKE_T_INT)
- return default_value;
- return head->u.integer;
-}
-
-/*
- * php_caudium_low_ub_write() writes data to the client connection. Might be
- * rewritten to do more direct IO to save CPU and the need to lock the
- * interpreter for better threading.
- */
-
-INLINE static int
-php_caudium_low_ub_write(const char *str, uint str_length TSRMLS_DC) {
- int sent_bytes = 0;
- struct pike_string *to_write = NULL;
- GET_THIS();
- if(!MY_FD_OBJ->prog) {
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- zend_bailout();
- return -1;
- }
- to_write = make_shared_binary_string(str, str_length);
- push_string(to_write);
- safe_apply(MY_FD_OBJ, "write", 1);
- if(Pike_sp[-1].type == PIKE_T_INT)
- sent_bytes = Pike_sp[-1].u.integer;
- pop_stack();
- if(sent_bytes != str_length) {
- /* This means the connection is closed. Dead. Gone. *sniff* */
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- zend_bailout();
- }
- return sent_bytes;
-}
-
-/*
- * php_caudium_sapi_ub_write() calls php_caudium_low_ub_write in a Pike thread
- * safe manner or writes directly to the output FD if RXML post-parsing is
- * disabled.
- */
-
-static int
-php_caudium_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- GET_THIS();
- int sent_bytes = 0, fd = MY_FD;
- if(fd)
- {
- for(sent_bytes=0;sent_bytes < str_length;)
- {
- int written;
- written = fd_write(fd, str + sent_bytes, str_length - sent_bytes);
- if(written < 0)
- {
- switch(errno)
- {
- default:
- /* This means the connection is closed. Dead. Gone. *sniff* */
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- zend_bailout();
- THIS->written += sent_bytes;
- return sent_bytes;
- case EINTR:
- case EWOULDBLOCK:
- continue;
- }
- } else {
- sent_bytes += written;
- }
- }
- THIS->written += sent_bytes;
- } else {
- THREAD_SAFE_RUN(sent_bytes = php_caudium_low_ub_write(str, str_length TSRMLS_CC),
- "write");
- }
- return sent_bytes;
-}
-
-/* php_caudium_set_header() sets a header in the header mapping. Called in a
- * thread safe manner from php_caudium_sapi_header_handler.
- */
-INLINE static void
-php_caudium_set_header(char *header_name, char *value, char *p)
-{
- struct svalue hsval;
- struct pike_string *hval, *ind, *hind;
- struct mapping *headermap;
- struct svalue *s_headermap, *soldval;
- int vallen;
- GET_THIS();
- // hval = make_shared_string(value);
- ind = make_shared_string(" _headers");
- hind = make_shared_binary_string(header_name,
- (int)(p - header_name));
-
- s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind);
- if(!s_headermap || s_headermap->type != PIKE_T_MAPPING)
- {
- struct svalue mappie;
- mappie.type = PIKE_T_MAPPING;
- headermap = allocate_mapping(1);
- mappie.u.mapping = headermap;
- mapping_string_insert(REQUEST_DATA, ind, &mappie);
- free_mapping(headermap);
- hval = make_shared_string(value);
- } else {
- headermap = s_headermap->u.mapping;
- soldval = low_mapping_string_lookup(headermap, hind);
- vallen = strlen(value);
- if(soldval != NULL &&
- soldval->type == PIKE_T_STRING &&
- soldval->u.string->size_shift == 0) {
- /* Existing, valid header. Prepend.*/
- hval = begin_shared_string(soldval->u.string->len + 1 + vallen);
- MEMCPY(hval->str, soldval->u.string->str, soldval->u.string->len);
- STR0(hval)[soldval->u.string->len] = '\0';
- MEMCPY(hval->str+soldval->u.string->len+1, value, vallen);
- hval = end_shared_string(hval);
- } else {
- hval = make_shared_string(value);
- }
- }
- hsval.type = PIKE_T_STRING;
- hsval.u.string = hval;
-
- mapping_string_insert(headermap, hind, &hsval);
-
- free_string(hval);
- free_string(ind);
- free_string(hind);
-}
-
-/*
- * php_caudium_sapi_header_handler() sets a HTTP reply header to be
- * sent to the client.
- */
-static int
-php_caudium_sapi_header_handler(sapi_header_struct *sapi_header,
- sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- char *header_name, *header_content, *p;
- header_name = sapi_header->header;
- header_content = p = strchr(header_name, ':');
-
- if(p) {
- do {
- header_content++;
- } while(*header_content == ' ');
- THREAD_SAFE_RUN(php_caudium_set_header(header_name, header_content, p), "header handler");
- }
- sapi_free_header(sapi_header);
- return 0;
-}
-
-/*
- * php_caudium_sapi_send_headers() flushes the headers to the client.
- * Called before real content is sent by PHP.
- */
-
-INLINE static int
-php_caudium_low_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- struct pike_string *ind;
- struct svalue *s_headermap;
- GET_THIS();
- if(!MY_FD_OBJ->prog) {
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- zend_bailout();
- return SAPI_HEADER_SEND_FAILED;
- }
- ind = make_shared_string(" _headers");
- s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind);
- free_string(ind);
-
- push_int(SG(sapi_headers).http_response_code);
- if(s_headermap && s_headermap->type == PIKE_T_MAPPING)
- ref_push_mapping(s_headermap->u.mapping);
- else
- push_int(0);
- safe_apply(MY_FD_OBJ, "send_headers", 2);
- pop_stack();
-
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-static int
-php_caudium_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- int res = 0;
- THREAD_SAFE_RUN(res = php_caudium_low_send_headers(sapi_headers TSRMLS_CC), "send headers");
- return res;
-}
-
-/*
- * php_caudium_sapi_read_post() reads a specified number of bytes from
- * the client. Used for POST/PUT requests.
- */
-
-INLINE static int php_caudium_low_read_post(char *buf, uint count_bytes)
-{
- uint total_read = 0;
- GET_THIS();
- TSRMLS_FETCH();
-
- if(!MY_FD_OBJ->prog)
- {
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- zend_bailout();
- return -1;
- }
- push_int(count_bytes);
- safe_apply(MY_FD_OBJ, "read_post", 1);
- if(Pike_sp[-1].type == PIKE_T_STRING) {
- MEMCPY(buf, Pike_sp[-1].u.string->str,
- (total_read = Pike_sp[-1].u.string->len));
- buf[total_read] = '\0';
- } else
- total_read = 0;
- pop_stack();
- return total_read;
-}
-
-static int
-php_caudium_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC)
-{
- uint total_read = 0;
- THREAD_SAFE_RUN(total_read = php_caudium_low_read_post(buf, count_bytes), "read post");
- return total_read;
-}
-
-/*
- * php_caudium_sapi_read_cookies() returns the Cookie header from
- * the HTTP request header
- */
-
-static char *
-php_caudium_sapi_read_cookies(TSRMLS_D)
-{
- char *cookies;
- cookies = lookup_string_header("HTTP_COOKIE", NULL);
- return cookies;
-}
-
-static void php_info_caudium(ZEND_MODULE_INFO_FUNC_ARGS)
-{
- /* char buf[512]; */
- php_info_print_table_start();
- php_info_print_table_row(2, "SAPI module version", "$Id$");
- /* php_info_print_table_row(2, "Build date", Ns_InfoBuildDate());
- php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile());
- php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog());
- php_info_print_table_row(2, "Installation path", Ns_InfoHomePath());
- php_info_print_table_row(2, "Hostname of server", Ns_InfoHostname());
- php_info_print_table_row(2, "Source code label", Ns_InfoLabel());
- php_info_print_table_row(2, "Server platform", Ns_InfoPlatform());
- snprintf(buf, 511, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion());
- php_info_print_table_row(2, "Server version", buf);
- snprintf(buf, 511, "%d day(s), %02d:%02d:%02d",
- uptime / 86400,
- (uptime / 3600) % 24,
- (uptime / 60) % 60,
- uptime % 60);
- php_info_print_table_row(2, "Server uptime", buf);
- */
- php_info_print_table_end();
-}
-
-static zend_module_entry php_caudium_module = {
- STANDARD_MODULE_HEADER,
- "Caudium",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- php_info_caudium,
- NULL,
- STANDARD_MODULE_PROPERTIES
-};
-
-
-INLINE static void low_sapi_caudium_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- int i;
- struct keypair *k;
- struct svalue *headers;
- struct pike_string *sind;
- struct svalue *ind;
- struct svalue *val;
- GET_THIS();
- php_register_variable("PHP_SELF", SG(request_info).request_uri,
- track_vars_array TSRMLS_CC);
- php_register_variable("GATEWAY_INTERFACE", "CGI/1.1",
- track_vars_array TSRMLS_CC);
- php_register_variable("REQUEST_METHOD",
- (char *) SG(request_info).request_method,
- track_vars_array TSRMLS_CC);
- php_register_variable("REQUEST_URI", SG(request_info).request_uri,
- track_vars_array TSRMLS_CC);
- php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated,
- track_vars_array TSRMLS_CC);
-
- sind = make_shared_string("env");
- headers = low_mapping_string_lookup(REQUEST_DATA, sind);
- free_string(sind);
- if(headers && headers->type == PIKE_T_MAPPING) {
- MY_MAPPING_LOOP(headers->u.mapping, i, k) {
- ind = &k->ind;
- val = &k->val;
- if(ind && ind->type == PIKE_T_STRING &&
- val && val->type == PIKE_T_STRING) {
- php_register_variable(ind->u.string->str, val->u.string->str,
- track_vars_array TSRMLS_CC );
- }
- }
- }
-}
-
-static void sapi_caudium_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- THREAD_SAFE_RUN(low_sapi_caudium_register_variables(track_vars_array TSRMLS_CC), "register_variables");
-}
-
-
-static int php_caudium_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, &php_caudium_module, 1)==FAILURE) {
- return FAILURE;
- }
- return SUCCESS;
-}
-
-
-/* this structure is static (as in "it does not change") */
-static sapi_module_struct caudium_sapi_module = {
- "caudium",
- "Caudium",
- php_caudium_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
- NULL, /* activate */
- NULL, /* deactivate */
- php_caudium_sapi_ub_write, /* unbuffered write */
- NULL, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
- php_error, /* error handler */
- php_caudium_sapi_header_handler, /* header handler */
- php_caudium_sapi_send_headers, /* send headers handler */
- NULL, /* send header handler */
- php_caudium_sapi_read_post, /* read POST data */
- php_caudium_sapi_read_cookies, /* read cookies */
- sapi_caudium_register_variables, /* register server variables */
- NULL, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-/*
- * php_caudium_module_main() is called by the per-request handler and
- * "executes" the script
- */
-
-static void php_caudium_module_main(php_caudium_request *ureq)
-{
- int res;
- zend_file_handle file_handle;
-#ifndef USE_PIKE_LEVEL_THREADS
- struct thread_state *state;
- extern struct program *thread_id_prog;
-#endif
- TSRMLS_FETCH();
- GET_THIS();
- THIS->filename = ureq->filename;
- THIS->done_cb = ureq->done_cb;
- THIS->my_fd_obj = ureq->my_fd_obj;
- THIS->my_fd = ureq->my_fd;
- THIS->request_data = ureq->request_data;
- free(ureq);
-
-#ifndef USE_PIKE_LEVEL_THREADS
- mt_lock_interpreter();
- init_interpreter();
-#if PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION < 1
- thread_id = low_clone(thread_id_prog);
- state = OBJ2THREAD(thread_id);
- Pike_stack_top=((char *)&state)+ (thread_stack_size-16384) * STACK_DIRECTION;
- recoveries = NULL;
- call_c_initializers(thread_id);
- OBJ2THREAD(thread_id)->id=th_self();
- num_threads++;
- thread_table_insert(thread_id);
- state->status=THREAD_RUNNING;
-#else
- Pike_interpreter.thread_id = low_clone(thread_id_prog);
- state = OBJ2THREAD(Pike_interpreter.thread_id);
- Pike_interpreter.stack_top=((char *)&state)+ (thread_stack_size-16384) * STACK_DIRECTION;
- Pike_interpreter.recoveries = NULL;
- call_c_initializers(Pike_interpreter.thread_id);
- state->id=th_self();
- // SWAP_OUT_THREAD(OBJ2THREAD(Pike_interpreter.thread_id));
- num_threads++;
- thread_table_insert(Pike_interpreter.thread_id);
- state->status=THREAD_RUNNING;
-#endif
- state->swapped = 0;
-#endif
- SG(request_info).query_string = lookup_string_header("QUERY_STRING", 0);
- SG(server_context) = (void *)1; /* avoid server_context == NULL */
-
- /* path_translated is apparently the absolute path to the file, not
- the translated PATH_INFO
- */
- SG(request_info).path_translated =
- lookup_string_header("SCRIPT_FILENAME", NULL);
- SG(request_info).request_uri = lookup_string_header("DOCUMENT_URI", NULL);
- if(!SG(request_info).request_uri)
- SG(request_info).request_uri = lookup_string_header("SCRIPT_NAME", NULL);
- SG(request_info).request_method = lookup_string_header("REQUEST_METHOD", "GET");
- SG(request_info).content_length = lookup_integer_header("HTTP_CONTENT_LENGTH", 0);
- SG(request_info).content_type = lookup_string_header("HTTP_CONTENT_TYPE", NULL);
- SG(sapi_headers).http_response_code = 200;
- if (!strcmp(SG(request_info).request_method, "HEAD")) {
- SG(request_info).headers_only = 1;
- } else {
- SG(request_info).headers_only = 0;
- }
-
- /* Let PHP4 handle the deconding of the AUTH */
- php_handle_auth_data(lookup_string_header("HTTP_AUTHORIZATION", NULL), TSRMLS_C);
- /* Swap out this thread and release the interpreter lock to allow
- * Pike threads to run. We wait since the above would otherwise require
- * a lot of unlock/lock.
- */
-#ifndef USE_PIKE_LEVEL_THREADS
- SWAP_OUT_THREAD(state);
- mt_unlock_interpreter();
-#else
- THREADS_ALLOW();
-#endif
-
-#ifdef VIRTUAL_DIR
- /* Change virtual directory, if the feature is enabled, which is
- * (almost) a requirement for PHP in Caudium. Might want to fail if it
- * isn't. Not a problem though, since it's on by default when using ZTS
- * which we require.
- */
- VCWD_CHDIR_FILE(THIS->filename->str);
-#endif
-
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = THIS->filename->str;
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
-
- THIS->written = 0;
- res = php_request_startup(TSRMLS_C);
-
- if(res == FAILURE) {
- THREAD_SAFE_RUN({
- apply_svalue(&THIS->done_cb, 0);
- pop_stack();
- free_struct(TSRMLS_C);
- }, "Negative run response");
- } else {
- php_execute_script(&file_handle TSRMLS_CC);
- php_request_shutdown(NULL);
- THREAD_SAFE_RUN({
- push_int(THIS->written);
- apply_svalue(&THIS->done_cb, 1);
- pop_stack();
- free_struct(TSRMLS_C);
- }, "positive run response");
- }
-
-#ifndef USE_PIKE_LEVEL_THREADS
- mt_lock_interpreter();
- SWAP_IN_THREAD(state);
-#if PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION < 1
- state->status=THREAD_EXITED;
- co_signal(& state->status_change);
- thread_table_delete(thread_id);
- free_object(thread_id);
- thread_id=NULL;
-#else
- state->status=THREAD_EXITED;
- co_signal(& state->status_change);
- thread_table_delete(Pike_interpreter.thread_id);
- free_object(Pike_interpreter.thread_id);
- Pike_interpreter.thread_id=NULL;
-#endif
- cleanup_interpret();
- num_threads--;
- mt_unlock_interpreter();
-#else
- THREADS_DISALLOW();
-#endif
-}
-
-/*
- * The php_caudium_request_handler() is called per request and handles
- * everything for one request.
- */
-
-void f_php_caudium_request_handler(INT32 args)
-{
- struct object *my_fd_obj;
- struct mapping *request_data;
- struct svalue *done_callback;
- struct pike_string *script;
- struct svalue *raw_fd;
- struct pike_string *ind;
- php_caudium_request *_request;
- THIS = malloc(sizeof(php_caudium_request));
- if(THIS == NULL)
- Pike_error("Out of memory.");
-
- get_all_args("PHP4.Interpreter->run", args, "%S%m%O%*", &script,
- &request_data, &my_fd_obj, &done_callback);
- if(done_callback->type != PIKE_T_FUNCTION)
- Pike_error("PHP4.Interpreter->run: Bad argument 4, expected function.\n");
- add_ref(request_data);
- add_ref(my_fd_obj);
- add_ref(script);
-
- THIS->request_data = request_data;
- THIS->my_fd_obj = my_fd_obj;
- THIS->filename = script;
- assign_svalue_no_free(&THIS->done_cb, done_callback);
-
- ind = make_shared_binary_string("my_fd", 5);
- raw_fd = low_mapping_string_lookup(THIS->request_data, ind);
- if(raw_fd && raw_fd->type == PIKE_T_OBJECT)
- {
- int fd = fd_from_object(raw_fd->u.object);
- if(fd == -1)
- THIS->my_fd = 0; /* Don't send directly to this FD... */
- else
- THIS->my_fd = fd;
- } else
- THIS->my_fd = 0;
-#ifdef USE_PIKE_LEVEL_THREADS
- php_caudium_module_main(THIS);
-#else
- th_farm((void (*)(void *))php_caudium_module_main, THIS);
-#endif
- pop_n_elems(args);
-}
-
-static void free_struct(TSRMLS_D)
-{
- GET_THIS();
- if(THIS->request_data) free_mapping(THIS->request_data);
- if(THIS->my_fd_obj) free_object(THIS->my_fd_obj);
- free_svalue(&THIS->done_cb);
- if(THIS->filename) free_string(THIS->filename);
- MEMSET(THIS, 0, sizeof(php_caudium_request));
-}
-
-
-/*
- * pike_module_init() is called by Pike once at startup
- *
- * This functions allocates basic structures
- */
-
-void pike_module_init( void )
-{
- if (!caudium_php_initialized) {
- caudium_php_initialized = 1;
- tsrm_startup(1, 1, 0, NULL);
- ts_allocate_id(&caudium_globals_id, sizeof(php_caudium_request), NULL, NULL);
- sapi_startup(&caudium_sapi_module);
- sapi_module.startup(&caudium_sapi_module);
- }
- start_new_program(); /* Text */
- pike_add_function("run", f_php_caudium_request_handler,
- "function(string, mapping, object, function:void)", 0);
- end_class("Interpreter", 0);
-}
-
-/*
- * pike_module_exit() performs the last steps before the
- * server exists. Shutdowns basic services and frees memory
- */
-
-void pike_module_exit(void)
-{
- caudium_php_initialized = 0;
- sapi_module.shutdown(&caudium_sapi_module);
- tsrm_shutdown();
-}
-#endif
diff --git a/sapi/caudium/config.m4 b/sapi/caudium/config.m4
deleted file mode 100644
index a4f76db1b6..0000000000
--- a/sapi/caudium/config.m4
+++ /dev/null
@@ -1,99 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-RESULT=no
-AC_MSG_CHECKING(for Caudium support)
-AC_ARG_WITH(caudium,
-[ --with-caudium=DIR Build PHP as a Pike module for use with Caudium
- DIR is the Caudium server dir, with the default value
- /usr/local/caudium/server.],
-[
- if test "$prefix" = "NONE"; then CPREF=/usr/local/; fi
- if test ! -d $withval ; then
- if test "$prefix" = "NONE"; then
- withval=/usr/local/caudium/server/
- else
- withval=$prefix/caudium/server/
- fi
- fi
- if test -f $withval/bin/caudium; then
- PIKE=$withval/bin/caudium
- elif test -f $withval/bin/pike; then
- PIKE=$withval/bin/pike
- else
- AC_MSG_ERROR(Couldn't find a pike in $withval/bin/)
- fi
- if $PIKE -e 'float v; int rel;sscanf(version(), "Pike v%f release %d", v, rel);v += rel/10000.0; if(v < 7.0268) exit(1); exit(0);'; then
- PIKE_MODULE_DIR=`$PIKE --show-paths 2>&1| grep '^Module' | sed -e 's/.*: //'`
- PIKE_INCLUDE_DIR=`echo $PIKE_MODULE_DIR | sed -e 's,lib/pike/modules,include/pike,' -e 's,lib/modules,include/pike,' `
- if test -z "$PIKE_INCLUDE_DIR" -o -z "$PIKE_MODULE_DIR"; then
- AC_MSG_ERROR(Failed to figure out Pike module and include directories)
- fi
- AC_MSG_RESULT(yes)
- PIKE=`echo $PIKE | pike -e 'int tries=100;
- string orig,pike=Stdio.File("stdin")->read()-"\n";
- orig=pike;
- if(search(orig, "/"))
- orig = combine_path(getcwd(), orig);
- while(!catch(pike=readlink(pike)) && tries--)
- ;
- write(combine_path(dirname(orig), pike)); '`
- PHP_ADD_INCLUDE($PIKE_INCLUDE_DIR)
- if test "$prefix" != "NONE"; then
- PIKE_C_INCLUDE=$prefix/include/`basename $PIKE`
- else
- PIKE_C_INCLUDE=/usr/local/include/`basename $PIKE`
- fi
- AC_MSG_CHECKING(for C includes in $PIKE_C_INCLUDE)
- if test -f $PIKE_C_INCLUDE/version.h; then
- PIKE_TEST_VER=`$PIKE -e 'string v; int rel;sscanf(version(), "Pike v%s release %d", v, rel); write(v+"."+rel);'`
- ###### VERSION MATCH CHECK #######
- PMAJOR="^#define PIKE_MAJOR_VERSION"
- PMINOR="^#define PIKE_MINOR_VERSION"
- PBUILD="^#define PIKE_BUILD_VERSION"
-
- PIKE_CMAJOR_VERSION=0
- PIKE_CMINOR_VERSION=0
- PIKE_CBUILD_VERSION=0
-
- PIKE_CMAJOR_VERSION=`grep "$PMAJOR" $PIKE_C_INCLUDE/version.h | sed -e 's/\(#define.*N \)\(.*\)/\2/'`
- if test -z "$PIKE_CMAJOR_VERSION"; then
- if test -n "`grep f_version $PIKE_C_INCLUDE/version.h`"; then
- PIKE_CMAJOR_VERSION=6
- fi
- else
- PIKE_CMINOR_VERSION=`grep "$PMINOR" $PIKE_C_INCLUDE/version.h | sed -e 's/\(#define.*N \)\(.*\)/\2/'`
- PIKE_CBUILD_VERSION=`grep "$PBUILD" $PIKE_C_INCLUDE/version.h | sed -e 's/\(#define.*N \)\(.*\)/\2/'`
- fi
-
- if test "$PIKE_TEST_VER" = "${PIKE_CMAJOR_VERSION}.${PIKE_CMINOR_VERSION}.${PIKE_CBUILD_VERSION}"; then
- PHP_ADD_INCLUDE($PIKE_C_INCLUDE)
- PIKE_INCLUDE_DIR="$PIKE_INCLUDE_DIR, $PIKE_C_INCLUDE"
- AC_MSG_RESULT(found)
- else
- AC_MSG_RESULT(version mismatch)
- fi
- else
- AC_MSG_RESULT(not found)
- fi
- else
- AC_MSG_ERROR(Caudium PHP4 requires Pike 7.0 or newer)
- fi
- PIKE_VERSION=`$PIKE -e 'string v; int rel;sscanf(version(), "Pike v%s release %d", v, rel); write(v+"."+rel);'`
- AC_DEFINE(HAVE_CAUDIUM,1,[Whether to compile with Caudium support])
- PHP_SELECT_SAPI(caudium, shared, caudium.c)
- INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $withval/lib/$PIKE_VERSION/PHP4.so"
- RESULT=" *** Pike binary used: $PIKE
- *** Pike include dir(s) used: $PIKE_INCLUDE_DIR
- *** Pike version: $PIKE_VERSION"
- dnl Always use threads since thread-free support really blows.
- PHP_BUILD_THREAD_SAFE
-
-])
-AC_MSG_RESULT($RESULT)
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
-
diff --git a/sapi/cgi/CREDITS b/sapi/cgi/CREDITS
deleted file mode 100644
index a1c6a0be59..0000000000
--- a/sapi/cgi/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-CGI / FastCGI
-Rasmus Lerdorf, Stig Bakken, Shane Caraveo
diff --git a/sapi/cgi/Makefile.frag b/sapi/cgi/Makefile.frag
deleted file mode 100644
index 57a3b2937c..0000000000
--- a/sapi/cgi/Makefile.frag
+++ /dev/null
@@ -1,2 +0,0 @@
-$(SAPI_CGI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
- $(BUILD_CGI)
diff --git a/sapi/cgi/README.FastCGI b/sapi/cgi/README.FastCGI
deleted file mode 100644
index 9e5d4ae97b..0000000000
--- a/sapi/cgi/README.FastCGI
+++ /dev/null
@@ -1,137 +0,0 @@
-Credits:
-Ben Mansell, Stephen Landamore, Daniel Silverstone, Shane Caraveo
-
-Building PHP
-------------
-
-You must add '--enable-fastcgi' to the configure command on Linux or
-OSX based systems to get fastcgi support in the php-cgi binary. You
-also must not use '--enable-discard-path'.
-
-Running the FastCGI PHP module
-------------------------------
-
-There are two ways to run the resulting 'php' binary after the fastcgi
-version has been built:
-
-1) Configure your web server to run the PHP binary itself.
-
-This is the simplest method, obviously you will have to configure your
-web server appropriately. Some web servers may also not support this method,
-or may not be as efficient.
-
-2) Run PHP separately from the web server.
-
-In this setup, PHP is started as a separate process entirely from the web
-server. It will listen on a socket for new FastCGI requests, and deliver
-PHP pages as appropriate. This is the recommended way of running PHP-FastCGI.
-To run this way, you must start the PHP binary running by giving it a port
-number to listen to on the command line, e.g.:
-
-./php -b 8002
-
-(you can also specify a bind address, e.g. ./php -b localhost:8002. However, this
- relies on the FastCGI devkit and does not seem to work properly)
-
-You must also configure your web server to connect to the appropriate port
-in order to talk to the PHP FastCGI process.
-
-The advantage of running PHP in this way is that it entirely separates the
-web server and PHP process, so that one cannot disrupt the other. It also
-allows PHP to be on an entirely separate machine from the web server if need
-be, you could even have several web servers utilising the same running PHP
-process if required!
-
-
-Using FastCGI PHP with Apache
-=============================
-
-First of all, you may well ask 'Why?'. After all, Apache already has mod_php.
-However, there are advantages to running PHP with FastCGI. Separating the
-PHP code from the web server removes 'bloat' from the main server, and should
-improve the performance of non-PHP requests. Secondly, having one permanent
-PHP process as opposed to one per apache process means that shared resources
-like persistent database connections are used more efficiently.
-
-First of all, make sure that the FastCGI module is enabled. You should have
-a line in your config like:
-
- LoadModule fastcgi_module /usr/lib/apache/2.0/mod_fastcgi.so
-
-Don't load mod_php, by the way. Make sure it is commented out!
-
- #LoadModule php4_module /usr/lib/apache/2.0/libphp4.so
-
-Now, we'll create a fcgi-bin directory, just like you would do with normal
-CGI scripts. You'll need to create a directory somewhere to store your
-FastCGI binaries. We'll use /space/fcgi-bin/ for this example. Remember to
-copy the FastCGI-PHP binary in there. (named 'php-cgi') This sets up
-php to run under mod_fastcgi as a dynamic server.
-
- ScriptAlias /fcgi-bin/ /space/fcgi-bin/
- <Location /fcgi-bin/>
- Options ExecCGI
- SetHandler fastcgi-script
- </Location>
-
-To setup a specific static configuration for php, you have to use
-the FastCgiServer configuration for mod_fastcgi. For this, do not
-use the above configuration, but rather the following.
-(see mod_fastcgi docs for more configuration information):
-
- Alias /fcgi-bin/ /space/fcgi-bin/
- FastCgiServer /path/to/php-cgi -processes 5
-
-For either of the above configurations, we need to tell Apache to
-use the FastCGI binary /fcgi-bin/php to deliver PHP pages.
-All that is needed is:
-
- AddType application/x-httpd-fastphp .php
- Action application/x-httpd-fastphp /fcgi-bin/php-cgi
-
-Now, if you restart Apache, php pages should now be delivered!
-
-Using FastCGI PHP with IIS or iPlanet
-=====================================
-
-FastCGI server plugins are available at www.caraveo.com/fastcgi/
-Documentation on these are sparse. iPlanet is not very tested,
-and no makefile exists yet for unix based iPlanet servers.
-
-
-Security
---------
-
-Be sure to run the php binary as an appropriate userid. Also, firewall out
-the port that PHP is listening on. In addition, you can set the environment
-variable FCGI_WEB_SERVER_ADDRS to control who can connect to the FastCGI.
-Set it to a comma separated list of IP addresses, e.g.:
-
-export FCGI_WEB_SERVER_ADDRS=199.170.183.28,199.170.183.71
-
-
-Tuning
-------
-
-There are a few tuning parameters that can be tweaked to control the
-performance of FastCGI PHP. The following are environment variables that can
-be set before running the PHP binary:
-
-PHP_FCGI_CHILDREN (default value: 8)
-
-This controls how many child processes the PHP process spawns. When the
-fastcgi starts, it creates a number of child processes which handle one
-page request at a time. So by default, you will be able to handle 8
-concurrent PHP page requests. Further requests will be queued.
-Increasing this number will allow for better concurrency, especially if you
-have pages that take a significant time to create, or supply a lot of data
-(e.g. downloading huge files via PHP). On the other hand, having more
-processes running will use more RAM, and letting too many PHP pages be
-generated concurrently will mean that each request will be slow.
-
-PHP_FCGI_MAX_REQUESTS (default value: 500)
-
-This controls how many requests each child process will handle before
-exitting. When one process exits, another will be created. This tuning is
-necessary because several PHP functions are known to have memory leaks. If the
-PHP processes were left around forever, they would be become very inefficient.
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
deleted file mode 100644
index e540039ee4..0000000000
--- a/sapi/cgi/cgi_main.c
+++ /dev/null
@@ -1,1593 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Stig Bakken <ssb@fast.no> |
- | Zeev Suraski <zeev@zend.com> |
- | FastCGI: Ben Mansell <php@slimyhorror.com> |
- | Shane Caraveo <shane@caraveo.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "php_globals.h"
-#include "php_variables.h"
-#include "zend_modules.h"
-
-#include "SAPI.h"
-
-#include <stdio.h>
-#include "php.h"
-#ifdef PHP_WIN32
-#include "win32/time.h"
-#include "win32/signal.h"
-#include <process.h>
-#endif
-#if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-#if HAVE_SETLOCALE
-#include <locale.h>
-#endif
-#include "zend.h"
-#include "zend_extensions.h"
-#include "php_ini.h"
-#include "php_globals.h"
-#include "php_main.h"
-#include "fopen_wrappers.h"
-#include "ext/standard/php_standard.h"
-#ifdef PHP_WIN32
-#include <io.h>
-#include <fcntl.h>
-#include "win32/php_registry.h"
-#endif
-
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-
-#ifdef __riscos__
-#include <unixlib/local.h>
-#endif
-
-#include "zend_compile.h"
-#include "zend_execute.h"
-#include "zend_highlight.h"
-#include "zend_indent.h"
-
-
-#include "php_getopt.h"
-
-#if PHP_FASTCGI
-#include "fcgi_config.h"
-#include "fcgiapp.h"
-/* don't want to include fcgios.h, causes conflicts */
-#ifdef PHP_WIN32
-extern int OS_SetImpersonate(void);
-#else
-/* XXX this will need to change later when threaded fastcgi is
- implemented. shane */
-struct sigaction act, old_term, old_quit, old_int;
-#endif
-
-static void (*php_php_import_environment_variables)(zval *array_ptr TSRMLS_DC);
-
-#ifndef PHP_WIN32
-/* these globals used for forking children on unix systems */
-/**
- * Number of child processes that will get created to service requests
- */
-static int children = 0;
-
-/**
- * Set to non-zero if we are the parent process
- */
-static int parent = 1;
-
-/**
- * Process group
- */
-static pid_t pgroup;
-#endif
-
-#endif
-
-#define PHP_MODE_STANDARD 1
-#define PHP_MODE_HIGHLIGHT 2
-#define PHP_MODE_INDENT 3
-#define PHP_MODE_LINT 4
-#define PHP_MODE_STRIP 5
-
-static char *optarg = NULL;
-static int optind = 1;
-
-static const opt_struct OPTIONS[] = {
- {'a', 0, "interactive"},
- {'C', 0, "no-chdir"},
- {'c', 1, "php-ini"},
- {'d', 1, "define"},
- {'e', 0, "profile-info"},
- {'f', 1, "file"},
- {'g', 1, "global"},
- {'h', 0, "help"},
- {'i', 0, "info"},
- {'l', 0, "syntax-check"},
- {'m', 0, "modules"},
- {'n', 0, "no-php-ini"},
- {'q', 0, "no-header"},
- {'s', 0, "syntax-highlight"},
- {'s', 0, "syntax-highlighting"},
- {'w', 0, "strip"},
- {'?', 0, "usage"},/* help alias (both '?' and 'usage') */
- {'v', 0, "version"},
- {'z', 1, "zend-extension"},
- {'-', 0, NULL} /* end of args */
-};
-
-#if ENABLE_PATHINFO_CHECK
-/* true global. this is retreived once only, even for fastcgi */
-long fix_pathinfo=1;
-#endif
-
-#ifdef PHP_WIN32
-#define TRANSLATE_SLASHES(path) \
- { \
- char *tmp = path; \
- while (*tmp) { \
- if (*tmp == '\\') *tmp = '/'; \
- tmp++; \
- } \
- }
-#else
-#define TRANSLATE_SLASHES(path)
-#endif
-
-static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
-{
- php_printf("%s\n", module->name);
- return 0;
-}
-
-static int module_name_cmp(const void *a, const void *b TSRMLS_DC)
-{
- Bucket *f = *((Bucket **) a);
- Bucket *s = *((Bucket **) b);
-
- return strcmp(((zend_module_entry *)f->pData)->name,
- ((zend_module_entry *)s->pData)->name);
-}
-
-static void print_modules(TSRMLS_D)
-{
- HashTable sorted_registry;
- zend_module_entry tmp;
-
- zend_hash_init(&sorted_registry, 50, NULL, NULL, 1);
- zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry));
- zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC);
- zend_hash_apply_with_argument(&sorted_registry, (apply_func_arg_t) print_module_info, NULL TSRMLS_CC);
- zend_hash_destroy(&sorted_registry);
-}
-
-static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC)
-{
- php_printf("%s\n", ext->name);
- return 0;
-}
-
-static int extension_name_cmp(const zend_llist_element **f,
- const zend_llist_element **s TSRMLS_DC)
-{
- return strcmp(((zend_extension *)(*f)->data)->name,
- ((zend_extension *)(*s)->data)->name);
-}
-
-static void print_extensions(TSRMLS_D)
-{
- zend_llist sorted_exts;
-
- zend_llist_copy(&sorted_exts, &zend_extensions);
- zend_llist_sort(&sorted_exts, extension_name_cmp TSRMLS_CC);
- zend_llist_apply_with_argument(&sorted_exts, (llist_apply_with_arg_func_t) print_extension_info, NULL TSRMLS_CC);
- zend_llist_destroy(&sorted_exts);
-}
-
-#ifndef STDOUT_FILENO
-#define STDOUT_FILENO 1
-#endif
-
-static inline size_t sapi_cgibin_single_write(const char *str, uint str_length TSRMLS_DC)
-{
-#ifdef PHP_WRITE_STDOUT
- long ret;
-#else
- size_t ret;
-#endif
-
-#if PHP_FASTCGI
- if (!FCGX_IsCGI()) {
- FCGX_Request *request = (FCGX_Request *)SG(server_context);
- long ret = FCGX_PutStr( str, str_length, request->out );
- if (ret <= 0) {
- return 0;
- }
- return ret;
- }
-#endif
-#ifdef PHP_WRITE_STDOUT
- ret = write(STDOUT_FILENO, str, str_length);
- if (ret <= 0) return 0;
- return ret;
-#else
- ret = fwrite(str, 1, MIN(str_length, 16384), stdout);
- return ret;
-#endif
-}
-
-static int sapi_cgibin_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- const char *ptr = str;
- uint remaining = str_length;
- size_t ret;
-
- while (remaining > 0)
- {
- ret = sapi_cgibin_single_write(ptr, remaining TSRMLS_CC);
- if (!ret) {
- php_handle_aborted_connection();
- }
- ptr += ret;
- remaining -= ret;
- }
-
- return str_length;
-}
-
-
-static void sapi_cgibin_flush(void *server_context)
-{
-#if PHP_FASTCGI
- if (!FCGX_IsCGI()) {
- FCGX_Request *request = (FCGX_Request *)server_context;
- if(!request || FCGX_FFlush( request->out ) == -1 ) {
- php_handle_aborted_connection();
- }
- } else
-#endif
- if (fflush(stdout)==EOF) {
- php_handle_aborted_connection();
- }
-}
-
-#define SAPI_CGI_MAX_HEADER_LENGTH 1024
-
-static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- char buf[SAPI_CGI_MAX_HEADER_LENGTH];
- sapi_header_struct *h;
- zend_llist_position pos;
- long rfc2616_headers = 0;
-
- if(SG(request_info).no_headers == 1) {
- return SAPI_HEADER_SENT_SUCCESSFULLY;
- }
- /* Check wheater to send RFC2616 style headers compatible with
- * PHP versions 4.2.3 and earlier compatible with web servers
- * such as IIS. Default is informal CGI RFC header compatible
- * with Apache.
- */
- if (cfg_get_long("cgi.rfc2616_headers", &rfc2616_headers) == FAILURE) {
- rfc2616_headers = 0;
- }
-
- if (SG(sapi_headers).http_response_code != 200) {
- int len;
-
- if (rfc2616_headers) {
- len = snprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH,
- "%s\r\n", SG(sapi_headers).http_status_line);
-
- if (len > SAPI_CGI_MAX_HEADER_LENGTH) {
- len = SAPI_CGI_MAX_HEADER_LENGTH;
- }
-
- } else {
- len = sprintf(buf, "Status: %d\r\n", SG(sapi_headers).http_response_code);
- }
-
- PHPWRITE_H(buf, len);
- }
-
- if (SG(sapi_headers).send_default_content_type) {
- char *hd;
-
- hd = sapi_get_default_content_type(TSRMLS_C);
- PHPWRITE_H("Content-type: ", sizeof("Content-type: ")-1);
- PHPWRITE_H(hd, strlen(hd));
- PHPWRITE_H("\r\n", 2);
- efree(hd);
- }
-
- h = zend_llist_get_first_ex(&sapi_headers->headers, &pos);
- while (h) {
- PHPWRITE_H(h->header, h->header_len);
- PHPWRITE_H("\r\n", 2);
- h = zend_llist_get_next_ex(&sapi_headers->headers, &pos);
- }
- PHPWRITE_H("\r\n", 2);
-
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-
-static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
- uint read_bytes=0, tmp_read_bytes;
-#if PHP_FASTCGI
- char *pos = buffer;
-#endif
-
- count_bytes = MIN(count_bytes, (uint)SG(request_info).content_length-SG(read_post_bytes));
- while (read_bytes < count_bytes) {
-#if PHP_FASTCGI
- if (!FCGX_IsCGI()) {
- FCGX_Request *request = (FCGX_Request *)SG(server_context);
- tmp_read_bytes = FCGX_GetStr( pos, count_bytes-read_bytes, request->in );
- pos += tmp_read_bytes;
- } else
-#endif
- tmp_read_bytes = read(0, buffer+read_bytes, count_bytes-read_bytes);
-
- if (tmp_read_bytes<=0) {
- break;
- }
- read_bytes += tmp_read_bytes;
- }
- return read_bytes;
-}
-
-static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC)
-{
-#if PHP_FASTCGI
- /* when php is started by mod_fastcgi, no regular environment
- is provided to PHP. It is always sent to PHP at the start
- of a request. So we have to do our own lookup to get env
- vars. This could probably be faster somehow. */
- if (!FCGX_IsCGI()) {
- FCGX_Request *request = (FCGX_Request *)SG(server_context);
- return FCGX_GetParam(name,request->envp);
- }
-#endif
- /* if cgi, or fastcgi and not found in fcgi env
- check the regular environment */
- return getenv(name);
-}
-
-static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC)
-{
- int len=0;
- char *buf = NULL;
- if (!name) return NULL;
- len = strlen(name) + (value?strlen(value):0) + sizeof("=") + 2;
- buf = (char *)emalloc(len);
- if (value) {
- snprintf(buf,len-1,"%s=%s", name, value);
- } else {
- snprintf(buf,len-1,"%s=", name);
- }
-#if PHP_FASTCGI
- /* when php is started by mod_fastcgi, no regular environment
- is provided to PHP. It is always sent to PHP at the start
- of a request. So we have to do our own lookup to get env
- vars. This could probably be faster somehow. */
- if (!FCGX_IsCGI()) {
- FCGX_Request *request = (FCGX_Request *)SG(server_context);
- FCGX_PutEnv(request,buf);
- efree(buf);
- return sapi_cgibin_getenv(name,0 TSRMLS_CC);
- }
-#endif
- /* if cgi, or fastcgi and not found in fcgi env
- check the regular environment
- this leaks, but it's only cgi anyway, we'll fix
- it for 5.0
- */
- if (value)
- putenv(strdup(buf));
- else
- putenv(buf);
- efree(buf);
- return getenv(name);
-}
-
-static char *sapi_cgi_read_cookies(TSRMLS_D)
-{
- return sapi_cgibin_getenv((char *)"HTTP_COOKIE",0 TSRMLS_CC);
-}
-
-#if PHP_FASTCGI
-void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
-{
- if (!FCGX_IsCGI()) {
- FCGX_Request *request = (FCGX_Request *)SG(server_context);
- char **env, *p, *t;
-
- for (env = request->envp; env != NULL && *env != NULL; env++) {
- p = strchr(*env, '=');
- if (!p) { /* malformed entry? */
- continue;
- }
- t = estrndup(*env, p - *env);
- php_register_variable(t, p+1, array_ptr TSRMLS_CC);
- efree(t);
- }
- }
- /* call php's original import as a catch-all */
- php_php_import_environment_variables(array_ptr TSRMLS_CC);
-}
-#endif
-
-static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- /* In CGI mode, we consider the environment to be a part of the server
- * variables
- */
- php_import_environment_variables(track_vars_array TSRMLS_CC);
- /* Build the special-case PHP_SELF variable for the CGI version */
- php_register_variable("PHP_SELF", (SG(request_info).request_uri ? SG(request_info).request_uri:""), track_vars_array TSRMLS_CC);
-}
-
-
-static void sapi_cgi_log_message(char *message)
-{
- if (php_header()) {
- fprintf(stderr, "%s", message);
- fprintf(stderr, "\n");
- }
-}
-
-static int sapi_cgi_deactivate(TSRMLS_D)
-{
- fflush(stdout);
- if(SG(request_info).argv0) {
- free(SG(request_info).argv0);
- SG(request_info).argv0 = NULL;
- }
- return SUCCESS;
-}
-
-
-static int php_cgi_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
- return FAILURE;
- }
- return SUCCESS;
-}
-
-
-/* {{{ sapi_module_struct cgi_sapi_module
- */
-static sapi_module_struct cgi_sapi_module = {
-#if PHP_FASTCGI
- "cgi-fcgi", /* name */
- "CGI/FastCGI", /* pretty name */
-#else
- "cgi", /* name */
- "CGI", /* pretty name */
-#endif
-
- php_cgi_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- sapi_cgi_deactivate, /* deactivate */
-
- sapi_cgibin_ub_write, /* unbuffered write */
- sapi_cgibin_flush, /* flush */
- NULL, /* get uid */
- sapi_cgibin_getenv, /* getenv */
-
- php_error, /* error handler */
-
- NULL, /* header handler */
- sapi_cgi_send_headers, /* send headers handler */
- NULL, /* send header handler */
-
- sapi_cgi_read_post, /* read POST data */
- sapi_cgi_read_cookies, /* read Cookies */
-
- sapi_cgi_register_variables, /* register server variables */
- sapi_cgi_log_message, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-/* }}} */
-
-/* {{{ php_cgi_usage
- */
-static void php_cgi_usage(char *argv0)
-{
- char *prog;
-
- prog = strrchr(argv0, '/');
- if (prog) {
- prog++;
- } else {
- prog = "php";
- }
-
- php_printf("Usage: %s [-q] [-h] [-s] [-v] [-i] [-f <file>]\n"
- " %s <file> [args...]\n"
- " -a Run interactively\n"
-#if PHP_FASTCGI
- " -b <address:port>|<port> Bind Path for external FASTCGI Server mode\n"
-#endif
- " -C Do not chdir to the script's directory\n"
- " -c <path>|<file> Look for php.ini file in this directory\n"
- " -n No php.ini file will be used\n"
- " -d foo[=bar] Define INI entry foo with value 'bar'\n"
- " -e Generate extended information for debugger/profiler\n"
- " -f <file> Parse <file>. Implies `-q'\n"
- " -h This help\n"
- " -i PHP information\n"
- " -l Syntax check only (lint)\n"
- " -m Show compiled in modules\n"
- " -q Quiet-mode. Suppress HTTP Header output.\n"
- " -s Display colour syntax highlighted source.\n"
- " -v Version number\n"
- " -w Display source with stripped comments and whitespace.\n"
- " -z <file> Load Zend extension <file>.\n",
- prog, prog);
-}
-/* }}} */
-
-/* {{{ init_request_info
-
- initializes request_info structure
-
- specificly in this section we handle proper translations
- for:
-
- PATH_INFO
- derived from the portion of the URI path following
- the script name but preceding any query data
- may be empty
-
- PATH_TRANSLATED
- derived by taking any path-info component of the
- request URI and performing any virtual-to-physical
- translation appropriate to map it onto the server's
- document repository structure
-
- empty if PATH_INFO is empty
-
- The env var PATH_TRANSLATED **IS DIFFERENT** than the
- request_info.path_translated variable, the latter should
- match SCRIPT_FILENAME instead.
-
- SCRIPT_NAME
- set to a URL path that could identify the CGI script
- rather than the interpreter. PHP_SELF is set to this.
-
- REQUEST_URI
- uri section following the domain:port part of a URI
-
- SCRIPT_FILENAME
- The virtual-to-physical translation of SCRIPT_NAME (as per
- PATH_TRANSLATED)
-
- These settings are documented at
- http://cgi-spec.golux.com/
-
-
- Based on the following URL request:
-
- http://localhost/info.php/test?a=b
-
- should produce, which btw is the same as if
- we were running under mod_cgi on apache (ie. not
- using ScriptAlias directives):
-
- PATH_INFO=/test
- PATH_TRANSLATED=/docroot/test
- SCRIPT_NAME=/info.php
- REQUEST_URI=/info.php/test?a=b
- SCRIPT_FILENAME=/docroot/info.php
- QUERY_STRING=a=b
-
- but what we get is (cgi/mod_fastcgi under apache):
-
- PATH_INFO=/info.php/test
- PATH_TRANSLATED=/docroot/info.php/test
- SCRIPT_NAME=/php/php-cgi (from the Action setting I suppose)
- REQUEST_URI=/info.php/test?a=b
- SCRIPT_FILENAME=/path/to/php/bin/php-cgi (Action setting translated)
- QUERY_STRING=a=b
-
- Comments in the code below refer to using the above URL in a request
-
- */
-static void init_request_info(TSRMLS_D)
-{
- char *env_script_filename = sapi_cgibin_getenv("SCRIPT_FILENAME",0 TSRMLS_CC);
- char *env_path_translated = sapi_cgibin_getenv("PATH_TRANSLATED",0 TSRMLS_CC);
- char *script_path_translated = env_script_filename;
-
-#if !DISCARD_PATH
- /* some broken servers do not have script_filename or argv0
- an example, IIS configured in some ways. then they do more
- broken stuff and set path_translated to the cgi script location */
- if (!script_path_translated && env_path_translated)
- script_path_translated = env_path_translated;
-#endif
-
- /* initialize the defaults */
- SG(request_info).path_translated = NULL;
- SG(request_info).request_method = NULL;
- SG(request_info).query_string = NULL;
- SG(request_info).request_uri = NULL;
- SG(request_info).content_type = NULL;
- SG(request_info).content_length = 0;
- SG(sapi_headers).http_response_code = 200;
-
- /* script_path_translated being set is a good indication that
- we are running in a cgi environment, since it is always
- null otherwise. otherwise, the filename
- of the script will be retreived later via argc/argv */
- if (script_path_translated) {
- const char *auth;
- char *content_length = sapi_cgibin_getenv("CONTENT_LENGTH",0 TSRMLS_CC);
- char *content_type = sapi_cgibin_getenv("CONTENT_TYPE",0 TSRMLS_CC);
- char *env_path_info = sapi_cgibin_getenv("PATH_INFO",0 TSRMLS_CC);
- char *env_script_name = sapi_cgibin_getenv("SCRIPT_NAME",0 TSRMLS_CC);
-#if ENABLE_PATHINFO_CHECK
- struct stat st;
- char *env_redirect_url = sapi_cgibin_getenv("REDIRECT_URL",0 TSRMLS_CC);
- char *env_document_root = sapi_cgibin_getenv("DOCUMENT_ROOT",0 TSRMLS_CC);
-
- if (fix_pathinfo) {
-
- /* save the originals first for anything we change later */
- if (env_path_translated)
- _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED",env_path_translated TSRMLS_CC);
- if (env_path_info)
- _sapi_cgibin_putenv("ORIG_PATH_INFO",env_path_info TSRMLS_CC);
- if (env_script_name)
- _sapi_cgibin_putenv("ORIG_SCRIPT_NAME",env_script_name TSRMLS_CC);
- if (env_script_filename)
- _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME",env_script_filename TSRMLS_CC);
-
- if (!env_document_root) {
- /* IIS version of DOCUMENT_ROOT, not avail in cgi, but is in fastcgi */
- env_document_root = sapi_cgibin_getenv("APPL_PHYSICAL_PATH",0 TSRMLS_CC);
- /* ini version of document root */
- if (!env_document_root)
- env_document_root = PG(doc_root);
-
- /* set the document root, this makes a more
- consistent env for php scripts */
- if (env_document_root) {
- env_document_root = _sapi_cgibin_putenv("DOCUMENT_ROOT",env_document_root TSRMLS_CC);
- /* fix docroot */
- TRANSLATE_SLASHES(env_document_root);
- }
- }
-
- if (env_redirect_url) {
- /*
- pretty much apache specific. If we have a redirect_url
- then our script_filename and script_name point to the
- php executable
- */
- script_path_translated = env_path_translated;
- /* we correct SCRIPT_NAME now in case we don't have PATH_INFO */
- env_script_name = _sapi_cgibin_putenv("SCRIPT_NAME",env_redirect_url TSRMLS_CC);
- }
-
-#ifdef __riscos__
- /* Convert path to unix format*/
- __riscosify_control|=__RISCOSIFY_DONT_CHECK_DIR;
- script_path_translated=__unixify(script_path_translated,0,NULL,1,0);
-#endif
-
- /*
- * if the file doesn't exist, try to extract PATH_INFO out
- * of it by stat'ing back through the '/'
- * this fixes url's like /info.php/test
- */
- if (script_path_translated && stat( script_path_translated, &st ) == -1 ) {
- char *pt = estrdup(script_path_translated);
- int len = strlen(pt);
- char *ptr;
-
- while( (ptr = strrchr(pt,'/')) || (ptr = strrchr(pt,'\\')) ) {
- *ptr = 0;
- if ( stat(pt, &st) == 0 && S_ISREG(st.st_mode) ) {
- /*
- * okay, we found the base script!
- * work out how many chars we had to strip off;
- * then we can modify PATH_INFO
- * accordingly
- *
- * we now have the makings of
- * PATH_INFO=/test
- * SCRIPT_FILENAME=/docroot/info.php
- *
- * we now need to figure out what docroot is.
- * if DOCUMENT_ROOT is set, this is easy, otherwise,
- * we have to play the game of hide and seek to figure
- * out what SCRIPT_NAME should be
- */
- int slen = len - strlen(pt);
- int pilen = strlen( env_path_info );
- char *path_info = env_path_info + pilen - slen;
-
- env_path_info = _sapi_cgibin_putenv("PATH_INFO",path_info TSRMLS_CC);
- script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME",pt TSRMLS_CC);
- TRANSLATE_SLASHES(pt);
-
- /* figure out docroot
- SCRIPT_FILENAME minus SCRIPT_NAME
- */
-
- if (env_document_root) {
- int l = strlen(env_document_root);
- int path_translated_len = 0;
- char *path_translated = NULL;
- if (env_document_root[l-1]=='/') --l;
-
- /* we have docroot, so we should have:
- * DOCUMENT_ROOT=/docroot
- * SCRIPT_FILENAME=/docroot/info.php
- *
- * SCRIPT_NAME is the portion of the path beyond docroot
- */
- env_script_name = _sapi_cgibin_putenv("SCRIPT_NAME",pt+l TSRMLS_CC);
-
- /*
- * PATH_TRANSATED = DOCUMENT_ROOT + PATH_INFO
- */
- path_translated_len = l + strlen(env_path_info) + 2;
- path_translated = (char *)emalloc(path_translated_len);
- *path_translated = 0;
- strncat(path_translated,env_document_root,l);
- strcat(path_translated,env_path_info);
- env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED",path_translated TSRMLS_CC);
- efree(path_translated);
- } else if (env_script_name &&
- strstr(pt,env_script_name)) {
- /*
- * PATH_TRANSATED = PATH_TRANSATED - SCRIPT_NAME + PATH_INFO
- */
- int ptlen = strlen(pt)-strlen(env_script_name);
- int path_translated_len = ptlen + strlen(env_path_info) + 2;
- char *path_translated = NULL;
- path_translated = (char *)emalloc(path_translated_len);
- *path_translated = 0;
- strncat(path_translated,pt,ptlen);
- strcat(path_translated,env_path_info);
- env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED",path_translated TSRMLS_CC);
- efree(path_translated);
- }
- break;
- }
- }
- if (!ptr) {
- /*
- * if we stripped out all the '/' and still didn't find
- * a valid path... we will fail, badly. of course we would
- * have failed anyway... we output 'no input file' now.
- */
- script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME",NULL TSRMLS_CC);
- SG(sapi_headers).http_response_code = 404;
- }
- if (pt) efree(pt);
- } else {
- /* make sure path_info/translated are empty */
- script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME",script_path_translated TSRMLS_CC);
- _sapi_cgibin_putenv("PATH_INFO",NULL TSRMLS_CC);
- _sapi_cgibin_putenv("PATH_TRANSLATED",NULL TSRMLS_CC);
- }
- SG(request_info).request_uri = sapi_cgibin_getenv("SCRIPT_NAME",0 TSRMLS_CC);
- } else {
-#endif
- /* pre 4.3 behaviour, shouldn't be used but provides BC */
- if (env_path_info)
- SG(request_info).request_uri = env_path_info;
- else
- SG(request_info).request_uri = env_script_name;
-#if !DISCARD_PATH
- script_path_translated = env_path_translated;
-#endif
-#if ENABLE_PATHINFO_CHECK
- }
-#endif
- SG(request_info).request_method = sapi_cgibin_getenv("REQUEST_METHOD",0 TSRMLS_CC);
- SG(request_info).query_string = sapi_cgibin_getenv("QUERY_STRING",0 TSRMLS_CC);
- if (script_path_translated)
- SG(request_info).path_translated = estrdup(script_path_translated);
- SG(request_info).content_type = (content_type ? content_type : "" );
- SG(request_info).content_length = (content_length?atoi(content_length):0);
-
- /* The CGI RFC allows servers to pass on unvalidated Authorization data */
- auth = sapi_cgibin_getenv("HTTP_AUTHORIZATION",0 TSRMLS_CC);
- php_handle_auth_data(auth TSRMLS_CC);
- }
-}
-/* }}} */
-
-static void define_command_line_ini_entry(char *arg)
-{
- char *name, *value;
-
- name = arg;
- value = strchr(arg, '=');
- if (value) {
- *value = 0;
- value++;
- } else {
- value = "1";
- }
- zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
-}
-
-
-static void php_register_command_line_global_vars(char **arg TSRMLS_DC)
-{
- char *var, *val;
-
- var = *arg;
- val = strchr(var, '=');
- if (!val) {
- printf("No value specified for variable '%s'\n", var);
- } else {
- *val++ = '\0';
- php_register_variable(var, val, NULL TSRMLS_CC);
- }
- efree(*arg);
-}
-
-#if PHP_FASTCGI
-/**
- * Clean up child processes upon exit
- */
-void fastcgi_cleanup(int signal)
-{
-
-#ifdef DEBUG_FASTCGI
- fprintf( stderr, "FastCGI shutdown, pid %d\n", getpid() );
-#endif
-
-#ifndef PHP_WIN32
- sigaction( SIGTERM, &old_term, 0 );
-
- /* Kill all the processes in our process group */
- kill( -pgroup, SIGTERM );
-#endif
-
- /* We should exit at this point, but MacOSX doesn't seem to */
- exit( 0 );
-}
-#endif
-
-/* {{{ main
- */
-int main(int argc, char *argv[])
-{
- int exit_status = SUCCESS;
- int cgi = 0, c, i, len;
- zend_file_handle file_handle;
- int retval = FAILURE;
- char *s;
-/* temporary locals */
- int behavior=PHP_MODE_STANDARD;
- int no_headers=0;
- int orig_optind=optind;
- char *orig_optarg=optarg;
- char *script_file=NULL;
- zend_llist global_vars;
- int interactive=0;
-#if FORCE_CGI_REDIRECT
- int force_redirect = 1;
- char *redirect_status_env = NULL;
-#endif
-
-/* end of temporary locals */
-#ifdef ZTS
- zend_compiler_globals *compiler_globals;
- zend_executor_globals *executor_globals;
- php_core_globals *core_globals;
- sapi_globals_struct *sapi_globals;
- void ***tsrm_ls;
-#endif
-
-#if PHP_FASTCGI
- int max_requests = 500;
- int requests = 0;
- int fastcgi = !FCGX_IsCGI();
- char *bindpath = NULL;
- int fcgi_fd = 0;
- FCGX_Request request;
-#ifdef PHP_WIN32
- int impersonate = 0;
-#else
- int status = 0;
-#endif
-#endif /* PHP_FASTCGI */
-
-#ifdef HAVE_SIGNAL_H
-#if defined(SIGPIPE) && defined(SIG_IGN)
- signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
- that sockets created via fsockopen()
- don't kill PHP if the remote site
- closes it. in apache|apxs mode apache
- does that for us! thies@thieso.net
- 20000419 */
-#endif
-#endif
-
-#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
-#endif
-
- sapi_startup(&cgi_sapi_module);
-
-#ifdef PHP_WIN32
- _fmode = _O_BINARY; /*sets default for file streams to binary */
- setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */
- setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */
- setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
-#endif
-
-#if PHP_FASTCGI
- if (!fastcgi) {
-#endif
- /* Make sure we detect we are a cgi - a bit redundancy here,
- but the default case is that we have to check only the first one. */
- if (getenv("SERVER_SOFTWARE")
- || getenv("SERVER_NAME")
- || getenv("GATEWAY_INTERFACE")
- || getenv("REQUEST_METHOD")) {
- cgi = 1;
- }
-#if PHP_FASTCGI
- }
-#endif
-
- if (!cgi
-#if PHP_FASTCGI
- /* allow ini override for fastcgi */
-#endif
- ) {
- while ((c=php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0))!=-1) {
- switch (c) {
- case 'c':
- cgi_sapi_module.php_ini_path_override = strdup(optarg);
- break;
- case 'n':
- cgi_sapi_module.php_ini_ignore = 1;
- break;
-#if PHP_FASTCGI
- /* if we're started on command line, check to see if
- we are being started as an 'external' fastcgi
- server by accepting a bindpath parameter. */
- case 'b':
- if (!fastcgi) bindpath= strdup(optarg);
- break;
-#endif
- }
-
- }
- optind = orig_optind;
- optarg = orig_optarg;
- }
-
-#ifdef ZTS
- compiler_globals = ts_resource(compiler_globals_id);
- executor_globals = ts_resource(executor_globals_id);
- core_globals = ts_resource(core_globals_id);
- sapi_globals = ts_resource(sapi_globals_id);
- tsrm_ls = ts_resource(0);
-#endif
-
- cgi_sapi_module.executable_location = argv[0];
-
- /* startup after we get the above ini override se we get things right */
- if (php_module_startup(&cgi_sapi_module, NULL, 0)==FAILURE) {
-#ifdef ZTS
- tsrm_shutdown();
-#endif
- return FAILURE;
- }
-
-#if FORCE_CGI_REDIRECT
- /* check force_cgi after startup, so we have proper output */
- if (cfg_get_long("cgi.force_redirect", &force_redirect) == FAILURE) {
- force_redirect = 1;
- }
- if (cgi && force_redirect) {
- if (cfg_get_string("cgi.redirect_status_env", &redirect_status_env) == FAILURE) {
- redirect_status_env = NULL;
- }
- /* Apache will generate REDIRECT_STATUS,
- * Netscape and redirect.so will generate HTTP_REDIRECT_STATUS.
- * redirect.so and installation instructions available from
- * http://www.koehntopp.de/php.
- * -- kk@netuse.de
- */
- if (!getenv("REDIRECT_STATUS")
- && !getenv ("HTTP_REDIRECT_STATUS")
- /* this is to allow a different env var to be configured
- in case some server does something different than above */
- && (!redirect_status_env || !getenv(redirect_status_env))
- ) {
- PUTS("<b>Security Alert!</b> The PHP CGI cannot be accessed directly.\n\n\
-<p>This PHP CGI binary was compiled with force-cgi-redirect enabled. This\n\
-means that a page will only be served up if the REDIRECT_STATUS CGI variable is\n\
-set, e.g. via an Apache Action directive.</p>\n\
-<p>For more information as to <i>why</i> this behaviour exists, see the <a href=\"http://php.net/security.cgi-bin\">\
-manual page for CGI security</a>.</p>\n\
-<p>For more information about changing this behaviour or re-enabling this webserver,\n\
-consult the installation file that came with this distribution, or visit \n\
-<a href=\"http://php.net/install.windows\">the manual page</a>.</p>\n");
-
-#ifdef ZTS
- tsrm_shutdown();
-#endif
-
- return FAILURE;
- }
- }
-#endif /* FORCE_CGI_REDIRECT */
-
-#if ENABLE_PATHINFO_CHECK
- if (cfg_get_long("cgi.fix_pathinfo", &fix_pathinfo) == FAILURE) {
- fix_pathinfo = 1;
- }
-#endif
-
-#if PHP_FASTCGI
- if (bindpath) {
- /* Pass on the arg to the FastCGI library, with one exception.
- * If just a port is specified, then we prepend a ':' onto the
- * path (it's what the fastcgi library expects)
- */
- int port = atoi( bindpath );
- if( port ) {
- char bindport[ 32 ];
- snprintf( bindport, 32, ":%s", bindpath );
- fcgi_fd = FCGX_OpenSocket( bindport, 128 );
- } else {
- fcgi_fd = FCGX_OpenSocket( bindpath, 128 );
- }
- if( fcgi_fd < 0 ) {
- fprintf( stderr, "Couldn't create FastCGI listen socket on port %s\n", bindpath);
-#ifdef ZTS
- tsrm_shutdown();
-#endif
- return FAILURE;
- }
- fastcgi = !FCGX_IsCGI();
- }
- if (fastcgi) {
- /* How many times to run PHP scripts before dying */
- if( getenv( "PHP_FCGI_MAX_REQUESTS" )) {
- max_requests = atoi( getenv( "PHP_FCGI_MAX_REQUESTS" ));
- if( !max_requests ) {
- fprintf( stderr,
- "PHP_FCGI_MAX_REQUESTS is not valid\n" );
- return FAILURE;
- }
- }
-
- /* make php call us to get _ENV vars */
- php_php_import_environment_variables = php_import_environment_variables;
- php_import_environment_variables = cgi_php_import_environment_variables;
-
- /* library is already initialized, now init our request */
- FCGX_Init();
- FCGX_InitRequest( &request, fcgi_fd, 0 );
-
-#ifndef PHP_WIN32
- /* Pre-fork, if required */
- if( getenv( "PHP_FCGI_CHILDREN" )) {
- children = atoi( getenv( "PHP_FCGI_CHILDREN" ));
- if( !children ) {
- fprintf( stderr,
- "PHP_FCGI_CHILDREN is not valid\n" );
- return FAILURE;
- }
- }
-
- if( children ) {
- int running = 0;
- int i;
- pid_t pid;
-
- /* Create a process group for ourself & children */
- setsid();
- pgroup = getpgrp();
-#ifdef DEBUG_FASTCGI
- fprintf( stderr, "Process group %d\n", pgroup );
-#endif
-
- /* Set up handler to kill children upon exit */
- act.sa_flags = 0;
- act.sa_handler = fastcgi_cleanup;
- if( sigaction( SIGTERM, &act, &old_term ) ||
- sigaction( SIGINT, &act, &old_int ) ||
- sigaction( SIGQUIT, &act, &old_quit )) {
- perror( "Can't set signals" );
- exit( 1 );
- }
-
- while( parent ) {
- do {
-#ifdef DEBUG_FASTCGI
- fprintf( stderr, "Forking, %d running\n",
- running );
-#endif
- pid = fork();
- switch( pid ) {
- case 0:
- /* One of the children.
- * Make sure we don't go round the
- * fork loop any more
- */
- parent = 0;
-
- /* don't catch our signals */
- sigaction( SIGTERM, &old_term, 0 );
- sigaction( SIGQUIT, &old_quit, 0 );
- sigaction( SIGINT, &old_int, 0 );
- break;
- case -1:
- perror( "php (pre-forking)" );
- exit( 1 );
- break;
- default:
- /* Fine */
- running++;
- break;
- }
- } while( parent && ( running < children ));
-
- if( parent ) {
-#ifdef DEBUG_FASTCGI
- fprintf( stderr, "Wait for kids, pid %d\n",
- getpid() );
-#endif
- wait( &status );
- running--;
- }
- }
- }
-
-#endif /* WIN32 */
- }
-#endif /* FASTCGI */
-
- zend_first_try {
- if (!cgi
-#if PHP_FASTCGI
- && !fastcgi
-#endif
- ) {
- while ((c=php_getopt(argc, argv, OPTIONS, &optarg, &optind, 1))!=-1) {
- switch (c) {
- case 'h':
- case '?':
- no_headers = 1;
- php_output_startup();
- php_output_activate(TSRMLS_C);
- SG(headers_sent) = 1;
- php_cgi_usage(argv[0]);
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
- }
- }
- optind = orig_optind;
- optarg = orig_optarg;
- }
-
-#if PHP_FASTCGI
- /* start of FAST CGI loop */
- /* Initialise FastCGI request structure */
-
-#ifdef PHP_WIN32
- /* attempt to set security impersonation for fastcgi
- will only happen on NT based OS, others will ignore it. */
- if (fastcgi) {
- if (cfg_get_long("fastcgi.impersonate", &impersonate) == FAILURE) {
- impersonate = 0;
- }
- if (impersonate) OS_SetImpersonate();
- }
-#endif
-
- while (!fastcgi
- || FCGX_Accept_r( &request ) >= 0) {
-#endif
-
-#if PHP_FASTCGI
- SG(server_context) = (void *) &request;
-#else
- SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */
-#endif
-
- init_request_info(TSRMLS_C);
-
- zend_llist_init(&global_vars, sizeof(char *), NULL, 0);
-
- CG(interactive) = 0;
-
- if (!cgi
-#if PHP_FASTCGI
- && !fastcgi
-#endif
- ) {
-
- if (cgi_sapi_module.php_ini_path_override && cgi_sapi_module.php_ini_ignore) {
- no_headers = 1;
- php_output_startup();
- php_output_activate(TSRMLS_C);
- SG(headers_sent) = 1;
- php_printf("You cannot use both -n and -c switch. Use -h for help.\n");
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- }
-
- while ((c = php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0)) != -1) {
- switch (c) {
-
- case 'a': /* interactive mode */
- printf("Interactive mode enabled\n\n");
- interactive=1;
- break;
-
- case 'C': /* don't chdir to the script directory */
- SG(options) |= SAPI_OPTION_NO_CHDIR;
- break;
- case 'd': /* define ini entries on command line */
- define_command_line_ini_entry(optarg);
- break;
-
- case 'e': /* enable extended info output */
- CG(extended_info) = 1;
- break;
-
- case 'f': /* parse file */
- script_file = estrdup(optarg);
- no_headers = 1;
- break;
-
- case 'g': /* define global variables on command line */
- {
- char *arg = estrdup(optarg);
-
- zend_llist_add_element(&global_vars, &arg);
- }
- break;
-
- case 'i': /* php info & quit */
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- php_module_shutdown(TSRMLS_C);
- return FAILURE;
- }
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
- php_print_info(0xFFFFFFFF TSRMLS_CC);
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
- case 'l': /* syntax check mode */
- no_headers = 1;
- behavior=PHP_MODE_LINT;
- break;
-
- case 'm': /* list compiled in modules */
- php_output_startup();
- php_output_activate(TSRMLS_C);
- SG(headers_sent) = 1;
- php_printf("[PHP Modules]\n");
- print_modules(TSRMLS_C);
- php_printf("\n[Zend Modules]\n");
- print_extensions(TSRMLS_C);
- php_printf("\n");
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
-#if 0 /* not yet operational, see also below ... */
- case '': /* generate indented source mode*/
- behavior=PHP_MODE_INDENT;
- break;
-#endif
-
- case 'q': /* do not generate HTTP headers */
- no_headers = 1;
- break;
-
- case 's': /* generate highlighted HTML from source */
- behavior=PHP_MODE_HIGHLIGHT;
- break;
-
- case 'v': /* show php version & quit */
- no_headers = 1;
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- php_module_shutdown(TSRMLS_C);
- return FAILURE;
- }
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
- php_printf("PHP %s (%s), Copyright (c) 1997-2003 The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
- case 'w':
- behavior=PHP_MODE_STRIP;
- break;
-
- case 'z': /* load extension file */
- zend_load_extension(optarg);
- break;
-
- default:
- break;
- }
- }
-
- if (!SG(request_info).query_string) {
- len = 0;
- if (script_file) {
- len += strlen(script_file) + 1;
- }
- for (i = optind; i < argc; i++) {
- len += strlen(argv[i]) + 1;
- }
-
- s = malloc(len + 1); /* leak - but only for command line version, so ok */
- *s = '\0'; /* we are pretending it came from the environment */
- if (script_file) {
- strcpy(s, script_file);
- if (optind<argc) {
- strcat(s, "+");
- }
- }
- for (i = optind, len = 0; i < argc; i++) {
- strcat(s, argv[i]);
- if (i < (argc - 1)) {
- strcat(s, "+");
- }
- }
- SG(request_info).query_string = s;
- }
-
- if (script_file) {
- /* override path_translated if -f on command line */
- SG(request_info).path_translated = script_file;
- }
-
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
-
- if (!SG(request_info).path_translated && argc > optind) {
- /* file is on command line, but not in -f opt */
- SG(request_info).path_translated = estrdup(argv[optind]);
- }
- } /* end !cgi && !fastcgi */
-
- /*
- we never take stdin if we're (f)cgi, always
- rely on the web server giving us the info
- we need in the environment.
- */
- if (cgi
-#if PHP_FASTCGI
- || fastcgi
-#endif
- )
- {
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = SG(request_info).path_translated;
- file_handle.handle.fp = NULL;
- } else {
- file_handle.filename = "-";
- file_handle.type = ZEND_HANDLE_FP;
- file_handle.handle.fp = stdin;
- }
-
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
-
- /* request startup only after we've done all we can to
- get path_translated */
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- php_module_shutdown(TSRMLS_C);
- return FAILURE;
- }
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
-
- /* This actually destructs the elements of the list - ugly hack */
- zend_llist_apply(&global_vars, (llist_apply_func_t) php_register_command_line_global_vars TSRMLS_CC);
- zend_llist_destroy(&global_vars);
-
- /*
- at this point path_translated will be set if:
- 1. we are running from shell and got filename was there
- 2. we are running as cgi or fastcgi
- */
- if (cgi || SG(request_info).path_translated) {
- retval = php_fopen_primary_script(&file_handle TSRMLS_CC);
- }
- /*
- if we are unable to open path_translated and we are not
- running from shell (so fp == NULL), then fail.
- */
- if (retval == FAILURE && file_handle.handle.fp == NULL) {
- SG(sapi_headers).http_response_code = 404;
- PUTS("No input file specified.\n");
- php_request_shutdown((void *) 0);
- php_module_shutdown(TSRMLS_C);
- return FAILURE;
- }
-
- if (file_handle.handle.fp && (file_handle.handle.fp != stdin)) {
- /* #!php support */
- c = fgetc(file_handle.handle.fp);
- if (c == '#') {
- while (c != 10 && c != 13) {
- c = fgetc(file_handle.handle.fp); /* skip to end of line */
- }
- /* handle situations where line is terminated by \r\n */
- if (c == 13) {
- if (fgetc(file_handle.handle.fp) != 10) {
- long pos = ftell(file_handle.handle.fp);
- fseek(file_handle.handle.fp, pos - 1, SEEK_SET);
- }
- }
- CG(start_lineno) = 2;
- } else {
- rewind(file_handle.handle.fp);
- }
- }
-
- switch (behavior) {
- case PHP_MODE_STANDARD:
- php_execute_script(&file_handle TSRMLS_CC);
- exit_status = EG(exit_status);
- break;
- case PHP_MODE_LINT:
- PG(during_request_startup) = 0;
- exit_status = php_lint_script(&file_handle TSRMLS_CC);
- if (exit_status==SUCCESS) {
- zend_printf("No syntax errors detected in %s\n", file_handle.filename);
- } else {
- zend_printf("Errors parsing %s\n", file_handle.filename);
- }
- break;
- case PHP_MODE_STRIP:
- if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {
- zend_strip(TSRMLS_C);
- fclose(file_handle.handle.fp);
- }
- return SUCCESS;
- break;
- case PHP_MODE_HIGHLIGHT:
- {
- zend_syntax_highlighter_ini syntax_highlighter_ini;
-
- if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {
- php_get_highlight_struct(&syntax_highlighter_ini);
- zend_highlight(&syntax_highlighter_ini TSRMLS_CC);
- fclose(file_handle.handle.fp);
- }
- return SUCCESS;
- }
- break;
-#if 0
- /* Zeev might want to do something with this one day */
- case PHP_MODE_INDENT:
- open_file_for_scanning(&file_handle TSRMLS_CC);
- zend_indent();
- fclose(file_handle.handle.fp);
- return SUCCESS;
- break;
-#endif
- }
-
- {
- char *path_translated;
-
- /* Go through this trouble so that the memory manager doesn't warn
- * about SG(request_info).path_translated leaking
- */
- if (SG(request_info).path_translated) {
- path_translated = strdup(SG(request_info).path_translated);
- STR_FREE(SG(request_info).path_translated);
- SG(request_info).path_translated = path_translated;
- }
-
- php_request_shutdown((void *) 0);
-
- if (SG(request_info).path_translated) {
- free(SG(request_info).path_translated);
- SG(request_info).path_translated = NULL;
- }
- }
-
-#if PHP_FASTCGI
- if (!fastcgi) break;
- /* only fastcgi will get here */
- requests++;
- if( max_requests && ( requests == max_requests )) {
- FCGX_Finish_r(&request);
- if (bindpath) free (bindpath);
- break;
- }
- /* end of fastcgi loop */
- }
-#endif
-
- if (cgi_sapi_module.php_ini_path_override) {
- free(cgi_sapi_module.php_ini_path_override);
- }
- } zend_catch {
- exit_status = 255;
- } zend_end_try();
-
- php_module_shutdown(TSRMLS_C);
- sapi_shutdown();
-
-#ifdef ZTS
- /*tsrm_shutdown();*/
-#endif
-
-#if PHP_WIN32 && ZEND_DEBUG && 0
- _CrtDumpMemoryLeaks( );
-#endif
-
- return exit_status;
-}
-/* }}} */
-
-/*
- * 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/cgi/config9.m4 b/sapi/cgi/config9.m4
deleted file mode 100644
index c6c5e665dd..0000000000
--- a/sapi/cgi/config9.m4
+++ /dev/null
@@ -1,171 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_ARG_ENABLE(cgi,
-[ --disable-cgi Disable building CGI version of PHP],
-[
- PHP_SAPI_CGI=$enableval
-],[
- PHP_SAPI_CGI=yes
-])
-
-AC_ARG_ENABLE(force-cgi-redirect,
-[ --enable-force-cgi-redirect
- Enable the security check for internal server
- redirects. You should use this if you are
- running the CGI version with Apache.],
-[
- PHP_FORCE_CGI_REDIRECT=$enableval
-],[
- PHP_FORCE_CGI_REDIRECT=no
-])
-
-AC_ARG_ENABLE(discard-path,
-[ --enable-discard-path If this is enabled, the PHP CGI binary
- can safely be placed outside of the
- web tree and people will not be able
- to circumvent .htaccess security.],
-[
- PHP_DISCARD_PATH=$enableval
-],[
- PHP_DISCARD_PATH=no
-])
-
-AC_ARG_ENABLE(fastcgi,
-[ --enable-fastcgi If this is enabled, the cgi module will
- be built with support for fastcgi also.],
-[
- PHP_ENABLE_FASTCGI=$enableval
-],[
- PHP_ENABLE_FASTCGI=no
-])
-
-AC_ARG_ENABLE(path-info-check,
-[ --disable-path-info-check If this is disabled, paths such as
- /info.php/test?a=b will fail to work.],
-[
- PHP_ENABLE_PATHINFO_CHECK=$enableval
-],[
- PHP_ENABLE_PATHINFO_CHECK=yes
-])
-
-AC_DEFUN(PHP_TEST_WRITE_STDOUT,[
- AC_CACHE_CHECK(whether writing to stdout works,ac_cv_write_stdout,[
- AC_TRY_RUN([
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#define TEXT "This is the test message -- "
-
-main()
-{
- int n;
-
- n = write(1, TEXT, sizeof(TEXT)-1);
- return (!(n == sizeof(TEXT)-1));
-}
- ],[
- ac_cv_write_stdout=yes
- ],[
- ac_cv_write_stdout=no
- ],[
- ac_cv_write_stdout=no
- ])
- ])
- if test "$ac_cv_write_stdout" = "yes"; then
- AC_DEFINE(PHP_WRITE_STDOUT, 1, [whether write(2) works])
- fi
-])
-
-
-if test "$PHP_SAPI" = "default"; then
- AC_MSG_CHECKING(for CGI build)
- if test "$PHP_SAPI_CGI" != "no"; then
- AC_MSG_RESULT(yes)
-
- PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/cgi/Makefile.frag)
- case $host_alias in
- *cygwin* )
- SAPI_CGI_PATH=sapi/cgi/php.exe
- ;;
- * )
- SAPI_CGI_PATH=sapi/cgi/php
- ;;
- esac
- PHP_SUBST(SAPI_CGI_PATH)
-
- PHP_TEST_WRITE_STDOUT
-
- AC_MSG_CHECKING(whether to force Apache CGI redirect)
- if test "$PHP_FORCE_CGI_REDIRECT" = "yes"; then
- REDIRECT=1
- else
- REDIRECT=0
- fi
- AC_DEFINE_UNQUOTED(FORCE_CGI_REDIRECT,$REDIRECT,[ ])
- AC_MSG_RESULT($PHP_FORCE_CGI_REDIRECT)
-
-
- AC_MSG_CHECKING(whether to discard path_info + path_translated)
- if test "$PHP_DISCARD_PATH" = "yes"; then
- DISCARD_PATH=1
- else
- DISCARD_PATH=0
- fi
- AC_DEFINE_UNQUOTED(DISCARD_PATH, $DISCARD_PATH, [ ])
- AC_MSG_RESULT($PHP_DISCARD_PATH)
-
- AC_MSG_CHECKING(whether to enable path info checking)
- if test "$PHP_ENABLE_PATHINFO_CHECK" = "yes"; then
- ENABLE_PATHINFO_CHECK=1
- else
- ENABLE_PATHINFO_CHECK=0
- fi
- AC_DEFINE_UNQUOTED(ENABLE_PATHINFO_CHECK, $ENABLE_PATHINFO_CHECK, [ ])
- AC_MSG_RESULT($PHP_ENABLE_PATHINFO_CHECK)
-
- AC_MSG_CHECKING(whether to enable fastcgi support)
- PHP_LIBFCGI_DIR="$abs_srcdir/sapi/cgi/libfcgi"
- if test -z $PHP_LIBFCGI_DIR; then
- echo "$PHP_LIBFCGI_DIR does not exist"
- exit 1
- fi
- if test "$PHP_ENABLE_FASTCGI" = "yes"; then
- PHP_FASTCGI=1
- PHP_FCGI_FILES="libfcgi/fcgi_stdio.c libfcgi/fcgiapp.c libfcgi/os_unix.c"
- PHP_FCGI_INCLUDE="-I$PHP_LIBFCGI_DIR/include"
- PHP_FCGI_STATIC=1
- else
- PHP_FASTCGI=0
- PHP_FCGI_FILES=""
- PHP_FCGI_INCLUDE=""
- PHP_FCGI_STATIC=0
- fi
- AC_DEFINE_UNQUOTED(PHP_FASTCGI, $PHP_FASTCGI, [ ])
- AC_DEFINE_UNQUOTED(PHP_FCGI_STATIC, $PHP_FCGI_STATIC, [ ])
- AC_MSG_RESULT($PHP_ENABLE_FASTCGI)
-
- INSTALL_IT="\$(INSTALL) -m 0755 \$(SAPI_CGI_PATH) \$(INSTALL_ROOT)\$(bindir)/php"
- PHP_SELECT_SAPI(cgi, program, $PHP_FCGI_FILES cgi_main.c getopt.c, $PHP_FCGI_INCLUDE, '$(SAPI_CGI_PATH)')
-
- case $host_alias in
- *darwin*)
- BUILD_CGI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_SAPI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
- ;;
- *)
- BUILD_CGI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
- ;;
- esac
-
- PHP_SUBST(BUILD_CGI)
-
- elif test "$PHP_SAPI_CLI" != "no"; then
- AC_MSG_RESULT(no)
- OVERALL_TARGET=
- PHP_SAPI=cli
- else
- AC_MSG_ERROR([No SAPIs selected.])
- fi
-fi
diff --git a/sapi/cgi/getopt.c b/sapi/cgi/getopt.c
deleted file mode 100644
index e048e95058..0000000000
--- a/sapi/cgi/getopt.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Marcus Boerger <helly@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
-#include "php_getopt.h"
-#define OPTERRCOLON (1)
-#define OPTERRNF (2)
-#define OPTERRARG (3)
-
-
-static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err)
-{
- if (show_err)
- {
- fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1);
- switch(err)
- {
- case OPTERRCOLON:
- fprintf(stderr, ": in flags\n");
- break;
- case OPTERRNF:
- fprintf(stderr, "option not found %c\n", argv[oint][optchr]);
- break;
- case OPTERRARG:
- fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]);
- break;
- default:
- fprintf(stderr, "unknown\n");
- break;
- }
- }
- return('?');
-}
-
-int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err)
-{
- static int optchr = 0;
- static int dash = 0; /* have already seen the - */
- int arg_start = 2;
-
- int opts_idx = -1;
-
- if (*optind >= argc) {
- return(EOF);
- }
- if (!dash) {
- if ((argv[*optind][0] != '-')) {
- return(EOF);
- } else {
- if (!argv[*optind][1])
- {
- /*
- * use to specify stdin. Need to let pgm process this and
- * the following args
- */
- return(EOF);
- }
- }
- }
- if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) {
- /* '--' indicates end of args if not followed by a known long option name */
- while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
- (*optind)++;
- return(EOF);
- } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) {
- break;
- }
- }
- optchr = 0;
- dash = 1;
- arg_start = 2 + strlen(opts[opts_idx].opt_name);
- }
- if (!dash) {
- dash = 1;
- optchr = 1;
- }
-
- /* Check if the guy tries to do a -: kind of flag */
- if (argv[*optind][optchr] == ':') {
- dash = 0;
- (*optind)++;
- return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err));
- }
- if (opts_idx < 0) {
- while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
- int errind = *optind;
- int errchr = optchr;
-
- if (!argv[*optind][optchr+1]) {
- dash = 0;
- (*optind)++;
- } else {
- optchr++;
- }
- return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err));
- } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) {
- break;
- }
- }
- }
- if (opts[opts_idx].need_param) {
- /* Check for cases where the value of the argument
- is in the form -<arg> <val> or in the form -<arg><val> */
- dash = 0;
- if(!argv[*optind][arg_start]) {
- (*optind)++;
- if (*optind == argc) {
- return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
- }
- *optarg = argv[(*optind)++];
- } else {
- *optarg = &argv[*optind][arg_start];
- (*optind)++;
- }
- return opts[opts_idx].opt_char;
- } else {
- if (arg_start == 2) {
- if (!argv[*optind][optchr+1])
- {
- dash = 0;
- (*optind)++;
- } else {
- optchr++;
- }
- } else {
- (*optind)++;
- }
- return opts[opts_idx].opt_char;
- }
- assert(0);
- return(0); /* never reached */
-}
diff --git a/sapi/cgi/libfcgi/LICENSE.TERMS b/sapi/cgi/libfcgi/LICENSE.TERMS
deleted file mode 100644
index 7e6bdfded7..0000000000
--- a/sapi/cgi/libfcgi/LICENSE.TERMS
+++ /dev/null
@@ -1,28 +0,0 @@
-This FastCGI application library source and object code (the
-"Software") and its documentation (the "Documentation") are
-copyrighted by Open Market, Inc ("Open Market"). The following terms
-apply to all files associated with the Software and Documentation
-unless explicitly disclaimed in individual files.
-
-Open Market permits you to use, copy, modify, distribute, and license
-this Software and the Documentation for any purpose, provided that
-existing copyright notices are retained in all copies and that this
-notice is included verbatim in any distributions. No written
-agreement, license, or royalty fee is required for any of the
-authorized uses. Modifications to this Software and Documentation may
-be copyrighted by their authors and need not follow the licensing
-terms described here. If modifications to this Software and
-Documentation have new licensing terms, the new terms must be clearly
-indicated on the first page of each file where they apply.
-
-OPEN MARKET MAKES NO EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE
-SOFTWARE OR THE DOCUMENTATION, INCLUDING WITHOUT LIMITATION ANY
-WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
-NO EVENT SHALL OPEN MARKET BE LIABLE TO YOU OR ANY THIRD PARTY FOR ANY
-DAMAGES ARISING FROM OR RELATING TO THIS SOFTWARE OR THE
-DOCUMENTATION, INCLUDING, WITHOUT LIMITATION, ANY INDIRECT, SPECIAL OR
-CONSEQUENTIAL DAMAGES OR SIMILAR DAMAGES, INCLUDING LOST PROFITS OR
-LOST DATA, EVEN IF OPEN MARKET HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES. THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS".
-OPEN MARKET HAS NO LIABILITY IN CONTRACT, TORT, NEGLIGENCE OR
-OTHERWISE ARISING OUT OF THIS SOFTWARE OR THE DOCUMENTATION.
diff --git a/sapi/cgi/libfcgi/acinclude.m4 b/sapi/cgi/libfcgi/acinclude.m4
deleted file mode 100644
index 20f02d8339..0000000000
--- a/sapi/cgi/libfcgi/acinclude.m4
+++ /dev/null
@@ -1,389 +0,0 @@
-dnl $Id$
-
-AC_DEFUN(FCGI_COMMON_CHECKS, [
- AC_MSG_CHECKING([for sun_len in sys/un.h])
- AC_EGREP_HEADER([sun_len], [sys/un.h],
- [AC_MSG_RESULT([yes])
- AC_DEFINE([HAVE_SOCKADDR_UN_SUN_LEN], [1],
- [Define if sockaddr_un in sys/un.h contains a sun_len component])],
- AC_MSG_RESULT([no]))
-
- AC_MSG_CHECKING([for fpos_t in stdio.h])
- AC_EGREP_HEADER([fpos_t], [stdio.h],
- [AC_MSG_RESULT([yes])
- AC_DEFINE([HAVE_FPOS], [1],
- [Define if the fpos_t typedef is in stdio.h])],
- AC_MSG_RESULT([no]))
-
- AC_CHECK_HEADERS([sys/socket.h netdb.h netinet/in.h arpa/inet.h])
- AC_CHECK_HEADERS([sys/time.h limits.h sys/param.h unistd.h])
-
- AC_MSG_CHECKING([for a fileno() prototype in stdio.h])
- AC_EGREP_HEADER([fileno], [stdio.h],
- [AC_MSG_RESULT([yes])
- AC_DEFINE([HAVE_FILENO_PROTO], [1],
- [Define if there's a fileno() prototype in stdio.h])],
- AC_MSG_RESULT([no]))
-
- if test "$HAVE_SYS_SOCKET_H"; then
- AC_MSG_CHECKING([for socklen_t in sys/socket.h])
- AC_EGREP_HEADER([socklen_t], [sys/socket.h],
- [AC_MSG_RESULT([yes])
- AC_DEFINE([HAVE_SOCKLEN], [1],
- [Define if the socklen_t typedef is in sys/socket.h])],
- AC_MSG_RESULT([no]))
- fi
-
- #--------------------------------------------------------------------
- # Do we need cross-process locking on this platform?
- #--------------------------------------------------------------------
- AC_MSG_CHECKING([whether cross-process locking is required by accept()])
- case "`uname -sr`" in
- IRIX\ 5.* | SunOS\ 5.* | UNIX_System_V\ 4.0)
- AC_MSG_RESULT([yes])
- AC_DEFINE([USE_LOCKING], [1],
- [Define if cross-process locking is required by accept()])
- ;;
- *)
- AC_MSG_RESULT([no])
- ;;
- esac
-
- #--------------------------------------------------------------------
- # Does va_arg(arg, long double) crash the compiler?
- # hpux 9.04 compiler does and so does Stratus FTX (uses HP's compiler)
- #--------------------------------------------------------------------
- AC_MSG_CHECKING([whether va_arg(arg, long double) crashes the compiler])
- AC_TRY_COMPILE([#include <stdarg.h>],
- [long double lDblArg; va_list arg; lDblArg = va_arg(arg, long double);],
- AC_MSG_RESULT([no]),
- [AC_MSG_RESULT([yes])
- AC_DEFINE([HAVE_VA_ARG_LONG_DOUBLE_BUG], [1],
- [Define if va_arg(arg, long double) crashes the compiler])])
-
- AC_C_CONST
-])
-
-
-dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
-dnl
-dnl This macro figures out how to build C programs using POSIX
-dnl threads. It sets the PTHREAD_LIBS output variable to the threads
-dnl library and linker flags, and the PTHREAD_CFLAGS output variable
-dnl to any special C compiler flags that are needed. (The user can also
-dnl force certain compiler flags/libs to be tested by setting these
-dnl environment variables.)
-dnl
-dnl Also sets PTHREAD_CC to any special C compiler that is needed for
-dnl multi-threaded programs (defaults to the value of CC otherwise).
-dnl (This is necessary on AIX to use the special cc_r compiler alias.)
-dnl
-dnl If you are only building threads programs, you may wish to
-dnl use these variables in your default LIBS, CFLAGS, and CC:
-dnl
-dnl LIBS="$PTHREAD_LIBS $LIBS"
-dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-dnl CC="$PTHREAD_CC"
-dnl
-dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
-dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE
-dnl to that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
-dnl
-dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
-dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands
-dnl to run it if it is not found. If ACTION-IF-FOUND is not specified,
-dnl the default action will define HAVE_PTHREAD.
-dnl
-dnl Please let the authors know if this macro fails on any platform,
-dnl or if you have any other suggestions or comments. This macro was
-dnl based on work by SGJ on autoconf scripts for FFTW (www.fftw.org)
-dnl (with help from M. Frigo), as well as ac_pthread and hb_pthread
-dnl macros posted by AFC to the autoconf macro repository. We are also
-dnl grateful for the helpful feedback of numerous users.
-dnl
-dnl @version $Id$
-dnl @author Steven G. Johnson <stevenj@alum.mit.edu> and Alejandro Forero Cuervo <bachue@bachue.com>
-
-AC_DEFUN([ACX_PTHREAD], [
-AC_REQUIRE([AC_CANONICAL_HOST])
-acx_pthread_ok=no
-
-# First, check if the POSIX threads header, pthread.h, is available.
-# If it isn't, don't bother looking for the threads libraries.
-AC_CHECK_HEADER(pthread.h, , acx_pthread_ok=noheader)
-
-# We must check for the threads library under a number of different
-# names; the ordering is very important because some systems
-# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
-# libraries is broken (non-POSIX).
-
-# First of all, check if the user has set any of the PTHREAD_LIBS,
-# etcetera environment variables, and if threads linking works using
-# them:
-if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
- save_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
- save_LIBS="$LIBS"
- LIBS="$PTHREAD_LIBS $LIBS"
- AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
- AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
- AC_MSG_RESULT($acx_pthread_ok)
- if test x"$acx_pthread_ok" = xno; then
- PTHREAD_LIBS=""
- PTHREAD_CFLAGS=""
- fi
- LIBS="$save_LIBS"
- CFLAGS="$save_CFLAGS"
-fi
-
-# Create a list of thread flags to try. Items starting with a "-" are
-# C compiler flags, and other items are library names, except for "none"
-# which indicates that we try without any flags at all.
-
-acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt"
-
-# The ordering *is* (sometimes) important. Some notes on the
-# individual items follow:
-
-# pthreads: AIX (must check this before -lpthread)
-# none: in case threads are in libc; should be tried before -Kthread and
-# other compiler flags to prevent continual compiler warnings
-# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
-# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
-# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
-# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
-# -pthreads: Solaris/gcc
-# -mthreads: Mingw32/gcc, Lynx/gcc
-# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
-# doesn't hurt to check since this sometimes defines pthreads too;
-# also defines -D_REENTRANT)
-# pthread: Linux, etcetera
-# --thread-safe: KAI C++
-
-case "${host_cpu}-${host_os}" in
- *solaris*)
-
- # On Solaris (at least, for some versions), libc contains stubbed
- # (non-functional) versions of the pthreads routines, so link-based
- # tests will erroneously succeed. (We need to link with -pthread or
- # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
- # a function called by this macro, so we could check for that, but
- # who knows whether they'll stub that too in a future libc.) So,
- # we'll just look for -pthreads and -lpthread first:
-
- acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
- ;;
-esac
-
-if test x"$acx_pthread_ok" = xno; then
-for flag in $acx_pthread_flags; do
-
- case $flag in
- none)
- AC_MSG_CHECKING([whether pthreads work without any flags])
- ;;
-
- -*)
- AC_MSG_CHECKING([whether pthreads work with $flag])
- PTHREAD_CFLAGS="$flag"
- ;;
-
- *)
- AC_MSG_CHECKING([for the pthreads library -l$flag])
- PTHREAD_LIBS="-l$flag"
- ;;
- esac
-
- save_LIBS="$LIBS"
- save_CFLAGS="$CFLAGS"
- LIBS="$PTHREAD_LIBS $LIBS"
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-
- # Check for various functions. We must include pthread.h,
- # since some functions may be macros. (On the Sequent, we
- # need a special flag -Kthread to make this header compile.)
- # We check for pthread_join because it is in -lpthread on IRIX
- # while pthread_create is in libc. We check for pthread_attr_init
- # due to DEC craziness with -lpthreads. We check for
- # pthread_cleanup_push because it is one of the few pthread
- # functions on Solaris that doesn't have a non-functional libc stub.
- # We try pthread_create on general principles.
- AC_TRY_LINK([#include <pthread.h>],
- [pthread_t th; pthread_join(th, 0);
- pthread_attr_init(0); pthread_cleanup_push(0, 0);
- pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
- [acx_pthread_ok=yes])
-
- LIBS="$save_LIBS"
- CFLAGS="$save_CFLAGS"
-
- AC_MSG_RESULT($acx_pthread_ok)
- if test "x$acx_pthread_ok" = xyes; then
- break;
- fi
-
- PTHREAD_LIBS=""
- PTHREAD_CFLAGS=""
-done
-fi
-
-# Various other checks:
-if test "x$acx_pthread_ok" = xyes; then
- save_LIBS="$LIBS"
- LIBS="$PTHREAD_LIBS $LIBS"
- save_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-
- # Detect AIX lossage: threads are created detached by default
- # and the JOINABLE attribute has a nonstandard name (UNDETACHED).
- AC_MSG_CHECKING([for joinable pthread attribute])
- AC_TRY_LINK([#include <pthread.h>],
- [int attr=PTHREAD_CREATE_JOINABLE;],
- ok=PTHREAD_CREATE_JOINABLE, ok=unknown)
- if test x"$ok" = xunknown; then
- AC_TRY_LINK([#include <pthread.h>],
- [int attr=PTHREAD_CREATE_UNDETACHED;],
- ok=PTHREAD_CREATE_UNDETACHED, ok=unknown)
- fi
- if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then
- AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok,
- [Define to the necessary symbol if this constant
- uses a non-standard name on your system.])
- fi
- AC_MSG_RESULT(${ok})
- if test x"$ok" = xunknown; then
- AC_MSG_WARN([we do not know how to create joinable pthreads])
- fi
-
- AC_MSG_CHECKING([if more special flags are required for pthreads])
- flag=no
- case "${host_cpu}-${host_os}" in
- *-aix* | *-freebsd*) flag="-D_THREAD_SAFE";;
- *solaris* | alpha*-osf*) flag="-D_REENTRANT";;
- esac
- AC_MSG_RESULT(${flag})
- if test "x$flag" != xno; then
- PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
- fi
-
- LIBS="$save_LIBS"
- CFLAGS="$save_CFLAGS"
-
- # More AIX lossage: must compile with cc_r
- AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
-else
- PTHREAD_CC="$CC"
-fi
-
-AC_SUBST(PTHREAD_LIBS)
-AC_SUBST(PTHREAD_CFLAGS)
-AC_SUBST(PTHREAD_CC)
-
-# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
-if test x"$acx_pthread_ok" = xyes; then
- ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
- :
-else
- acx_pthread_ok=no
- $2
-fi
-
-])dnl ACX_PTHREAD
-
-
-
-dnl @synopsis AC_PROG_CC_WARNINGS([ANSI])
-dnl
-dnl Enables a reasonable set of warnings for the C compiler. Optionally,
-dnl if the first argument is nonempty, turns on flags which enforce and/or
-dnl enable proper ANSI C if such flags are known to the compiler used.
-dnl
-dnl Currently this macro knows about GCC, Solaris C compiler,
-dnl Digital Unix C compiler, C for AIX Compiler, HP-UX C compiler,
-dnl and IRIX C compiler.
-dnl
-dnl @version $Id$
-dnl @author Ville Laurikari <vl@iki.fi>
-dnl
-AC_DEFUN([AC_PROG_CC_WARNINGS], [
- ansi=$1
- if test -z "$ansi"; then
- msg="for C compiler warning flags"
- else
- msg="for C compiler warning and ANSI conformance flags"
- fi
- AC_CACHE_CHECK($msg, ac_cv_prog_cc_warnings, [
- if test -n "$CC"; then
- cat > conftest.c <<EOF
-int main(int argc, char **argv) { return 0; }
-EOF
-
- dnl GCC
- if test "$GCC" = "yes"; then
- if test -z "$ansi"; then
- ac_cv_prog_cc_warnings="-Wall"
- else
- ac_cv_prog_cc_warnings="-Wall -ansi -pedantic"
- fi
-
- dnl Solaris C compiler
- elif $CC -flags 2>&1 | grep "Xc.*strict ANSI C" > /dev/null 2>&1 &&
- $CC -c -v -Xc conftest.c > /dev/null 2>&1 &&
- test -f conftest.o; then
- if test -z "$ansi"; then
- ac_cv_prog_cc_warnings="-v"
- else
- ac_cv_prog_cc_warnings="-v -Xc"
- fi
-
- dnl HP-UX C compiler
- elif $CC > /dev/null 2>&1 &&
- $CC -c -Aa +w1 conftest.c > /dev/null 2>&1 &&
- test -f conftest.o; then
- if test -z "$ansi"; then
- ac_cv_prog_cc_warnings="+w1"
- else
- ac_cv_prog_cc_warnings="+w1 -Aa"
- fi
-
- dnl Digital Unix C compiler
- elif ! $CC > /dev/null 2>&1 &&
- $CC -c -verbose -w0 -warnprotos -std1 conftest.c > /dev/null 2>&1 &&
- test -f conftest.o; then
- if test -z "$ansi"; then
- ac_cv_prog_cc_warnings="-verbose -w0 -warnprotos"
- else
- ac_cv_prog_cc_warnings="-verbose -w0 -warnprotos -std1"
- fi
-
- dnl C for AIX Compiler
- elif $CC > /dev/null 2>&1 | grep AIX > /dev/null 2>&1 &&
- $CC -c -qlanglvl=ansi -qinfo=all conftest.c > /dev/null 2>&1 &&
- test -f conftest.o; then
- if test -z "$ansi"; then
- ac_cv_prog_cc_warnings="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd"
- else
- ac_cv_prog_cc_warnings="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd -qlanglvl=ansi"
- fi
-
- dnl IRIX C compiler
- elif $CC -fullwarn -ansi -ansiE > /dev/null 2>&1 &&
- test -f conftest.o; then
- if test -z "$ansi"; then
- ac_cv_prog_cc_warnings="-fullwarn"
- else
- ac_cv_prog_cc_warnings="-fullwarn -ansi -ansiE"
- fi
-
- fi
- rm -f conftest.*
- fi
- if test -n "$ac_cv_prog_cc_warnings"; then
- CFLAGS="$CFLAGS $ac_cv_prog_cc_warnings"
- else
- ac_cv_prog_cc_warnings="unknown"
- fi
- ])
-])
-
-
diff --git a/sapi/cgi/libfcgi/fcgi_stdio.c b/sapi/cgi/libfcgi/fcgi_stdio.c
deleted file mode 100644
index 39a56315fd..0000000000
--- a/sapi/cgi/libfcgi/fcgi_stdio.c
+++ /dev/null
@@ -1,801 +0,0 @@
-/*
- * fcgi_stdio.c --
- *
- * FastCGI-stdio compatibility package
- *
- *
- * Copyright (c) 1996 Open Market, Inc.
- *
- * See the file "LICENSE.TERMS" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- */
-
-#ifndef lint
-static const char rcsid[] = "$Id$";
-#endif /* not lint */
-
-#include <errno.h> /* for errno */
-#include <stdarg.h> /* for va_arg */
-#include <stdlib.h> /* for malloc */
-#include <string.h> /* for strerror */
-
-#include "fcgi_config.h"
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef _WIN32
-#define DLLAPI __declspec(dllexport)
-#endif
-
-#include "fcgiapp.h"
-#include "fcgios.h"
-#include "fcgimisc.h"
-
-#define NO_FCGI_DEFINES
-#include "fcgi_stdio.h"
-#undef NO_FCGI_DEFINES
-
-#ifndef _WIN32
-
-extern char **environ;
-
-#ifdef HAVE_FILENO_PROTO
-#include <stdio.h>
-#else
-extern int fileno(FILE *stream);
-#endif
-
-extern FILE *fdopen(int fildes, const char *type);
-extern FILE *popen(const char *command, const char *type);
-extern int pclose(FILE *stream);
-
-#else /* _WIN32 */
-
-#define popen _popen
-#define pclose _pclose
-
-#endif /* _WIN32 */
-
-FCGI_FILE _fcgi_sF[3];
-
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_Accept --
- *
- * Accepts a new request from the HTTP server and creates
- * a conventional execution environment for the request.
- *
- * If the application was invoked as a FastCGI server,
- * the first call to FCGI_Accept indicates that the application
- * has completed its initialization and is ready to accept
- * a request. Subsequent calls to FCGI_Accept indicate that
- * the application has completed its processing of the
- * current request and is ready to accept a new request.
- *
- * If the application was invoked as a CGI program, the first
- * call to FCGI_Accept is essentially a no-op and the second
- * call returns EOF (-1).
- *
- * Results:
- * 0 for successful call, -1 for error (application should exit).
- *
- * Side effects:
- * If the application was invoked as a FastCGI server,
- * and this is not the first call to this procedure,
- * FCGI_Accept first performs the equivalent of FCGI_Finish.
- *
- * On every call, FCGI_Accept accepts the new request and
- * reads the FCGI_PARAMS stream into an environment array,
- * i.e. a NULL-terminated array of strings of the form
- * ``name=value''. It assigns a pointer to this array
- * to the global variable environ, used by the standard
- * library function getenv. It creates new FCGI_FILE *s
- * representing input from the HTTP server, output to the HTTP
- * server, and error output to the HTTP server, and assigns these
- * new files to stdin, stdout, and stderr respectively.
- *
- * DO NOT mutate or retain pointers to environ or any values
- * contained in it (e.g. to the result of calling getenv(3)),
- * since these are freed by the next call to FCGI_Finish or
- * FCGI_Accept. In particular do not use setenv(3) or putenv(3)
- * in conjunction with FCGI_Accept.
- *
- *----------------------------------------------------------------------
- */
-static int acceptCalled = FALSE;
-static int isCGI = FALSE;
-
-int FCGI_Accept(void)
-{
- if(!acceptCalled) {
- /*
- * First call to FCGI_Accept. Is application running
- * as FastCGI or as CGI?
- */
- isCGI = FCGX_IsCGI();
- acceptCalled = TRUE;
- atexit(&FCGI_Finish);
- } else if(isCGI) {
- /*
- * Not first call to FCGI_Accept and running as CGI means
- * application is done.
- */
- return(EOF);
- }
- if(isCGI) {
- FCGI_stdin->stdio_stream = stdin;
- FCGI_stdin->fcgx_stream = NULL;
- FCGI_stdout->stdio_stream = stdout;
- FCGI_stdout->fcgx_stream = NULL;
- FCGI_stderr->stdio_stream = stderr;
- FCGI_stderr->fcgx_stream = NULL;
- } else {
- FCGX_Stream *in, *out, *error;
- FCGX_ParamArray envp;
- int acceptResult = FCGX_Accept(&in, &out, &error, &envp);
- if(acceptResult < 0) {
- return acceptResult;
- }
- FCGI_stdin->stdio_stream = NULL;
- FCGI_stdin->fcgx_stream = in;
- FCGI_stdout->stdio_stream = NULL;
- FCGI_stdout->fcgx_stream = out;
- FCGI_stderr->stdio_stream = NULL;
- FCGI_stderr->fcgx_stream = error;
- environ = envp;
- }
- return 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_Finish --
- *
- * Finishes the current request from the HTTP server.
- *
- * Side effects:
- *
- * Flushes any buffered output to the HTTP server. Then frees
- * all storage allocated by the previous call, including all
- * storage reachable from the value of environ set by the previous
- * call to FCGI_Accept.
- *
- * DO NOT use stdin, stdout, stderr, or environ between calling
- * FCGI_Finish and calling FCGI_Accept.
- *
- * DO NOT mutate or retain pointers to environ or any values
- * contained in it (e.g. to the result of calling getenv(3)),
- * since these are freed by the next call to FCGI_Finish or
- * FCGI_Accept. In particular do not use setenv(3) or putenv(3)
- * in conjunction with FCGI_Accept.
- *
- *----------------------------------------------------------------------
- */
-void FCGI_Finish(void)
-{
- if(!acceptCalled || isCGI) {
- return;
- }
- FCGX_Finish();
- FCGI_stdin->fcgx_stream = NULL;
- FCGI_stdout->fcgx_stream = NULL;
- FCGI_stderr->fcgx_stream = NULL;
- environ = NULL;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_StartFilterData --
- *
- *
- * The current request is for the filter role, and stdin is
- * positioned at EOF of FCGI_STDIN. The call repositions
- * stdin to the start of FCGI_DATA.
- * If the preconditions are not met (e.g. FCGI_STDIN has not
- * been read to EOF), the call sets the stream error code to
- * FCGX_CALL_SEQ_ERROR.
- *
- * Results:
- * 0 for a normal return, < 0 for error
- *
- *----------------------------------------------------------------------
- */
-int FCGI_StartFilterData(void)
-{
- if(FCGI_stdin->stdio_stream) {
- return -1;
- } else {
- return FCGX_StartFilterData(FCGI_stdin->fcgx_stream);
- }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_SetExitStatus --
- *
- * Sets the exit status for the current request. The exit status
- * is the status code the request would have exited with, had
- * the request been run as a CGI program. You can call
- * FCGI_SetExitStatus several times during a request; the last call
- * before the request ends (by calling FCGI_Accept) determines the
- * value.
- *
- *----------------------------------------------------------------------
- */
-void FCGI_SetExitStatus(int status)
-{
- if(FCGI_stdin->fcgx_stream) {
- FCGX_SetExitStatus(status, FCGI_stdin->fcgx_stream);
- }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_perror --
- *
- * Wrapper for function defined in H&S Section 11.2
- *
- *----------------------------------------------------------------------
- */
-void FCGI_perror(const char *str)
-{
- FCGI_fputs(str, FCGI_stderr);
- FCGI_fputs(": ", FCGI_stderr);
- FCGI_fputs(strerror(OS_Errno), FCGI_stderr);
- return;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_OpenFromFILE --
- *
- * Constructs a new FCGI_FILE * from the FILE *stream.
- *
- * Results:
- * NULL if stream == NULL or storage could not be allocated,
- * otherwise the new FCGI_FILE *.
- *
- *----------------------------------------------------------------------
- */
-static FCGI_FILE *FCGI_OpenFromFILE(FILE *stream)
-{
- FCGI_FILE *fp;
-
- if (stream == NULL)
- return NULL;
-
- fp = (FCGI_FILE *) malloc(sizeof(FCGI_FILE));
- if (fp != NULL)
- {
- fp->stdio_stream = stream;
- fp->fcgx_stream = NULL;
- }
-
- return fp;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_fopen, FCGI_fclose, FCGI_fflush, FCGI_freopen --
- *
- * Wrappers for functions defined in H&S Section 15.2
- *
- *----------------------------------------------------------------------
- */
-FCGI_FILE *FCGI_fopen(const char *path, const char *mode)
-{
- FILE * file = fopen(path, mode);
- FCGI_FILE * fcgi_file = FCGI_OpenFromFILE(file);
-
- if (file && !fcgi_file)
- fclose(file);
-
- return fcgi_file;
-}
-
-int FCGI_fclose(FCGI_FILE *fp)
-{
- int n = EOF;
- if(fp->stdio_stream) {
- n = fclose(fp->stdio_stream);
- fp->stdio_stream = NULL;
- } else if(fp->fcgx_stream) {
- n = FCGX_FClose(fp->fcgx_stream);
- fp->fcgx_stream = NULL;
- }
- if((fp != FCGI_stdin) && (fp != FCGI_stdout) && (fp != FCGI_stderr)) {
- free(fp);
- }
- return n;
-}
-
-int FCGI_fflush(FCGI_FILE *fp)
-{
- if(fp == NULL)
- return fflush(NULL);
- if(fp->stdio_stream)
- return fflush(fp->stdio_stream);
- else if(fp->fcgx_stream)
- return FCGX_FFlush(fp->fcgx_stream);
- return EOF;
-}
-
-FCGI_FILE *FCGI_freopen(const char *path, const char *mode,
- FCGI_FILE *fp)
-{
- if(fp->stdio_stream) {
- if(freopen(path, mode, fp->stdio_stream) == NULL)
- return NULL;
- else
- return fp;
- } else if(fp->fcgx_stream) {
- (void) FCGX_FClose(fp->fcgx_stream);
- fp->stdio_stream = fopen(path, mode);
- if(fp->stdio_stream == NULL)
- return NULL;
- else {
- fp->fcgx_stream = NULL;
- return fp;
- }
- }
- return NULL;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_setvbuf, FCGI_setbuf --
- *
- * Wrappers for functions defined in H&S Section 15.3
- *
- *----------------------------------------------------------------------
- */
-int FCGI_setvbuf(FCGI_FILE *fp, char *buf, int bufmode, size_t size)
-{
- if(fp->stdio_stream)
- return setvbuf(fp->stdio_stream, buf, bufmode, size);
- else {
- return -1;
- }
-}
-
-void FCGI_setbuf(FCGI_FILE *fp, char *buf)
-{
- if(fp->stdio_stream)
- setbuf(fp->stdio_stream, buf);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_fseek, FCGI_ftell, FCGI_rewind, FCGI_fgetpos, FCGI_fsetpos --
- *
- * Wrappers for functions defined in H&S Section 15.5
- *
- *----------------------------------------------------------------------
- */
-int FCGI_fseek(FCGI_FILE *fp, long offset, int whence)
-{
- if(fp->stdio_stream)
- return fseek(fp->stdio_stream, offset, whence);
- else {
- OS_SetErrno(ESPIPE);
- return -1;
- }
-}
-
-int FCGI_ftell(FCGI_FILE *fp)
-{
- if(fp->stdio_stream)
- return ftell(fp->stdio_stream);
- else {
- OS_SetErrno(ESPIPE);
- return -1;
- }
-}
-
-void FCGI_rewind(FCGI_FILE *fp)
-{
- if(fp->stdio_stream)
- rewind(fp->stdio_stream);
- else
- OS_SetErrno(ESPIPE);
-}
-
-#ifdef HAVE_FPOS
-int FCGI_fgetpos(FCGI_FILE *fp, fpos_t *pos)
-{
- if(fp->stdio_stream)
- return fgetpos(fp->stdio_stream, pos);
- else {
- OS_SetErrno(ESPIPE);
- return -1;
- }
-}
-
-int FCGI_fsetpos(FCGI_FILE *fp, const fpos_t *pos)
-{
- if(fp->stdio_stream)
- return fsetpos(fp->stdio_stream, pos);
- else {
- OS_SetErrno(ESPIPE);
- return -1;
- }
-}
-#endif
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_fgetc, FCGI_getchar, FCGI_ungetc --
- *
- * Wrappers for functions defined in H&S Section 15.6
- *
- * XXX: getc and getchar are generally defined as macros
- * for performance reasons
- *
- *----------------------------------------------------------------------
- */
-int FCGI_fgetc(FCGI_FILE *fp)
-{
- if(fp->stdio_stream)
- return fgetc(fp->stdio_stream);
- else if(fp->fcgx_stream)
- return FCGX_GetChar(fp->fcgx_stream);
- return EOF;
-}
-
-int FCGI_getchar(void)
-{
- return FCGI_fgetc(FCGI_stdin);
-}
-
-int FCGI_ungetc(int c, FCGI_FILE *fp)
-{
- if(fp->stdio_stream)
- return ungetc(c, fp->stdio_stream);
- else if(fp->fcgx_stream)
- return FCGX_UnGetChar(c, fp->fcgx_stream);
- return EOF;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_fgets, FCGI_gets --
- *
- * Wrappers for functions defined in H&S Section 15.7
- *
- *----------------------------------------------------------------------
- */
-char *FCGI_fgets(char *str, int size, FCGI_FILE *fp)
-{
- if(fp->stdio_stream)
- return fgets(str, size, fp->stdio_stream);
- else if(fp->fcgx_stream)
- return FCGX_GetLine(str, size, fp->fcgx_stream);
- return NULL;
-}
-
-/*
- * The gets() function reads characters from the standard input stream
- * into the array pointed to by str until a newline character is read
- * or an end-of-file condition is encountered. The newline character
- * is discarded and the string is terminated with a null character.
- */
-char *FCGI_gets(char *str)
-{
- char *s;
- int c;
-
- for (s = str; ((c = FCGI_getchar()) != '\n');) {
- if(c == EOF) {
- if(s == str)
- return NULL;
- else
- break;
- } else
- *s++ = (char) c;
- }
- *s = 0;
- return str;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Wrappers for functions defined in H&S Section 15.8
- *
- * XXX: missing: fscanf, scanf
- *
- *----------------------------------------------------------------------
- */
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_fputc, FCGI_putchar --
- *
- * Wrappers for functions defined in H&S Section 15.9
- *
- * XXX: putc and putchar are generally defined as macros
- * for performance reasons
- *
- *----------------------------------------------------------------------
- */
-int FCGI_fputc(int c, FCGI_FILE *fp)
-{
- if(fp->stdio_stream)
- return fputc(c, fp->stdio_stream);
- else if(fp->fcgx_stream)
- return FCGX_PutChar(c, fp->fcgx_stream);
- else return EOF;
-}
-
-int FCGI_putchar(int c)
-{
- return FCGI_fputc(c, FCGI_stdout);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_fputs, FCGI_puts
- *
- * Wrappers for functions defined in H&S Section 15.10
- *
- *----------------------------------------------------------------------
- */
-int FCGI_fputs(const char *str, FCGI_FILE *fp)
-{
- if(fp->stdio_stream)
- return fputs(str, fp->stdio_stream);
- else if(fp->fcgx_stream)
- return FCGX_PutS(str, fp->fcgx_stream);
- return EOF;
-}
-
-int FCGI_puts(const char *str)
-{
- int n;
- if(FCGI_stdout->stdio_stream) {
- n = fputs(str, FCGI_stdout->stdio_stream);
- if(n < 0)
- return n;
- else
- return fputc('\n', FCGI_stdout->stdio_stream);
- } else if(FCGI_stdout->fcgx_stream) {
- n = FCGX_PutS(str, FCGI_stdout->fcgx_stream);
- if(n < 0)
- return n;
- else
- return FCGX_PutChar('\n', FCGI_stdout->fcgx_stream);
- }
- return EOF;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_fprintf, FCGI_printf --
- *
- * Wrappers for functions defined in H&S Section 15.11
- *
- *----------------------------------------------------------------------
- */
-int FCGI_fprintf(FCGI_FILE *fp, const char *format, ...)
-{
- va_list ap;
- int n = 0;
- va_start(ap, format);
- if(fp->stdio_stream)
- n = vfprintf(fp->stdio_stream, format, ap);
- else if(fp->fcgx_stream)
- n = FCGX_VFPrintF(fp->fcgx_stream, format, ap);
- va_end(ap);
- return n;
-}
-
-int FCGI_printf(const char *format, ...)
-{
- va_list ap;
- int n;
- va_start(ap, format);
- n = FCGI_vfprintf(FCGI_stdout, format, ap);
- va_end(ap);
- return n;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_vfprintf, FCGI_vprintf --
- *
- * Wrappers for functions defined in H&S Section 15.12
- *
- *----------------------------------------------------------------------
- */
-int FCGI_vfprintf(FCGI_FILE *fp, const char *format, va_list ap)
-{
- if(fp->stdio_stream)
- return vfprintf(fp->stdio_stream, format, ap);
- else if(fp->fcgx_stream)
- return FCGX_VFPrintF(fp->fcgx_stream, format, ap);
- return EOF;
-}
-
-int FCGI_vprintf(const char *format, va_list ap)
-{
- if(FCGI_stdout->stdio_stream)
- return vfprintf(FCGI_stdout->stdio_stream, format, ap);
- else if(FCGI_stdout->fcgx_stream)
- return FCGX_VFPrintF(FCGI_stdout->fcgx_stream, format, ap);
- return EOF;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_fread, FCGI_fwrite --
- *
- * Wrappers for functions defined in H&S Section 15.13
- *
- *----------------------------------------------------------------------
- */
-size_t FCGI_fread(void *ptr, size_t size, size_t nmemb, FCGI_FILE *fp)
-{
- int n;
- if(fp->stdio_stream)
- return fread(ptr, size, nmemb, fp->stdio_stream);
- else if(fp->fcgx_stream) {
- if((size * nmemb) == 0) {
- return 0;
- }
- n = FCGX_GetStr((char *) ptr, size * nmemb, fp->fcgx_stream);
- return (n/size);
- }
- return (size_t)EOF;
-}
-
-size_t FCGI_fwrite(void *ptr, size_t size, size_t nmemb, FCGI_FILE *fp)
-{
- int n;
- if(fp->stdio_stream)
- return fwrite(ptr, size, nmemb, fp->stdio_stream);
- else if(fp->fcgx_stream) {
- if((size * nmemb) == 0) {
- return 0;
- }
- n = FCGX_PutStr((char *) ptr, size * nmemb, fp->fcgx_stream);
- return (n/size);
- }
- return (size_t)EOF;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_feof, FCGI_ferror, FCGI_clearerr --
- *
- * Wrappers for functions defined in H&S Section 15.14
- *
- *----------------------------------------------------------------------
- */
-int FCGI_feof(FCGI_FILE *fp)
-{
- if(fp->stdio_stream) {
- return feof(fp->stdio_stream);
- } else if (fp->fcgx_stream){
- return FCGX_HasSeenEOF(fp->fcgx_stream);
- }
- return -1;
-
-}
-
-int FCGI_ferror(FCGI_FILE *fp)
-{
- if(fp->stdio_stream) {
- return ferror(fp->stdio_stream);
- } else if(fp->fcgx_stream) {
- return FCGX_GetError(fp->fcgx_stream);
- }
- return -1;
-}
-
-void FCGI_clearerr(FCGI_FILE *fp)
-{
- if(fp->stdio_stream) {
- clearerr(fp->stdio_stream);
- } else if(fp->fcgx_stream) {
- FCGX_ClearError(fp->fcgx_stream);
- }
- return;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_tmpfile --
- *
- * Wrappers for function defined in H&S Section 15.16
- *
- *----------------------------------------------------------------------
- */
-FCGI_FILE *FCGI_tmpfile(void)
-{
- FILE * file = tmpfile();
- FCGI_FILE * fcgi_file = FCGI_OpenFromFILE(file);
-
- if (file && !fcgi_file)
- fclose(file);
-
- return fcgi_file;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGI_fileno, FCGI_fdopen, FCGI_popen, FCGI_pclose --
- *
- * Wrappers for POSIX, X/OPEN functions not in ISO C
- *
- *----------------------------------------------------------------------
- */
-int FCGI_fileno(FCGI_FILE *fp)
-{
- if(fp->stdio_stream)
- return fileno(fp->stdio_stream);
- else
- return -1;
-}
-
-FCGI_FILE *FCGI_fdopen(int fd, const char *mode)
-{
- FILE * file = fdopen(fd, mode);
- FCGI_FILE * fcgi_file = FCGI_OpenFromFILE(file);
-
- if (file && !fcgi_file)
- fclose(file);
-
- return fcgi_file;
-}
-
-FCGI_FILE *FCGI_popen(const char *cmd, const char *type)
-{
- FILE * file = popen(cmd, type);
- FCGI_FILE * fcgi_file = FCGI_OpenFromFILE(file);
-
- if (file && !fcgi_file)
- pclose(file);
-
- return fcgi_file;
-}
-
-int FCGI_pclose(FCGI_FILE *fp)
-{
- int n = EOF;
- if (fp->stdio_stream) {
- n = pclose(fp->stdio_stream);
- fp->stdio_stream = NULL;
- } else if(fp->fcgx_stream) {
- /*
- * The caller is deeply confused; don't free the storage.
- */
- return EOF;
- }
- if((fp != FCGI_stdin) && (fp != FCGI_stdout) && (fp != FCGI_stderr)) {
- free(fp);
- }
- return n;
-}
diff --git a/sapi/cgi/libfcgi/fcgiapp.c b/sapi/cgi/libfcgi/fcgiapp.c
deleted file mode 100644
index 75d91f5b93..0000000000
--- a/sapi/cgi/libfcgi/fcgiapp.c
+++ /dev/null
@@ -1,2323 +0,0 @@
-/*
- * fcgiapp.c --
- *
- * FastCGI application library: request-at-a-time
- *
- *
- * Copyright (c) 1996 Open Market, Inc.
- *
- * See the file "LICENSE.TERMS" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- */
-#ifndef lint
-static const char rcsid[] = "$Id$";
-#endif /* not lint */
-
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h> /* for fcntl */
-#include <math.h>
-#include <memory.h> /* for memchr() */
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "fcgi_config.h"
-
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h> /* for getpeername */
-#endif
-
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef HAVE_LIMITS_H
-#include <limits.h>
-#endif
-
-#ifdef _WIN32
-#define DLLAPI __declspec(dllexport)
-#endif
-
-#include "fcgimisc.h"
-#include "fastcgi.h"
-#include "fcgios.h"
-#include "fcgiapp.h"
-
-/*
- * This is a workaround for one version of the HP C compiler
- * (c89 on HP-UX 9.04, also Stratus FTX), which will dump core
- * if given 'long double' for varargs.
- */
-#ifdef HAVE_VA_ARG_LONG_DOUBLE_BUG
-#define LONG_DOUBLE double
-#else
-#define LONG_DOUBLE long double
-#endif
-
-/*
- * Globals
- */
-static int libInitialized = 0;
-static int isFastCGI = -1;
-static char *webServerAddressList = NULL;
-static FCGX_Request the_request;
-void _FCGX_FreeStream(FCGX_Stream **streamPtr, int freeData);
-
-void FCGX_ShutdownPending(void)
-{
- OS_ShutdownPending();
-}
-
-static void *Malloc(size_t size)
-{
- void *result = malloc(size);
- ASSERT(size == 0 || result != NULL);
- return result;
-}
-
-static char *StringCopy(char *str)
-{
- int strLen = strlen(str);
- char *newString = (char *)Malloc(strLen + 1);
- memcpy(newString, str, strLen);
- newString[strLen] = '\000';
- return newString;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_GetChar --
- *
- * Reads a byte from the input stream and returns it.
- *
- * Results:
- * The byte, or EOF (-1) if the end of input has been reached.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_GetChar(FCGX_Stream *stream)
-{
- if(stream->rdNext != stream->stop)
- return *stream->rdNext++;
- if(stream->isClosed || !stream->isReader)
- return EOF;
- stream->fillBuffProc(stream);
- stream->stopUnget = stream->rdNext;
- if(stream->rdNext != stream->stop)
- return *stream->rdNext++;
- ASSERT(stream->isClosed); /* bug in fillBufProc if not */
- return EOF;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_GetStr --
- *
- * Reads up to n consecutive bytes from the input stream
- * into the character array str. Performs no interpretation
- * of the input bytes.
- *
- * Results:
- * Number of bytes read. If result is smaller than n,
- * the end of input has been reached.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_GetStr(char *str, int n, FCGX_Stream *stream)
-{
- int m, bytesMoved;
-
- if(n <= 0) {
- return 0;
- }
- /*
- * Fast path: n bytes are already available
- */
- if(n <= (stream->stop - stream->rdNext)) {
- memcpy(str, stream->rdNext, n);
- stream->rdNext += n;
- return n;
- }
- /*
- * General case: stream is closed or buffer fill procedure
- * needs to be called
- */
- bytesMoved = 0;
- for (;;) {
- if(stream->rdNext != stream->stop) {
- m = min(n - bytesMoved, stream->stop - stream->rdNext);
- memcpy(str, stream->rdNext, m);
- bytesMoved += m;
- stream->rdNext += m;
- if(bytesMoved == n)
- return bytesMoved;
- str += m;
- }
- if(stream->isClosed || !stream->isReader)
- return bytesMoved;
- stream->fillBuffProc(stream);
- stream->stopUnget = stream->rdNext;
- }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_GetLine --
- *
- * Reads up to n-1 consecutive bytes from the input stream
- * into the character array str. Stops before n-1 bytes
- * have been read if '\n' or EOF is read. The terminating '\n'
- * is copied to str. After copying the last byte into str,
- * stores a '\0' terminator.
- *
- * Results:
- * NULL if EOF is the first thing read from the input stream,
- * str otherwise.
- *
- *----------------------------------------------------------------------
- */
-char *FCGX_GetLine(char *str, int n, FCGX_Stream *stream)
-{
- int c;
- char *p = str;
-
- n--;
- while (n > 0) {
- c = FCGX_GetChar(stream);
- if(c == EOF) {
- if(p == str)
- return NULL;
- else
- break;
- }
- *p++ = (char) c;
- n--;
- if(c == '\n')
- break;
- }
- *p = '\0';
- return str;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_UnGetChar --
- *
- * Pushes back the character c onto the input stream. One
- * character of pushback is guaranteed once a character
- * has been read. No pushback is possible for EOF.
- *
- * Results:
- * Returns c if the pushback succeeded, EOF if not.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_UnGetChar(int c, FCGX_Stream *stream) {
- if(c == EOF
- || stream->isClosed
- || !stream->isReader
- || stream->rdNext == stream->stopUnget)
- return EOF;
- --(stream->rdNext);
- *stream->rdNext = (unsigned char) c;
- return c;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_HasSeenEOF --
- *
- * Returns EOF if end-of-file has been detected while reading
- * from stream; otherwise returns 0.
- *
- * Note that FCGX_HasSeenEOF(s) may return 0, yet an immediately
- * following FCGX_GetChar(s) may return EOF. This function, like
- * the standard C stdio function feof, does not provide the
- * ability to peek ahead.
- *
- * Results:
- * EOF if end-of-file has been detected, 0 if not.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_HasSeenEOF(FCGX_Stream *stream) {
- return (stream->isClosed) ? EOF : 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_PutChar --
- *
- * Writes a byte to the output stream.
- *
- * Results:
- * The byte, or EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_PutChar(int c, FCGX_Stream *stream)
-{
- if(stream->wrNext != stream->stop)
- return (*stream->wrNext++ = (unsigned char) c);
- if(stream->isClosed || stream->isReader)
- return EOF;
- stream->emptyBuffProc(stream, FALSE);
- if(stream->wrNext != stream->stop)
- return (*stream->wrNext++ = (unsigned char) c);
- ASSERT(stream->isClosed); /* bug in emptyBuffProc if not */
- return EOF;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_PutStr --
- *
- * Writes n consecutive bytes from the character array str
- * into the output stream. Performs no interpretation
- * of the output bytes.
- *
- * Results:
- * Number of bytes written (n) for normal return,
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_PutStr(const char *str, int n, FCGX_Stream *stream)
-{
- int m, bytesMoved;
-
- /*
- * Fast path: room for n bytes in the buffer
- */
- if(n <= (stream->stop - stream->wrNext)) {
- memcpy(stream->wrNext, str, n);
- stream->wrNext += n;
- return n;
- }
- /*
- * General case: stream is closed or buffer empty procedure
- * needs to be called
- */
- bytesMoved = 0;
- for (;;) {
- if(stream->wrNext != stream->stop) {
- m = min(n - bytesMoved, stream->stop - stream->wrNext);
- memcpy(stream->wrNext, str, m);
- bytesMoved += m;
- stream->wrNext += m;
- if(bytesMoved == n)
- return bytesMoved;
- str += m;
- }
- if(stream->isClosed || stream->isReader)
- return -1;
- stream->emptyBuffProc(stream, FALSE);
- }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_PutS --
- *
- * Writes a character string to the output stream.
- *
- * Results:
- * number of bytes written for normal return,
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_PutS(const char *str, FCGX_Stream *stream)
-{
- return FCGX_PutStr(str, strlen(str), stream);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_FPrintF --
- *
- * Performs output formatting and writes the results
- * to the output stream.
- *
- * Results:
- * number of bytes written for normal return,
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_FPrintF(FCGX_Stream *stream, const char *format, ...)
-{
- int result;
- va_list ap;
- va_start(ap, format);
- result = FCGX_VFPrintF(stream, format, ap);
- va_end(ap);
- return result;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_VFPrintF --
- *
- * Performs output formatting and writes the results
- * to the output stream.
- *
- * Results:
- * number of bytes written for normal return,
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-
-#define PRINTF_BUFFLEN 100
- /*
- * More than sufficient space for all unmodified conversions
- * except %s and %f.
- */
-#define FMT_BUFFLEN 25
- /*
- * Max size of a format specifier is 1 + 5 + 7 + 7 + 2 + 1 + slop
- */
-static void CopyAndAdvance(char **destPtr, char **srcPtr, int n);
-
-int FCGX_VFPrintF(FCGX_Stream *stream, const char *format, va_list arg)
-{
- char *f, *fStop, *percentPtr, *p, *fmtBuffPtr, *buffPtr;
- int op, performedOp, sizeModifier, buffCount = 0, buffLen, specifierLength;
- int fastPath, n, auxBuffLen = 0, buffReqd, minWidth, precision, exp;
- char *auxBuffPtr = NULL;
- int streamCount = 0;
- char fmtBuff[FMT_BUFFLEN];
- char buff[PRINTF_BUFFLEN];
-
- int intArg;
- short shortArg;
- long longArg;
- unsigned unsignedArg;
- unsigned long uLongArg;
- unsigned short uShortArg;
- char *charPtrArg = NULL;
- void *voidPtrArg;
- int *intPtrArg;
- long *longPtrArg;
- short *shortPtrArg;
- double doubleArg = 0.0;
- LONG_DOUBLE lDoubleArg = 0.0L;
-
- fmtBuff[0] = '%';
- f = (char *) format;
- fStop = f + strlen(f);
- while (f != fStop) {
- percentPtr = (char *)memchr(f, '%', fStop - f);
- if(percentPtr == NULL) percentPtr = fStop;
- if(percentPtr != f) {
- if(FCGX_PutStr(f, percentPtr - f, stream) < 0)
- goto ErrorReturn;
- streamCount += percentPtr - f;
- f = percentPtr;
- if(f == fStop) break;
- }
- fastPath = TRUE;
- /*
- * The following loop always executes either once or twice.
- */
- for (;;) {
- if(fastPath) {
- /*
- * Fast path: Scan optimistically, hoping that no flags,
- * minimum field width, or precision are specified.
- * Use the preallocated buffer, which is large enough
- * for all fast path cases. If the conversion specifier
- * is really more complex, run the loop a second time
- * using the slow path.
- * Note that fast path execution of %s bypasses the buffer
- * and %f is not attempted on the fast path due to
- * its large buffering requirements.
- */
- op = *(percentPtr + 1);
- switch(op) {
- case 'l':
- case 'L':
- case 'h':
- sizeModifier = op;
- op = *(percentPtr + 2);
- fmtBuff[1] = (char) sizeModifier;
- fmtBuff[2] = (char) op;
- fmtBuff[3] = '\0';
- specifierLength = 3;
- break;
- default:
- sizeModifier = ' ';
- fmtBuff[1] = (char) op;
- fmtBuff[2] = '\0';
- specifierLength = 2;
- break;
- }
- buffPtr = buff;
- buffLen = PRINTF_BUFFLEN;
- } else {
- /*
- * Slow path: Scan the conversion specifier and construct
- * a new format string, compute an upper bound on the
- * amount of buffering that sprintf will require,
- * and allocate a larger buffer if necessary.
- */
- p = percentPtr + 1;
- fmtBuffPtr = &fmtBuff[1];
- /*
- * Scan flags
- */
- n = strspn(p, "-0+ #");
- if(n > 5)
- goto ErrorReturn;
- CopyAndAdvance(&fmtBuffPtr, &p, n);
- /*
- * Scan minimum field width
- */
- n = strspn(p, "0123456789");
- if(n == 0) {
- if(*p == '*') {
- minWidth = va_arg(arg, int);
- if(abs(minWidth) > 999999)
- goto ErrorReturn;
- /*
- * The following use of strlen rather than the
- * value returned from sprintf is because SUNOS4
- * returns a char * instead of an int count.
- */
- sprintf(fmtBuffPtr, "%d", minWidth);
- fmtBuffPtr += strlen(fmtBuffPtr);
- p++;
- } else {
- minWidth = 0;
- }
- } else if(n <= 6) {
- minWidth = strtol(p, NULL, 10);
- CopyAndAdvance(&fmtBuffPtr, &p, n);
- } else {
- goto ErrorReturn;
- }
- /*
- * Scan precision
- */
- if(*p == '.') {
- CopyAndAdvance(&fmtBuffPtr, &p, 1);
- n = strspn(p, "0123456789");
- if(n == 0) {
- if(*p == '*') {
- precision = va_arg(arg, int);
- if(precision < 0) precision = 0;
- if(precision > 999999)
- goto ErrorReturn;
- /*
- * The following use of strlen rather than the
- * value returned from sprintf is because SUNOS4
- * returns a char * instead of an int count.
- */
- sprintf(fmtBuffPtr, "%d", precision);
- fmtBuffPtr += strlen(fmtBuffPtr);
- p++;
- } else {
- precision = 0;
- }
- } else if(n <= 6) {
- precision = strtol(p, NULL, 10);
- CopyAndAdvance(&fmtBuffPtr, &p, n);
- } else {
- goto ErrorReturn;
- }
- } else {
- precision = -1;
- }
- /*
- * Scan size modifier and conversion operation
- */
- switch(*p) {
- case 'l':
- case 'L':
- case 'h':
- sizeModifier = *p;
- CopyAndAdvance(&fmtBuffPtr, &p, 1);
- break;
- default:
- sizeModifier = ' ';
- break;
- }
- op = *p;
- CopyAndAdvance(&fmtBuffPtr, &p, 1);
- ASSERT(fmtBuffPtr - fmtBuff < FMT_BUFFLEN);
- *fmtBuffPtr = '\0';
- specifierLength = p - percentPtr;
- /*
- * Bound the required buffer size. For s and f
- * conversions this requires examining the argument.
- */
- switch(op) {
- case 'd':
- case 'i':
- case 'u':
- case 'o':
- case 'x':
- case 'X':
- case 'c':
- case 'p':
- buffReqd = max(precision, 46);
- break;
- case 's':
- charPtrArg = va_arg(arg, char *);
- if (!charPtrArg) charPtrArg = "(null)";
- if(precision == -1) {
- buffReqd = strlen(charPtrArg);
- } else {
- p = (char *)memchr(charPtrArg, '\0', precision);
- buffReqd =
- (p == NULL) ? precision : p - charPtrArg;
- }
- break;
- case 'f':
- switch(sizeModifier) {
- case ' ':
- doubleArg = va_arg(arg, double);
- frexp(doubleArg, &exp);
- break;
- case 'L':
- lDoubleArg = va_arg(arg, LONG_DOUBLE);
- /* XXX Need to check for the presence of
- * frexpl() and use it if available */
- frexp((double) lDoubleArg, &exp);
- break;
- default:
- goto ErrorReturn;
- }
- if(precision == -1) precision = 6;
- buffReqd = precision + 3 + ((exp > 0) ? exp/3 : 0);
- break;
- case 'e':
- case 'E':
- case 'g':
- case 'G':
- if(precision == -1) precision = 6;
- buffReqd = precision + 8;
- break;
- case 'n':
- case '%':
- default:
- goto ErrorReturn;
- break;
- }
- buffReqd = max(buffReqd + 10, minWidth);
- /*
- * Allocate the buffer
- */
- if(buffReqd <= PRINTF_BUFFLEN) {
- buffPtr = buff;
- buffLen = PRINTF_BUFFLEN;
- } else {
- if(auxBuffPtr == NULL || buffReqd > auxBuffLen) {
- if(auxBuffPtr != NULL) free(auxBuffPtr);
- auxBuffPtr = (char *)Malloc(buffReqd);
- auxBuffLen = buffReqd;
- if(auxBuffPtr == NULL)
- goto ErrorReturn;
- }
- buffPtr = auxBuffPtr;
- buffLen = auxBuffLen;
- }
- }
- /*
- * This giant switch statement requires the following variables
- * to be set up: op, sizeModifier, arg, buffPtr, fmtBuff.
- * When fastPath == FALSE and op == 's' or 'f', the argument
- * has been read into charPtrArg, doubleArg, or lDoubleArg.
- * The statement produces the boolean performedOp, TRUE iff
- * the op/sizeModifier were executed and argument consumed;
- * if performedOp, the characters written into buffPtr[]
- * and the character count buffCount (== EOF meaning error).
- *
- * The switch cases are arranged in the same order as in the
- * description of fprintf in section 15.11 of Harbison and Steele.
- */
- performedOp = TRUE;
- switch(op) {
- case 'd':
- case 'i':
- switch(sizeModifier) {
- case ' ':
- intArg = va_arg(arg, int);
- sprintf(buffPtr, fmtBuff, intArg);
- buffCount = strlen(buffPtr);
- break;
- case 'l':
- longArg = va_arg(arg, long);
- sprintf(buffPtr, fmtBuff, longArg);
- buffCount = strlen(buffPtr);
- break;
- case 'h':
- shortArg = (short) va_arg(arg, int);
- sprintf(buffPtr, fmtBuff, shortArg);
- buffCount = strlen(buffPtr);
- break;
- default:
- goto ErrorReturn;
- }
- break;
- case 'u':
- case 'o':
- case 'x':
- case 'X':
- switch(sizeModifier) {
- case ' ':
- unsignedArg = va_arg(arg, unsigned);
- sprintf(buffPtr, fmtBuff, unsignedArg);
- buffCount = strlen(buffPtr);
- break;
- case 'l':
- uLongArg = va_arg(arg, unsigned long);
- sprintf(buffPtr, fmtBuff, uLongArg);
- buffCount = strlen(buffPtr);
- break;
- case 'h':
- uShortArg = (unsigned short) va_arg(arg, int);
- sprintf(buffPtr, fmtBuff, uShortArg);
- buffCount = strlen(buffPtr);
- break;
- default:
- goto ErrorReturn;
- }
- break;
- case 'c':
- switch(sizeModifier) {
- case ' ':
- intArg = va_arg(arg, int);
- sprintf(buffPtr, fmtBuff, intArg);
- buffCount = strlen(buffPtr);
- break;
- case 'l':
- /*
- * XXX: Allowed by ISO C Amendment 1, but
- * many platforms don't yet support wint_t
- */
- goto ErrorReturn;
- default:
- goto ErrorReturn;
- }
- break;
- case 's':
- switch(sizeModifier) {
- case ' ':
- if(fastPath) {
- buffPtr = va_arg(arg, char *);
- buffCount = strlen(buffPtr);
- buffLen = buffCount + 1;
- } else {
- sprintf(buffPtr, fmtBuff, charPtrArg);
- buffCount = strlen(buffPtr);
- }
- break;
- case 'l':
- /*
- * XXX: Don't know how to convert a sequence
- * of wide characters into a byte stream, or
- * even how to predict the buffering required.
- */
- goto ErrorReturn;
- default:
- goto ErrorReturn;
- }
- break;
- case 'p':
- if(sizeModifier != ' ')
- goto ErrorReturn;
- voidPtrArg = va_arg(arg, void *);
- sprintf(buffPtr, fmtBuff, voidPtrArg);
- buffCount = strlen(buffPtr);
- break;
- case 'n':
- switch(sizeModifier) {
- case ' ':
- intPtrArg = va_arg(arg, int *);
- *intPtrArg = streamCount;
- break;
- case 'l':
- longPtrArg = va_arg(arg, long *);
- *longPtrArg = streamCount;
- break;
- case 'h':
- shortPtrArg = (short *) va_arg(arg, short *);
- *shortPtrArg = (short) streamCount;
- break;
- default:
- goto ErrorReturn;
- }
- buffCount = 0;
- break;
- case 'f':
- if(fastPath) {
- performedOp = FALSE;
- break;
- }
- switch(sizeModifier) {
- case ' ':
- sprintf(buffPtr, fmtBuff, doubleArg);
- buffCount = strlen(buffPtr);
- break;
- case 'L':
- sprintf(buffPtr, fmtBuff, lDoubleArg);
- buffCount = strlen(buffPtr);
- break;
- default:
- goto ErrorReturn;
- }
- break;
- case 'e':
- case 'E':
- case 'g':
- case 'G':
- switch(sizeModifier) {
- case ' ':
- doubleArg = va_arg(arg, double);
- sprintf(buffPtr, fmtBuff, doubleArg);
- buffCount = strlen(buffPtr);
- break;
- case 'L':
- lDoubleArg = va_arg(arg, LONG_DOUBLE);
- sprintf(buffPtr, fmtBuff, lDoubleArg);
- buffCount = strlen(buffPtr);
- break;
- default:
- goto ErrorReturn;
- }
- break;
- case '%':
- if(sizeModifier != ' ')
- goto ErrorReturn;
- buff[0] = '%';
- buffCount = 1;
- break;
- case '\0':
- goto ErrorReturn;
- default:
- performedOp = FALSE;
- break;
- } /* switch(op) */
- if(performedOp) break;
- if(!fastPath)
- goto ErrorReturn;
- fastPath = FALSE;
- } /* for (;;) */
- ASSERT(buffCount < buffLen);
- if(buffCount > 0) {
- if(FCGX_PutStr(buffPtr, buffCount, stream) < 0)
- goto ErrorReturn;
- streamCount += buffCount;
- } else if(buffCount < 0) {
- goto ErrorReturn;
- }
- f += specifierLength;
- } /* while(f != fStop) */
- goto NormalReturn;
- ErrorReturn:
- streamCount = -1;
- NormalReturn:
- if(auxBuffPtr != NULL) free(auxBuffPtr);
- return streamCount;
-}
-
-/*
- * Copy n characters from *srcPtr to *destPtr, then increment
- * both *srcPtr and *destPtr by n.
- */
-static void CopyAndAdvance(char **destPtr, char **srcPtr, int n)
-{
- char *dest = *destPtr;
- char *src = *srcPtr;
- int i;
- for (i = 0; i < n; i++)
- *dest++ = *src++;
- *destPtr = dest;
- *srcPtr = src;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_FFlush --
- *
- * Flushes any buffered output.
- *
- * Server-push is a legitimate application of FCGX_FFlush.
- * Otherwise, FCGX_FFlush is not very useful, since FCGX_Accept
- * does it implicitly. FCGX_FFlush may reduce performance
- * by increasing the total number of operating system calls
- * the application makes.
- *
- * Results:
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_FFlush(FCGX_Stream *stream)
-{
- if(!stream || stream->isClosed || stream->isReader)
- return 0;
- stream->emptyBuffProc(stream, FALSE);
- return (stream->isClosed) ? -1 : 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_FClose --
- *
- * Performs FCGX_FFlush and closes the stream.
- *
- * This is not a very useful operation, since FCGX_Accept
- * does it implicitly. Closing the out stream before the
- * err stream results in an extra write if there's nothing
- * in the err stream, and therefore reduces performance.
- *
- * Results:
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_FClose(FCGX_Stream *stream)
-{
- if (stream == NULL) return 0;
-
- if(!stream->wasFCloseCalled) {
- if(!stream->isReader) {
- stream->emptyBuffProc(stream, TRUE);
- }
- stream->wasFCloseCalled = TRUE;
- stream->isClosed = TRUE;
- if(stream->isReader) {
- stream->wrNext = stream->stop = stream->rdNext;
- } else {
- stream->rdNext = stream->stop = stream->wrNext;
- }
- }
- return (stream->FCGI_errno == 0) ? 0 : EOF;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * SetError --
- *
- * An error has occurred; save the error code in the stream
- * for diagnostic purposes and set the stream state so that
- * reads return EOF and writes have no effect.
- *
- *----------------------------------------------------------------------
- */
-static void SetError(FCGX_Stream *stream, int FCGI_errno)
-{
- /*
- * Preserve only the first error.
- */
- if(stream->FCGI_errno == 0) {
- stream->FCGI_errno = FCGI_errno;
- stream->isClosed = TRUE;
- }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_GetError --
- *
- * Return the stream error code. 0 means no error, > 0
- * is an errno(2) error, < 0 is an FCGX_errno error.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_GetError(FCGX_Stream *stream) {
- return stream->FCGI_errno;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_ClearError --
- *
- * Clear the stream error code and end-of-file indication.
- *
- *----------------------------------------------------------------------
- */
-void FCGX_ClearError(FCGX_Stream *stream) {
- stream->FCGI_errno = 0;
- /*
- * stream->isClosed = FALSE;
- * XXX: should clear isClosed but work is needed to make it safe
- * to do so. For example, if an application calls FClose, gets
- * an I/O error on the write, calls ClearError and retries
- * the FClose, FClose (really EmptyBuffProc) will write a second
- * EOF record. If an application calls PutChar instead of FClose
- * after the ClearError, the application will write more data.
- * The stream's state must discriminate between various states
- * of the stream that are now all lumped under isClosed.
- */
-}
-
-
-
-/*
- *----------------------------------------------------------------------
- *
- * NewParams --
- *
- * Creates a new Params structure.
- *
- * Results:
- * Pointer to the new structure.
- *
- *----------------------------------------------------------------------
- */
-static ParamsPtr NewParams(int length)
-{
- ParamsPtr result;
- result = (Params *)Malloc(sizeof(Params));
- result->vec = (char **)Malloc(length * sizeof(char *));
- result->length = length;
- result->cur = result->vec;
- *result->cur = NULL;
- return result;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FreeParams --
- *
- * Frees a Params structure and all the parameters it contains.
- *
- * Side effects:
- * env becomes invalid.
- *
- *----------------------------------------------------------------------
- */
-static void FreeParams(ParamsPtr *paramsPtrPtr)
-{
- ParamsPtr paramsPtr = *paramsPtrPtr;
- char **p;
- if(paramsPtr == NULL) {
- return;
- }
- for (p = paramsPtr->vec; p < paramsPtr->cur; p++) {
- free(*p);
- }
- free(paramsPtr->vec);
- free(paramsPtr);
- *paramsPtrPtr = NULL;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * PutParam --
- *
- * Add a name/value pair to a Params structure.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Parameters structure updated.
- *
- *----------------------------------------------------------------------
- */
-static void PutParam(ParamsPtr paramsPtr, char *nameValue)
-{
- int size;
-
- *paramsPtr->cur++ = nameValue;
- size = paramsPtr->cur - paramsPtr->vec;
- if(size >= paramsPtr->length) {
- paramsPtr->length *= 2;
- paramsPtr->vec = (FCGX_ParamArray)realloc(paramsPtr->vec, paramsPtr->length * sizeof(char *));
- paramsPtr->cur = paramsPtr->vec + size;
- }
- *paramsPtr->cur = NULL;
-}
-
-
-void FCGX_PutEnv(FCGX_Request *request, char *var)
-{
- char *nameValue;
- char *e, **p;
- int len;
-
- if (!strchr(var,'=')) {
- return;
- }
- nameValue = StringCopy(var);
- e = strchr(nameValue,'=');
- *e = 0;
-
- /* find the name and replace it */
- len = strlen(nameValue);
-
- for (p = request->envp; p && *p; ++p) {
- if((strncmp(nameValue, *p, len) == 0) && ((*p)[len] == '=')) {
- free(*p);
- *e = '=';
- *p = nameValue;
- return;
- }
- }
- *e = '=';
- /* this is a new var, add it to the environment */
- PutParam(request->paramsPtr,nameValue);
- request->envp = request->paramsPtr->vec;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_GetParam -- obtain value of FCGI parameter in environment
- *
- *
- * Results:
- * Value bound to name, NULL if name not present in the
- * environment envp. Caller must not mutate the result
- * or retain it past the end of this request.
- *
- *----------------------------------------------------------------------
- */
-char *FCGX_GetParam(const char *name, FCGX_ParamArray envp)
-{
- int len;
- char **p;
-
- if (name == NULL || envp == NULL) return NULL;
-
- len = strlen(name);
-
- for (p = envp; p && *p; ++p) {
- if((strncmp(name, *p, len) == 0) && ((*p)[len] == '=')) {
- return *p+len+1;
- }
- }
- return NULL;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Start of FastCGI-specific code
- *
- *----------------------------------------------------------------------
- */
-
-/*
- *----------------------------------------------------------------------
- *
- * ReadParams --
- *
- * Reads FastCGI name-value pairs from stream until EOF. Converts
- * each pair to name=value format and adds it to Params structure.
- *
- *----------------------------------------------------------------------
- */
-static int ReadParams(Params *paramsPtr, FCGX_Stream *stream)
-{
- int nameLen, valueLen;
- unsigned char lenBuff[3];
- char *nameValue;
-
- while((nameLen = FCGX_GetChar(stream)) != EOF) {
- /*
- * Read name length (one or four bytes) and value length
- * (one or four bytes) from stream.
- */
- if((nameLen & 0x80) != 0) {
- if(FCGX_GetStr((char *) &lenBuff[0], 3, stream) != 3) {
- SetError(stream, FCGX_PARAMS_ERROR);
- return -1;
- }
- nameLen = ((nameLen & 0x7f) << 24) + (lenBuff[0] << 16)
- + (lenBuff[1] << 8) + lenBuff[2];
- }
- if((valueLen = FCGX_GetChar(stream)) == EOF) {
- SetError(stream, FCGX_PARAMS_ERROR);
- return -1;
- }
- if((valueLen & 0x80) != 0) {
- if(FCGX_GetStr((char *) &lenBuff[0], 3, stream) != 3) {
- SetError(stream, FCGX_PARAMS_ERROR);
- return -1;
- }
- valueLen = ((valueLen & 0x7f) << 24) + (lenBuff[0] << 16)
- + (lenBuff[1] << 8) + lenBuff[2];
- }
- /*
- * nameLen and valueLen are now valid; read the name and value
- * from stream and construct a standard environment entry.
- */
- nameValue = (char *)Malloc(nameLen + valueLen + 2);
- if(FCGX_GetStr(nameValue, nameLen, stream) != nameLen) {
- SetError(stream, FCGX_PARAMS_ERROR);
- free(nameValue);
- return -1;
- }
- *(nameValue + nameLen) = '=';
- if(FCGX_GetStr(nameValue + nameLen + 1, valueLen, stream)
- != valueLen) {
- SetError(stream, FCGX_PARAMS_ERROR);
- free(nameValue);
- return -1;
- }
- *(nameValue + nameLen + valueLen + 1) = '\0';
- PutParam(paramsPtr, nameValue);
- }
- return 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * MakeHeader --
- *
- * Constructs an FCGI_Header struct.
- *
- *----------------------------------------------------------------------
- */
-static FCGI_Header MakeHeader(
- int type,
- int requestId,
- int contentLength,
- int paddingLength)
-{
- FCGI_Header header;
- ASSERT(contentLength >= 0 && contentLength <= FCGI_MAX_LENGTH);
- ASSERT(paddingLength >= 0 && paddingLength <= 0xff);
- header.version = FCGI_VERSION_1;
- header.type = (unsigned char) type;
- header.requestIdB1 = (unsigned char) ((requestId >> 8) & 0xff);
- header.requestIdB0 = (unsigned char) ((requestId ) & 0xff);
- header.contentLengthB1 = (unsigned char) ((contentLength >> 8) & 0xff);
- header.contentLengthB0 = (unsigned char) ((contentLength ) & 0xff);
- header.paddingLength = (unsigned char) paddingLength;
- header.reserved = 0;
- return header;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * MakeEndRequestBody --
- *
- * Constructs an FCGI_EndRequestBody struct.
- *
- *----------------------------------------------------------------------
- */
-static FCGI_EndRequestBody MakeEndRequestBody(
- int appStatus,
- int protocolStatus)
-{
- FCGI_EndRequestBody body;
- body.appStatusB3 = (unsigned char) ((appStatus >> 24) & 0xff);
- body.appStatusB2 = (unsigned char) ((appStatus >> 16) & 0xff);
- body.appStatusB1 = (unsigned char) ((appStatus >> 8) & 0xff);
- body.appStatusB0 = (unsigned char) ((appStatus ) & 0xff);
- body.protocolStatus = (unsigned char) protocolStatus;
- memset(body.reserved, 0, sizeof(body.reserved));
- return body;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * MakeUnknownTypeBody --
- *
- * Constructs an FCGI_MakeUnknownTypeBody struct.
- *
- *----------------------------------------------------------------------
- */
-static FCGI_UnknownTypeBody MakeUnknownTypeBody(
- int type)
-{
- FCGI_UnknownTypeBody body;
- body.type = (unsigned char) type;
- memset(body.reserved, 0, sizeof(body.reserved));
- return body;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * AlignInt8 --
- *
- * Returns the smallest integer greater than or equal to n
- * that's a multiple of 8.
- *
- *----------------------------------------------------------------------
- */
-static int AlignInt8(unsigned n) {
- return (n + 7) & (UINT_MAX - 7);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * AlignPtr8 --
- *
- * Returns the smallest pointer greater than or equal to p
- * that's a multiple of 8.
- *
- *----------------------------------------------------------------------
- */
-static unsigned char *AlignPtr8(unsigned char *p) {
- unsigned long u = (unsigned long) p;
- u = ((u + 7) & (ULONG_MAX - 7)) - u;
- return p + u;
-}
-
-
-/*
- * State associated with a stream
- */
-typedef struct FCGX_Stream_Data {
- unsigned char *buff; /* buffer after alignment */
- int bufflen; /* number of bytes buff can store */
- unsigned char *mBuff; /* buffer as returned by Malloc */
- unsigned char *buffStop; /* reader: last valid byte + 1 of entire buffer.
- * stop generally differs from buffStop for
- * readers because of record structure.
- * writer: buff + bufflen */
- int type; /* reader: FCGI_PARAMS or FCGI_STDIN
- * writer: FCGI_STDOUT or FCGI_STDERR */
- int eorStop; /* reader: stop stream at end-of-record */
- int skip; /* reader: don't deliver content bytes */
- int contentLen; /* reader: bytes of unread content */
- int paddingLen; /* reader: bytes of unread padding */
- int isAnythingWritten; /* writer: data has been written to ipcFd */
- int rawWrite; /* writer: write data without stream headers */
- FCGX_Request *reqDataPtr; /* request data not specific to one stream */
-} FCGX_Stream_Data;
-
-/*
- *----------------------------------------------------------------------
- *
- * WriteCloseRecords --
- *
- * Writes an EOF record for the stream content if necessary.
- * If this is the last writer to close, writes an FCGI_END_REQUEST
- * record.
- *
- *----------------------------------------------------------------------
- */
-static void WriteCloseRecords(struct FCGX_Stream *stream)
-{
- FCGX_Stream_Data *data = (FCGX_Stream_Data *)stream->data;
- /*
- * Enter rawWrite mode so final records won't be encapsulated as
- * stream data.
- */
- data->rawWrite = TRUE;
- /*
- * Generate EOF for stream content if needed.
- */
- if(!(data->type == FCGI_STDERR
- && stream->wrNext == data->buff
- && !data->isAnythingWritten)) {
- FCGI_Header header;
- header = MakeHeader(data->type, data->reqDataPtr->requestId, 0, 0);
- FCGX_PutStr((char *) &header, sizeof(header), stream);
- };
- /*
- * Generate FCGI_END_REQUEST record if needed.
- */
- if(data->reqDataPtr->nWriters == 1) {
- FCGI_EndRequestRecord endRequestRecord;
- endRequestRecord.header = MakeHeader(FCGI_END_REQUEST,
- data->reqDataPtr->requestId,
- sizeof(endRequestRecord.body), 0);
- endRequestRecord.body = MakeEndRequestBody(
- data->reqDataPtr->appStatus, FCGI_REQUEST_COMPLETE);
- FCGX_PutStr((char *) &endRequestRecord,
- sizeof(endRequestRecord), stream);
- }
- data->reqDataPtr->nWriters--;
-}
-
-
-
-static int write_it_all(int fd, char *buf, int len)
-{
- int wrote;
-
- while (len) {
- wrote = OS_Write(fd, buf, len);
- if (wrote < 0)
- return wrote;
- len -= wrote;
- buf += wrote;
- }
- return len;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * EmptyBuffProc --
- *
- * Encapsulates any buffered stream content in a FastCGI
- * record. Writes the data, making the buffer empty.
- *
- *----------------------------------------------------------------------
- */
-static void EmptyBuffProc(struct FCGX_Stream *stream, int doClose)
-{
- FCGX_Stream_Data *data = (FCGX_Stream_Data *)stream->data;
- int cLen, eLen;
- /*
- * If the buffer contains stream data, fill in the header.
- * Pad the record to a multiple of 8 bytes in length. Padding
- * can't overflow the buffer because the buffer is a multiple
- * of 8 bytes in length. If the buffer contains no stream
- * data, reclaim the space reserved for the header.
- */
- if(!data->rawWrite) {
- cLen = stream->wrNext - data->buff - sizeof(FCGI_Header);
- if(cLen > 0) {
- eLen = AlignInt8(cLen);
- /*
- * Giving the padding a well-defined value keeps Purify happy.
- */
- memset(stream->wrNext, 0, eLen - cLen);
- stream->wrNext += eLen - cLen;
- *((FCGI_Header *) data->buff)
- = MakeHeader(data->type,
- data->reqDataPtr->requestId, cLen, eLen - cLen);
- } else {
- stream->wrNext = data->buff;
- }
- }
- if(doClose) {
- WriteCloseRecords(stream);
- };
- if (stream->wrNext != data->buff) {
- data->isAnythingWritten = TRUE;
- if (write_it_all(data->reqDataPtr->ipcFd, (char *)data->buff, stream->wrNext - data->buff) < 0) {
- SetError(stream, OS_Errno);
- return;
- }
- stream->wrNext = data->buff;
- }
- /*
- * The buffer is empty.
- */
- if(!data->rawWrite) {
- stream->wrNext += sizeof(FCGI_Header);
- }
-}
-
-/*
- * Return codes for Process* functions
- */
-#define STREAM_RECORD 0
-#define SKIP 1
-#define BEGIN_RECORD 2
-#define MGMT_RECORD 3
-
-/*
- *----------------------------------------------------------------------
- *
- * ProcessManagementRecord --
- *
- * Reads and responds to a management record. The only type of
- * management record this library understands is FCGI_GET_VALUES.
- * The only variables that this library's FCGI_GET_VALUES
- * understands are FCGI_MAX_CONNS, FCGI_MAX_REQS, and FCGI_MPXS_CONNS.
- * Ignore other FCGI_GET_VALUES variables; respond to other
- * management records with a FCGI_UNKNOWN_TYPE record.
- *
- *----------------------------------------------------------------------
- */
-static int ProcessManagementRecord(int type, FCGX_Stream *stream)
-{
- FCGX_Stream_Data *data = (FCGX_Stream_Data *)stream->data;
- ParamsPtr paramsPtr = NewParams(3);
- char **pPtr;
- char response[64]; /* 64 = 8 + 3*(1+1+14+1)* + padding */
- char *responseP = &response[FCGI_HEADER_LEN];
- char *name, value = '\0';
- int len, paddedLen;
- if(type == FCGI_GET_VALUES) {
- ReadParams(paramsPtr, stream);
- if((FCGX_GetError(stream) != 0) || (data->contentLen != 0)) {
- FreeParams(&paramsPtr);
- return FCGX_PROTOCOL_ERROR;
- }
- for (pPtr = paramsPtr->vec; pPtr < paramsPtr->cur; pPtr++) {
- name = *pPtr;
- *(strchr(name, '=')) = '\0';
- if(strcmp(name, FCGI_MAX_CONNS) == 0) {
- value = '1';
- } else if(strcmp(name, FCGI_MAX_REQS) == 0) {
- value = '1';
- } else if(strcmp(name, FCGI_MPXS_CONNS) == 0) {
- value = '0';
- } else {
- name = NULL;
- }
- if(name != NULL) {
- len = strlen(name);
- sprintf(responseP, "%c%c%s%c", len, 1, name, value);
- responseP += len + 3;
- }
- }
- len = responseP - &response[FCGI_HEADER_LEN];
- paddedLen = AlignInt8(len);
- *((FCGI_Header *) response)
- = MakeHeader(FCGI_GET_VALUES_RESULT, FCGI_NULL_REQUEST_ID,
- len, paddedLen - len);
- FreeParams(&paramsPtr);
- } else {
- paddedLen = len = sizeof(FCGI_UnknownTypeBody);
- ((FCGI_UnknownTypeRecord *) response)->header
- = MakeHeader(FCGI_UNKNOWN_TYPE, FCGI_NULL_REQUEST_ID,
- len, 0);
- ((FCGI_UnknownTypeRecord *) response)->body
- = MakeUnknownTypeBody(type);
- }
- if (write_it_all(data->reqDataPtr->ipcFd, response, FCGI_HEADER_LEN + paddedLen) < 0) {
- SetError(stream, OS_Errno);
- return -1;
- }
-
- return MGMT_RECORD;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * ProcessBeginRecord --
- *
- * Reads an FCGI_BEGIN_REQUEST record.
- *
- * Results:
- * BEGIN_RECORD for normal return. FCGX_PROTOCOL_ERROR for
- * protocol error. SKIP for attempt to multiplex
- * connection. -1 for error from write (errno in stream).
- *
- * Side effects:
- * In case of BEGIN_RECORD return, stores requestId, role,
- * keepConnection values, and sets isBeginProcessed = TRUE.
- *
- *----------------------------------------------------------------------
- */
-static int ProcessBeginRecord(int requestId, FCGX_Stream *stream)
-{
- FCGX_Stream_Data *data = (FCGX_Stream_Data *)stream->data;
- FCGI_BeginRequestBody body;
- if(requestId == 0 || data->contentLen != sizeof(body)) {
- return FCGX_PROTOCOL_ERROR;
- }
- if(data->reqDataPtr->isBeginProcessed) {
- /*
- * The Web server is multiplexing the connection. This library
- * doesn't know how to handle multiplexing, so respond with
- * FCGI_END_REQUEST{protocolStatus = FCGI_CANT_MPX_CONN}
- */
- FCGI_EndRequestRecord endRequestRecord;
- endRequestRecord.header = MakeHeader(FCGI_END_REQUEST,
- requestId, sizeof(endRequestRecord.body), 0);
- endRequestRecord.body
- = MakeEndRequestBody(0, FCGI_CANT_MPX_CONN);
- if (write_it_all(data->reqDataPtr->ipcFd, (char *)&endRequestRecord, sizeof(endRequestRecord)) < 0) {
- SetError(stream, OS_Errno);
- return -1;
- }
-
- return SKIP;
- }
- /*
- * Accept this new request. Read the record body.
- */
- data->reqDataPtr->requestId = requestId;
- if(FCGX_GetStr((char *) &body, sizeof(body), stream)
- != sizeof(body)) {
- return FCGX_PROTOCOL_ERROR;
- }
- data->reqDataPtr->keepConnection = (body.flags & FCGI_KEEP_CONN);
- data->reqDataPtr->role = (body.roleB1 << 8) + body.roleB0;
- data->reqDataPtr->isBeginProcessed = TRUE;
- return BEGIN_RECORD;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * ProcessHeader --
- *
- * Interprets FCGI_Header. Processes FCGI_BEGIN_REQUEST and
- * management records here; extracts information from stream
- * records (FCGI_PARAMS, FCGI_STDIN) into stream.
- *
- * Results:
- * >= 0 for a normal return, < 0 for error
- *
- * Side effects:
- * XXX: Many (more than there used to be).
- * If !stream->isRequestIdSet, ProcessHeader initializes
- * stream->requestId from header and sets stream->isRequestIdSet
- * to TRUE. ProcessHeader also sets stream->contentLen to header's
- * contentLength, and sets stream->paddingLen to the header's
- * paddingLength.
- *
- *----------------------------------------------------------------------
- */
-static int ProcessHeader(FCGI_Header header, FCGX_Stream *stream)
-{
- FCGX_Stream_Data *data = (FCGX_Stream_Data *)stream->data;
- int requestId;
- if(header.version != FCGI_VERSION_1) {
- return FCGX_UNSUPPORTED_VERSION;
- }
- requestId = (header.requestIdB1 << 8)
- + header.requestIdB0;
- data->contentLen = (header.contentLengthB1 << 8)
- + header.contentLengthB0;
- data->paddingLen = header.paddingLength;
- if(header.type == FCGI_BEGIN_REQUEST) {
- return ProcessBeginRecord(requestId, stream);
- }
- if(requestId == FCGI_NULL_REQUEST_ID) {
- return ProcessManagementRecord(header.type, stream);
- }
- if(requestId != data->reqDataPtr->requestId) {
- return SKIP;
- }
- if(header.type != data->type) {
- return FCGX_PROTOCOL_ERROR;
- }
- return STREAM_RECORD;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FillBuffProc --
- *
- * Reads bytes from the ipcFd, supplies bytes to a stream client.
- *
- *----------------------------------------------------------------------
- */
-static void FillBuffProc(FCGX_Stream *stream)
-{
- FCGX_Stream_Data *data = (FCGX_Stream_Data *)stream->data;
- FCGI_Header header;
- int headerLen = 0;
- int status, count;
-
- for (;;) {
- /*
- * If data->buff is empty, do a read.
- */
- if(stream->rdNext == data->buffStop) {
- count = OS_Read(data->reqDataPtr->ipcFd, (char *)data->buff,
- data->bufflen);
- if(count <= 0) {
- SetError(stream, (count == 0 ? FCGX_PROTOCOL_ERROR : OS_Errno));
- return;
- }
- stream->rdNext = data->buff;
- data->buffStop = data->buff + count;
- }
- /*
- * Now data->buff is not empty. If the current record contains
- * more content bytes, deliver all that are present in data->buff.
- */
- if(data->contentLen > 0) {
- count = min(data->contentLen, data->buffStop - stream->rdNext);
- data->contentLen -= count;
- if(!data->skip) {
- stream->wrNext = stream->stop = stream->rdNext + count;
- return;
- } else {
- stream->rdNext += count;
- if(data->contentLen > 0) {
- continue;
- } else {
- data->skip = FALSE;
- }
- }
- }
- /*
- * If the current record (whose content has been fully consumed by
- * the client) was padded, skip over the padding bytes.
- */
- if(data->paddingLen > 0) {
- count = min(data->paddingLen, data->buffStop - stream->rdNext);
- data->paddingLen -= count;
- stream->rdNext += count;
- if(data->paddingLen > 0) {
- continue;
- }
- }
- /*
- * All done with the current record, including the padding.
- * If we're in a recursive call from ProcessHeader, deliver EOF.
- */
- if(data->eorStop) {
- stream->stop = stream->rdNext;
- stream->isClosed = TRUE;
- return;
- }
- /*
- * Fill header with bytes from the input buffer.
- */
- count = min((int)sizeof(header) - headerLen,
- data->buffStop - stream->rdNext);
- memcpy(((char *)(&header)) + headerLen, stream->rdNext, count);
- headerLen += count;
- stream->rdNext += count;
- if(headerLen < sizeof(header)) {
- continue;
- };
- headerLen = 0;
- /*
- * Interpret header. eorStop prevents ProcessHeader from reading
- * past the end-of-record when using stream to read content.
- */
- data->eorStop = TRUE;
- stream->stop = stream->rdNext;
- status = ProcessHeader(header, stream);
- data->eorStop = FALSE;
- stream->isClosed = FALSE;
- switch(status) {
- case STREAM_RECORD:
- /*
- * If this stream record header marked the end of stream
- * data deliver EOF to the stream client, otherwise loop
- * and deliver data.
- *
- * XXX: If this is final stream and
- * stream->rdNext != data->buffStop, buffered
- * data is next request (server pipelining)?
- */
- if(data->contentLen == 0) {
- stream->wrNext = stream->stop = stream->rdNext;
- stream->isClosed = TRUE;
- return;
- }
- break;
- case SKIP:
- data->skip = TRUE;
- break;
- case BEGIN_RECORD:
- /*
- * If this header marked the beginning of a new
- * request, return role information to caller.
- */
- return;
- break;
- case MGMT_RECORD:
- break;
- default:
- ASSERT(status < 0);
- SetError(stream, status);
- return;
- break;
- }
- }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * NewStream --
- *
- * Creates a stream to read or write from an open ipcFd.
- * The stream performs reads/writes of up to bufflen bytes.
- *
- *----------------------------------------------------------------------
- */
-static FCGX_Stream *NewStream(
- FCGX_Request *reqDataPtr, int bufflen, int isReader, int streamType)
-{
- /*
- * XXX: It would be a lot cleaner to have a NewStream that only
- * knows about the type FCGX_Stream, with all other
- * necessary data passed in. It appears that not just
- * data and the two procs are needed for initializing stream,
- * but also data->buff and data->buffStop. This has implications
- * for procs that want to swap buffers, too.
- */
- FCGX_Stream *stream = (FCGX_Stream *)Malloc(sizeof(FCGX_Stream));
- FCGX_Stream_Data *data = (FCGX_Stream_Data *)Malloc(sizeof(FCGX_Stream_Data));
- data->reqDataPtr = reqDataPtr;
- bufflen = AlignInt8(min(max(bufflen, 32), FCGI_MAX_LENGTH + 1));
- data->bufflen = bufflen;
- data->mBuff = (unsigned char *)Malloc(bufflen);
- data->buff = AlignPtr8(data->mBuff);
- if(data->buff != data->mBuff) {
- data->bufflen -= 8;
- }
- if(isReader) {
- data->buffStop = data->buff;
- } else {
- data->buffStop = data->buff + data->bufflen;
- }
- data->type = streamType;
- data->eorStop = FALSE;
- data->skip = FALSE;
- data->contentLen = 0;
- data->paddingLen = 0;
- data->isAnythingWritten = FALSE;
- data->rawWrite = FALSE;
-
- stream->data = data;
- stream->isReader = isReader;
- stream->isClosed = FALSE;
- stream->wasFCloseCalled = FALSE;
- stream->FCGI_errno = 0;
- if(isReader) {
- stream->fillBuffProc = FillBuffProc;
- stream->emptyBuffProc = NULL;
- stream->rdNext = data->buff;
- stream->stop = stream->rdNext;
- stream->stopUnget = data->buff;
- stream->wrNext = stream->stop;
- } else {
- stream->fillBuffProc = NULL;
- stream->emptyBuffProc = EmptyBuffProc;
- stream->wrNext = data->buff + sizeof(FCGI_Header);
- stream->stop = data->buffStop;
- stream->stopUnget = NULL;
- stream->rdNext = stream->stop;
- }
- return stream;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_FreeStream --
- *
- * Frees all storage allocated when *streamPtr was created,
- * and nulls out *streamPtr.
- *
- *----------------------------------------------------------------------
- */
-void FCGX_FreeStream(FCGX_Stream **streamPtr)
-{
- _FCGX_FreeStream(streamPtr, TRUE);
-}
-
-void _FCGX_FreeStream(FCGX_Stream **streamPtr, int freeData)
-{
- FCGX_Stream *stream = *streamPtr;
- FCGX_Stream_Data *data;
- if(stream == NULL) {
- return;
- }
- data = (FCGX_Stream_Data *)stream->data;
- if (freeData && data->reqDataPtr) free(data->reqDataPtr);
- data->reqDataPtr = NULL;
- free(data->mBuff);
- free(data);
- free(stream);
- *streamPtr = NULL;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * SetReaderType --
- *
- * Re-initializes the stream to read data of the specified type.
- *
- *----------------------------------------------------------------------
- */
-static FCGX_Stream *SetReaderType(FCGX_Stream *stream, int streamType)
-{
- FCGX_Stream_Data *data = (FCGX_Stream_Data *)stream->data;
- ASSERT(stream->isReader);
- data->type = streamType;
- data->eorStop = FALSE;
- data->skip = FALSE;
- data->contentLen = 0;
- data->paddingLen = 0;
- stream->wrNext = stream->stop = stream->rdNext;
- stream->isClosed = FALSE;
- return stream;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * NewReader --
- *
- * Creates a stream to read streamType records for the given
- * request. The stream performs OS reads of up to bufflen bytes.
- *
- *----------------------------------------------------------------------
- */
-static FCGX_Stream *NewReader(FCGX_Request *reqDataPtr, int bufflen, int streamType)
-{
- return NewStream(reqDataPtr, bufflen, TRUE, streamType);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * NewWriter --
- *
- * Creates a stream to write streamType FastCGI records, using
- * the ipcFd and RequestId contained in *reqDataPtr.
- * The stream performs OS writes of up to bufflen bytes.
- *
- *----------------------------------------------------------------------
- */
-static FCGX_Stream *NewWriter(FCGX_Request *reqDataPtr, int bufflen, int streamType)
-{
- return NewStream(reqDataPtr, bufflen, FALSE, streamType);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_CreateWriter --
- *
- * Creates a stream to write streamType FastCGI records, using
- * the given ipcFd and request Id. This function is provided
- * for use by cgi-fcgi. In order to be defensive against misuse,
- * this function leaks a little storage; cgi-fcgi doesn't care.
- *
- *----------------------------------------------------------------------
- */
-FCGX_Stream *FCGX_CreateWriter(
- int ipcFd,
- int requestId,
- int bufflen,
- int streamType)
-{
- FCGX_Request *reqDataPtr = (FCGX_Request *)Malloc(sizeof(FCGX_Request));
- reqDataPtr->ipcFd = ipcFd;
- reqDataPtr->requestId = requestId;
- /*
- * Suppress writing an FCGI_END_REQUEST record.
- */
- reqDataPtr->nWriters = 2;
- return NewWriter(reqDataPtr, bufflen, streamType);
-}
-
-/*
- *======================================================================
- * Control
- *======================================================================
- */
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_IsCGI --
- *
- * This routine determines if the process is running as a CGI or
- * FastCGI process. The distinction is made by determining whether
- * FCGI_LISTENSOCK_FILENO is a listener ipcFd or the end of a
- * pipe (ie. standard in).
- *
- * Results:
- * TRUE if the process is a CGI process, FALSE if FastCGI.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_IsCGI(void)
-{
- if (isFastCGI != -1) {
- return !isFastCGI;
- }
-
- if (!libInitialized) {
- int rc = FCGX_Init();
- if (rc) {
- /* exit() isn't great, but hey */
- //exit((rc < 0) ? rc : -rc);
- return 0;
- }
- }
-
- isFastCGI = OS_IsFcgi(FCGI_LISTENSOCK_FILENO);
-
- return !isFastCGI;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Finish --
- *
- * Finishes the current request from the HTTP server.
- *
- * Side effects:
- *
- * Finishes the request accepted by (and frees any
- * storage allocated by) the previous call to FCGX_Accept.
- *
- * DO NOT retain pointers to the envp array or any strings
- * contained in it (e.g. to the result of calling FCGX_GetParam),
- * since these will be freed by the next call to FCGX_Finish
- * or FCGX_Accept.
- *
- *----------------------------------------------------------------------
- */
-
-void FCGX_Finish(void)
-{
- FCGX_Finish_r(&the_request);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Finish_r --
- *
- * Finishes the current request from the HTTP server.
- *
- * Side effects:
- *
- * Finishes the request accepted by (and frees any
- * storage allocated by) the previous call to FCGX_Accept.
- *
- * DO NOT retain pointers to the envp array or any strings
- * contained in it (e.g. to the result of calling FCGX_GetParam),
- * since these will be freed by the next call to FCGX_Finish
- * or FCGX_Accept.
- *
- *----------------------------------------------------------------------
- */
-void FCGX_Finish_r(FCGX_Request *reqDataPtr)
-{
- int close;
-
- if (reqDataPtr == NULL) {
- return;
- }
-
- close = !reqDataPtr->keepConnection;
-
- /* This should probably use a 'status' member instead of 'in' */
- if (reqDataPtr->in) {
- close |= FCGX_FClose(reqDataPtr->err);
- close |= FCGX_FClose(reqDataPtr->out);
-
- close |= FCGX_GetError(reqDataPtr->in);
- }
-
- FCGX_Free(reqDataPtr, close);
-}
-
-void FCGX_Free(FCGX_Request * request, int close)
-{
- if (request == NULL)
- return;
-
- _FCGX_FreeStream(&request->in, FALSE);
- _FCGX_FreeStream(&request->out, FALSE);
- _FCGX_FreeStream(&request->err, FALSE);
- FreeParams(&request->paramsPtr);
- request->envp = NULL;
-
- if (close) {
- OS_IpcClose(request->ipcFd);
- request->ipcFd = -1;
- }
-}
-
-int FCGX_OpenSocket(const char *path, int backlog)
-{
- int rc = OS_CreateLocalIpcFd(path, backlog, 1);
- if (rc == FCGI_LISTENSOCK_FILENO && isFastCGI == 0) {
- /* XXX probably need to call OS_LibInit() again for Win */
- isFastCGI = 1;
- }
- return rc;
-}
-
-int FCGX_InitRequest(FCGX_Request *request, int sock, int flags)
-{
- memset(request, 0, sizeof(FCGX_Request));
-
- /* @@@ Should check that sock is open and listening */
- request->listen_sock = sock;
-
- /* @@@ Should validate against "known" flags */
- request->flags = flags;
-
- request->ipcFd = -1;
-
- return 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Init --
- *
- * Initilize the FCGX library. This is called by FCGX_Accept()
- * but must be called by the user when using FCGX_Accept_r().
- *
- * Results:
- * 0 for successful call.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_Init(void)
-{
- char *p;
-
- if (libInitialized) {
- return 0;
- }
-
- FCGX_InitRequest(&the_request, FCGI_LISTENSOCK_FILENO, 0);
-
- if (OS_LibInit(NULL) == -1) {
- return OS_Errno ? OS_Errno : -9997;
- }
-
- p = getenv("FCGI_WEB_SERVER_ADDRS");
- webServerAddressList = p ? StringCopy(p) : NULL;
-
- libInitialized = 1;
- return 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Accept --
- *
- * Accepts a new request from the HTTP server.
- *
- * Results:
- * 0 for successful call, -1 for error.
- *
- * Side effects:
- *
- * Finishes the request accepted by (and frees any
- * storage allocated by) the previous call to FCGX_Accept.
- * Creates input, output, and error streams and
- * assigns them to *in, *out, and *err respectively.
- * Creates a parameters data structure to be accessed
- * via getenv(3) (if assigned to environ) or by FCGX_GetParam
- * and assigns it to *envp.
- *
- * DO NOT retain pointers to the envp array or any strings
- * contained in it (e.g. to the result of calling FCGX_GetParam),
- * since these will be freed by the next call to FCGX_Finish
- * or FCGX_Accept.
- *
- *----------------------------------------------------------------------
- */
-
-int FCGX_Accept(
- FCGX_Stream **in,
- FCGX_Stream **out,
- FCGX_Stream **err,
- FCGX_ParamArray *envp)
-{
- int rc;
-
- if (! libInitialized) {
- rc = FCGX_Init();
- if (rc) {
- return rc;
- }
- }
-
- rc = FCGX_Accept_r(&the_request);
-
- *in = the_request.in;
- *out = the_request.out;
- *err = the_request.err;
- *envp = the_request.envp;
-
- return rc;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Accept_r --
- *
- * Accepts a new request from the HTTP server.
- *
- * Results:
- * 0 for successful call, -1 for error.
- *
- * Side effects:
- *
- * Finishes the request accepted by (and frees any
- * storage allocated by) the previous call to FCGX_Accept.
- * Creates input, output, and error streams and
- * assigns them to *in, *out, and *err respectively.
- * Creates a parameters data structure to be accessed
- * via getenv(3) (if assigned to environ) or by FCGX_GetParam
- * and assigns it to *envp.
- *
- * DO NOT retain pointers to the envp array or any strings
- * contained in it (e.g. to the result of calling FCGX_GetParam),
- * since these will be freed by the next call to FCGX_Finish
- * or FCGX_Accept.
- *
- *----------------------------------------------------------------------
- */
-int FCGX_Accept_r(FCGX_Request *reqDataPtr)
-{
- if (!libInitialized) {
- return -9998;
- }
-
- /* Finish the current request, if any. */
- FCGX_Finish_r(reqDataPtr);
-
- for (;;) {
- /*
- * If a connection isn't open, accept a new connection (blocking).
- * If an OS error occurs in accepting the connection,
- * return -1 to the caller, who should exit.
- */
- if (reqDataPtr->ipcFd < 0) {
- int fail_on_intr = reqDataPtr->flags & FCGI_FAIL_ACCEPT_ON_INTR;
-
- reqDataPtr->ipcFd = OS_Accept(reqDataPtr->listen_sock, fail_on_intr, webServerAddressList);
- if (reqDataPtr->ipcFd < 0) {
- return (errno > 0) ? (0 - errno) : -9999;
- }
- }
- /*
- * A connection is open. Read from the connection in order to
- * get the request's role and environment. If protocol or other
- * errors occur, close the connection and try again.
- */
- reqDataPtr->isBeginProcessed = FALSE;
- reqDataPtr->in = NewReader(reqDataPtr, 8192, 0);
- FillBuffProc(reqDataPtr->in);
- if(!reqDataPtr->isBeginProcessed) {
- goto TryAgain;
- }
- {
- char *roleStr;
- switch(reqDataPtr->role) {
- case FCGI_RESPONDER:
- roleStr = "FCGI_ROLE=RESPONDER";
- break;
- case FCGI_AUTHORIZER:
- roleStr = "FCGI_ROLE=AUTHORIZER";
- break;
- case FCGI_FILTER:
- roleStr = "FCGI_ROLE=FILTER";
- break;
- default:
- goto TryAgain;
- }
- reqDataPtr->paramsPtr = NewParams(30);
- PutParam(reqDataPtr->paramsPtr, StringCopy(roleStr));
- }
- SetReaderType(reqDataPtr->in, FCGI_PARAMS);
- if(ReadParams(reqDataPtr->paramsPtr, reqDataPtr->in) >= 0) {
- /*
- * Finished reading the environment. No errors occurred, so
- * leave the connection-retry loop.
- */
- break;
- }
-
- /*
- * Close the connection and try again.
- */
-TryAgain:
- FCGX_Free(reqDataPtr, 1);
-
- } /* for (;;) */
- /*
- * Build the remaining data structures representing the new
- * request and return successfully to the caller.
- */
- SetReaderType(reqDataPtr->in, FCGI_STDIN);
- reqDataPtr->out = NewWriter(reqDataPtr, 8192, FCGI_STDOUT);
- reqDataPtr->err = NewWriter(reqDataPtr, 512, FCGI_STDERR);
- reqDataPtr->nWriters = 2;
- reqDataPtr->envp = reqDataPtr->paramsPtr->vec;
- return 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_StartFilterData --
- *
- * stream is an input stream for a FCGI_FILTER request.
- * stream is positioned at EOF on FCGI_STDIN.
- * Repositions stream to the start of FCGI_DATA.
- * If the preconditions are not met (e.g. FCGI_STDIN has not
- * been read to EOF) sets the stream error code to
- * FCGX_CALL_SEQ_ERROR.
- *
- * Results:
- * 0 for a normal return, < 0 for error
- *
- *----------------------------------------------------------------------
- */
-
-int FCGX_StartFilterData(FCGX_Stream *stream)
-{
- FCGX_Stream_Data *data = (FCGX_Stream_Data *)stream->data;
- if(data->reqDataPtr->role != FCGI_FILTER
- || !stream->isReader
- || !stream->isClosed
- || data->type != FCGI_STDIN) {
- SetError(stream, FCGX_CALL_SEQ_ERROR);
- return -1;
- }
- SetReaderType(stream, FCGI_DATA);
- return 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_SetExitStatus --
- *
- * Sets the exit status for stream's request. The exit status
- * is the status code the request would have exited with, had
- * the request been run as a CGI program. You can call
- * SetExitStatus several times during a request; the last call
- * before the request ends determines the value.
- *
- *----------------------------------------------------------------------
- */
-
-void FCGX_SetExitStatus(int status, FCGX_Stream *stream)
-{
- FCGX_Stream_Data *data = (FCGX_Stream_Data *)stream->data;
- data->reqDataPtr->appStatus = status;
-}
-
diff --git a/sapi/cgi/libfcgi/include/fastcgi.h b/sapi/cgi/libfcgi/include/fastcgi.h
deleted file mode 100644
index 36b4725ba1..0000000000
--- a/sapi/cgi/libfcgi/include/fastcgi.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * fastcgi.h --
- *
- * Defines for the FastCGI protocol.
- *
- *
- * Copyright (c) 1995-1996 Open Market, Inc.
- *
- * See the file "LICENSE.TERMS" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * $Id$
- */
-
-#ifndef _FASTCGI_H
-#define _FASTCGI_H
-
-/*
- * Listening socket file number
- */
-#define FCGI_LISTENSOCK_FILENO 0
-
-typedef struct {
- unsigned char version;
- unsigned char type;
- unsigned char requestIdB1;
- unsigned char requestIdB0;
- unsigned char contentLengthB1;
- unsigned char contentLengthB0;
- unsigned char paddingLength;
- unsigned char reserved;
-} FCGI_Header;
-
-#define FCGI_MAX_LENGTH 0xffff
-
-/*
- * Number of bytes in a FCGI_Header. Future versions of the protocol
- * will not reduce this number.
- */
-#define FCGI_HEADER_LEN 8
-
-/*
- * Value for version component of FCGI_Header
- */
-#define FCGI_VERSION_1 1
-
-/*
- * Values for type component of FCGI_Header
- */
-#define FCGI_BEGIN_REQUEST 1
-#define FCGI_ABORT_REQUEST 2
-#define FCGI_END_REQUEST 3
-#define FCGI_PARAMS 4
-#define FCGI_STDIN 5
-#define FCGI_STDOUT 6
-#define FCGI_STDERR 7
-#define FCGI_DATA 8
-#define FCGI_GET_VALUES 9
-#define FCGI_GET_VALUES_RESULT 10
-#define FCGI_UNKNOWN_TYPE 11
-#define FCGI_MAXTYPE (FCGI_UNKNOWN_TYPE)
-
-/*
- * Value for requestId component of FCGI_Header
- */
-#define FCGI_NULL_REQUEST_ID 0
-
-
-typedef struct {
- unsigned char roleB1;
- unsigned char roleB0;
- unsigned char flags;
- unsigned char reserved[5];
-} FCGI_BeginRequestBody;
-
-typedef struct {
- FCGI_Header header;
- FCGI_BeginRequestBody body;
-} FCGI_BeginRequestRecord;
-
-/*
- * Mask for flags component of FCGI_BeginRequestBody
- */
-#define FCGI_KEEP_CONN 1
-
-/*
- * Values for role component of FCGI_BeginRequestBody
- */
-#define FCGI_RESPONDER 1
-#define FCGI_AUTHORIZER 2
-#define FCGI_FILTER 3
-
-
-typedef struct {
- unsigned char appStatusB3;
- unsigned char appStatusB2;
- unsigned char appStatusB1;
- unsigned char appStatusB0;
- unsigned char protocolStatus;
- unsigned char reserved[3];
-} FCGI_EndRequestBody;
-
-typedef struct {
- FCGI_Header header;
- FCGI_EndRequestBody body;
-} FCGI_EndRequestRecord;
-
-/*
- * Values for protocolStatus component of FCGI_EndRequestBody
- */
-#define FCGI_REQUEST_COMPLETE 0
-#define FCGI_CANT_MPX_CONN 1
-#define FCGI_OVERLOADED 2
-#define FCGI_UNKNOWN_ROLE 3
-
-
-/*
- * Variable names for FCGI_GET_VALUES / FCGI_GET_VALUES_RESULT records
- */
-#define FCGI_MAX_CONNS "FCGI_MAX_CONNS"
-#define FCGI_MAX_REQS "FCGI_MAX_REQS"
-#define FCGI_MPXS_CONNS "FCGI_MPXS_CONNS"
-
-
-typedef struct {
- unsigned char type;
- unsigned char reserved[7];
-} FCGI_UnknownTypeBody;
-
-typedef struct {
- FCGI_Header header;
- FCGI_UnknownTypeBody body;
-} FCGI_UnknownTypeRecord;
-
-#endif /* _FASTCGI_H */
-
diff --git a/sapi/cgi/libfcgi/include/fcgi_config.h b/sapi/cgi/libfcgi/include/fcgi_config.h
deleted file mode 100644
index 22256df328..0000000000
--- a/sapi/cgi/libfcgi/include/fcgi_config.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* hack workaround for libfcgi configure */
-#ifdef _WIN32
-#include "fcgi_config_win32.h"
-#else
-#include "main/php_config.h"
-#endif
-
diff --git a/sapi/cgi/libfcgi/include/fcgi_config_win32.h b/sapi/cgi/libfcgi/include/fcgi_config_win32.h
deleted file mode 100644
index 81ff264d9f..0000000000
--- a/sapi/cgi/libfcgi/include/fcgi_config_win32.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/* fcgi_config.h. Generated automatically by configure. */
-/* fcgi_config.h.in. Generated automatically from configure.in by autoheader. */
-
-/* Define if you have the <arpa/inet.h> header file. */
-#define HAVE_ARPA_INET_H 1
-
-/* Define if you have the <dlfcn.h> header file. */
-#define HAVE_DLFCN_H 1
-
-/* Define if there's a fileno() prototype in stdio.h */
-#define HAVE_FILENO_PROTO 1
-
-/* Define if the fpos_t typedef is in stdio.h */
-#define HAVE_FPOS 1
-
-/* Define if you have the <inttypes.h> header file. */
-#define HAVE_INTTYPES_H 1
-
-/* Define if you have the `dnet_stub' library (-ldnet_stub). */
-/* #undef HAVE_LIBDNET_STUB */
-
-/* Define if you have the `ieee' library (-lieee). */
-/* #undef HAVE_LIBIEEE */
-
-/* Define if you have the `nsl' library (-lnsl). */
-#define HAVE_LIBNSL 1
-
-/* Define if you have the pthread library */
-#define HAVE_LIBPTHREAD 1
-
-/* Define if you have the `resolv' library (-lresolv). */
-#define HAVE_LIBRESOLV 1
-
-/* Define if you have the `socket' library (-lsocket). */
-#define HAVE_LIBSOCKET 1
-
-/* Define if you have the <limits.h> header file. */
-#define HAVE_LIMITS_H 1
-
-/* Define if you have the <memory.h> header file. */
-#define HAVE_MEMORY_H 1
-
-/* Define if you have the <netdb.h> header file. */
-/* #define HAVE_NETDB_H 1 */
-
-/* Define if you have the <netinet/in.h> header file. */
-#define HAVE_NETINET_IN_H 1
-
-/* Define if sockaddr_un in sys/un.h contains a sun_len component */
-/* #undef HAVE_SOCKADDR_UN_SUN_LEN */
-
-/* Define if the socklen_t typedef is in sys/socket.h */
-/* #undef HAVE_SOCKLEN */
-
-/* Define if you have the <stdint.h> header file. */
-/* #undef HAVE_STDINT_H */
-
-/* Define if you have the <stdlib.h> header file. */
-#define HAVE_STDLIB_H 1
-
-/* Define if you have the `strerror' function. */
-#define HAVE_STRERROR 1
-
-/* Define if you have the <strings.h> header file. */
-#define HAVE_STRINGS_H 1
-
-/* Define if you have the <string.h> header file. */
-#define HAVE_STRING_H 1
-
-/* Define if you have the <sys/param.h> header file. */
-/* #define HAVE_SYS_PARAM_H 1 */
-
-/* Define if you have the <sys/socket.h> header file. */
-/*#define HAVE_SYS_SOCKET_H 1*/
-
-/* Define if you have the <sys/stat.h> header file. */
-#define HAVE_SYS_STAT_H 1
-
-/* Define if you have the <sys/time.h> header file. */
-/*#define HAVE_SYS_TIME_H 1*/
-
-/* Define if you have the <sys/types.h> header file. */
-#define HAVE_SYS_TYPES_H 1
-
-/* Define if you have the <unistd.h> header file. */
-/*#define HAVE_UNISTD_H 1*/
-
-/* Define if va_arg(arg, long double) crashes the compiler */
-/* #undef HAVE_VA_ARG_LONG_DOUBLE_BUG */
-
-/* Name of package */
-#define PACKAGE "fcgi"
-
-/* Define if you have the ANSI C header files. */
-#define STDC_HEADERS 1
-
-/* Define if cross-process locking is required by accept() */
-#define USE_LOCKING 1
-
-/* Version number of package */
-#define VERSION "2.2.2"
-
-/* Define to empty if `const' does not conform to ANSI C. */
-/* #undef const */
-
-/* Define as `__inline' if that's what the C compiler calls it, or to nothing
- if it is not supported. */
-/* #undef inline */
-
-/* Define to `int' if <sys/types.h> does not define. */
-#define ssize_t int \ No newline at end of file
diff --git a/sapi/cgi/libfcgi/include/fcgi_config_x86.h b/sapi/cgi/libfcgi/include/fcgi_config_x86.h
deleted file mode 100644
index f56b3af75d..0000000000
--- a/sapi/cgi/libfcgi/include/fcgi_config_x86.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Default fcgi_config.h when building on WinNT (configure is not run).
- */
-
-/* Define if you have the <arpa/inet.h> header file. */
-#undef HAVE_ARPA_INET_H
-
-/* Define if there's a fileno() prototype in stdio.h */
-#undef HAVE_FILENO_PROTO
-
-/* Define if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* Define if we have f{set,get}pos functions */
-#define HAVE_FPOS 1
-
-/* Define if you have the `dnet_stub' library (-ldnet_stub). */
-#undef HAVE_LIBDNET_STUB
-
-/* Define if you have the `ieee' library (-lieee). */
-#undef HAVE_LIBIEEE
-
-/* Define if you have the `nsl' library (-lnsl). */
-#undef HAVE_LIBNSL
-
-/* Define if you have the pthread library */
-#undef HAVE_LIBPTHREAD
-
-/* Define if you have the `resolv' library (-lresolv). */
-#undef HAVE_LIBRESOLV
-
-/* Define if you have the `socket' library (-lsocket). */
-#undef HAVE_LIBSOCKET
-
-/* Define if you have the <limits.h> header file. */
-#define HAVE_LIMITS_H 1
-
-/* Define if we need cross-process locking */
-#undef USE_LOCKING
-
-/* Define if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Define if you have the <netdb.h> header file. */
-#undef HAVE_NETDB_H
-
-/* Define if you have the <netinet/in.h> header file. */
-#undef HAVE_NETINET_IN_H
-
-/* Define if sockaddr_un in sys/un.h contains a sun_len component */
-#undef HAVE_SOCKADDR_UN_SUN_LEN
-
-/* Define if the socklen_t typedef is in sys/socket.h */
-#undef HAVE_SOCKLEN
-
-/* Define if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define if you have the `strerror' function. */
-#define HAVE_STRERROR 1
-
-/* Define if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define if you have the <sys/param.h> header file. */
-#undef HAVE_SYS_PARAM_H
-
-/* Define if you have the <sys/socket.h> header file. */
-#undef HAVE_SYS_SOCKET_H
-
-/* Define if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define if you have the <sys/time.h> header file. */
-#undef HAVE_SYS_TIME_H
-
-/* Define if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Define if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* Define if va_arg(arg, long double) crashes the compiler */
-#undef HAVE_VA_ARG_LONG_DOUBLE_BUG
-
-/* Define if you have the ANSI C header files. */
-#undef STDC_HEADERS
-
-/* Define to empty if `const' does not conform to ANSI C. */
-#undef const
-
-/* Define as `__inline' if that's what the C compiler calls it, or to nothing
- if it is not supported. */
-#undef inline
-
-/* Define to `int' if <sys/types.h> does not define. */
-#undef ssize_t
diff --git a/sapi/cgi/libfcgi/include/fcgi_stdio.h b/sapi/cgi/libfcgi/include/fcgi_stdio.h
deleted file mode 100644
index 518462b591..0000000000
--- a/sapi/cgi/libfcgi/include/fcgi_stdio.h
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * fcgi_stdio.h --
- *
- * FastCGI-stdio compatibility package
- *
- *
- * Copyright (c) 1996 Open Market, Inc.
- *
- * See the file "LICENSE.TERMS" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * $Id$
- */
-
-#ifndef _FCGI_STDIO
-#define _FCGI_STDIO 1
-
-#include <stdio.h>
-#include <sys/types.h>
-#include "fcgiapp.h"
-
-#if defined (c_plusplus) || defined (__cplusplus)
-extern "C" {
-#endif
-
-#ifndef DLLAPI
-#ifdef _WIN32
-#if defined(_LIB) || defined(FCGI_STATIC)
-#define DLLAPI
-#else
-#define DLLAPI __declspec(dllimport)
-#endif
-#else
-#define DLLAPI
-#endif
-#endif
-
-/*
- * Wrapper type for FILE
- */
-
-typedef struct {
- FILE *stdio_stream;
- FCGX_Stream *fcgx_stream;
-} FCGI_FILE;
-
-/*
- * The four new functions and two new macros
- */
-
-DLLAPI int FCGI_Accept(void);
-DLLAPI void FCGI_Finish(void);
-DLLAPI int FCGI_StartFilterData(void);
-DLLAPI void FCGI_SetExitStatus(int status);
-
-#define FCGI_ToFILE(fcgi_file) (fcgi_file->stdio_stream)
-#define FCGI_ToFcgiStream(fcgi_file) (fcgi_file->fcgx_stream)
-
-/*
- * Wrapper stdin, stdout, and stderr variables, set up by FCGI_Accept()
- */
-
-DLLAPI extern FCGI_FILE _fcgi_sF[];
-#define FCGI_stdin (&_fcgi_sF[0])
-#define FCGI_stdout (&_fcgi_sF[1])
-#define FCGI_stderr (&_fcgi_sF[2])
-
-/*
- * Wrapper function prototypes, grouped according to sections
- * of Harbison & Steele, "C: A Reference Manual," fourth edition,
- * Prentice-Hall, 1995.
- */
-
-DLLAPI void FCGI_perror(const char *str);
-
-DLLAPI FCGI_FILE *FCGI_fopen(const char *path, const char *mode);
-DLLAPI int FCGI_fclose(FCGI_FILE *fp);
-DLLAPI int FCGI_fflush(FCGI_FILE *fp);
-DLLAPI FCGI_FILE *FCGI_freopen(const char *path, const char *mode, FCGI_FILE *fp);
-
-DLLAPI int FCGI_setvbuf(FCGI_FILE *fp, char *buf, int bufmode, size_t size);
-DLLAPI void FCGI_setbuf(FCGI_FILE *fp, char *buf);
-
-DLLAPI int FCGI_fseek(FCGI_FILE *fp, long offset, int whence);
-DLLAPI int FCGI_ftell(FCGI_FILE *fp);
-DLLAPI void FCGI_rewind(FCGI_FILE *fp);
-#ifdef HAVE_FPOS
-DLLAPI int FCGI_fgetpos(FCGI_FILE *fp, fpos_t *pos);
-DLLAPI int FCGI_fsetpos(FCGI_FILE *fp, const fpos_t *pos);
-#endif
-DLLAPI int FCGI_fgetc(FCGI_FILE *fp);
-DLLAPI int FCGI_getchar(void);
-DLLAPI int FCGI_ungetc(int c, FCGI_FILE *fp);
-
-DLLAPI char *FCGI_fgets(char *str, int size, FCGI_FILE *fp);
-DLLAPI char *FCGI_gets(char *str);
-
-/*
- * Not yet implemented
- *
- * int FCGI_fscanf(FCGI_FILE *fp, const char *format, ...);
- * int FCGI_scanf(const char *format, ...);
- *
- */
-
-DLLAPI int FCGI_fputc(int c, FCGI_FILE *fp);
-DLLAPI int FCGI_putchar(int c);
-
-DLLAPI int FCGI_fputs(const char *str, FCGI_FILE *fp);
-DLLAPI int FCGI_puts(const char *str);
-
-DLLAPI int FCGI_fprintf(FCGI_FILE *fp, const char *format, ...);
-DLLAPI int FCGI_printf(const char *format, ...);
-
-DLLAPI int FCGI_vfprintf(FCGI_FILE *fp, const char *format, va_list ap);
-DLLAPI int FCGI_vprintf(const char *format, va_list ap);
-
-DLLAPI size_t FCGI_fread(void *ptr, size_t size, size_t nmemb, FCGI_FILE *fp);
-DLLAPI size_t FCGI_fwrite(void *ptr, size_t size, size_t nmemb, FCGI_FILE *fp);
-
-DLLAPI int FCGI_feof(FCGI_FILE *fp);
-DLLAPI int FCGI_ferror(FCGI_FILE *fp);
-DLLAPI void FCGI_clearerr(FCGI_FILE *fp);
-
-DLLAPI FCGI_FILE *FCGI_tmpfile(void);
-
-DLLAPI int FCGI_fileno(FCGI_FILE *fp);
-DLLAPI FCGI_FILE *FCGI_fdopen(int fd, const char *mode);
-DLLAPI FCGI_FILE *FCGI_popen(const char *cmd, const char *type);
-DLLAPI int FCGI_pclose(FCGI_FILE *);
-
-/*
- * The remaining definitions are for application programs,
- * not for fcgi_stdio.c
- */
-
-#ifndef NO_FCGI_DEFINES
-
-/*
- * Replace standard types, variables, and functions with FastCGI wrappers.
- * Use undef in case a macro is already defined.
- */
-
-#undef FILE
-#define FILE FCGI_FILE
-
-#undef stdin
-#define stdin FCGI_stdin
-#undef stdout
-#define stdout FCGI_stdout
-#undef stderr
-#define stderr FCGI_stderr
-
-#undef perror
-#define perror FCGI_perror
-
-#undef fopen
-#define fopen FCGI_fopen
-#undef fclose
-#define fclose FCGI_fclose
-#undef fflush
-#define fflush FCGI_fflush
-#undef freopen
-#define freopen FCGI_freopen
-
-#undef setvbuf
-#define setvbuf FCGI_setvbuf
-#undef setbuf
-#define setbuf FCGI_setbuf
-
-#undef fseek
-#define fseek FCGI_fseek
-#undef ftell
-#define ftell FCGI_ftell
-#undef rewind
-#define rewind FCGI_rewind
-#undef fgetpos
-#define fgetpos FCGI_fgetpos
-#undef fsetpos
-#define fsetpos FCGI_fsetpos
-
-#undef fgetc
-#define fgetc FCGI_fgetc
-#undef getc
-#define getc FCGI_fgetc
-#undef getchar
-#define getchar FCGI_getchar
-#undef ungetc
-#define ungetc FCGI_ungetc
-
-#undef fgets
-#define fgets FCGI_fgets
-#undef gets
-#define gets FCGI_gets
-
-#undef fputc
-#define fputc FCGI_fputc
-#undef putc
-#define putc FCGI_fputc
-#undef putchar
-#define putchar FCGI_putchar
-
-#undef fputs
-#define fputs FCGI_fputs
-#undef puts
-#define puts FCGI_puts
-
-#undef fprintf
-#define fprintf FCGI_fprintf
-#undef printf
-#define printf FCGI_printf
-
-#undef vfprintf
-#define vfprintf FCGI_vfprintf
-#undef vprintf
-#define vprintf FCGI_vprintf
-
-#undef fread
-#define fread FCGI_fread
-#undef fwrite
-#define fwrite FCGI_fwrite
-
-#undef feof
-#define feof FCGI_feof
-#undef ferror
-#define ferror FCGI_ferror
-#undef clearerr
-#define clearerr FCGI_clearerr
-
-#undef tmpfile
-#define tmpfile FCGI_tmpfile
-
-#undef fileno
-#define fileno FCGI_fileno
-#undef fdopen
-#define fdopen FCGI_fdopen
-#undef popen
-#define popen FCGI_popen
-#undef pclose
-#define pclose FCGI_pclose
-
-#endif /* NO_FCGI_DEFINES */
-
-#if defined (__cplusplus) || defined (c_plusplus)
-} /* terminate extern "C" { */
-#endif
-
-#endif /* _FCGI_STDIO */
-
diff --git a/sapi/cgi/libfcgi/include/fcgiapp.h b/sapi/cgi/libfcgi/include/fcgiapp.h
deleted file mode 100644
index 8e35e0776c..0000000000
--- a/sapi/cgi/libfcgi/include/fcgiapp.h
+++ /dev/null
@@ -1,640 +0,0 @@
-/*
- * fcgiapp.h --
- *
- * Definitions for FastCGI application server programs
- *
- *
- * Copyright (c) 1996 Open Market, Inc.
- *
- * See the file "LICENSE.TERMS" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * $Id$
- */
-
-#ifndef _FCGIAPP_H
-#define _FCGIAPP_H
-
-/* Hack to see if we are building TCL - TCL needs varargs not stdarg */
-#ifndef TCL_LIBRARY
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-#ifndef DLLAPI
-#ifdef _WIN32
-#if defined(_LIB) || defined(FCGI_STATIC)
-#define DLLAPI
-#else
-#define DLLAPI __declspec(dllimport)
-#endif
-#else
-#define DLLAPI
-#endif
-#endif
-
-#if defined (c_plusplus) || defined (__cplusplus)
-extern "C" {
-#endif
-
-/*
- * Error codes. Assigned to avoid conflict with EOF and errno(2).
- */
-#define FCGX_UNSUPPORTED_VERSION -2
-#define FCGX_PROTOCOL_ERROR -3
-#define FCGX_PARAMS_ERROR -4
-#define FCGX_CALL_SEQ_ERROR -5
-
-/*
- * This structure defines the state of a FastCGI stream.
- * Streams are modeled after the FILE type defined in stdio.h.
- * (We wouldn't need our own if platform vendors provided a
- * standard way to subclass theirs.)
- * The state of a stream is private and should only be accessed
- * by the procedures defined below.
- */
-typedef struct FCGX_Stream {
- unsigned char *rdNext; /* reader: first valid byte
- * writer: equals stop */
- unsigned char *wrNext; /* writer: first free byte
- * reader: equals stop */
- unsigned char *stop; /* reader: last valid byte + 1
- * writer: last free byte + 1 */
- unsigned char *stopUnget; /* reader: first byte of current buffer
- * fragment, for ungetc
- * writer: undefined */
- int isReader;
- int isClosed;
- int wasFCloseCalled;
- int FCGI_errno; /* error status */
- void (*fillBuffProc) (struct FCGX_Stream *stream);
- void (*emptyBuffProc) (struct FCGX_Stream *stream, int doClose);
- void *data;
-} FCGX_Stream;
-
-/*
- * An environment (as defined by environ(7)): A NULL-terminated array
- * of strings, each string having the form name=value.
- */
-typedef char **FCGX_ParamArray;
-
-/*
- * A vector of pointers representing the parameters received
- * by a FastCGI application server, with the vector's length
- * and last valid element so adding new parameters is efficient.
- */
-
-typedef struct Params {
- FCGX_ParamArray vec; /* vector of strings */
- int length; /* number of string vec can hold */
- char **cur; /* current item in vec; *cur == NULL */
-} Params;
-typedef Params *ParamsPtr;
-
-/*
- * FCGX_Request Flags
- *
- * Setting FCGI_FAIL_ACCEPT_ON_INTR prevents FCGX_Accept() from
- * restarting upon being interrupted.
- */
-#define FCGI_FAIL_ACCEPT_ON_INTR 1
-
-/*
- * FCGX_Request -- State associated with a request.
- *
- * Its exposed for API simplicity, I expect parts of it to change!
- */
-typedef struct FCGX_Request {
- int requestId; /* valid if isBeginProcessed */
- int role;
- FCGX_Stream *in;
- FCGX_Stream *out;
- FCGX_Stream *err;
- FCGX_ParamArray envp;
-
- /* Don't use anything below here */
-
- ParamsPtr paramsPtr;
- int ipcFd; /* < 0 means no connection */
- int isBeginProcessed; /* FCGI_BEGIN_REQUEST seen */
- int keepConnection; /* don't close ipcFd at end of request */
- int appStatus;
- int nWriters; /* number of open writers (0..2) */
- int flags;
- int listen_sock;
-} FCGX_Request;
-
-
-/*
- *======================================================================
- * Control
- *======================================================================
- */
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_IsCGI --
- *
- * Returns TRUE iff this process appears to be a CGI process
- * rather than a FastCGI process.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_IsCGI(void);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Init --
- *
- * Initialize the FCGX library. Call in multi-threaded apps
- * before calling FCGX_Accept_r().
- *
- * Returns 0 upon success.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_Init(void);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_OpenSocket --
- *
- * Create a FastCGI listen socket.
- *
- * path is the Unix domain socket (named pipe for WinNT), or a colon
- * followed by a port number. e.g. "/tmp/fastcgi/mysocket", ":5000"
- *
- * backlog is the listen queue depth used in the listen() call.
- *
- * Returns the socket's file descriptor or -1 on error.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_OpenSocket(const char *path, int backlog);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_InitRequest --
- *
- * Initialize a FCGX_Request for use with FCGX_Accept_r().
- *
- * sock is a file descriptor returned by FCGX_OpenSocket() or 0 (default).
- * The only supported flag at this time is FCGI_FAIL_ON_INTR.
- *
- * Returns 0 upon success.
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_InitRequest(FCGX_Request *request, int sock, int flags);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Accept_r --
- *
- * Accept a new request (multi-thread safe). Be sure to call
- * FCGX_Init() first.
- *
- * Results:
- * 0 for successful call, -1 for error.
- *
- * Side effects:
- *
- * Finishes the request accepted by (and frees any
- * storage allocated by) the previous call to FCGX_Accept.
- * Creates input, output, and error streams and
- * assigns them to *in, *out, and *err respectively.
- * Creates a parameters data structure to be accessed
- * via getenv(3) (if assigned to environ) or by FCGX_GetParam
- * and assigns it to *envp.
- *
- * DO NOT retain pointers to the envp array or any strings
- * contained in it (e.g. to the result of calling FCGX_GetParam),
- * since these will be freed by the next call to FCGX_Finish
- * or FCGX_Accept.
- *
- * DON'T use the FCGX_Request, its structure WILL change.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_Accept_r(FCGX_Request *request);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Finish_r --
- *
- * Finish the request (multi-thread safe).
- *
- * Side effects:
- *
- * Finishes the request accepted by (and frees any
- * storage allocated by) the previous call to FCGX_Accept.
- *
- * DO NOT retain pointers to the envp array or any strings
- * contained in it (e.g. to the result of calling FCGX_GetParam),
- * since these will be freed by the next call to FCGX_Finish
- * or FCGX_Accept.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI void FCGX_Finish_r(FCGX_Request *request);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Free --
- *
- * Free the memory and, if close is true,
- * IPC FD associated with the request (multi-thread safe).
- *
- *----------------------------------------------------------------------
- */
-DLLAPI void FCGX_Free(FCGX_Request * request, int close);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Accept --
- *
- * Accept a new request (NOT multi-thread safe).
- *
- * Results:
- * 0 for successful call, -1 for error.
- *
- * Side effects:
- *
- * Finishes the request accepted by (and frees any
- * storage allocated by) the previous call to FCGX_Accept.
- * Creates input, output, and error streams and
- * assigns them to *in, *out, and *err respectively.
- * Creates a parameters data structure to be accessed
- * via getenv(3) (if assigned to environ) or by FCGX_GetParam
- * and assigns it to *envp.
- *
- * DO NOT retain pointers to the envp array or any strings
- * contained in it (e.g. to the result of calling FCGX_GetParam),
- * since these will be freed by the next call to FCGX_Finish
- * or FCGX_Accept.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_Accept(
- FCGX_Stream **in,
- FCGX_Stream **out,
- FCGX_Stream **err,
- FCGX_ParamArray *envp);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_Finish --
- *
- * Finish the current request (NOT multi-thread safe).
- *
- * Side effects:
- *
- * Finishes the request accepted by (and frees any
- * storage allocated by) the previous call to FCGX_Accept.
- *
- * DO NOT retain pointers to the envp array or any strings
- * contained in it (e.g. to the result of calling FCGX_GetParam),
- * since these will be freed by the next call to FCGX_Finish
- * or FCGX_Accept.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI void FCGX_Finish(void);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_StartFilterData --
- *
- * stream is an input stream for a FCGI_FILTER request.
- * stream is positioned at EOF on FCGI_STDIN.
- * Repositions stream to the start of FCGI_DATA.
- * If the preconditions are not met (e.g. FCGI_STDIN has not
- * been read to EOF) sets the stream error code to
- * FCGX_CALL_SEQ_ERROR.
- *
- * Results:
- * 0 for a normal return, < 0 for error
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_StartFilterData(FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_SetExitStatus --
- *
- * Sets the exit status for stream's request. The exit status
- * is the status code the request would have exited with, had
- * the request been run as a CGI program. You can call
- * SetExitStatus several times during a request; the last call
- * before the request ends determines the value.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI void FCGX_SetExitStatus(int status, FCGX_Stream *stream);
-
-/*
- *======================================================================
- * Parameters
- *======================================================================
- */
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_GetParam -- obtain value of FCGI parameter in environment
- *
- *
- * Results:
- * Value bound to name, NULL if name not present in the
- * environment envp. Caller must not mutate the result
- * or retain it past the end of this request.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI char *FCGX_GetParam(const char *name, FCGX_ParamArray envp);
-DLLAPI void FCGX_PutEnv(FCGX_Request *request, char *nameValue);
-
-/*
- *======================================================================
- * Readers
- *======================================================================
- */
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_GetChar --
- *
- * Reads a byte from the input stream and returns it.
- *
- * Results:
- * The byte, or EOF (-1) if the end of input has been reached.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_GetChar(FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_UnGetChar --
- *
- * Pushes back the character c onto the input stream. One
- * character of pushback is guaranteed once a character
- * has been read. No pushback is possible for EOF.
- *
- * Results:
- * Returns c if the pushback succeeded, EOF if not.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_UnGetChar(int c, FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_GetStr --
- *
- * Reads up to n consecutive bytes from the input stream
- * into the character array str. Performs no interpretation
- * of the input bytes.
- *
- * Results:
- * Number of bytes read. If result is smaller than n,
- * the end of input has been reached.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_GetStr(char *str, int n, FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_GetLine --
- *
- * Reads up to n-1 consecutive bytes from the input stream
- * into the character array str. Stops before n-1 bytes
- * have been read if '\n' or EOF is read. The terminating '\n'
- * is copied to str. After copying the last byte into str,
- * stores a '\0' terminator.
- *
- * Results:
- * NULL if EOF is the first thing read from the input stream,
- * str otherwise.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI char *FCGX_GetLine(char *str, int n, FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_HasSeenEOF --
- *
- * Returns EOF if end-of-file has been detected while reading
- * from stream; otherwise returns 0.
- *
- * Note that FCGX_HasSeenEOF(s) may return 0, yet an immediately
- * following FCGX_GetChar(s) may return EOF. This function, like
- * the standard C stdio function feof, does not provide the
- * ability to peek ahead.
- *
- * Results:
- * EOF if end-of-file has been detected, 0 if not.
- *
- *----------------------------------------------------------------------
- */
-
-DLLAPI int FCGX_HasSeenEOF(FCGX_Stream *stream);
-
-/*
- *======================================================================
- * Writers
- *======================================================================
- */
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_PutChar --
- *
- * Writes a byte to the output stream.
- *
- * Results:
- * The byte, or EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_PutChar(int c, FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_PutStr --
- *
- * Writes n consecutive bytes from the character array str
- * into the output stream. Performs no interpretation
- * of the output bytes.
- *
- * Results:
- * Number of bytes written (n) for normal return,
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_PutStr(const char *str, int n, FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_PutS --
- *
- * Writes a null-terminated character string to the output stream.
- *
- * Results:
- * number of bytes written for normal return,
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_PutS(const char *str, FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_FPrintF, FCGX_VFPrintF --
- *
- * Performs printf-style output formatting and writes the results
- * to the output stream.
- *
- * Results:
- * number of bytes written for normal return,
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_FPrintF(FCGX_Stream *stream, const char *format, ...);
-
-DLLAPI int FCGX_VFPrintF(FCGX_Stream *stream, const char *format, va_list arg);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_FFlush --
- *
- * Flushes any buffered output.
- *
- * Server-push is a legitimate application of FCGX_FFlush.
- * Otherwise, FCGX_FFlush is not very useful, since FCGX_Accept
- * does it implicitly. Calling FCGX_FFlush in non-push applications
- * results in extra writes and therefore reduces performance.
- *
- * Results:
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_FFlush(FCGX_Stream *stream);
-
-/*
- *======================================================================
- * Both Readers and Writers
- *======================================================================
- */
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_FClose --
- *
- * Closes the stream. For writers, flushes any buffered
- * output.
- *
- * Close is not a very useful operation since FCGX_Accept
- * does it implicitly. Closing the out stream before the
- * err stream results in an extra write if there's nothing
- * in the err stream, and therefore reduces performance.
- *
- * Results:
- * EOF (-1) if an error occurred.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_FClose(FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_GetError --
- *
- * Return the stream error code. 0 means no error, > 0
- * is an errno(2) error, < 0 is an FastCGI error.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI int FCGX_GetError(FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_ClearError --
- *
- * Clear the stream error code and end-of-file indication.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI void FCGX_ClearError(FCGX_Stream *stream);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_CreateWriter --
- *
- * Create a FCGX_Stream (used by cgi-fcgi). This shouldn't
- * be needed by a FastCGI applictaion.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI FCGX_Stream *FCGX_CreateWriter(
- int socket,
- int requestId,
- int bufflen,
- int streamType);
-
-/*
- *----------------------------------------------------------------------
- *
- * FCGX_FreeStream --
- *
- * Free a FCGX_Stream (used by cgi-fcgi). This shouldn't
- * be needed by a FastCGI applictaion.
- *
- *----------------------------------------------------------------------
- */
-DLLAPI void FCGX_FreeStream(FCGX_Stream **stream);
-
-/* ----------------------------------------------------------------------
- *
- * Prevent the lib from accepting any new requests. Signal handler safe.
- *
- * ----------------------------------------------------------------------
- */
-DLLAPI void FCGX_ShutdownPending(void);
-
-#if defined (__cplusplus) || defined (c_plusplus)
-} /* terminate extern "C" { */
-#endif
-
-#endif /* _FCGIAPP_H */
diff --git a/sapi/cgi/libfcgi/include/fcgiappmisc.h b/sapi/cgi/libfcgi/include/fcgiappmisc.h
deleted file mode 100644
index db8651a44b..0000000000
--- a/sapi/cgi/libfcgi/include/fcgiappmisc.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * fcgiappmisc.h --
- *
- * Functions implemented by fcgiapp.h that aren't needed
- * by normal applications, but may be useful to special
- * applications.
- *
- *
- * Copyright (c) 1996 Open Market, Inc.
- *
- * See the file "LICENSE.TERMS" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * $Id$
- */
-
-#ifndef _FCGIAPPMISC_H
-#define _FCGIAPPMISC_H
-
-#include "fcgiapp.h" /* for FCGX_Stream */
-
-#if defined (c_plusplus) || defined (__cplusplus)
-extern "C" {
-#endif
-
-#ifdef _WIN32
-#ifndef DLLAPI
-#ifdef FCGI_STATIC
-#define DLLAPI
-#else
-#define DLLAPI __declspec(dllimport)
-#endif
-#endif
-#else
-#define DLLAPI
-#endif
-
-DLLAPI FCGX_Stream *CreateWriter(
- int socket,
- int requestId,
- int bufflen,
- int streamType);
-
-DLLAPI void FreeStream(FCGX_Stream **stream);
-
-#if defined (__cplusplus) || defined (c_plusplus)
-} /* terminate extern "C" { */
-#endif
-
-#endif /* _FCGIAPPMISC_H */
diff --git a/sapi/cgi/libfcgi/include/fcgimisc.h b/sapi/cgi/libfcgi/include/fcgimisc.h
deleted file mode 100644
index 20ee4a0cf0..0000000000
--- a/sapi/cgi/libfcgi/include/fcgimisc.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * fcgimisc.h --
- *
- * Miscellaneous definitions
- *
- *
- * Copyright (c) 1996 Open Market, Inc.
- *
- * See the file "LICENSE.TERMS" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * $Id$
- */
-
-#ifndef _FCGIMISC_H
-#define _FCGIMISC_H
-
-#ifndef FALSE
-#define FALSE (0)
-#endif
-
-#ifndef TRUE
-#define TRUE (1)
-#endif
-
-#ifndef min
-#define min(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
-#ifndef max
-#define max(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
-#ifndef ASSERT
-#define ASSERT(assertion) assert(assertion)
-#endif
-
-#endif /* _FCGIMISC_H */
diff --git a/sapi/cgi/libfcgi/include/fcgio.h b/sapi/cgi/libfcgi/include/fcgio.h
deleted file mode 100644
index 865bff385b..0000000000
--- a/sapi/cgi/libfcgi/include/fcgio.h
+++ /dev/null
@@ -1,147 +0,0 @@
-//
-// Provides support for FastCGI via C++ iostreams.
-//
-// $Id$
-//
-// This work is based on routines written by George Feinberg. They
-// have been mostly re-written and extensively changed by
-// Michael Richards.
-//
-// Rewritten again with bug fixes and numerous enhancements by
-// Michael Shell.
-//
-// And rewritten again by Rob Saccoccio.
-//
-// Special Thanks to Dietmar Kuehl for his help and the numerous custom
-// streambuf examples on his web site.
-//
-// Copyright (c) 2000 Tux the Linux Penguin
-// Copyright (c) 2001 Rob Saccoccio and Chelsea Networks
-//
-// You are free to use this software without charge or royalty
-// as long as this notice is not removed or altered, and recognition
-// is given to the author(s)
-//
-// This code is offered as-is without any warranty either expressed or
-// implied; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. If it breaks, you get to keep
-// both halves.
-
-#ifndef FCGIO_H
-#define FCGIO_H
-
-#include <iostream.h>
-
-#include "fcgiapp.h"
-
-#ifndef DLLAPI
-#ifdef _WIN32
-#define DLLAPI __declspec(dllimport)
-#else
-#define DLLAPI
-#endif
-#endif
-
-/*
- * fcgi_streambuf
- */
-class fcgi_streambuf : public streambuf
-{
-public:
-
- // Note that if no buf is assigned (the default), iostream methods
- // such as peek(), unget() and putback() will fail. If a buf is
- // assigned, I/O is a bit less effecient and output streams will
- // have to be flushed (or the streambuf destroyed) before the next
- // call to "accept".
- DLLAPI fcgi_streambuf(FCGX_Stream * fcgx, char * buf, int len);
-
- DLLAPI fcgi_streambuf(char * buf, int len);
-
- DLLAPI fcgi_streambuf(FCGX_Stream * fcgx = NULL);
-
- DLLAPI ~fcgi_streambuf(void);
-
- DLLAPI int attach(FCGX_Stream * fcgx);
-
-protected:
-
- // Consume the put area (if buffered) and c (if c is not EOF).
- DLLAPI virtual int overflow(int);
-
- // Flush the put area (if buffered) and the FCGX buffer to the client.
- DLLAPI virtual int sync();
-
- // Remove and return the current character.
- DLLAPI virtual int uflow();
-
- // Fill the get area (if buffered) and return the current character.
- DLLAPI virtual int underflow();
-
- // Use a buffer. The only reasons that a buffer would be useful is
- // to support the use of the unget()/putback() or seek() methods. Using
- // a buffer will result in less efficient I/O. Note: the underlying
- // FastCGI library (FCGX) maintains its own input and output buffers.
- DLLAPI virtual streambuf * setbuf(char * buf, int len);
-
- DLLAPI virtual int xsgetn(char * s, int n);
- DLLAPI virtual int xsputn(const char * s, int n);
-
-private:
-
- FCGX_Stream * fcgx;
-
- // buf is just handy to have around
- char * buf;
-
- // this isn't kept by the base class
- int bufsize;
-
- void init(FCGX_Stream * fcgx, char * buf, int bufsize);
-
- void reset(void);
-};
-
-/*
- * fcgi_istream - deprecated
- */
-class fcgi_istream : public istream
-{
-public:
-
- // deprecated
- DLLAPI fcgi_istream(FCGX_Stream * fcgx = NULL);
-
- // deprecated
- DLLAPI ~fcgi_istream(void) {}
-
- // deprecated
- DLLAPI virtual void attach(FCGX_Stream * fcgx);
-
-private:
-
- fcgi_streambuf fcgi_strmbuf;
-};
-
-/*
- * fcgi_ostream - deprecated
- */
-class fcgi_ostream : public ostream
-{
-public:
-
- // deprecated
- DLLAPI fcgi_ostream(FCGX_Stream * fcgx = NULL);
-
- // deprecated
- DLLAPI ~fcgi_ostream(void) {}
-
- // deprecated
- DLLAPI virtual void attach(FCGX_Stream *fcgx);
-
-private:
-
- fcgi_streambuf fcgi_strmbuf;
-};
-
-#endif /* FCGIO_H */
diff --git a/sapi/cgi/libfcgi/include/fcgios.h b/sapi/cgi/libfcgi/include/fcgios.h
deleted file mode 100644
index e0f8373fb7..0000000000
--- a/sapi/cgi/libfcgi/include/fcgios.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * fcgios.h --
- *
- * Description of file.
- *
- *
- * Copyright (c) 1996 Open Market, Inc.
- * All rights reserved.
- *
- * This file contains proprietary and confidential information and
- * remains the unpublished property of Open Market, Inc. Use,
- * disclosure, or reproduction is prohibited except as permitted by
- * express written license agreement with Open Market, Inc.
- *
- * Bill Snapper
- * snapper@openmarket.com
- */
-#ifndef _FCGIOS_H
-#define _FCGIOS_H
-
-#ifdef _WIN32
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <winsock2.h>
-#endif
-
-#include "fcgi_config.h"
-
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
-#if defined (c_plusplus) || defined (__cplusplus)
-extern "C" {
-#endif
-
-#ifdef _WIN32
-#define OS_Errno GetLastError()
-#define OS_SetErrno(err) SetLastError(err)
-#ifndef O_NONBLOCK
-#define O_NONBLOCK 0x0004 /* no delay */
-#endif
-#else /* !_WIN32 */
-#define OS_Errno errno
-#define OS_SetErrno(err) errno = (err)
-#endif /* !_WIN32 */
-
-#ifndef DLLAPI
-#ifdef _WIN32
-#if defined(_LIB) || defined(FCGI_STATIC)
-#define DLLAPI
-#else
-#define DLLAPI __declspec(dllimport)
-#endif
-#else
-#define DLLAPI
-#endif
-#endif
-
-
-/* This is the initializer for a "struct timeval" used in a select() call
- * right after a new request is accept()ed to determine readablity. Its
- * a drop-dead timer. Its only used for AF_UNIX sockets (not TCP sockets).
- * Its a workaround for a kernel bug in Linux 2.0.x and SCO Unixware.
- * Making this as small as possible, yet remain reliable would be best.
- * 2 seconds is very conservative. 0,0 is not reliable. The shorter the
- * timeout, the faster request processing will recover. The longer the
- * timeout, the more likely this application being "busy" will cause other
- * requests to abort and cause more dead sockets that need this timeout. */
-#define READABLE_UNIX_FD_DROP_DEAD_TIMEVAL 2,0
-
-#ifndef STDIN_FILENO
-#define STDIN_FILENO 0
-#endif
-
-#ifndef STDOUT_FILENO
-#define STDOUT_FILENO 1
-#endif
-
-#ifndef STDERR_FILENO
-#define STDERR_FILENO 2
-#endif
-
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 1024
-#endif
-
-#ifndef X_OK
-#define X_OK 0x01
-#endif
-
-#ifndef _CLIENTDATA
-# if defined(__STDC__) || defined(__cplusplus)
- typedef void *ClientData;
-# else
- typedef int *ClientData;
-# endif /* __STDC__ */
-#define _CLIENTDATA
-#endif
-#define MUTEX_VARNAME "_FCGI_MUTEX_"
-#define SHUTDOWN_EVENT_NAME "_FCGI_SHUTDOWN_EVENT_"
-
-typedef void (*OS_AsyncProc) (ClientData clientData, int len);
-
-DLLAPI int OS_LibInit(int stdioFds[3]);
-DLLAPI void OS_LibShutdown(void);
-DLLAPI int OS_CreateLocalIpcFd(const char *bindPath, int backlog, int bCreateMutex);
-DLLAPI int OS_FcgiConnect(char *bindPath);
-DLLAPI int OS_Read(int fd, char * buf, size_t len);
-DLLAPI int OS_Write(int fd, char * buf, size_t len);
-#ifdef _WIN32
-DLLAPI int OS_SpawnChild(char *execPath, int listenFd, PROCESS_INFORMATION *pInfo, char *env);
-#else
-DLLAPI int OS_SpawnChild(char *execPath, int listenfd);
-#endif
-DLLAPI int OS_AsyncReadStdin(void *buf, int len, OS_AsyncProc procPtr,
- ClientData clientData);
-DLLAPI int OS_AsyncRead(int fd, int offset, void *buf, int len,
- OS_AsyncProc procPtr, ClientData clientData);
-DLLAPI int OS_AsyncWrite(int fd, int offset, void *buf, int len,
- OS_AsyncProc procPtr, ClientData clientData);
-DLLAPI int OS_Close(int fd);
-DLLAPI int OS_CloseRead(int fd);
-DLLAPI int OS_DoIo(struct timeval *tmo);
-DLLAPI int OS_Accept(int listen_sock, int fail_on_intr, const char *webServerAddrs);
-DLLAPI int OS_IpcClose(int ipcFd);
-DLLAPI int OS_IsFcgi(int sock);
-DLLAPI void OS_SetFlags(int fd, int flags);
-
-DLLAPI void OS_ShutdownPending(void);
-
-#ifdef _WIN32
-DLLAPI int OS_SetImpersonate(void);
-#endif
-
-#if defined (__cplusplus) || defined (c_plusplus)
-} /* terminate extern "C" { */
-#endif
-
-#endif /* _FCGIOS_H */
diff --git a/sapi/cgi/libfcgi/libfcgi.m4 b/sapi/cgi/libfcgi/libfcgi.m4
deleted file mode 100644
index 28e73d46a0..0000000000
--- a/sapi/cgi/libfcgi/libfcgi.m4
+++ /dev/null
@@ -1,77 +0,0 @@
-dnl $Id$
-dnl
-dnl This file is an input file used by the GNU "autoconf" program to
-dnl generate the file "configure", which is run during the build
-dnl to configure the system for the local environment.
-
-#AC_INIT
-#AM_INIT_AUTOMAKE(fcgi, 2.2.3-SNAP-0203171857)
-
-#AM_CONFIG_HEADER(include/fcgi_config.h)
-
-#AC_PROG_CC
-#AC_PROG_CPP
-#AC_PROG_INSTALL
-#AC_PROG_LIBTOOL
-
-#AC_PROG_CXX
-
-#AC_LANG([C++])
-
-#dnl autoconf defaults CXX to 'g++', so its unclear whether it exists/works
-#AC_MSG_CHECKING([whether $CXX works])
-#AC_TRY_COMPILE([#include <iostream>],
-# [std::cout << "ok";],
-# [AC_MSG_RESULT(yes)
-# LIBFCGIXX=libfcgi++.la
-# ECHO_CPP=echo-cpp${EXEEXT}
-# AC_MSG_CHECKING([whether cin has a streambuf assignment operator])
-# AC_TRY_COMPILE([#include <iostream>],
-# [cin = static_cast<streambuf *>(0);],
-# [AC_MSG_RESULT(yes)
-# AC_DEFINE([HAVE_IOSTREAM_WITHASSIGN_STREAMBUF], [1],
-# [Define if cin/cout/cerr has a streambuf assignment operator])],
-# [AC_MSG_RESULT(no)])
-# AC_MSG_CHECKING([whether char_type is defined in the context of streambuf])
-# AC_TRY_COMPILE([#include <iostream>],
-# [class fcgi_streambuf : public std::streambuf { char_type ct; }],
-# [AC_MSG_RESULT(yes)
-# AC_DEFINE([HAVE_STREAMBUF_CHAR_TYPE], [1],
-# [Define if char_type is defined in the context of streambuf])],
-# [AC_MSG_RESULT(no)])],
-# [AC_MSG_RESULT(no)])
-#AC_SUBST(LIBFCGIXX)
-#AC_SUBST(ECHO_CPP)
-
-#AC_LANG([C])
-
-AC_CHECK_LIB([nsl], [gethostbyname])
-AC_CHECK_LIB([socket], [socket])
-
-ACX_PTHREAD([THREADED=threaded${EXEEXT}])
-AC_SUBST([THREADED])
-
-FCGI_COMMON_CHECKS
-
-AC_REPLACE_FUNCS([strerror])
-
-#AC_C_INLINE
-
-#--------------------------------------------------------------------
-# This is a little hokie in that it avoids including config.guess
-# and config.sub in the distribution, but its been working so far.
-# Windows builds don't run configure so we should be safe fixing
-# this to 'unix' (at least for now).
-#--------------------------------------------------------------------
-#SYSTEM=unix
-#AC_SUBST([SYSTEM])
-
-#AC_PROG_CC_WARNINGS
-
-#AC_CONFIG_FILES([Makefile
-# cgi-fcgi/Makefile
-# include/Makefile
-# libfcgi/Makefile
-# examples/Makefile])
-
-#AC_OUTPUT
diff --git a/sapi/cgi/libfcgi/os_unix.c b/sapi/cgi/libfcgi/os_unix.c
deleted file mode 100644
index 6d4e103272..0000000000
--- a/sapi/cgi/libfcgi/os_unix.c
+++ /dev/null
@@ -1,1268 +0,0 @@
-/*
- * os_unix.c --
- *
- * Description of file.
- *
- *
- * Copyright (c) 1995 Open Market, Inc.
- * All rights reserved.
- *
- * This file contains proprietary and confidential information and
- * remains the unpublished property of Open Market, Inc. Use,
- * disclosure, or reproduction is prohibited except as permitted by
- * express written license agreement with Open Market, Inc.
- *
- * Bill Snapper
- * snapper@openmarket.com
- */
-
-#ifndef lint
-static const char rcsid[] = "$Id$";
-#endif /* not lint */
-
-#include "fcgi_config.h"
-
-#include <sys/types.h>
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#include <arpa/inet.h>
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h> /* for fcntl */
-#include <math.h>
-#include <memory.h> /* for memchr() */
-#include <netinet/tcp.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <sys/un.h>
-#include <signal.h>
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h> /* for getpeername */
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include "fastcgi.h"
-#include "fcgimisc.h"
-#include "fcgios.h"
-
-#ifndef INADDR_NONE
-#define INADDR_NONE ((unsigned long) -1)
-#endif
-
-/*
- * This structure holds an entry for each oustanding async I/O operation.
- */
-typedef struct {
- OS_AsyncProc procPtr; /* callout completion procedure */
- ClientData clientData; /* caller private data */
- int fd;
- int len;
- int offset;
- void *buf;
- int inUse;
-} AioInfo;
-
-/*
- * Entries in the async I/O table are allocated 2 per file descriptor.
- *
- * Read Entry Index = fd * 2
- * Write Entry Index = (fd * 2) + 1
- */
-#define AIO_RD_IX(fd) (fd * 2)
-#define AIO_WR_IX(fd) ((fd * 2) + 1)
-
-static int asyncIoInUse = FALSE;
-static int asyncIoTableSize = 16;
-static AioInfo *asyncIoTable = NULL;
-
-static int libInitialized = FALSE;
-
-static fd_set readFdSet;
-static fd_set writeFdSet;
-
-static fd_set readFdSetPost;
-static int numRdPosted = 0;
-static fd_set writeFdSetPost;
-static int numWrPosted = 0;
-static int volatile maxFd = -1;
-
-static int shutdownPending = FALSE;
-static int shutdownNow = FALSE;
-
-void OS_ShutdownPending()
-{
- shutdownPending = TRUE;
-}
-
-static void OS_Sigusr1Handler(int signo)
-{
- OS_ShutdownPending();
-}
-
-static void OS_SigpipeHandler(int signo)
-{
- ;
-}
-
-static void installSignalHandler(int signo, const struct sigaction * act, int force)
-{
- struct sigaction sa;
-
- sigaction(signo, NULL, &sa);
-
- if (force || sa.sa_handler == SIG_DFL)
- {
- sigaction(signo, act, NULL);
- }
-}
-
-static void OS_InstallSignalHandlers(int force)
-{
- struct sigaction sa;
-
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = 0;
-
- sa.sa_handler = OS_SigpipeHandler;
- installSignalHandler(SIGPIPE, &sa, force);
-
- sa.sa_handler = OS_Sigusr1Handler;
- installSignalHandler(SIGUSR1, &sa, force);
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_LibInit --
- *
- * Set up the OS library for use.
- *
- * NOTE: This function is really only needed for application
- * asynchronous I/O. It will most likely change in the
- * future to setup the multi-threaded environment.
- *
- * Results:
- * Returns 0 if success, -1 if not.
- *
- * Side effects:
- * Async I/O table allocated and initialized.
- *
- *--------------------------------------------------------------
- */
-int OS_LibInit(int stdioFds[3])
-{
- if(libInitialized)
- return 0;
-
- asyncIoTable = (AioInfo *)malloc(asyncIoTableSize * sizeof(AioInfo));
- if(asyncIoTable == NULL) {
- errno = ENOMEM;
- return -1;
- }
- memset((char *) asyncIoTable, 0,
- asyncIoTableSize * sizeof(AioInfo));
-
- FD_ZERO(&readFdSet);
- FD_ZERO(&writeFdSet);
- FD_ZERO(&readFdSetPost);
- FD_ZERO(&writeFdSetPost);
-
- OS_InstallSignalHandlers(FALSE);
-
- libInitialized = TRUE;
-
- return 0;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_LibShutdown --
- *
- * Shutdown the OS library.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Memory freed, fds closed.
- *
- *--------------------------------------------------------------
- */
-void OS_LibShutdown()
-{
- if(!libInitialized)
- return;
-
- free(asyncIoTable);
- asyncIoTable = NULL;
- libInitialized = FALSE;
- return;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_BuildSockAddrUn --
- *
- * Using the pathname bindPath, fill in the sockaddr_un structure
- * *servAddrPtr and the length of this structure *servAddrLen.
- *
- * The format of the sockaddr_un structure changed incompatibly in
- * 4.3BSD Reno. Digital UNIX supports both formats, other systems
- * support one or the other.
- *
- * Results:
- * 0 for normal return, -1 for failure (bindPath too long).
- *
- *----------------------------------------------------------------------
- */
-
-static int OS_BuildSockAddrUn(const char *bindPath,
- struct sockaddr_un *servAddrPtr,
- int *servAddrLen)
-{
- int bindPathLen = strlen(bindPath);
-
-#ifdef HAVE_SOCKADDR_UN_SUN_LEN /* 4.3BSD Reno and later: BSDI, DEC */
- if(bindPathLen >= sizeof(servAddrPtr->sun_path)) {
- return -1;
- }
-#else /* 4.3 BSD Tahoe: Solaris, HPUX, DEC, ... */
- if(bindPathLen > sizeof(servAddrPtr->sun_path)) {
- return -1;
- }
-#endif
- memset((char *) servAddrPtr, 0, sizeof(*servAddrPtr));
- servAddrPtr->sun_family = AF_UNIX;
- memcpy(servAddrPtr->sun_path, bindPath, bindPathLen);
-#ifdef HAVE_SOCKADDR_UN_SUN_LEN /* 4.3BSD Reno and later: BSDI, DEC */
- *servAddrLen = sizeof(servAddrPtr->sun_len)
- + sizeof(servAddrPtr->sun_family)
- + bindPathLen + 1;
- servAddrPtr->sun_len = *servAddrLen;
-#else /* 4.3 BSD Tahoe: Solaris, HPUX, DEC, ... */
- *servAddrLen = sizeof(servAddrPtr->sun_family) + bindPathLen;
-#endif
- return 0;
-}
-union SockAddrUnion {
- struct sockaddr_un unixVariant;
- struct sockaddr_in inetVariant;
-};
-
-/*
- * OS_CreateLocalIpcFd --
- *
- * This procedure is responsible for creating the listener socket
- * on Unix for local process communication. It will create a
- * domain socket or a TCP/IP socket bound to "localhost" and return
- * a file descriptor to it to the caller.
- * bCreateMutex is ignored for unix
- *
- * Results:
- * Listener socket created. This call returns either a valid
- * file descriptor or -1 on error.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-int OS_CreateLocalIpcFd(const char *bindPath, int backlog, int bCreateMutex)
-{
- int listenSock, servLen;
- union SockAddrUnion sa;
- int tcp = FALSE;
- unsigned long tcp_ia = 0;
- char *tp;
- short port = 0;
- char host[MAXPATHLEN];
-
- strcpy(host, bindPath);
- if((tp = strchr(host, ':')) != 0) {
- *tp++ = 0;
- if((port = atoi(tp)) == 0) {
- *--tp = ':';
- } else {
- tcp = TRUE;
- }
- }
- if(tcp) {
- if (!*host || !strcmp(host,"*")) {
- tcp_ia = htonl(INADDR_ANY);
- } else {
- tcp_ia = inet_addr(host);
- if (tcp_ia == INADDR_NONE) {
- struct hostent * hep;
- hep = gethostbyname(host);
- if ((!hep) || (hep->h_addrtype != AF_INET || !hep->h_addr_list[0])) {
- fprintf(stderr, "Cannot resolve host name %s -- exiting!\n", host);
- return -1;
- }
- if (hep->h_addr_list[1]) {
- fprintf(stderr, "Host %s has multiple addresses ---\n", host);
- fprintf(stderr, "you must choose one explicitly!!!\n");
- return -1;
- }
- tcp_ia = ((struct in_addr *) (hep->h_addr))->s_addr;
- }
- }
- }
-
- if(tcp) {
- listenSock = socket(AF_INET, SOCK_STREAM, 0);
- if(listenSock >= 0) {
- int flag = 1;
- if(setsockopt(listenSock, SOL_SOCKET, SO_REUSEADDR,
- (char *) &flag, sizeof(flag)) < 0) {
- fprintf(stderr, "Can't set SO_REUSEADDR.\n");
- return -1;
- }
- }
- } else {
- listenSock = socket(AF_UNIX, SOCK_STREAM, 0);
- }
- if(listenSock < 0) {
- return -1;
- }
-
- /*
- * Bind the listening socket.
- */
- if(tcp) {
- memset((char *) &sa.inetVariant, 0, sizeof(sa.inetVariant));
- sa.inetVariant.sin_family = AF_INET;
- sa.inetVariant.sin_addr.s_addr = tcp_ia;
- sa.inetVariant.sin_port = htons(port);
- servLen = sizeof(sa.inetVariant);
- } else {
- unlink(bindPath);
- if(OS_BuildSockAddrUn(bindPath, &sa.unixVariant, &servLen)) {
- fprintf(stderr, "Listening socket's path name is too long.\n");
- return -1;
- }
- }
- if(bind(listenSock, (struct sockaddr *) &sa.unixVariant, servLen) < 0
- || listen(listenSock, backlog) < 0) {
- perror("bind/listen");
- return -1;
- }
-
- return listenSock;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_FcgiConnect --
- *
- * Create the socket and connect to the remote application if
- * possible.
- *
- * This was lifted from the cgi-fcgi application and was abstracted
- * out because Windows NT does not have a domain socket and must
- * use a named pipe which has a different API altogether.
- *
- * Results:
- * -1 if fail or a valid file descriptor if connection succeeds.
- *
- * Side effects:
- * Remote connection established.
- *
- *----------------------------------------------------------------------
- */
-int OS_FcgiConnect(char *bindPath)
-{
- union SockAddrUnion sa;
- int servLen, resultSock;
- int connectStatus;
- char *tp;
- char host[MAXPATHLEN];
- short port = 0;
- int tcp = FALSE;
-
- strcpy(host, bindPath);
- if((tp = strchr(host, ':')) != 0) {
- *tp++ = 0;
- if((port = atoi(tp)) == 0) {
- *--tp = ':';
- } else {
- tcp = TRUE;
- }
- }
- if(tcp == TRUE) {
- struct hostent *hp;
- if((hp = gethostbyname((*host ? host : "localhost"))) == NULL) {
- fprintf(stderr, "Unknown host: %s\n", bindPath);
- return -1;
- }
- sa.inetVariant.sin_family = AF_INET;
- memcpy(&sa.inetVariant.sin_addr, hp->h_addr, hp->h_length);
- sa.inetVariant.sin_port = htons(port);
- servLen = sizeof(sa.inetVariant);
- resultSock = socket(AF_INET, SOCK_STREAM, 0);
- } else {
- if(OS_BuildSockAddrUn(bindPath, &sa.unixVariant, &servLen)) {
- fprintf(stderr, "Listening socket's path name is too long.\n");
- return -1;
- }
- resultSock = socket(AF_UNIX, SOCK_STREAM, 0);
- }
-
- ASSERT(resultSock >= 0);
- connectStatus = connect(resultSock, (struct sockaddr *) &sa.unixVariant,
- servLen);
- if(connectStatus >= 0) {
- return resultSock;
- } else {
- /*
- * Most likely (errno == ENOENT || errno == ECONNREFUSED)
- * and no FCGI application server is running.
- */
- close(resultSock);
- return -1;
- }
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_Read --
- *
- * Pass through to the unix read function.
- *
- * Results:
- * Returns number of byes read, 0, or -1 failure: errno
- * contains actual error.
- *
- * Side effects:
- * None.
- *
- *--------------------------------------------------------------
- */
-int OS_Read(int fd, char * buf, size_t len)
-{
- if (shutdownNow) return -1;
- return(read(fd, buf, len));
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_Write --
- *
- * Pass through to unix write function.
- *
- * Results:
- * Returns number of byes read, 0, or -1 failure: errno
- * contains actual error.
- *
- * Side effects:
- * none.
- *
- *--------------------------------------------------------------
- */
-int OS_Write(int fd, char * buf, size_t len)
-{
- if (shutdownNow) return -1;
- return(write(fd, buf, len));
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_SpawnChild --
- *
- * Spawns a new FastCGI listener process.
- *
- * Results:
- * 0 if success, -1 if error.
- *
- * Side effects:
- * Child process spawned.
- *
- *----------------------------------------------------------------------
- */
-int OS_SpawnChild(char *appPath, int listenFd)
-{
- int forkResult;
-
- forkResult = fork();
- if(forkResult < 0) {
- return -1;
- }
-
- if(forkResult == 0) {
- /*
- * Close STDIN unconditionally. It's used by the parent
- * process for CGI communication. The FastCGI applciation
- * will be replacing this with the FastCGI listenFd IF
- * STDIN_FILENO is the same as FCGI_LISTENSOCK_FILENO
- * (which it is on Unix). Regardless, STDIN, STDOUT, and
- * STDERR will be closed as the FastCGI process uses a
- * multiplexed socket in their place.
- */
- close(STDIN_FILENO);
-
- /*
- * If the listenFd is already the value of FCGI_LISTENSOCK_FILENO
- * we're set. If not, change it so the child knows where to
- * get the listen socket from.
- */
- if(listenFd != FCGI_LISTENSOCK_FILENO) {
- dup2(listenFd, FCGI_LISTENSOCK_FILENO);
- close(listenFd);
- }
-
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
-
- /*
- * We're a child. Exec the application.
- *
- * XXX: entire environment passes through
- */
- execl(appPath, appPath, NULL);
- /*
- * XXX: Can't do this as we've already closed STDERR!!!
- *
- * perror("exec");
- */
- return -1;
- }
- return 0;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_AsyncReadStdin --
- *
- * This initiates an asynchronous read on the standard
- * input handle.
- *
- * The abstraction is necessary because Windows NT does not
- * have a clean way of "select"ing a file descriptor for
- * I/O.
- *
- * Results:
- * -1 if error, 0 otherwise.
- *
- * Side effects:
- * Asynchronous bit is set in the readfd variable and
- * request is enqueued.
- *
- *--------------------------------------------------------------
- */
-int OS_AsyncReadStdin(void *buf, int len, OS_AsyncProc procPtr,
- ClientData clientData)
-{
- int index = AIO_RD_IX(STDIN_FILENO);
-
- asyncIoInUse = TRUE;
- ASSERT(asyncIoTable[index].inUse == 0);
- asyncIoTable[index].procPtr = procPtr;
- asyncIoTable[index].clientData = clientData;
- asyncIoTable[index].fd = STDIN_FILENO;
- asyncIoTable[index].len = len;
- asyncIoTable[index].offset = 0;
- asyncIoTable[index].buf = buf;
- asyncIoTable[index].inUse = 1;
- FD_SET(STDIN_FILENO, &readFdSet);
- if(STDIN_FILENO > maxFd)
- maxFd = STDIN_FILENO;
- return 0;
-}
-
-static void GrowAsyncTable(void)
-{
- int oldTableSize = asyncIoTableSize;
-
- asyncIoTableSize = asyncIoTableSize * 2;
- asyncIoTable = (AioInfo *)realloc(asyncIoTable, asyncIoTableSize * sizeof(AioInfo));
- if(asyncIoTable == NULL) {
- errno = ENOMEM;
- exit(errno);
- }
- memset((char *) &asyncIoTable[oldTableSize], 0,
- oldTableSize * sizeof(AioInfo));
-
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_AsyncRead --
- *
- * This initiates an asynchronous read on the file
- * handle which may be a socket or named pipe.
- *
- * We also must save the ProcPtr and ClientData, so later
- * when the io completes, we know who to call.
- *
- * We don't look at any results here (the ReadFile may
- * return data if it is cached) but do all completion
- * processing in OS_Select when we get the io completion
- * port done notifications. Then we call the callback.
- *
- * Results:
- * -1 if error, 0 otherwise.
- *
- * Side effects:
- * Asynchronous I/O operation is queued for completion.
- *
- *--------------------------------------------------------------
- */
-int OS_AsyncRead(int fd, int offset, void *buf, int len,
- OS_AsyncProc procPtr, ClientData clientData)
-{
- int index = AIO_RD_IX(fd);
-
- ASSERT(asyncIoTable != NULL);
- asyncIoInUse = TRUE;
-
- if(fd > maxFd)
- maxFd = fd;
-
- if(index >= asyncIoTableSize) {
- GrowAsyncTable();
- }
-
- ASSERT(asyncIoTable[index].inUse == 0);
- asyncIoTable[index].procPtr = procPtr;
- asyncIoTable[index].clientData = clientData;
- asyncIoTable[index].fd = fd;
- asyncIoTable[index].len = len;
- asyncIoTable[index].offset = offset;
- asyncIoTable[index].buf = buf;
- asyncIoTable[index].inUse = 1;
- FD_SET(fd, &readFdSet);
- return 0;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_AsyncWrite --
- *
- * This initiates an asynchronous write on the "fake" file
- * descriptor (which may be a file, socket, or named pipe).
- * We also must save the ProcPtr and ClientData, so later
- * when the io completes, we know who to call.
- *
- * We don't look at any results here (the WriteFile generally
- * completes immediately) but do all completion processing
- * in OS_DoIo when we get the io completion port done
- * notifications. Then we call the callback.
- *
- * Results:
- * -1 if error, 0 otherwise.
- *
- * Side effects:
- * Asynchronous I/O operation is queued for completion.
- *
- *--------------------------------------------------------------
- */
-int OS_AsyncWrite(int fd, int offset, void *buf, int len,
- OS_AsyncProc procPtr, ClientData clientData)
-{
- int index = AIO_WR_IX(fd);
-
- asyncIoInUse = TRUE;
-
- if(fd > maxFd)
- maxFd = fd;
-
- if(index >= asyncIoTableSize) {
- GrowAsyncTable();
- }
-
- ASSERT(asyncIoTable[index].inUse == 0);
- asyncIoTable[index].procPtr = procPtr;
- asyncIoTable[index].clientData = clientData;
- asyncIoTable[index].fd = fd;
- asyncIoTable[index].len = len;
- asyncIoTable[index].offset = offset;
- asyncIoTable[index].buf = buf;
- asyncIoTable[index].inUse = 1;
- FD_SET(fd, &writeFdSet);
- return 0;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_Close --
- *
- * Closes the descriptor. This is a pass through to the
- * Unix close.
- *
- * Results:
- * 0 for success, -1 on failure
- *
- * Side effects:
- * None.
- *
- *--------------------------------------------------------------
- */
-int OS_Close(int fd)
-{
- if (fd == -1)
- return 0;
-
- if (asyncIoInUse) {
- int index = AIO_RD_IX(fd);
-
- FD_CLR(fd, &readFdSet);
- FD_CLR(fd, &readFdSetPost);
- if (asyncIoTable[index].inUse != 0) {
- asyncIoTable[index].inUse = 0;
- }
-
- FD_CLR(fd, &writeFdSet);
- FD_CLR(fd, &writeFdSetPost);
- index = AIO_WR_IX(fd);
- if (asyncIoTable[index].inUse != 0) {
- asyncIoTable[index].inUse = 0;
- }
-
- if (maxFd == fd) {
- maxFd--;
- }
- }
- return close(fd);
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_CloseRead --
- *
- * Cancel outstanding asynchronous reads and prevent subsequent
- * reads from completing.
- *
- * Results:
- * Socket or file is shutdown. Return values mimic Unix shutdown:
- * 0 success, -1 failure
- *
- *--------------------------------------------------------------
- */
-int OS_CloseRead(int fd)
-{
- if(asyncIoTable[AIO_RD_IX(fd)].inUse != 0) {
- asyncIoTable[AIO_RD_IX(fd)].inUse = 0;
- FD_CLR(fd, &readFdSet);
- }
-
- return shutdown(fd, 0);
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_DoIo --
- *
- * This function was formerly OS_Select. It's purpose is
- * to pull I/O completion events off the queue and dispatch
- * them to the appropriate place.
- *
- * Results:
- * Returns 0.
- *
- * Side effects:
- * Handlers are called.
- *
- *--------------------------------------------------------------
- */
-int OS_DoIo(struct timeval *tmo)
-{
- int fd, len, selectStatus;
- OS_AsyncProc procPtr;
- ClientData clientData;
- AioInfo *aioPtr;
- fd_set readFdSetCpy;
- fd_set writeFdSetCpy;
-
- asyncIoInUse = TRUE;
- FD_ZERO(&readFdSetCpy);
- FD_ZERO(&writeFdSetCpy);
-
- for(fd = 0; fd <= maxFd; fd++) {
- if(FD_ISSET(fd, &readFdSet)) {
- FD_SET(fd, &readFdSetCpy);
- }
- if(FD_ISSET(fd, &writeFdSet)) {
- FD_SET(fd, &writeFdSetCpy);
- }
- }
-
- /*
- * If there were no completed events from a prior call, see if there's
- * any work to do.
- */
- if(numRdPosted == 0 && numWrPosted == 0) {
- selectStatus = select((maxFd+1), &readFdSetCpy, &writeFdSetCpy,
- NULL, tmo);
- if(selectStatus < 0) {
- /*exit(errno);*/
- /* not sure what's best to do here */
- return -1;
- }
-
- for(fd = 0; fd <= maxFd; fd++) {
- /*
- * Build up a list of completed events. We'll work off of
- * this list as opposed to looping through the read and write
- * fd sets since they can be affected by a callbacl routine.
- */
- if(FD_ISSET(fd, &readFdSetCpy)) {
- numRdPosted++;
- FD_SET(fd, &readFdSetPost);
- FD_CLR(fd, &readFdSet);
- }
-
- if(FD_ISSET(fd, &writeFdSetCpy)) {
- numWrPosted++;
- FD_SET(fd, &writeFdSetPost);
- FD_CLR(fd, &writeFdSet);
- }
- }
- }
-
- if(numRdPosted == 0 && numWrPosted == 0)
- return 0;
-
- for(fd = 0; fd <= maxFd; fd++) {
- /*
- * Do reads and dispatch callback.
- */
- if(FD_ISSET(fd, &readFdSetPost)
- && asyncIoTable[AIO_RD_IX(fd)].inUse) {
-
- numRdPosted--;
- FD_CLR(fd, &readFdSetPost);
- aioPtr = &asyncIoTable[AIO_RD_IX(fd)];
-
- len = read(aioPtr->fd, aioPtr->buf, aioPtr->len);
-
- procPtr = aioPtr->procPtr;
- aioPtr->procPtr = NULL;
- clientData = aioPtr->clientData;
- aioPtr->inUse = 0;
-
- (*procPtr)(clientData, len);
- }
-
- /*
- * Do writes and dispatch callback.
- */
- if(FD_ISSET(fd, &writeFdSetPost) &&
- asyncIoTable[AIO_WR_IX(fd)].inUse) {
-
- numWrPosted--;
- FD_CLR(fd, &writeFdSetPost);
- aioPtr = &asyncIoTable[AIO_WR_IX(fd)];
-
- len = write(aioPtr->fd, aioPtr->buf, aioPtr->len);
-
- procPtr = aioPtr->procPtr;
- aioPtr->procPtr = NULL;
- clientData = aioPtr->clientData;
- aioPtr->inUse = 0;
- (*procPtr)(clientData, len);
- }
- }
- return 0;
-}
-
-/*
- * Not all systems have strdup().
- * @@@ autoconf should determine whether or not this is needed, but for now..
- */
-static char * str_dup(const char * str)
-{
- char * sdup = (char *) malloc(strlen(str) + 1);
-
- if (sdup)
- strcpy(sdup, str);
-
- return sdup;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * ClientAddrOK --
- *
- * Checks if a client address is in a list of allowed addresses
- *
- * Results:
- * TRUE if address list is empty or client address is present
- * in the list, FALSE otherwise.
- *
- *----------------------------------------------------------------------
- */
-static int ClientAddrOK(struct sockaddr_in *saPtr, const char *clientList)
-{
- int result = FALSE;
- char *clientListCopy, *cur, *next;
-
- if (clientList == NULL || *clientList == '\0') {
- return TRUE;
- }
-
- clientListCopy = str_dup(clientList);
-
- for (cur = clientListCopy; cur != NULL; cur = next) {
- next = strchr(cur, ',');
- if (next != NULL) {
- *next++ = '\0';
- }
- if (inet_addr(cur) == saPtr->sin_addr.s_addr) {
- result = TRUE;
- break;
- }
- }
-
- free(clientListCopy);
- return result;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * AcquireLock --
- *
- * On platforms that implement concurrent calls to accept
- * on a shared listening ipcFd, returns 0. On other platforms,
- * acquires an exclusive lock across all processes sharing a
- * listening ipcFd, blocking until the lock has been acquired.
- *
- * Results:
- * 0 for successful call, -1 in case of system error (fatal).
- *
- * Side effects:
- * This process now has the exclusive lock.
- *
- *----------------------------------------------------------------------
- */
-static int AcquireLock(int sock, int fail_on_intr)
-{
-#ifdef USE_LOCKING
- do {
- struct flock lock;
- lock.l_type = F_WRLCK;
- lock.l_start = 0;
- lock.l_whence = SEEK_SET;
- lock.l_len = 0;
-
- if (fcntl(sock, F_SETLKW, &lock) != -1)
- return 0;
- } while (errno == EINTR
- && ! fail_on_intr
- && ! shutdownPending);
-
- return -1;
-
-#else
- return 0;
-#endif
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * ReleaseLock --
- *
- * On platforms that implement concurrent calls to accept
- * on a shared listening ipcFd, does nothing. On other platforms,
- * releases an exclusive lock acquired by AcquireLock.
- *
- * Results:
- * 0 for successful call, -1 in case of system error (fatal).
- *
- * Side effects:
- * This process no longer holds the lock.
- *
- *----------------------------------------------------------------------
- */
-static int ReleaseLock(int sock)
-{
-#ifdef USE_LOCKING
- do {
- struct flock lock;
- lock.l_type = F_UNLCK;
- lock.l_start = 0;
- lock.l_whence = SEEK_SET;
- lock.l_len = 0;
-
- if (fcntl(sock, F_SETLK, &lock) != -1)
- return 0;
- } while (errno == EINTR);
-
- return -1;
-
-#else
- return 0;
-#endif
-}
-
-/**********************************************************************
- * Determine if the errno resulting from a failed accept() warrants a
- * retry or exit(). Based on Apache's http_main.c accept() handling
- * and Stevens' Unix Network Programming Vol 1, 2nd Ed, para. 15.6.
- */
-static int is_reasonable_accept_errno (const int error)
-{
- switch (error) {
-#ifdef EPROTO
- /* EPROTO on certain older kernels really means ECONNABORTED, so
- * we need to ignore it for them. See discussion in new-httpd
- * archives nh.9701 search for EPROTO. Also see nh.9603, search
- * for EPROTO: There is potentially a bug in Solaris 2.x x<6, and
- * other boxes that implement tcp sockets in userland (i.e. on top of
- * STREAMS). On these systems, EPROTO can actually result in a fatal
- * loop. See PR#981 for example. It's hard to handle both uses of
- * EPROTO. */
- case EPROTO:
-#endif
-#ifdef ECONNABORTED
- case ECONNABORTED:
-#endif
- /* Linux generates the rest of these, other tcp stacks (i.e.
- * bsd) tend to hide them behind getsockopt() interfaces. They
- * occur when the net goes sour or the client disconnects after the
- * three-way handshake has been done in the kernel but before
- * userland has picked up the socket. */
-#ifdef ECONNRESET
- case ECONNRESET:
-#endif
-#ifdef ETIMEDOUT
- case ETIMEDOUT:
-#endif
-#ifdef EHOSTUNREACH
- case EHOSTUNREACH:
-#endif
-#ifdef ENETUNREACH
- case ENETUNREACH:
-#endif
- return 1;
-
- default:
- return 0;
- }
-}
-
-/**********************************************************************
- * This works around a problem on Linux 2.0.x and SCO Unixware (maybe
- * others?). When a connect() is made to a Unix Domain socket, but its
- * not accept()ed before the web server gets impatient and close()s, an
- * accept() results in a valid file descriptor, but no data to read.
- * This causes a block on the first read() - which never returns!
- *
- * Another approach to this is to write() to the socket to provoke a
- * SIGPIPE, but this is a pain because of the FastCGI protocol, the fact
- * that whatever is written has to be universally ignored by all FastCGI
- * web servers, and a SIGPIPE handler has to be installed which returns
- * (or SIGPIPE is ignored).
- *
- * READABLE_UNIX_FD_DROP_DEAD_TIMEVAL = 2,0 by default.
- *
- * Making it shorter is probably safe, but I'll leave that to you. Making
- * it 0,0 doesn't work reliably. The shorter you can reliably make it,
- * the faster your application will be able to recover (waiting 2 seconds
- * may _cause_ the problem when there is a very high demand). At any rate,
- * this is better than perma-blocking.
- */
-static int is_af_unix_keeper(const int fd)
-{
- struct timeval tval = { READABLE_UNIX_FD_DROP_DEAD_TIMEVAL };
- fd_set read_fds;
-
- FD_ZERO(&read_fds);
- FD_SET(fd, &read_fds);
-
- return select(fd + 1, &read_fds, NULL, NULL, &tval) >= 0 && FD_ISSET(fd, &read_fds);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_Accept --
- *
- * Accepts a new FastCGI connection. This routine knows whether
- * we're dealing with TCP based sockets or NT Named Pipes for IPC.
- *
- * Results:
- * -1 if the operation fails, otherwise this is a valid IPC fd.
- *
- * Side effects:
- * New IPC connection is accepted.
- *
- *----------------------------------------------------------------------
- */
-int OS_Accept(int listen_sock, int fail_on_intr, const char *webServerAddrs)
-{
- int socket = -1;
- union {
- struct sockaddr_un un;
- struct sockaddr_in in;
- } sa;
-
- for (;;) {
- if (AcquireLock(listen_sock, fail_on_intr))
- return -1;
-
- for (;;) {
- do {
-#ifdef HAVE_SOCKLEN
- socklen_t len = sizeof(sa);
-#else
- int len = sizeof(sa);
-#endif
- if (shutdownPending) break;
- /* There's a window here */
-
- socket = accept(listen_sock, (struct sockaddr *)&sa, &len);
- } while (socket < 0
- && errno == EINTR
- && ! fail_on_intr
- && ! shutdownPending);
-
- if (socket < 0) {
- if (shutdownPending || ! is_reasonable_accept_errno(errno)) {
- int errnoSave = errno;
-
- ReleaseLock(listen_sock);
-
- if (! shutdownPending) {
- errno = errnoSave;
- }
-
- return (-1);
- }
- errno = 0;
- }
- else { /* socket >= 0 */
- int set = 1;
-
- if (sa.in.sin_family != AF_INET)
- break;
-
-#ifdef TCP_NODELAY
- /* No replies to outgoing data, so disable Nagle */
- setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, (char *)&set, sizeof(set));
-#endif
-
- /* Check that the client IP address is approved */
- if (ClientAddrOK(&sa.in, webServerAddrs))
- break;
-
- close(socket);
- } /* socket >= 0 */
- } /* for(;;) */
-
- if (ReleaseLock(listen_sock))
- return (-1);
-
- if (sa.in.sin_family != AF_UNIX || is_af_unix_keeper(socket))
- break;
-
- close(socket);
- } /* while(1) - lock */
-
- return (socket);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_IpcClose
- *
- * OS IPC routine to close an IPC connection.
- *
- * Results:
- *
- *
- * Side effects:
- * IPC connection is closed.
- *
- *----------------------------------------------------------------------
- */
-int OS_IpcClose(int ipcFd)
-{
- return OS_Close(ipcFd);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_IsFcgi --
- *
- * Determines whether this process is a FastCGI process or not.
- *
- * Results:
- * Returns 1 if FastCGI, 0 if not.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-int OS_IsFcgi(int sock)
-{
- union {
- struct sockaddr_in in;
- struct sockaddr_un un;
- } sa;
-#ifdef HAVE_SOCKLEN
- socklen_t len = sizeof(sa);
-#else
- int len = sizeof(sa);
-#endif
-
- errno = 0;
-
- if (getpeername(sock, (struct sockaddr *)&sa, &len) != 0 && errno == ENOTCONN) {
- return TRUE;
- }
- else {
- return FALSE;
- }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_SetFlags --
- *
- * Sets selected flag bits in an open file descriptor.
- *
- *----------------------------------------------------------------------
- */
-void OS_SetFlags(int fd, int flags)
-{
- int val;
- if((val = fcntl(fd, F_GETFL, 0)) < 0) {
- return;
- }
- val |= flags;
- if(fcntl(fd, F_SETFL, val) < 0) {
- return;
- }
-}
diff --git a/sapi/cgi/libfcgi/os_win32.c b/sapi/cgi/libfcgi/os_win32.c
deleted file mode 100644
index 723ef81060..0000000000
--- a/sapi/cgi/libfcgi/os_win32.c
+++ /dev/null
@@ -1,2067 +0,0 @@
-/*
- * os_win32.c --
- *
- *
- * Copyright (c) 1995 Open Market, Inc.
- * All rights reserved.
- *
- * This file contains proprietary and confidential information and
- * remains the unpublished property of Open Market, Inc. Use,
- * disclosure, or reproduction is prohibited except as permitted by
- * express written license agreement with Open Market, Inc.
- *
- * Bill Snapper
- * snapper@openmarket.com
- *
- * (Special thanks to Karen and Bill. They made my job much easier and
- * significantly more enjoyable.)
- */
-#ifndef lint
-static const char rcsid[] = "$Id$";
-#endif /* not lint */
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <winsock2.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <stdio.h>
-#include <sys/timeb.h>
-
-#define DLLAPI __declspec(dllexport)
-
-#include "fcgimisc.h"
-#include "fcgios.h"
-
-#define WIN32_OPEN_MAX 128 /* XXX: Small hack */
-
-/*
- * millisecs to wait for a client connection before checking the
- * shutdown flag (then go back to waiting for a connection, etc).
- */
-#define ACCEPT_TIMEOUT 1000
-
-#define LOCALHOST "localhost"
-
-static HANDLE hIoCompPort = INVALID_HANDLE_VALUE;
-static HANDLE hStdinCompPort = INVALID_HANDLE_VALUE;
-static HANDLE hStdinThread = INVALID_HANDLE_VALUE;
-
-static HANDLE stdioHandles[3] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
- INVALID_HANDLE_VALUE};
-
-static HANDLE acceptMutex = INVALID_HANDLE_VALUE;
-
-static BOOLEAN shutdownPending = FALSE;
-static BOOLEAN shutdownNow = FALSE;
-
-static BOOLEAN bImpersonate = FALSE;
-/*
- * An enumeration of the file types
- * supported by the FD_TABLE structure.
- *
- * XXX: Not all currently supported. This allows for future
- * functionality.
- */
-typedef enum {
- FD_UNUSED,
- FD_FILE_SYNC,
- FD_FILE_ASYNC,
- FD_SOCKET_SYNC,
- FD_SOCKET_ASYNC,
- FD_PIPE_SYNC,
- FD_PIPE_ASYNC
-} FILE_TYPE;
-
-typedef union {
- HANDLE fileHandle;
- SOCKET sock;
- unsigned int value;
-} DESCRIPTOR;
-
-/*
- * Structure used to map file handle and socket handle
- * values into values that can be used to create unix-like
- * select bitmaps, read/write for both sockets/files.
- */
-struct FD_TABLE {
- DESCRIPTOR fid;
- FILE_TYPE type;
- char *path;
- DWORD Errno;
- unsigned long instance;
- int status;
- int offset; /* only valid for async file writes */
- LPDWORD offsetHighPtr; /* pointers to offset high and low words */
- LPDWORD offsetLowPtr; /* only valid for async file writes (logs) */
- HANDLE hMapMutex; /* mutex handle for multi-proc offset update */
- LPVOID ovList; /* List of associated OVERLAPPED_REQUESTs */
-};
-
-/*
- * XXX Note there is no dyanmic sizing of this table, so if the
- * number of open file descriptors exceeds WIN32_OPEN_MAX the
- * app will blow up.
- */
-static struct FD_TABLE fdTable[WIN32_OPEN_MAX];
-
-static CRITICAL_SECTION fdTableCritical;
-
-struct OVERLAPPED_REQUEST {
- OVERLAPPED overlapped;
- unsigned long instance; /* file instance (won't match after a close) */
- OS_AsyncProc procPtr; /* callback routine */
- ClientData clientData; /* callback argument */
- ClientData clientData1; /* additional clientData */
-};
-typedef struct OVERLAPPED_REQUEST *POVERLAPPED_REQUEST;
-
-static const char *bindPathPrefix = "\\\\.\\pipe\\FastCGI\\";
-
-static FILE_TYPE listenType = FD_UNUSED;
-
-// XXX This should be a DESCRIPTOR
-static HANDLE hListen = INVALID_HANDLE_VALUE;
-
-static OVERLAPPED listenOverlapped;
-static BOOLEAN libInitialized = FALSE;
-
-/*
- *--------------------------------------------------------------
- *
- * Win32NewDescriptor --
- *
- * Set up for I/O descriptor masquerading.
- *
- * Results:
- * Returns "fake id" which masquerades as a UNIX-style "small
- * non-negative integer" file/socket descriptor.
- * Win32_* routine below will "do the right thing" based on the
- * descriptor's actual type. -1 indicates failure.
- *
- * Side effects:
- * Entry in fdTable is reserved to represent the socket/file.
- *
- *--------------------------------------------------------------
- */
-static int Win32NewDescriptor(FILE_TYPE type, int fd, int desiredFd)
-{
- int index = -1;
-
- EnterCriticalSection(&fdTableCritical);
-
- /*
- * If desiredFd is set, try to get this entry (this is used for
- * mapping stdio handles). Otherwise try to get the fd entry.
- * If this is not available, find a the first empty slot. .
- */
- if (desiredFd >= 0 && desiredFd < WIN32_OPEN_MAX)
- {
- if (fdTable[desiredFd].type == FD_UNUSED)
- {
- index = desiredFd;
- }
- }
- else if (fd > 0)
- {
- if (fd < WIN32_OPEN_MAX && fdTable[fd].type == FD_UNUSED)
- {
- index = fd;
- }
- else
- {
- int i;
-
- for (i = 1; i < WIN32_OPEN_MAX; ++i)
- {
- if (fdTable[i].type == FD_UNUSED)
- {
- index = i;
- break;
- }
- }
- }
- }
-
- if (index != -1)
- {
- fdTable[index].fid.value = fd;
- fdTable[index].type = type;
- fdTable[index].path = NULL;
- fdTable[index].Errno = NO_ERROR;
- fdTable[index].status = 0;
- fdTable[index].offset = -1;
- fdTable[index].offsetHighPtr = fdTable[index].offsetLowPtr = NULL;
- fdTable[index].hMapMutex = NULL;
- fdTable[index].ovList = NULL;
- }
-
- LeaveCriticalSection(&fdTableCritical);
- return index;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * StdinThread--
- *
- * This thread performs I/O on stadard input. It is needed
- * because you can't guarantee that all applications will
- * create standard input with sufficient access to perform
- * asynchronous I/O. Since we don't want to block the app
- * reading from stdin we make it look like it's using I/O
- * completion ports to perform async I/O.
- *
- * Results:
- * Data is read from stdin and posted to the io completion
- * port.
- *
- * Side effects:
- * None.
- *
- *--------------------------------------------------------------
- */
-static void StdinThread(LPDWORD startup){
-
- int doIo = TRUE;
- unsigned long fd;
- unsigned long bytesRead;
- POVERLAPPED_REQUEST pOv;
-
- // Touch the arg to prevent warning
- startup = NULL;
-
- while(doIo) {
- /*
- * Block until a request to read from stdin comes in or a
- * request to terminate the thread arrives (fd = -1).
- */
- if (!GetQueuedCompletionStatus(hStdinCompPort, &bytesRead, &fd,
- (LPOVERLAPPED *)&pOv, (DWORD)-1) && !pOv) {
- doIo = 0;
- break;
- }
-
- ASSERT((fd == STDIN_FILENO) || (fd == -1));
- if(fd == -1) {
- doIo = 0;
- break;
- }
- ASSERT(pOv->clientData1 != NULL);
-
- if(ReadFile(stdioHandles[STDIN_FILENO], pOv->clientData1, bytesRead,
- &bytesRead, NULL)) {
- PostQueuedCompletionStatus(hIoCompPort, bytesRead,
- STDIN_FILENO, (LPOVERLAPPED)pOv);
- } else {
- doIo = 0;
- break;
- }
- }
-
- ExitThread(0);
-}
-
-void OS_ShutdownPending(void)
-{
- shutdownPending = TRUE;
-}
-
-/* XXX Need a shutdown now event */
-static DWORD WINAPI ShutdownRequestThread(LPVOID arg)
-{
- HANDLE shutdownEvent = (HANDLE) arg;
- WaitForSingleObject(shutdownEvent, INFINITE);
- shutdownPending = TRUE;
- // Before an accept() is entered the shutdownPending flag is checked.
- // If set, OS_Accept() will return -1. If not, it waits
- // on a connection request for one second, checks the flag, & repeats.
- // Only one process/thread is allowed to do this at time by
- // wrapping the accept() with mutex.
- return 0;
-}
-
-int OS_SetImpersonate(void)
-{
- char *os_name = NULL;
- os_name = getenv("OS");
- if (os_name && stricmp(os_name, "Windows_NT") == 0) {
- bImpersonate = TRUE;
- return 1;
- }
- return 0;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_LibInit --
- *
- * Set up the OS library for use.
- *
- * Results:
- * Returns 0 if success, -1 if not.
- *
- * Side effects:
- * Sockets initialized, pseudo file descriptors setup, etc.
- *
- *--------------------------------------------------------------
- */
-int OS_LibInit(int stdioFds[3])
-{
- WORD wVersion;
- WSADATA wsaData;
- int err;
- int fakeFd;
- DWORD threadId;
- char *cLenPtr = NULL;
- char *val = NULL;
-
- if(libInitialized)
- return 0;
-
- InitializeCriticalSection(&fdTableCritical);
-
- /*
- * Initialize windows sockets library.
- */
- wVersion = MAKEWORD(2,0);
- err = WSAStartup( wVersion, &wsaData );
- if (err) {
- fprintf(stderr, "Error starting Windows Sockets. Error: %d",
- WSAGetLastError());
- //exit(111);
- return -1;
- }
-
- /*
- * Create the I/O completion port to be used for our I/O queue.
- */
- if (hIoCompPort == INVALID_HANDLE_VALUE) {
- hIoCompPort = CreateIoCompletionPort (INVALID_HANDLE_VALUE, NULL,
- 0, 1);
- if(hIoCompPort == INVALID_HANDLE_VALUE) {
- printf("<H2>OS_LibInit Failed CreateIoCompletionPort! ERROR: %d</H2>\r\n\r\n",
- GetLastError());
- return -1;
- }
- }
-
- /*
- * If a shutdown event is in the env, save it (I don't see any to
- * remove it from the environment out from under the application).
- * Spawn a thread to wait on the shutdown request.
- */
- val = getenv(SHUTDOWN_EVENT_NAME);
- if (val != NULL)
- {
- HANDLE shutdownEvent = (HANDLE) atoi(val);
-
- if (! CreateThread(NULL, 0, ShutdownRequestThread,
- shutdownEvent, 0, NULL))
- {
- return -1;
- }
- }
-
- /*
- * If an accept mutex is in the env, save it and remove it.
- */
- val = getenv(MUTEX_VARNAME);
- if (val != NULL)
- {
- acceptMutex = (HANDLE) atoi(val);
- }
-
-
- /*
- * Determine if this library is being used to listen for FastCGI
- * connections. This is communicated by STDIN containing a
- * valid handle to a listener object. In this case, both the
- * "stdout" and "stderr" handles will be INVALID (ie. closed) by
- * the starting process.
- *
- * The trick is determining if this is a pipe or a socket...
- *
- * XXX: Add the async accept test to determine socket or handle to a
- * pipe!!!
- */
- if((GetStdHandle(STD_OUTPUT_HANDLE) == INVALID_HANDLE_VALUE) &&
- (GetStdHandle(STD_ERROR_HANDLE) == INVALID_HANDLE_VALUE) &&
- (GetStdHandle(STD_INPUT_HANDLE) != INVALID_HANDLE_VALUE) )
- {
- DWORD pipeMode = PIPE_READMODE_BYTE | PIPE_WAIT;
- HANDLE oldStdIn = GetStdHandle(STD_INPUT_HANDLE);
-
- // Move the handle to a "low" number
- if (! DuplicateHandle(GetCurrentProcess(), oldStdIn,
- GetCurrentProcess(), &hListen,
- 0, TRUE, DUPLICATE_SAME_ACCESS))
- {
- return -1;
- }
-
- if (! SetStdHandle(STD_INPUT_HANDLE, hListen))
- {
- return -1;
- }
-
- CloseHandle(oldStdIn);
-
- /*
- * Set the pipe handle state so that it operates in wait mode.
- *
- * NOTE: The listenFd is not mapped to a pseudo file descriptor
- * as all work done on it is contained to the OS library.
- *
- * XXX: Initial assumption is that SetNamedPipeHandleState will
- * fail if this is an IP socket...
- */
- if (SetNamedPipeHandleState(hListen, &pipeMode, NULL, NULL))
- {
- listenType = FD_PIPE_SYNC;
- listenOverlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- }
- else
- {
- listenType = FD_SOCKET_SYNC;
- }
- }
-
- /*
- * If there are no stdioFds passed in, we're done.
- */
- if(stdioFds == NULL) {
- libInitialized = 1;
- return 0;
- }
-
- /*
- * Setup standard input asynchronous I/O. There is actually a separate
- * thread spawned for this purpose. The reason for this is that some
- * web servers use anonymous pipes for the connection between itself
- * and a CGI application. Anonymous pipes can't perform asynchronous
- * I/O or use I/O completion ports. Therefore in order to present a
- * consistent I/O dispatch model to an application we emulate I/O
- * completion port behavior by having the standard input thread posting
- * messages to the hIoCompPort which look like a complete overlapped
- * I/O structure. This keeps the event dispatching simple from the
- * application perspective.
- */
- stdioHandles[STDIN_FILENO] = GetStdHandle(STD_INPUT_HANDLE);
-
- if(!SetHandleInformation(stdioHandles[STDIN_FILENO],
- HANDLE_FLAG_INHERIT, 0)) {
-/*
- * XXX: Causes error when run from command line. Check KB
- err = GetLastError();
- DebugBreak();
- exit(99);
- */
- return -1;
- }
-
- if ((fakeFd = Win32NewDescriptor(FD_PIPE_SYNC,
- (int)stdioHandles[STDIN_FILENO],
- STDIN_FILENO)) == -1) {
- return -1;
- } else {
- /*
- * Set stdin equal to our pseudo FD and create the I/O completion
- * port to be used for async I/O.
- */
- stdioFds[STDIN_FILENO] = fakeFd;
- }
-
- /*
- * Create the I/O completion port to be used for communicating with
- * the thread doing I/O on standard in. This port will carry read
- * and possibly thread termination requests to the StdinThread.
- */
- if (hStdinCompPort == INVALID_HANDLE_VALUE) {
- hStdinCompPort = CreateIoCompletionPort (INVALID_HANDLE_VALUE, NULL,
- 0, 1);
- if(hStdinCompPort == INVALID_HANDLE_VALUE) {
- printf("<H2>OS_LibInit Failed CreateIoCompletionPort: STDIN! ERROR: %d</H2>\r\n\r\n",
- GetLastError());
- return -1;
- }
- }
-
- /*
- * Create the thread that will read stdin if the CONTENT_LENGTH
- * is non-zero.
- */
- if((cLenPtr = getenv("CONTENT_LENGTH")) != NULL &&
- atoi(cLenPtr) > 0) {
- hStdinThread = CreateThread(NULL, 8192,
- (LPTHREAD_START_ROUTINE)&StdinThread,
- NULL, 0, &threadId);
- if (hStdinThread == NULL) {
- printf("<H2>OS_LibInit Failed to create STDIN thread! ERROR: %d</H2>\r\n\r\n",
- GetLastError());
- return -1;
- }
- }
-
- /*
- * STDOUT will be used synchronously.
- *
- * XXX: May want to convert this so that it could be used for OVERLAPPED
- * I/O later. If so, model it after the Stdin I/O as stdout is
- * also incapable of async I/O on some servers.
- */
- stdioHandles[STDOUT_FILENO] = GetStdHandle(STD_OUTPUT_HANDLE);
- if(!SetHandleInformation(stdioHandles[STDOUT_FILENO],
- HANDLE_FLAG_INHERIT, FALSE)) {
- //exit(99);
- return -1;
- }
-
- if ((fakeFd = Win32NewDescriptor(FD_PIPE_SYNC,
- (int)stdioHandles[STDOUT_FILENO],
- STDOUT_FILENO)) == -1) {
- return -1;
- } else {
- /*
- * Set stdout equal to our pseudo FD
- */
- stdioFds[STDOUT_FILENO] = fakeFd;
- }
-
- stdioHandles[STDERR_FILENO] = GetStdHandle(STD_ERROR_HANDLE);
- if(!SetHandleInformation(stdioHandles[STDERR_FILENO],
- HANDLE_FLAG_INHERIT, FALSE)) {
- //exit(99);
- return -1;
- }
- if ((fakeFd = Win32NewDescriptor(FD_PIPE_SYNC,
- (int)stdioHandles[STDERR_FILENO],
- STDERR_FILENO)) == -1) {
- return -1;
- } else {
- /*
- * Set stderr equal to our pseudo FD
- */
- stdioFds[STDERR_FILENO] = fakeFd;
- }
-
- return 0;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_LibShutdown --
- *
- * Shutdown the OS library.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Memory freed, handles closed.
- *
- *--------------------------------------------------------------
- */
-void OS_LibShutdown()
-{
-
- if (hIoCompPort != INVALID_HANDLE_VALUE)
- {
- CloseHandle(hIoCompPort);
- hIoCompPort = INVALID_HANDLE_VALUE;
- }
-
- if (hStdinCompPort != INVALID_HANDLE_VALUE)
- {
- CloseHandle(hStdinCompPort);
- hStdinCompPort = INVALID_HANDLE_VALUE;
- }
-
- if (acceptMutex != INVALID_HANDLE_VALUE)
- {
- ReleaseMutex(acceptMutex);
- CloseHandle(acceptMutex);
- }
-
- /* we only want to do this if we're not a web server */
- if (stdioHandles[0] != INVALID_HANDLE_VALUE) {
- DisconnectNamedPipe(hListen);
- CancelIo(hListen);
- if (bImpersonate) RevertToSelf();
- }
-
- DeleteCriticalSection(&fdTableCritical);
- WSACleanup();
-}
-
-/*
- *--------------------------------------------------------------
- *
- * Win32FreeDescriptor --
- *
- * Free I/O descriptor entry in fdTable.
- *
- * Results:
- * Frees I/O descriptor entry in fdTable.
- *
- * Side effects:
- * None.
- *
- *--------------------------------------------------------------
- */
-static void Win32FreeDescriptor(int fd)
-{
- /* Catch it if fd is a bogus value */
- ASSERT((fd >= 0) && (fd < WIN32_OPEN_MAX));
-
- EnterCriticalSection(&fdTableCritical);
-
- if (fdTable[fd].type != FD_UNUSED)
- {
- switch (fdTable[fd].type)
- {
- case FD_FILE_SYNC:
- case FD_FILE_ASYNC:
-
- /* Free file path string */
- ASSERT(fdTable[fd].path != NULL);
-
- free(fdTable[fd].path);
- fdTable[fd].path = NULL;
- break;
- case FD_PIPE_ASYNC:
- break;
- default:
- break;
- }
-
- ASSERT(fdTable[fd].path == NULL);
-
- fdTable[fd].type = FD_UNUSED;
- fdTable[fd].path = NULL;
- fdTable[fd].Errno = NO_ERROR;
- fdTable[fd].offsetHighPtr = fdTable[fd].offsetLowPtr = NULL;
-
- if (fdTable[fd].hMapMutex != NULL)
- {
- CloseHandle(fdTable[fd].hMapMutex);
- fdTable[fd].hMapMutex = NULL;
- }
- }
-
- LeaveCriticalSection(&fdTableCritical);
-
- return;
-}
-
-static short getPort(const char * bindPath)
-{
- short port = 0;
- char * p = strchr(bindPath, ':');
-
- if (p && *++p)
- {
- char buf[6];
-
- strncpy(buf, p, 6);
- buf[5] = '\0';
-
- port = (short) atoi(buf);
- }
-
- return port;
-}
-
-/**
-This function builds a Dacl which grants the creator of the objects
-FILE_ALL_ACCESS and Everyone FILE_GENERIC_READ and FILE_GENERIC_WRITE
-access to the object.
-
-This Dacl allows for higher security than a NULL Dacl, which is common for
-named-pipes, as this only grants the creator/owner write access to the
-security descriptor, and grants Everyone the ability to "use" the named-pipe.
-This scenario prevents a malevolent user from disrupting service by preventing
-arbitrary access manipulation.
-**/
-BOOL
-BuildNamedPipeAcl(
- PACL pAcl,
- PDWORD cbAclSize
- )
-{
- DWORD dwAclSize;
-
- SID_IDENTIFIER_AUTHORITY siaWorld = SECURITY_WORLD_SID_AUTHORITY;
- SID_IDENTIFIER_AUTHORITY siaCreator = SECURITY_CREATOR_SID_AUTHORITY;
-
- BYTE BufEveryoneSid[32];
- BYTE BufOwnerSid[32];
-
- PSID pEveryoneSid = (PSID)BufEveryoneSid;
- PSID pOwnerSid = (PSID)BufOwnerSid;
-
- //
- // compute size of acl
- //
- dwAclSize = sizeof(ACL) +
- 2 * ( sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) ) +
- GetSidLengthRequired( 1 ) + // well-known Everyone Sid
- GetSidLengthRequired( 1 ) ; // well-known Creator Owner Sid
-
- if(*cbAclSize < dwAclSize) {
- *cbAclSize = dwAclSize;
- return FALSE;
- }
-
- *cbAclSize = dwAclSize;
-
- //
- // intialize well known sids
- //
-
- if(!InitializeSid(pEveryoneSid, &siaWorld, 1)) return FALSE;
- *GetSidSubAuthority(pEveryoneSid, 0) = SECURITY_WORLD_RID;
-
- if(!InitializeSid(pOwnerSid, &siaCreator, 1)) return FALSE;
- *GetSidSubAuthority(pOwnerSid, 0) = SECURITY_CREATOR_OWNER_RID;
-
- if(!InitializeAcl(pAcl, dwAclSize, ACL_REVISION))
- return FALSE;
-
- //
- //
- if(!AddAccessAllowedAce(
- pAcl,
- ACL_REVISION,
- FILE_GENERIC_READ | FILE_GENERIC_WRITE,
- pEveryoneSid
- ))
- return FALSE;
-
- //
- //
- return AddAccessAllowedAce(
- pAcl,
- ACL_REVISION,
- FILE_ALL_ACCESS,
- pOwnerSid
- );
-}
-
-
-/*
- * OS_CreateLocalIpcFd --
- *
- * This procedure is responsible for creating the listener pipe
- * on Windows NT for local process communication. It will create a
- * named pipe and return a file descriptor to it to the caller.
- *
- * Results:
- * Listener pipe created. This call returns either a valid
- * pseudo file descriptor or -1 on error.
- *
- * Side effects:
- * Listener pipe and IPC address are stored in the FCGI info
- * structure.
- * 'errno' will set on errors (-1 is returned).
- *
- *----------------------------------------------------------------------
- */
-int OS_CreateLocalIpcFd(const char *bindPath, int backlog, int bCreateMutex)
-{
- int pseudoFd = -1;
- short port = getPort(bindPath);
- HANDLE mutex = INVALID_HANDLE_VALUE;
- char mutexEnvString[100];
-
- if (bCreateMutex) {
- mutex = CreateMutex(NULL, FALSE, NULL);
- if (! SetHandleInformation(mutex, HANDLE_FLAG_INHERIT, TRUE))
- {
- CloseHandle(mutex);
- return -3;
- }
- // This is a nail for listening to more than one port..
- // This should really be handled by the caller.
- _snprintf(mutexEnvString, sizeof(mutexEnvString)-1, MUTEX_VARNAME "=%d", (int) mutex);
- putenv(mutexEnvString);
- }
-
- // There's nothing to be gained (at the moment) by a shutdown Event
-
- if (port && *bindPath != ':' && strncmp(bindPath, LOCALHOST, strlen(LOCALHOST)))
- {
- fprintf(stderr, "To start a service on a TCP port can not "
- "specify a host name.\n"
- "You should either use \"localhost:<port>\" or "
- " just use \":<port>.\"\n");
- //exit(1);
- if (bCreateMutex) CloseHandle(mutexEnvString);
- return -1;
- }
-
- listenType = (port) ? FD_SOCKET_SYNC : FD_PIPE_ASYNC;
-
- if (port)
- {
- SOCKET listenSock;
- struct sockaddr_in sockAddr;
- int sockLen = sizeof(sockAddr);
-
- memset(&sockAddr, 0, sizeof(sockAddr));
- sockAddr.sin_family = AF_INET;
- sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
- sockAddr.sin_port = htons(port);
-
- listenSock = socket(AF_INET, SOCK_STREAM, 0);
- if (listenSock == INVALID_SOCKET)
- {
- if (bCreateMutex)CloseHandle(mutexEnvString);
- return -4;
- }
-
- if (bind(listenSock, (struct sockaddr *) &sockAddr, sockLen) )
- {
- if (bCreateMutex)CloseHandle(mutexEnvString);
- return -12;
- }
-
- if (listen(listenSock, backlog))
- {
- if (bCreateMutex)CloseHandle(mutexEnvString);
- return -5;
- }
-
- pseudoFd = Win32NewDescriptor(listenType, listenSock, -1);
-
- if (pseudoFd == -1)
- {
- if (bCreateMutex)CloseHandle(mutexEnvString);
- closesocket(listenSock);
- return -6;
- }
-
- hListen = (HANDLE) listenSock;
- }
- else
- {
- SECURITY_ATTRIBUTES sa;
- SECURITY_DESCRIPTOR sd;
- BYTE AclBuf[ 64 ];
- DWORD cbAclSize = 64;
- PACL pAcl = (PACL)AclBuf;
-
- HANDLE hListenPipe = INVALID_HANDLE_VALUE;
- char *pipePath = malloc(strlen(bindPathPrefix) + strlen(bindPath) + 1);
-
- if (! pipePath)
- {
- if (bCreateMutex)CloseHandle(mutexEnvString);
- return -7;
- }
-
- strcpy(pipePath, bindPathPrefix);
- strcat(pipePath, bindPath);
-
- if (bImpersonate) {
- // get the security attributes for Everybody to connect
- // we do this so that multithreaded servers that run
- // threads under secured users can access pipes created
- // by a system level thread (for instance, IIS)
- //
- // suppress errors regarding startup directory, etc
- //
- SetErrorMode(SEM_FAILCRITICALERRORS);
-
- if(!BuildNamedPipeAcl(pAcl, &cbAclSize)) {
- fprintf(stderr, "BuildNamedPipeAcl");
- return -100;
- }
-
- if(!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) {
- fprintf(stderr, "InitializeSecurityDescriptor");
- return -100;
- }
-
- if(!SetSecurityDescriptorDacl(&sd, TRUE, pAcl, FALSE)) {
- fprintf(stderr, "SetSecurityDescriptorDacl");
- return -100;
- }
-
- sa.nLength = sizeof(SECURITY_ATTRIBUTES);
- sa.lpSecurityDescriptor = &sd; // default Dacl of caller
- sa.bInheritHandle = TRUE;
-
- }
-
- hListenPipe = CreateNamedPipe(pipePath,
- PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
- PIPE_TYPE_BYTE | PIPE_WAIT | PIPE_READMODE_BYTE,
- PIPE_UNLIMITED_INSTANCES,
- 4096, 4096, 0, bImpersonate?&sa:NULL);
-
- free(pipePath);
-
- if (hListenPipe == INVALID_HANDLE_VALUE)
- {
- if (bCreateMutex)CloseHandle(mutexEnvString);
- return -8;
- }
-
- if (! SetHandleInformation(hListenPipe, HANDLE_FLAG_INHERIT, TRUE))
- {
- if (bCreateMutex)CloseHandle(mutexEnvString);
- return -9;
- }
-
- pseudoFd = Win32NewDescriptor(listenType, (int) hListenPipe, -1);
-
- if (pseudoFd == -1)
- {
- if (bCreateMutex)CloseHandle(mutexEnvString);
- CloseHandle(hListenPipe);
- return -10;
- }
-
- hListen = (HANDLE) hListenPipe;
- }
-
- return pseudoFd;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_FcgiConnect --
- *
- * Create the pipe pathname connect to the remote application if
- * possible.
- *
- * Results:
- * -1 if fail or a valid handle if connection succeeds.
- *
- * Side effects:
- * Remote connection established.
- *
- *----------------------------------------------------------------------
- */
-int OS_FcgiConnect(char *bindPath)
-{
- short port = getPort(bindPath);
- int pseudoFd = -1;
- unsigned int flags = FILE_FLAG_OVERLAPPED;
- if (port)
- {
- struct hostent *hp;
- char *host = NULL;
- struct sockaddr_in sockAddr;
- int sockLen = sizeof(sockAddr);
- SOCKET sock;
-
- if (*bindPath != ':')
- {
- char * p = strchr(bindPath, ':');
- if (p) {
- int len = p - bindPath + 1;
-
- host = (char *)malloc(len);
- if (!host) {
- fprintf(stderr, "Unable to allocate memory\n");
- return -1;
- }
- strncpy(host, bindPath, len);
- host[len-1] = '\0';
- }
- }
-
- hp = gethostbyname(host ? host : LOCALHOST);
-
- if (host)
- {
- free(host);
- }
-
- if (hp == NULL)
- {
- fprintf(stderr, "Unknown host: %s\n", bindPath);
- return -1;
- }
-
- memset(&sockAddr, 0, sizeof(sockAddr));
- sockAddr.sin_family = AF_INET;
- memcpy(&sockAddr.sin_addr, hp->h_addr, hp->h_length);
- sockAddr.sin_port = htons(port);
-
- sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock == INVALID_SOCKET)
- {
- return -1;
- }
-
- if (connect(sock, (struct sockaddr *) &sockAddr, sockLen) == SOCKET_ERROR)
- {
- closesocket(sock);
- return -1;
- }
-
- pseudoFd = Win32NewDescriptor(FD_SOCKET_SYNC, sock, -1);
- if (pseudoFd == -1)
- {
- closesocket(sock);
- return -1;
- }
- }
- else
- {
- char *pipePath = malloc(strlen(bindPathPrefix) + strlen(bindPath) + 1);
- HANDLE hPipe;
-
- if (! pipePath)
- {
- return -1;
- }
-
- strcpy(pipePath, bindPathPrefix);
- strcat(pipePath, bindPath);
-
- if (bImpersonate) {
- flags |= SECURITY_SQOS_PRESENT | SECURITY_IMPERSONATION;
- }
-
- hPipe = CreateFile(pipePath,
- GENERIC_WRITE | GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- flags,
- NULL);
-
- free(pipePath);
-
- if( hPipe == INVALID_HANDLE_VALUE || hPipe == 0)
- {
- return -1;
- }
-
- pseudoFd = Win32NewDescriptor(FD_PIPE_ASYNC, (int) hPipe, -1);
-
- if (pseudoFd == -1)
- {
- CloseHandle(hPipe);
- return -1;
- }
-
- /*
- * Set stdin equal to our pseudo FD and create the I/O completion
- * port to be used for async I/O.
- */
- if (! CreateIoCompletionPort(hPipe, hIoCompPort, pseudoFd, 1))
- {
- Win32FreeDescriptor(pseudoFd);
- CloseHandle(hPipe);
- return -1;
- }
- }
-
- return pseudoFd;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_Read --
- *
- * Pass through to the appropriate NT read function.
- *
- * Results:
- * Returns number of byes read. Mimics unix read:.
- * n bytes read, 0 or -1 failure: errno contains actual error
- *
- * Side effects:
- * None.
- *
- *--------------------------------------------------------------
- */
-int OS_Read(int fd, char * buf, size_t len)
-{
- DWORD bytesRead;
- int ret = -1;
-
- ASSERT((fd >= 0) && (fd < WIN32_OPEN_MAX));
-
- if (shutdownNow) return -1;
-
- switch (fdTable[fd].type)
- {
- case FD_FILE_SYNC:
- case FD_FILE_ASYNC:
- case FD_PIPE_SYNC:
- case FD_PIPE_ASYNC:
-
- if (ReadFile(fdTable[fd].fid.fileHandle, buf, len, &bytesRead, NULL))
- {
- ret = bytesRead;
- }
- else
- {
- fdTable[fd].Errno = GetLastError();
- ret = -1;
- }
-
- break;
-
- case FD_SOCKET_SYNC:
- case FD_SOCKET_ASYNC:
-
- ret = recv(fdTable[fd].fid.sock, buf, len, 0);
- if (ret == SOCKET_ERROR)
- {
- fdTable[fd].Errno = WSAGetLastError();
- ret = -1;
- }
-
- break;
-
- default:
-
- ASSERT(0);
- }
-
- return ret;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_Write --
- *
- * Perform a synchronous OS write.
- *
- * Results:
- * Returns number of bytes written. Mimics unix write:
- * n bytes written, 0 or -1 failure (??? couldn't find man page).
- *
- * Side effects:
- * none.
- *
- *--------------------------------------------------------------
- */
-int OS_Write(int fd, char * buf, size_t len)
-{
- DWORD bytesWritten;
- int ret = -1;
-
- ASSERT(fd >= 0 && fd < WIN32_OPEN_MAX);
-
- if (shutdownNow) return -1;
-
- switch (fdTable[fd].type)
- {
- case FD_FILE_SYNC:
- case FD_FILE_ASYNC:
- case FD_PIPE_SYNC:
- case FD_PIPE_ASYNC:
-
- if (WriteFile(fdTable[fd].fid.fileHandle, buf, len, &bytesWritten, NULL))
- {
- ret = bytesWritten;
- }
- else
- {
- fdTable[fd].Errno = GetLastError();
- }
-
- break;
-
- case FD_SOCKET_SYNC:
- case FD_SOCKET_ASYNC:
-
- ret = send(fdTable[fd].fid.sock, buf, len, 0);
- if (ret == SOCKET_ERROR)
- {
- fdTable[fd].Errno = WSAGetLastError();
- ret = -1;
- }
-
- break;
-
- default:
-
- ASSERT(0);
- }
-
- return ret;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_SpawnChild --
- *
- * Spawns a new server listener process, and stores the information
- * relating to the child in the supplied record. A wait handler is
- * registered on the child's completion. This involves creating
- * a process on NT and preparing a command line with the required
- * state (currently a -childproc flag and the server socket to use
- * for accepting connections).
- *
- * Results:
- * 0 if success, -1 if error.
- *
- * Side effects:
- * Child process spawned.
- *
- *----------------------------------------------------------------------
- */
-int OS_SpawnChild(char *execPath, int listenFd, PROCESS_INFORMATION *pInfo, char *env)
-{
- STARTUPINFO StartupInfo;
- BOOL success;
-
- memset((void *)&StartupInfo, 0, sizeof(STARTUPINFO));
- StartupInfo.cb = sizeof (STARTUPINFO);
- StartupInfo.lpReserved = NULL;
- StartupInfo.lpReserved2 = NULL;
- StartupInfo.cbReserved2 = 0;
- StartupInfo.lpDesktop = NULL;
- StartupInfo.wShowWindow = SW_HIDE;
- /*
- * FastCGI on NT will set the listener pipe HANDLE in the stdin of
- * the new process. The fact that there is a stdin and NULL handles
- * for stdout and stderr tells the FastCGI process that this is a
- * FastCGI process and not a CGI process.
- */
- StartupInfo.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
- /*
- * XXX: Do I have to dup the handle before spawning the process or is
- * it sufficient to use the handle as it's reference counted
- * by NT anyway?
- */
- StartupInfo.hStdInput = fdTable[listenFd].fid.fileHandle;
- StartupInfo.hStdOutput = INVALID_HANDLE_VALUE;
- StartupInfo.hStdError = INVALID_HANDLE_VALUE;
-
- /*
- * Make the listener socket inheritable.
- */
- success = SetHandleInformation(StartupInfo.hStdInput, HANDLE_FLAG_INHERIT,
- TRUE);
- if(!success) {
- //exit(99);
- return -1;
- }
-
- /*
- * XXX: Might want to apply some specific security attributes to the
- * processes.
- */
- success = CreateProcess(execPath, /* LPCSTR address of module name */
- NULL, /* LPCSTR address of command line */
- NULL, /* Process security attributes */
- NULL, /* Thread security attributes */
- TRUE, /* Inheritable Handes inherited. */
- 0, /* DWORD creation flags */
- env, /* Use parent environment block */
- NULL, /* Address of current directory name */
- &StartupInfo, /* Address of STARTUPINFO */
- pInfo); /* Address of PROCESS_INFORMATION */
- if(success) {
- return 0;
- } else {
- return -1;
- }
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_AsyncReadStdin --
- *
- * This initiates an asynchronous read on the standard
- * input handle. This handle is not guaranteed to be
- * capable of performing asynchronous I/O so we send a
- * message to the StdinThread to do the synchronous read.
- *
- * Results:
- * -1 if error, 0 otherwise.
- *
- * Side effects:
- * Asynchronous message is queued to the StdinThread and an
- * overlapped structure is allocated/initialized.
- *
- *--------------------------------------------------------------
- */
-int OS_AsyncReadStdin(void *buf, int len, OS_AsyncProc procPtr,
- ClientData clientData)
-{
- POVERLAPPED_REQUEST pOv;
-
- ASSERT(fdTable[STDIN_FILENO].type != FD_UNUSED);
-
- pOv = (POVERLAPPED_REQUEST)malloc(sizeof(struct OVERLAPPED_REQUEST));
- ASSERT(pOv);
- memset((void *)pOv, 0, sizeof(struct OVERLAPPED_REQUEST));
- pOv->clientData1 = (ClientData)buf;
- pOv->instance = fdTable[STDIN_FILENO].instance;
- pOv->procPtr = procPtr;
- pOv->clientData = clientData;
-
- PostQueuedCompletionStatus(hStdinCompPort, len, STDIN_FILENO,
- (LPOVERLAPPED)pOv);
- return 0;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_AsyncRead --
- *
- * This initiates an asynchronous read on the file
- * handle which may be a socket or named pipe.
- *
- * We also must save the ProcPtr and ClientData, so later
- * when the io completes, we know who to call.
- *
- * We don't look at any results here (the ReadFile may
- * return data if it is cached) but do all completion
- * processing in OS_Select when we get the io completion
- * port done notifications. Then we call the callback.
- *
- * Results:
- * -1 if error, 0 otherwise.
- *
- * Side effects:
- * Asynchronous I/O operation is queued for completion.
- *
- *--------------------------------------------------------------
- */
-int OS_AsyncRead(int fd, int offset, void *buf, int len,
- OS_AsyncProc procPtr, ClientData clientData)
-{
- DWORD bytesRead;
- POVERLAPPED_REQUEST pOv;
-
- /*
- * Catch any bogus fd values
- */
- ASSERT((fd >= 0) && (fd < WIN32_OPEN_MAX));
- /*
- * Confirm that this is an async fd
- */
- ASSERT(fdTable[fd].type != FD_UNUSED);
- ASSERT(fdTable[fd].type != FD_FILE_SYNC);
- ASSERT(fdTable[fd].type != FD_PIPE_SYNC);
- ASSERT(fdTable[fd].type != FD_SOCKET_SYNC);
-
- pOv = (POVERLAPPED_REQUEST)malloc(sizeof(struct OVERLAPPED_REQUEST));
- ASSERT(pOv);
- memset((void *)pOv, 0, sizeof(struct OVERLAPPED_REQUEST));
- /*
- * Only file offsets should be non-zero, but make sure.
- */
- if (fdTable[fd].type == FD_FILE_ASYNC)
- if (fdTable[fd].offset >= 0)
- pOv->overlapped.Offset = fdTable[fd].offset;
- else
- pOv->overlapped.Offset = offset;
- pOv->instance = fdTable[fd].instance;
- pOv->procPtr = procPtr;
- pOv->clientData = clientData;
- bytesRead = fd;
- /*
- * ReadFile returns: TRUE success, FALSE failure
- */
- if (!ReadFile(fdTable[fd].fid.fileHandle, buf, len, &bytesRead,
- (LPOVERLAPPED)pOv)) {
- fdTable[fd].Errno = GetLastError();
- if(fdTable[fd].Errno == ERROR_NO_DATA ||
- fdTable[fd].Errno == ERROR_PIPE_NOT_CONNECTED) {
- PostQueuedCompletionStatus(hIoCompPort, 0, fd, (LPOVERLAPPED)pOv);
- return 0;
- }
- if(fdTable[fd].Errno != ERROR_IO_PENDING) {
- PostQueuedCompletionStatus(hIoCompPort, 0, fd, (LPOVERLAPPED)pOv);
- return -1;
- }
- fdTable[fd].Errno = 0;
- }
- return 0;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_AsyncWrite --
- *
- * This initiates an asynchronous write on the "fake" file
- * descriptor (which may be a file, socket, or named pipe).
- * We also must save the ProcPtr and ClientData, so later
- * when the io completes, we know who to call.
- *
- * We don't look at any results here (the WriteFile generally
- * completes immediately) but do all completion processing
- * in OS_DoIo when we get the io completion port done
- * notifications. Then we call the callback.
- *
- * Results:
- * -1 if error, 0 otherwise.
- *
- * Side effects:
- * Asynchronous I/O operation is queued for completion.
- *
- *--------------------------------------------------------------
- */
-int OS_AsyncWrite(int fd, int offset, void *buf, int len,
- OS_AsyncProc procPtr, ClientData clientData)
-{
- DWORD bytesWritten;
- POVERLAPPED_REQUEST pOv;
-
- /*
- * Catch any bogus fd values
- */
- ASSERT((fd >= 0) && (fd < WIN32_OPEN_MAX));
- /*
- * Confirm that this is an async fd
- */
- ASSERT(fdTable[fd].type != FD_UNUSED);
- ASSERT(fdTable[fd].type != FD_FILE_SYNC);
- ASSERT(fdTable[fd].type != FD_PIPE_SYNC);
- ASSERT(fdTable[fd].type != FD_SOCKET_SYNC);
-
- pOv = (POVERLAPPED_REQUEST)malloc(sizeof(struct OVERLAPPED_REQUEST));
- ASSERT(pOv);
- memset((void *)pOv, 0, sizeof(struct OVERLAPPED_REQUEST));
- /*
- * Only file offsets should be non-zero, but make sure.
- */
- if (fdTable[fd].type == FD_FILE_ASYNC)
- /*
- * Only file opened via OS_AsyncWrite with
- * O_APPEND will have an offset != -1.
- */
- if (fdTable[fd].offset >= 0)
- /*
- * If the descriptor has a memory mapped file
- * handle, take the offsets from there.
- */
- if (fdTable[fd].hMapMutex != NULL) {
- /*
- * Wait infinitely; this *should* not cause problems.
- */
- WaitForSingleObject(fdTable[fd].hMapMutex, INFINITE);
-
- /*
- * Retrieve the shared offset values.
- */
- pOv->overlapped.OffsetHigh = *(fdTable[fd].offsetHighPtr);
- pOv->overlapped.Offset = *(fdTable[fd].offsetLowPtr);
-
- /*
- * Update the shared offset values for the next write
- */
- *(fdTable[fd].offsetHighPtr) += 0; /* XXX How do I handle overflow */
- *(fdTable[fd].offsetLowPtr) += len;
-
- ReleaseMutex(fdTable[fd].hMapMutex);
- } else
- pOv->overlapped.Offset = fdTable[fd].offset;
- else
- pOv->overlapped.Offset = offset;
- pOv->instance = fdTable[fd].instance;
- pOv->procPtr = procPtr;
- pOv->clientData = clientData;
- bytesWritten = fd;
- /*
- * WriteFile returns: TRUE success, FALSE failure
- */
- if (!WriteFile(fdTable[fd].fid.fileHandle, buf, len, &bytesWritten,
- (LPOVERLAPPED)pOv)) {
- fdTable[fd].Errno = GetLastError();
- if(fdTable[fd].Errno != ERROR_IO_PENDING) {
- PostQueuedCompletionStatus(hIoCompPort, 0, fd, (LPOVERLAPPED)pOv);
- return -1;
- }
- fdTable[fd].Errno = 0;
- }
- if (fdTable[fd].offset >= 0)
- fdTable[fd].offset += len;
- return 0;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_Close --
- *
- * Closes the descriptor with routine appropriate for
- * descriptor's type.
- *
- * Results:
- * Socket or file is closed. Return values mimic Unix close:
- * 0 success, -1 failure
- *
- * Side effects:
- * Entry in fdTable is marked as free.
- *
- *--------------------------------------------------------------
- */
-int OS_Close(int fd)
-{
- int ret = 0;
-
- /*
- * Catch it if fd is a bogus value
- */
- ASSERT((fd >= 0) && (fd < WIN32_OPEN_MAX));
- ASSERT(fdTable[fd].type != FD_UNUSED);
-
- switch (fdTable[fd].type) {
- case FD_PIPE_SYNC:
- case FD_PIPE_ASYNC:
- case FD_FILE_SYNC:
- case FD_FILE_ASYNC:
- /*
- * CloseHandle returns: TRUE success, 0 failure
- */
- /*
- XXX don't close here, fcgi apps fail if we do so
- need to examine resource leaks if any might exist
- if (CloseHandle(fdTable[fd].fid.fileHandle) == FALSE)
- ret = -1;
- */
- break;
- case FD_SOCKET_SYNC:
- case FD_SOCKET_ASYNC:
- /*
- * Closing a socket that has an async read outstanding causes a
- * tcp reset and possible data loss. The shutdown call seems to
- * prevent this.
- */
-
- /* shutdown(fdTable[fd].fid.sock, SD_BOTH); */
-
- {
- char buf[16];
- int r;
-
- shutdown(fdTable[fd].fid.sock,SD_SEND);
-
- do
- {
- r = recv(fdTable[fd].fid.sock,buf,16,0);
- } while (r > 0);
- }
- /*
- * closesocket returns: 0 success, SOCKET_ERROR failure
- */
- if (closesocket(fdTable[fd].fid.sock) == SOCKET_ERROR)
- ret = -1;
- break;
- default:
- return -1; /* fake failure */
- }
-
- Win32FreeDescriptor(fd);
- return ret;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_CloseRead --
- *
- * Cancel outstanding asynchronous reads and prevent subsequent
- * reads from completing.
- *
- * Results:
- * Socket or file is shutdown. Return values mimic Unix shutdown:
- * 0 success, -1 failure
- *
- *--------------------------------------------------------------
- */
-int OS_CloseRead(int fd)
-{
- int ret = 0;
-
- /*
- * Catch it if fd is a bogus value
- */
- ASSERT((fd >= 0) && (fd < WIN32_OPEN_MAX));
- ASSERT(fdTable[fd].type == FD_SOCKET_ASYNC
- || fdTable[fd].type == FD_SOCKET_SYNC);
-
- if (shutdown(fdTable[fd].fid.sock,SD_RECEIVE) == SOCKET_ERROR)
- ret = -1;
- return ret;
-}
-
-/*
- *--------------------------------------------------------------
- *
- * OS_DoIo --
- *
- * This function was formerly OS_Select. It's purpose is
- * to pull I/O completion events off the queue and dispatch
- * them to the appropriate place.
- *
- * Results:
- * Returns 0.
- *
- * Side effects:
- * Handlers are called.
- *
- *--------------------------------------------------------------
- */
-int OS_DoIo(struct timeval *tmo)
-{
- unsigned long fd;
- unsigned long bytes;
- POVERLAPPED_REQUEST pOv;
- struct timeb tb;
- int ms;
- int ms_last;
- int err;
-
- /* XXX
- * We can loop in here, but not too long, as wait handlers
- * must run.
- * For cgi stdin, apparently select returns when io completion
- * ports don't, so don't wait the full timeout.
- */
- if(tmo)
- ms = (tmo->tv_sec*1000 + tmo->tv_usec/1000) / 2;
- else
- ms = 1000;
- ftime(&tb);
- ms_last = tb.time*1000 + tb.millitm;
- while (ms >= 0) {
- if(tmo && (ms = tmo->tv_sec*1000 + tmo->tv_usec/1000)> 100)
- ms = 100;
- if (!GetQueuedCompletionStatus(hIoCompPort, &bytes, &fd,
- (LPOVERLAPPED *)&pOv, ms) && !pOv) {
- err = WSAGetLastError();
- return 0; /* timeout */
- }
-
- ASSERT((fd >= 0) && (fd < WIN32_OPEN_MAX));
- /* call callback if descriptor still valid */
- ASSERT(pOv);
- if(pOv->instance == fdTable[fd].instance)
- (*pOv->procPtr)(pOv->clientData, bytes);
- free(pOv);
-
- ftime(&tb);
- ms -= (tb.time*1000 + tb.millitm - ms_last);
- ms_last = tb.time*1000 + tb.millitm;
- }
- return 0;
-}
-
-static int isAddrOK(struct sockaddr_in * inet_sockaddr, const char * okAddrs)
-{
- static const char *token = " ,;:\t";
- char *ipaddr;
- char *p;
-
- if (okAddrs == NULL) return TRUE;
-
- ipaddr = inet_ntoa(inet_sockaddr->sin_addr);
- p = strstr(okAddrs, ipaddr);
-
- if (p == NULL) return FALSE;
-
- if (p == okAddrs)
- {
- p += strlen(ipaddr);
- return (strchr(token, *p) != NULL);
- }
-
- if (strchr(token, *--p) != NULL)
- {
- p += strlen(ipaddr) + 1;
- return (strchr(token, *p) != NULL);
- }
-
- return FALSE;
-}
-
-#ifndef NO_WSAACEPT
-static int CALLBACK isAddrOKCallback(LPWSABUF lpCallerId,
- LPWSABUF dc0,
- LPQOS dc1,
- LPQOS dc2,
- LPWSABUF dc3,
- LPWSABUF dc4,
- GROUP *dc5,
- DWORD data)
-{
- struct sockaddr_in *sockaddr = (struct sockaddr_in *) lpCallerId->buf;
-
- // Touch the args to avoid warnings
- dc0 = NULL; dc1 = NULL; dc2 = NULL; dc3 = NULL; dc4 = NULL; dc5 = NULL;
-
- if ((void *) data == NULL) return CF_ACCEPT;
-
- if (sockaddr->sin_family != AF_INET) return CF_ACCEPT;
-
- return isAddrOK(sockaddr, (const char *) data) ? CF_ACCEPT : CF_REJECT;
-}
-#endif
-
-static printLastError(const char * text)
-{
- LPVOID buf;
-
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- GetLastError(),
- 0,
- (LPTSTR) &buf,
- 0,
- NULL
- );
-
- fprintf(stderr, "%s: %s\n", text, (LPCTSTR) buf);
- LocalFree(buf);
-}
-
-static int acceptNamedPipe()
-{
- int ipcFd = -1;
-
- if (! ConnectNamedPipe(hListen, &listenOverlapped))
- {
- switch (GetLastError())
- {
- case ERROR_PIPE_CONNECTED:
-
- // A client connected after CreateNamedPipe but
- // before ConnectNamedPipe. Its a good connection.
-
- break;
-
- case ERROR_IO_PENDING:
-
- // Wait for a connection to complete.
-
- while (WaitForSingleObject(listenOverlapped.hEvent,
- ACCEPT_TIMEOUT) == WAIT_TIMEOUT)
- {
- if (shutdownPending)
- {
- OS_LibShutdown();
- return -1;
- }
- }
-
- break;
-
- case ERROR_PIPE_LISTENING:
-
- // The pipe handle is in nonblocking mode.
-
- case ERROR_NO_DATA:
-
- // The previous client closed its handle (and we failed
- // to call DisconnectNamedPipe)
-
- default:
-
- printLastError("unexpected ConnectNamedPipe() error");
- }
- }
-
- //
- // impersonate the client
- //
- if(bImpersonate && !ImpersonateNamedPipeClient(hListen)) {
- DisconnectNamedPipe(hListen);
- } else {
- ipcFd = Win32NewDescriptor(FD_PIPE_SYNC, (int) hListen, -1);
- if (ipcFd == -1)
- {
- DisconnectNamedPipe(hListen);
- if (bImpersonate) RevertToSelf();
- }
- }
-
- return ipcFd;
-}
-
-static int acceptSocket(const char *webServerAddrs)
-{
- SOCKET hSock;
- int ipcFd = -1;
-
- for (;;)
- {
- struct sockaddr sockaddr;
- int sockaddrLen = sizeof(sockaddr);
-
- for (;;)
- {
- const struct timeval timeout = {1, 0};
- fd_set readfds;
-
- FD_ZERO(&readfds);
- FD_SET((unsigned int) hListen, &readfds);
-
- if (select(0, &readfds, NULL, NULL, &timeout) == 0)
- {
- if (shutdownPending)
- {
- OS_LibShutdown();
- return -1;
- }
- }
- else
- {
- break;
- }
- }
-
-#if NO_WSAACEPT
- hSock = accept((SOCKET) hListen, &sockaddr, &sockaddrLen);
-
- if (hSock == INVALID_SOCKET)
- {
- break;
- }
-
- if (isAddrOK((struct sockaddr_in *) &sockaddr, webServerAddrs))
- {
- break;
- }
-
- closesocket(hSock);
-#else
- hSock = WSAAccept((unsigned int) hListen,
- &sockaddr,
- &sockaddrLen,
- isAddrOKCallback,
- (DWORD) webServerAddrs);
-
- if (hSock != INVALID_SOCKET)
- {
- break;
- }
-
- if (WSAGetLastError() != WSAECONNREFUSED)
- {
- break;
- }
-#endif
- }
-
- if (hSock == INVALID_SOCKET)
- {
- /* Use FormatMessage() */
- fprintf(stderr, "accept()/WSAAccept() failed: %d", WSAGetLastError());
- return -1;
- }
-
- ipcFd = Win32NewDescriptor(FD_SOCKET_SYNC, hSock, -1);
- if (ipcFd == -1)
- {
- closesocket(hSock);
- }
-
- return ipcFd;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_Accept --
- *
- * Accepts a new FastCGI connection. This routine knows whether
- * we're dealing with TCP based sockets or NT Named Pipes for IPC.
- *
- * fail_on_intr is ignored in the Win lib.
- *
- * Results:
- * -1 if the operation fails, otherwise this is a valid IPC fd.
- *
- *----------------------------------------------------------------------
- */
-int OS_Accept(int listen_sock, int fail_on_intr, const char *webServerAddrs)
-{
- int ipcFd = -1;
-
- // Touch args to prevent warnings
- listen_sock = 0; fail_on_intr = 0;
-
- // @todo Muliple listen sockets and sockets other than 0 are not
- // supported due to the use of globals.
-
- if (shutdownPending)
- {
- OS_LibShutdown();
- return -1;
- }
-
- // The mutex is to keep other processes (and threads, when supported)
- // from going into the accept cycle. The accept cycle needs to
- // periodically break out to check the state of the shutdown flag
- // and there's no point to having more than one thread do that.
-
- if (acceptMutex != INVALID_HANDLE_VALUE)
- {
- DWORD ret;
- while ((ret = WaitForSingleObject(acceptMutex, ACCEPT_TIMEOUT)) == WAIT_TIMEOUT)
- {
- if (shutdownPending) break;
- }
- if (ret == WAIT_FAILED) {
- printLastError("WaitForSingleObject() failed");
- return -1;
- }
- }
-
- if (shutdownPending)
- {
- OS_LibShutdown();
- }
- else if (listenType == FD_PIPE_SYNC)
- {
- ipcFd = acceptNamedPipe();
- }
- else if (listenType == FD_SOCKET_SYNC)
- {
- ipcFd = acceptSocket(webServerAddrs);
- }
- else
- {
- fprintf(stderr, "unknown listenType (%d)\n", listenType);
- }
-
- if (acceptMutex != INVALID_HANDLE_VALUE)
- {
- ReleaseMutex(acceptMutex);
- }
-
- return ipcFd;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_IpcClose
- *
- * OS IPC routine to close an IPC connection.
- *
- * Results:
- *
- *
- * Side effects:
- * IPC connection is closed.
- *
- *----------------------------------------------------------------------
- */
-int OS_IpcClose(int ipcFd)
-{
- if (ipcFd == -1)
- return 0;
-
- /*
- * Catch it if fd is a bogus value
- */
- ASSERT((ipcFd >= 0) && (ipcFd < WIN32_OPEN_MAX));
- ASSERT(fdTable[ipcFd].type != FD_UNUSED);
-
- switch(listenType) {
-
- case FD_PIPE_SYNC:
- /*
- * Make sure that the client (ie. a Web Server in this case) has
- * read all data from the pipe before we disconnect.
- */
- if(!FlushFileBuffers(fdTable[ipcFd].fid.fileHandle))
- return -1;
- if(DisconnectNamedPipe(fdTable[ipcFd].fid.fileHandle)) {
- OS_Close(ipcFd);
- if (bImpersonate) RevertToSelf();
- return 0;
- } else {
- return -1;
- }
- break;
-
- case FD_SOCKET_SYNC:
- OS_Close(ipcFd);
- return 0;
- break;
-
- case FD_UNUSED:
- default:
- //exit(106);
- return -1;
- break;
- }
- return -1;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_IsFcgi --
- *
- * Determines whether this process is a FastCGI process or not.
- *
- * Results:
- * Returns 1 if FastCGI, 0 if not.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-int OS_IsFcgi(int sock)
-{
- // Touch args to prevent warnings
- sock = 0;
-
- /* XXX This is broken for sock */
-
- return (listenType != FD_UNUSED);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * OS_SetFlags --
- *
- * Sets selected flag bits in an open file descriptor. Currently
- * this is only to put a SOCKET into non-blocking mode.
- *
- *----------------------------------------------------------------------
- */
-void OS_SetFlags(int fd, int flags)
-{
- unsigned long pLong = 1L;
-
- if (fdTable[fd].type == FD_SOCKET_SYNC && flags == O_NONBLOCK) {
- if (ioctlsocket(fdTable[fd].fid.sock, FIONBIO, &pLong) ==
- SOCKET_ERROR) {
- //exit(WSAGetLastError());
- SetLastError(WSAGetLastError());
- return;
- }
- if (!CreateIoCompletionPort((HANDLE)fdTable[fd].fid.sock,
- hIoCompPort, fd, 1)) {
- //err = GetLastError();
- //exit(err);
- return;
- }
-
- fdTable[fd].type = FD_SOCKET_ASYNC;
- }
- return;
-}
-
diff --git a/sapi/cgi/libfcgi/strerror.c b/sapi/cgi/libfcgi/strerror.c
deleted file mode 100644
index fac7c8eda2..0000000000
--- a/sapi/cgi/libfcgi/strerror.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * The terms in the file "LICENSE.TERMS" do not apply to this file.
- * See terms below.
- *
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-/*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/
-static char *rcsid = "$Id$";
-#endif /* LIBC_SCCS and not lint */
-
-#include "fcgi_config.h"
-
-#if ! defined (HAVE_STRERROR)
-#include <string.h>
-
-/*
- * Since perror() is not allowed to change the contents of strerror()'s
- * static buffer, both functions supply their own buffers to the
- * internal function __strerror().
- */
-
-char *
-__strerror(int num, char *buf)
-{
-#define UPREFIX "Unknown error: "
- extern char *sys_errlist[];
- extern int sys_nerr;
- register unsigned int errnum;
- register char *p, *t;
- char tmp[40];
-
- errnum = num; /* convert to unsigned */
- if (errnum < sys_nerr)
- return(sys_errlist[errnum]);
-
- /* Do this by hand, so we don't include stdio(3). */
- t = tmp;
- do {
- *t++ = "0123456789"[errnum % 10];
- } while (errnum /= 10);
-
- strcpy (buf, UPREFIX);
- for (p = buf + sizeof(UPREFIX) -1;;) {
- *p++ = *--t;
- if (t <= tmp)
- break;
- }
-
- return buf;
-}
-
-
-char *
-strerror(int num)
-{
- static char buf[40]; /* 64-bit number + slop */
- return __strerror(num, buf);
-}
-
-#endif
diff --git a/sapi/cgi/php.sym b/sapi/cgi/php.sym
deleted file mode 100644
index e69de29bb2..0000000000
--- a/sapi/cgi/php.sym
+++ /dev/null
diff --git a/sapi/cgi/php_getopt.h b/sapi/cgi/php_getopt.h
deleted file mode 100644
index 1e2355ff63..0000000000
--- a/sapi/cgi/php_getopt.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Marcus Boerger <helly@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-#include "php.h"
-
-/* Define structure for one recognized option (both single char and long name).
- * If short_open is '-' this is the last option.
- */
-typedef struct _opt_struct {
- const char opt_char;
- const int need_param;
- const char * opt_name;
-} opt_struct;
-
-int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err);
diff --git a/sapi/cli/CREDITS b/sapi/cli/CREDITS
deleted file mode 100644
index fac101d747..0000000000
--- a/sapi/cli/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-CLI
-Edin Kadribasic, Marcus Boerger
diff --git a/sapi/cli/Makefile.frag b/sapi/cli/Makefile.frag
deleted file mode 100644
index df6c86f2f2..0000000000
--- a/sapi/cli/Makefile.frag
+++ /dev/null
@@ -1,9 +0,0 @@
-$(SAPI_CLI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_CLI_OBJS)
- $(BUILD_CLI)
-
-install-cli: $(SAPI_CLI_PATH)
- @echo "Installing PHP CLI binary: $(INSTALL_ROOT)$(bindir)/"
- @$(INSTALL_CLI)
- @echo "Installing PHP CLI man page: $(INSTALL_ROOT)$(mandir)/man1/"
- @$(mkinstalldirs) $(INSTALL_ROOT)$(mandir)/man1
- @$(INSTALL_DATA) $(builddir)/php.1 $(INSTALL_ROOT)$(mandir)/man1/php.1
diff --git a/sapi/cli/README b/sapi/cli/README
deleted file mode 100644
index e6bf5cc6c6..0000000000
--- a/sapi/cli/README
+++ /dev/null
@@ -1,19 +0,0 @@
-The CLI (command line interface) SAPI has been introduced
-with a goal of making PHP better at supporting the creation of
-stand alone applications.
-
-It is based on CGI SAPI with all CGI specific things removed.
-
-The main differences between the two:
-
-* CLI is started up in quiet mode by default.
- (-q switch kept for compatibility)
-* It does not change the working directory to that of the script.
- (-C switch kept for compatibility)
-* Plain text error message
-* $argc and $argv registered irrespective of register_globals
- and register_argc_argv php.ini settings.
-* implicit_flush always on
-* -r option which allows execution of PHP code directly from
- the command line (e.g. php -r 'echo md5("test");' )
-* max_execution_time is set to unlimited, overriding php.ini setting.
diff --git a/sapi/cli/TODO b/sapi/cli/TODO
deleted file mode 100644
index ccb980f459..0000000000
--- a/sapi/cli/TODO
+++ /dev/null
@@ -1,6 +0,0 @@
-TODO:
-
-- plain text "php -i" and phpinfo()
-- fix the so called CLI defaults set by zend_alter_ini_entry() in php_ini.c.
- They currently cannot be set within the PHP.INI file but can be with the -d
- command line switch and during runtime.
diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4
deleted file mode 100644
index 7651e702b3..0000000000
--- a/sapi/cli/config.m4
+++ /dev/null
@@ -1,40 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for CLI build)
-
-AC_ARG_ENABLE(cli,
-[ --disable-cli Disable building CLI version of PHP
- (this forces --without-pear).],
-[
- PHP_SAPI_CLI=$enableval
-],[
- PHP_SAPI_CLI=yes
-])
-
-if test "$PHP_SAPI_CLI" != "no"; then
- PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/cli/Makefile.frag,$abs_srcdir/sapi/cli,sapi/cli)
- SAPI_CLI_PATH=sapi/cli/php
- PHP_SUBST(SAPI_CLI_PATH)
-
- case $host_alias in
- *darwin*)
- BUILD_CLI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_CLI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
- ;;
- *cygwin*)
- SAPI_CLI_PATH=sapi/cli/php.exe
- BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
- ;;
- *)
- BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
- ;;
- esac
- INSTALL_CLI="\$(mkinstalldirs) \$(INSTALL_ROOT)\$(bindir); \$(INSTALL) -m 0755 \$(SAPI_CLI_PATH) \$(INSTALL_ROOT)\$(bindir)/php"
-
- PHP_SUBST(BUILD_CLI)
- PHP_SUBST(INSTALL_CLI)
- PHP_OUTPUT(sapi/cli/php.1)
-fi
-
-AC_MSG_RESULT($PHP_SAPI_CLI)
diff --git a/sapi/cli/getopt.c b/sapi/cli/getopt.c
deleted file mode 100644
index e048e95058..0000000000
--- a/sapi/cli/getopt.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Marcus Boerger <helly@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
-#include "php_getopt.h"
-#define OPTERRCOLON (1)
-#define OPTERRNF (2)
-#define OPTERRARG (3)
-
-
-static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err)
-{
- if (show_err)
- {
- fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1);
- switch(err)
- {
- case OPTERRCOLON:
- fprintf(stderr, ": in flags\n");
- break;
- case OPTERRNF:
- fprintf(stderr, "option not found %c\n", argv[oint][optchr]);
- break;
- case OPTERRARG:
- fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]);
- break;
- default:
- fprintf(stderr, "unknown\n");
- break;
- }
- }
- return('?');
-}
-
-int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err)
-{
- static int optchr = 0;
- static int dash = 0; /* have already seen the - */
- int arg_start = 2;
-
- int opts_idx = -1;
-
- if (*optind >= argc) {
- return(EOF);
- }
- if (!dash) {
- if ((argv[*optind][0] != '-')) {
- return(EOF);
- } else {
- if (!argv[*optind][1])
- {
- /*
- * use to specify stdin. Need to let pgm process this and
- * the following args
- */
- return(EOF);
- }
- }
- }
- if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) {
- /* '--' indicates end of args if not followed by a known long option name */
- while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
- (*optind)++;
- return(EOF);
- } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) {
- break;
- }
- }
- optchr = 0;
- dash = 1;
- arg_start = 2 + strlen(opts[opts_idx].opt_name);
- }
- if (!dash) {
- dash = 1;
- optchr = 1;
- }
-
- /* Check if the guy tries to do a -: kind of flag */
- if (argv[*optind][optchr] == ':') {
- dash = 0;
- (*optind)++;
- return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err));
- }
- if (opts_idx < 0) {
- while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
- int errind = *optind;
- int errchr = optchr;
-
- if (!argv[*optind][optchr+1]) {
- dash = 0;
- (*optind)++;
- } else {
- optchr++;
- }
- return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err));
- } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) {
- break;
- }
- }
- }
- if (opts[opts_idx].need_param) {
- /* Check for cases where the value of the argument
- is in the form -<arg> <val> or in the form -<arg><val> */
- dash = 0;
- if(!argv[*optind][arg_start]) {
- (*optind)++;
- if (*optind == argc) {
- return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
- }
- *optarg = argv[(*optind)++];
- } else {
- *optarg = &argv[*optind][arg_start];
- (*optind)++;
- }
- return opts[opts_idx].opt_char;
- } else {
- if (arg_start == 2) {
- if (!argv[*optind][optchr+1])
- {
- dash = 0;
- (*optind)++;
- } else {
- optchr++;
- }
- } else {
- (*optind)++;
- }
- return opts[opts_idx].opt_char;
- }
- assert(0);
- return(0); /* never reached */
-}
diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in
deleted file mode 100644
index 9e6b2c075d..0000000000
--- a/sapi/cli/php.1.in
+++ /dev/null
@@ -1,387 +0,0 @@
-./" +----------------------------------------------------------------------+
-./" | PHP Version 4 |
-./" +----------------------------------------------------------------------+
-./" | Copyright (c) 1997-2003 The PHP Group |
-./" +----------------------------------------------------------------------+
-./" | This source file is subject to version 2.02 of the PHP license, |
-./" | that is bundled with this package in the file LICENSE, and is |
-./" | available at through the world-wide-web at |
-./" | http://www.php.net/license/2_02.txt. |
-./" | If you did not receive a copy of the PHP license and are unable to |
-./" | obtain it through the world-wide-web, please send a note to |
-./" | license@php.net so we can mail you a copy immediately. |
-./" +----------------------------------------------------------------------+
-./" | Author: Marcus Boerger <helly@php.net> |
-./" +----------------------------------------------------------------------+
-./"
-./" $Id$
-./"
-.TH PHP 1 "Feb 2003" "The PHP Group" "Scripting Language"
-.SH NAME
-.TP 15
-.B php
-PHP Command Line Interface 'CLI'
-.SH SYNOPSIS
-.B php
-[options] [
-.B \-f ]
-.IR file
-[[\-\-]
-.IR args.\|.\|. ]
-.LP
-.B php
-[options]
-.B \-r
-.IR code
-[[\-\-]
-.IR args.\|.\|. ]
-.LP
-.B php
-[options] [\-B
-.IR code ]
-.B \-R
-.IR code
-[\-E
-.IR code ]
-[[\-\-]
-.IR args.\|.\|. ]
-.LP
-.B php
-[options] [\-B
-.IR code ]
-.B \-F
-.IR file
-[\-E
-.IR code ]
-[[\-\-]
-.IR args.\|.\|. ]
-.LP
-.B php
-[options] \-\- [
-.IR args.\|.\|. ]
-.LP
-.SH DESCRIPTION
-.B PHP
-is a widely\-used general\-purpose scripting language that is especially suited for
-Web development and can be embedded into HTML. This is the command line interface
-that enables you to the following:
-.P
-You can parse and execute files by using parameter \-f followed by the name of the
-.IR file
-to be executed.
-.LP
-Using parameter \-r you can directly execute PHP
-.IR code
-simply as you would do inside a
-.B \.php
-file when using the
-.B eval()
-function.
-.LP
-It is also possible to process the standard input line by line using either
-the parameter \-R or \-F. In this mode each separate input line causes the
-.IR code
-specified by \-R or the
-.IR file
-specified by \-F to be executed.
-You can access the input line by \fB$argn\fP. While processing the input lines
-.B $argi
-contains the number of the actual line being processed. Further more
-the paramters \-B and \-E can be used to execute
-.IR code
-(see \-r) before and
-after all input lines have been processed respectively.
-.LP
-If none of \-r \-f \-B \-R \-F or \-E is present but a single parameter is given
-then this parameter is taken as the filename to parse and execute (same as
-with \-f). If no parameter is present then the standard input is read and
-executed.
-.SH OPTIONS
-.TP 15
-.PD 0
-.B \-\-interactive
-.TP
-.PD 1
-.B \-a
-Run interactively
-.TP
-.PD 0
-.B \-\-php\-ini \fIpath\fP|\fIfile\fP
-.TP
-.PD 1
-.B \-c \fIpath\fP|\fIfile\fP
-Look for
-.B php.ini
-file in the directory
-.IR path
-or use the specified
-.IR file
-.TP
-.PD 0
-.B \-\-no\-php\-ini
-.TP
-.PD 1
-.B \-n
-No
-.B php.ini
-file will be used
-.TP
-.PD 0
-.B \-\-define \fIfoo\fP[=\fIbar\fP]
-.TP
-.PD 1
-.B \-d \fIfoo\fP[=\fIbar\fP]
-Define INI entry
-.IR foo
-with value
-.IR bar
-.TP
-.B \-e
-Generate extended information for debugger/profiler
-.TP
-.PD 0
-.B \-\-file \fIfile\fP
-.TP
-.PD 1
-.B \-f \fIfile\fP
-Parse and execute
-.IR file
-.TP
-.PD 0
-.B \-\-global \fIname\fP
-.TP
-.PD 1
-.B \-g \fIname\fP
-Make variable
-.IR name
-global in script.
-.TP
-.PD 0
-.B \-\-help
-.TP
-.PD 1
-.B \-h
-This help
-.TP
-.PD 0
-.B \-\-hide\-args
-.TP
-.PD 1
-.B \-H
-Hide script name (\fIfile\fP) and parameters (\fIargs\.\.\.\fP) from external
-tools. For example you may want to use this when a php script is started as
-a daemon and the command line contains sensitive data such as passwords.
-.TP
-.PD 0
-.B \-\-info
-.TP
-.PD 1
-.B \-i
-PHP information and configuration
-.TP
-.PD 0
-.B \-\-syntax\-check
-.TP
-.PD 1
-.B \-l
-Syntax check only (lint)
-.TP
-.PD 0
-.B \-\-modules
-.TP
-.PD 1
-.B \-m
-Show compiled in modules
-.TP
-.PD 0
-.B \-\-run \fIcode\fP
-.TP
-.PD 1
-.B \-r \fIcode\fP
-Run PHP
-.IR code
-without using script tags
-.B '<?..?>'
-.TP
-.PD 0
-.B \-\-process\-begin \fIcode\fP
-.TP
-.PD 1
-.B \-B \fIcode\fP
-Run PHP
-.IR code
-before processing input lines
-.TP
-.PD 0
-.B \-\-process\-code \fIcode\fP
-.TP
-.PD 1
-.B \-R \fIcode\fP
-Run PHP
-.IR code
-for every input line
-.TP
-.PD 0
-.B \-\-process\-file \fIfile\fP
-.TP
-.PD 1
-.B \-F \fIfile\fP
-Parse and execute
-.IR file
-for every input line
-.TP
-.PD 0
-.B \-\-process\-end \fIcode\fP
-.TP
-.PD 1
-.B \-E \fIcode\fP
-Run PHP
-.IR code
-after processing all input lines
-.TP
-.PD 0
-.B \-\-syntax\-highlight
-.TP
-.PD 1
-.B \-s
-Display colour syntax highlighted source
-.TP
-.PD 0
-.B \-\-version
-.TP
-.PD 1
-.B \-v
-Version number
-.TP
-.PD 0
-.B \-\-stripped
-.TP
-.PD 1
-.B \-w
-Display source with stripped comments and whitespace
-.TP
-.PD 0
-.B \-\-zend\-extension \fIfile\fP
-.TP
-.PD 1
-.B \-z \fIfile\fP
-Load Zend extension
-.IR file
-.TP
-.IR args.\|.\|.
-Arguments passed to script. Use
-.B '\-\-'
-.IR args
-when first argument starts with
-.B '\-'
-or script is read from stdin
-.SH FILES
-.TP 15
-.B php\-cli.ini
-The configuration file for the CLI version of PHP.
-.TP
-.B php.ini
-The standard configuration file will only be used when
-.B php\-cli.ini
-cannot not be found.
-.SH EXAMPLES
-.TP 5
-\fIphp -r 'echo "Hello World\\n";'\fP
-This command simply writes the text "Hello World" to stabdard out.
-.TP
-\fIphp \-r 'print_r(gd_info());'\fP
-This shows the configuration of your gd extension. You can use this
-to easily check which imag formats you can use. If you have any
-dynamic modules you may want to use the same ini file that php uses
-when executed from your webserver. There are more extensions which
-have such a function. For dba use:
-.RS
-\fIphp \-r 'print_r(dba_handlers(1));'\fP
-.RE
-.TP
-\fIphp \-R'echo strip_tags($argn)."\\n";\fP
-This PHP command strips off the HTML tags line by line and outputs the
-result. To see how it works you can first look at the following PHP command '
-\fIphp \-d html_errors=1 \-i\fP' which uses PHP to output HTML formatted
-configuration information. If you then combine those two
-\'\fIphp \.\.\.|php \.\.\.\fP\' you\'ll see what happens.
-.TP
-\fIphp \-E 'echo "Lines: $argi\\n";'\fP
-Using this PHP command you can count the lines being input.
-.TP
-\fIphp \-R '$l+=count(file($argn));' \-E'echo "Lines:$l\\n";'\fP
-In this example PHP expects each input line beeing a file. It counts all lines
-of the files specified by each input line and shows the summarized result.
-You may combine this with tools like find and change the php scriptlet.
-.TP
-\fIphp \-R 'echo "$argn\\n"; fgets(STDIN);'\fP
-Since you have access to STDIN from within \-B \-R \-F and \-E you can skip
-certain input lines with your code. But note that in such cases $argi only
-counts the lines being processed by php itself. Having read this you will
-guess what the above program does: skipping every second input line.
-.SH TIPS
-You can use a shebang line to automatically invoke php
-from scripts. Only the CLI version of PHP will ignore
-such a first line as shown below:
-.P
-.PD 0
-.RS
-#!/bin/php
-.P
-<?php
-.P
- // your script
-.P
-?>
-.RE
-.PD 1
-.P
-.SH SEE ALSO
-For a more or less complete description of PHP look here:
-.PD 0
-.P
-.B http://www.php.net/manual/
-.PD 1
-.P
-A nice introduction to PHP by Stig Sæther Bakken can be found here:
-.PD 0
-.P
-.B http://www.zend.com/zend/art/intro.php
-.PD 1
-.SH BUGS
-You can view the list of known bugs or add any new bug you
-found here:
-.PD 0
-.P
-.B http://bugs.php.net
-.PD 1
-.SH AUTHORS
-The PHP Group: Thies C. Arntzen, Stig Bakken, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski.
-.P
-Additional work for the CLI sapi was done by Edin Kadribasic and Marcus Boerger.
-.P
-A List of active developers can be found here:
-.PD 0
-.P
-.B http://www.php.net/credits.php
-.PD 1
-.P
-And last but not least PHP was developed with the help of a huge amount of
-contributors all around the world.
-.SH VERSION INFORMATION
-This manpage describes \fBphp\fP, version @PHP_VERSION@.
-.SH COPYRIGHT
-Copyright \(co 1997\-2003 The PHP Group
-.LP
-This source file is subject to version 2.02 of the PHP license,
-that is bundled with this package in the file LICENSE, and is
-available at through the world-wide-web at
-.PD 0
-.P
-.B http://www.php.net/license/2_02.txt
-.PD 1
-.P
-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
-.B license@php.net
-so we can mail you a copy immediately.
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
deleted file mode 100644
index 339e5ea105..0000000000
--- a/sapi/cli/php_cli.c
+++ /dev/null
@@ -1,1020 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Edin Kadribasic <edink@php.net> |
- | Marcus Boerger <helly@php.net> |
- | Parts based on CGI SAPI Module by |
- | Rasmus Lerdorf, Stig Bakken and Zeev Suraski |
- +----------------------------------------------------------------------+
-*/
-
-
-#include "php.h"
-#include "php_globals.h"
-#include "php_variables.h"
-#include "zend_hash.h"
-#include "zend_modules.h"
-
-#include "SAPI.h"
-
-#include <stdio.h>
-#include "php.h"
-#ifdef PHP_WIN32
-#include "win32/time.h"
-#include "win32/signal.h"
-#include <process.h>
-#endif
-#if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-#if HAVE_SETLOCALE
-#include <locale.h>
-#endif
-#include "zend.h"
-#include "zend_extensions.h"
-#include "php_ini.h"
-#include "php_globals.h"
-#include "php_main.h"
-#include "fopen_wrappers.h"
-#include "ext/standard/php_standard.h"
-#ifdef PHP_WIN32
-#include <io.h>
-#include <fcntl.h>
-#include "win32/php_registry.h"
-#endif
-
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-
-#ifdef __riscos__
-#include <unixlib/local.h>
-#endif
-
-#include "zend_compile.h"
-#include "zend_execute.h"
-#include "zend_highlight.h"
-#include "zend_indent.h"
-
-
-#include "php_getopt.h"
-
-#define PHP_MODE_STANDARD 1
-#define PHP_MODE_HIGHLIGHT 2
-#define PHP_MODE_INDENT 3
-#define PHP_MODE_LINT 4
-#define PHP_MODE_STRIP 5
-#define PHP_MODE_CLI_DIRECT 6
-#define PHP_MODE_PROCESS_STDIN 7
-
-static char *optarg = NULL;
-static int optind = 1;
-
-static const opt_struct OPTIONS[] = {
- {'a', 0, "interactive"},
- {'B', 1, "process-begin"},
- {'C', 0, "no-chdir"}, /* for compatibility with CGI (do not chdir to script directory) */
- {'c', 1, "php-ini"},
- {'d', 1, "define"},
- {'E', 1, "process-end"},
- {'e', 0, "profile-info"},
- {'F', 1, "process-file"},
- {'f', 1, "file"},
- {'g', 1, "global"},
- {'h', 0, "help"},
- {'i', 0, "info"},
- {'l', 0, "syntax-check"},
- {'m', 0, "modules"},
- {'n', 0, "no-php-ini"},
- {'q', 0, "no-header"}, /* for compatibility with CGI (do not generate HTTP headers) */
- {'R', 1, "process-code"},
- {'H', 0, "hide-args"},
- {'r', 1, "run"},
- {'s', 0, "syntax-highlight"},
- {'s', 0, "syntax-highlighting"},
- {'w', 0, "strip"},
- {'?', 0, "usage"},/* help alias (both '?' and 'usage') */
- {'v', 0, "version"},
- {'z', 1, "zend-extension"},
- {'-', 0, NULL} /* end of args */
-};
-
-static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
-{
- php_printf("%s\n", module->name);
- return 0;
-}
-
-static int module_name_cmp(const void *a, const void *b TSRMLS_DC)
-{
- Bucket *f = *((Bucket **) a);
- Bucket *s = *((Bucket **) b);
-
- return strcmp(((zend_module_entry *)f->pData)->name,
- ((zend_module_entry *)s->pData)->name);
-}
-
-static void print_modules(TSRMLS_D)
-{
- HashTable sorted_registry;
- zend_module_entry tmp;
-
- zend_hash_init(&sorted_registry, 50, NULL, NULL, 1);
- zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry));
- zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC);
- zend_hash_apply_with_argument(&sorted_registry, (apply_func_arg_t) print_module_info, NULL TSRMLS_CC);
- zend_hash_destroy(&sorted_registry);
-}
-
-static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC)
-{
- php_printf("%s\n", ext->name);
- return 0;
-}
-
-static int extension_name_cmp(const zend_llist_element **f,
- const zend_llist_element **s TSRMLS_DC)
-{
- return strcmp(((zend_extension *)(*f)->data)->name,
- ((zend_extension *)(*s)->data)->name);
-}
-
-static void print_extensions(TSRMLS_D)
-{
- zend_llist sorted_exts;
-
- zend_llist_copy(&sorted_exts, &zend_extensions);
- zend_llist_sort(&sorted_exts, extension_name_cmp TSRMLS_CC);
- zend_llist_apply_with_argument(&sorted_exts, (llist_apply_with_arg_func_t) print_extension_info, NULL TSRMLS_CC);
- zend_llist_destroy(&sorted_exts);
-}
-
-#ifndef STDOUT_FILENO
-#define STDOUT_FILENO 1
-#endif
-
-static inline size_t sapi_cli_single_write(const char *str, uint str_length)
-{
-#ifdef PHP_WRITE_STDOUT
- long ret;
-
- ret = write(STDOUT_FILENO, str, str_length);
- if (ret <= 0) {
- return 0;
- }
- return ret;
-#else
- size_t ret;
-
- ret = fwrite(str, 1, MIN(str_length, 16384), stdout);
- return ret;
-#endif
-}
-
-static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- const char *ptr = str;
- uint remaining = str_length;
- size_t ret;
-
- while (remaining > 0)
- {
- ret = sapi_cli_single_write(ptr, remaining);
- if (!ret) {
- php_handle_aborted_connection();
- }
- ptr += ret;
- remaining -= ret;
- }
-
- return str_length;
-}
-
-
-static void sapi_cli_flush(void *server_context)
-{
- if (fflush(stdout)==EOF) {
- php_handle_aborted_connection();
- }
-}
-
-static char *php_self = "";
-static char *script_filename = "";
-
-static void sapi_cli_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- /* In CGI mode, we consider the environment to be a part of the server
- * variables
- */
- php_import_environment_variables(track_vars_array TSRMLS_CC);
-
- /* Build the special-case PHP_SELF variable for the CLI version */
- php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC);
- php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC);
- /* filenames are empty for stdin */
- php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC);
- php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC);
- /* just make it available */
- php_register_variable("DOCUMENT_ROOT", "", track_vars_array TSRMLS_CC);
-}
-
-
-static void sapi_cli_log_message(char *message)
-{
- if (php_header()) {
- fprintf(stderr, "%s", message);
- fprintf(stderr, "\n");
- }
-}
-
-static int sapi_cli_deactivate(TSRMLS_D)
-{
- fflush(stdout);
- if(SG(request_info).argv0) {
- free(SG(request_info).argv0);
- SG(request_info).argv0 = NULL;
- }
- return SUCCESS;
-}
-
-static char* sapi_cli_read_cookies(TSRMLS_D)
-{
- return NULL;
-}
-
-static void sapi_cli_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC)
-{
- if (sapi_header) {
- PHPWRITE_H(sapi_header->header, sapi_header->header_len);
- }
- PHPWRITE_H("\r\n", 2);
-}
-
-
-static int php_cli_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
- return FAILURE;
- }
- return SUCCESS;
-}
-
-
-/* {{{ sapi_module_struct cli_sapi_module
- */
-static sapi_module_struct cli_sapi_module = {
- "cli", /* name */
- "Command Line Interface", /* pretty name */
-
- php_cli_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- sapi_cli_deactivate, /* deactivate */
-
- sapi_cli_ub_write, /* unbuffered write */
- sapi_cli_flush, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error, /* error handler */
-
- NULL, /* header handler */
- NULL, /* send headers handler */
- sapi_cli_send_header, /* send header handler */
-
- NULL, /* read POST data */
- sapi_cli_read_cookies, /* read Cookies */
-
- sapi_cli_register_variables, /* register server variables */
- sapi_cli_log_message, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-/* }}} */
-
-/* {{{ php_cli_usage
- */
-static void php_cli_usage(char *argv0)
-{
- char *prog;
-
- prog = strrchr(argv0, '/');
- if (prog) {
- prog++;
- } else {
- prog = "php";
- }
-
- php_printf( "Usage: %s [options] [-f] <file> [--] [args...]\n"
- " %s [options] -r <code> [--] [args...]\n"
- " %s [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]\n"
- " %s [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]\n"
- " %s [options] -- [args...]\n"
- "\n"
- " -a Run interactively\n"
- " -c <path>|<file> Look for php.ini file in this directory\n"
- " -n No php.ini file will be used\n"
- " -d foo[=bar] Define INI entry foo with value 'bar'\n"
- " -e Generate extended information for debugger/profiler\n"
- " -f <file> Parse <file>.\n"
- " -h This help\n"
- " -i PHP information\n"
- " -l Syntax check only (lint)\n"
- " -m Show compiled in modules\n"
- " -r <code> Run PHP <code> without using script tags <?..?>\n"
- " -B <begin_code> Run PHP <begin_code> before processing input lines\n"
- " -R <code> Run PHP <code> for every input line\n"
- " -F <file> Parse and execute <file> for every input line\n"
- " -E <end_code> Run PHP <end_code> after processing all input lines\n"
- " -H Hide any passed arguments from external tools.\n"
- " -s Display colour syntax highlighted source.\n"
- " -v Version number\n"
- " -w Display source with stripped comments and whitespace.\n"
- " -z <file> Load Zend extension <file>.\n"
- "\n"
- " args... Arguments passed to script. Use -- args when first argument\n"
- " starts with - or script is read from stdin\n"
- "\n"
- , prog, prog, prog, prog, prog);
-}
-/* }}} */
-
-static void define_command_line_ini_entry(char *arg)
-{
- char *name, *value;
-
- name = arg;
- value = strchr(arg, '=');
- if (value) {
- *value = 0;
- value++;
- } else {
- value = "1";
- }
- zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
-}
-
-
-static void php_register_command_line_global_vars(char **arg TSRMLS_DC)
-{
- char *var, *val;
-
- var = *arg;
- val = strchr(var, '=');
- if (!val) {
- printf("No value specified for variable '%s'\n", var);
- } else {
- *val++ = '\0';
- php_register_variable(var, val, NULL TSRMLS_CC);
- }
- efree(*arg);
-}
-
-static php_stream_context *sc_in_process = NULL;
-static php_stream *s_in_process = NULL;
-
-static void cli_register_file_handles(TSRMLS_D)
-{
- zval *zin, *zout, *zerr;
- php_stream *s_in, *s_out, *s_err;
- php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL;
- zend_constant ic, oc, ec;
-
- MAKE_STD_ZVAL(zin);
- MAKE_STD_ZVAL(zout);
- MAKE_STD_ZVAL(zerr);
-
- s_in = php_stream_open_wrapper_ex("php://stdin", "rb", 0, NULL, sc_in);
- s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out);
- s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err);
-
- if (s_in==NULL || s_out==NULL || s_err==NULL) {
- return;
- }
-
- sc_in_process = sc_in;
- s_in_process = s_in;
-
- php_stream_to_zval(s_in, zin);
- php_stream_to_zval(s_out, zout);
- php_stream_to_zval(s_err, zerr);
-
- ic.value = *zin;
- ic.flags = CONST_CS;
- ic.name = zend_strndup("STDIN", 6);
- ic.name_len = 6;
- zend_register_constant(&ic TSRMLS_CC);
-
- oc.value = *zout;
- oc.flags = CONST_CS;
- oc.name = zend_strndup("STDOUT", 7);
- oc.name_len = 7;
- zend_register_constant(&oc TSRMLS_CC);
-
- ec.value = *zerr;
- ec.flags = CONST_CS;
- ec.name = zend_strndup("STDERR", 7);
- ec.name_len = 7;
- zend_register_constant(&ec TSRMLS_CC);
-
- FREE_ZVAL(zin);
- FREE_ZVAL(zout);
- FREE_ZVAL(zerr);
-}
-
-static const char *param_mode_conflict = "Either execute direct code, process stdin or use a file.\n";
-
-/* {{{ cli_seek_file_begin
- */
-static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno TSRMLS_DC)
-{
- int c;
-
- *lineno = 1;
-
- if (!(file_handle->handle.fp = VCWD_FOPEN(script_file, "rb"))) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- php_printf("Could not open input file: %s.\n", script_file);
- return FAILURE;
- }
- file_handle->filename = script_file;
- /* #!php support */
- c = fgetc(file_handle->handle.fp);
- if (c == '#') {
- while (c != 10 && c != 13) {
- c = fgetc(file_handle->handle.fp); /* skip to end of line */
- }
- /* handle situations where line is terminated by \r\n */
- if (c == 13) {
- if (fgetc(file_handle->handle.fp) != 10) {
- long pos = ftell(file_handle->handle.fp);
- fseek(file_handle->handle.fp, pos - 1, SEEK_SET);
- }
- }
- *lineno = 2;
- } else {
- rewind(file_handle->handle.fp);
- }
- return SUCCESS;
-}
-/* }} */
-
-/* {{{ main
- */
-int main(int argc, char *argv[])
-{
- int exit_status = SUCCESS;
- int c;
- zend_file_handle file_handle;
-/* temporary locals */
- int behavior=PHP_MODE_STANDARD;
- int no_headers=1;
- int orig_optind=optind;
- char *orig_optarg=optarg;
- char *arg_free=NULL, **arg_excp=&arg_free;
- char *script_file=NULL;
- zend_llist global_vars;
- int interactive=0;
- int module_started = 0;
- int lineno = 0;
- char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL;
- const char *param_error=NULL;
- int scan_input = 0;
- int hide_argv = 0;
-/* end of temporary locals */
-#ifdef ZTS
- zend_compiler_globals *compiler_globals;
- zend_executor_globals *executor_globals;
- php_core_globals *core_globals;
- sapi_globals_struct *sapi_globals;
- void ***tsrm_ls;
-#endif
-
-
-#ifdef HAVE_SIGNAL_H
-#if defined(SIGPIPE) && defined(SIG_IGN)
- signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
- that sockets created via fsockopen()
- don't kill PHP if the remote site
- closes it. in apache|apxs mode apache
- does that for us! thies@thieso.net
- 20000419 */
-#endif
-#endif
-
-
-#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
-#endif
-
- sapi_startup(&cli_sapi_module);
-
-#ifdef PHP_WIN32
- _fmode = _O_BINARY; /*sets default for file streams to binary */
- setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */
- setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */
- setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
-#endif
-
-
- while ((c = php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0))!=-1) {
- switch (c) {
- case 'c':
- cli_sapi_module.php_ini_path_override = strdup(optarg);
- break;
- case 'n':
- cli_sapi_module.php_ini_ignore = 1;
- break;
- }
- }
- optind = orig_optind;
- optarg = orig_optarg;
-
- cli_sapi_module.executable_location = argv[0];
-
-#ifdef ZTS
- compiler_globals = ts_resource(compiler_globals_id);
- executor_globals = ts_resource(executor_globals_id);
- core_globals = ts_resource(core_globals_id);
- sapi_globals = ts_resource(sapi_globals_id);
- tsrm_ls = ts_resource(0);
-#endif
-
- /* startup after we get the above ini override se we get things right */
- if (php_module_startup(&cli_sapi_module, NULL, 0)==FAILURE) {
- /* there is no way to see if we must call zend_ini_deactivate()
- * since we cannot check if EG(ini_directives) has been initialised
- * because the executor's constructor does not set initialize it.
- * Apart from that there seems no need for zend_ini_deactivate() yet.
- * So we goto out_err.*/
- exit_status = 1;
- goto out_err;
- }
- module_started = 1;
-
- zend_first_try {
- zend_llist_init(&global_vars, sizeof(char *), NULL, 0);
-
- /* Set some CLI defaults */
- SG(options) |= SAPI_OPTION_NO_CHDIR;
- zend_alter_ini_entry("register_argc_argv", 19, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("implicit_flush", 15, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
-
- zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */
-
- if (cli_sapi_module.php_ini_path_override && cli_sapi_module.php_ini_ignore) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- PUTS("You cannot use both -n and -c switch. Use -h for help.\n");
- exit(1);
- }
-
- while ((c = php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0)) != -1) {
- switch (c) {
-
- case 'h': /* help & quit */
- case '?':
- no_headers = 1;
- php_output_startup();
- php_output_activate(TSRMLS_C);
- SG(headers_sent) = 1;
- php_cli_usage(argv[0]);
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
- case 'a': /* interactive mode */
- printf("Interactive mode enabled\n\n");
- interactive=1;
- break;
-
- case 'C': /* don't chdir to the script directory */
- /* This is default so NOP */
- break;
- case 'd': /* define ini entries on command line */
- define_command_line_ini_entry(optarg);
- break;
-
- case 'e': /* enable extended info output */
- CG(extended_info) = 1;
- break;
-
- case 'F':
- if (behavior == PHP_MODE_PROCESS_STDIN) {
- if (exec_run || script_file) {
- param_error = "You can use -R or -F only once.\n";
- break;
- }
- } else if (behavior != PHP_MODE_STANDARD) {
- param_error = param_mode_conflict;
- break;
- }
- behavior=PHP_MODE_PROCESS_STDIN;
- script_file = optarg;
- no_headers = 1;
- break;
-
- case 'f': /* parse file */
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
- param_error = param_mode_conflict;
- break;
- } else if (script_file) {
- param_error = "You can use -f only once.\n";
- break;
- }
- script_file = optarg;
- no_headers = 1;
- break;
-
- case 'g': /* define global variables on command line */
- {
- char *arg = estrdup(optarg);
-
- zend_llist_add_element(&global_vars, &arg);
- }
- break;
-
- case 'i': /* php info & quit */
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- goto err;
- }
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
- php_print_info(0xFFFFFFFF TSRMLS_CC);
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
- case 'l': /* syntax check mode */
- if (behavior != PHP_MODE_STANDARD) {
- break;
- }
- no_headers = 1;
- behavior=PHP_MODE_LINT;
- break;
-
- case 'm': /* list compiled in modules */
- php_output_startup();
- php_output_activate(TSRMLS_C);
- SG(headers_sent) = 1;
- php_printf("[PHP Modules]\n");
- print_modules(TSRMLS_C);
- php_printf("\n[Zend Modules]\n");
- print_extensions(TSRMLS_C);
- php_printf("\n");
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
-#if 0 /* not yet operational, see also below ... */
- case '': /* generate indented source mode*/
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
- param_error = "Source indenting only works for files.\n";
- break;
- }
- behavior=PHP_MODE_INDENT;
- break;
-#endif
-
- case 'q': /* do not generate HTTP headers */
- /* This is default so NOP */
- break;
-
- case 'r': /* run code from command line */
- if (behavior == PHP_MODE_CLI_DIRECT) {
- if (exec_direct || script_file) {
- param_error = "You can use -r only once.\n";
- break;
- }
- } else if (behavior != PHP_MODE_STANDARD) {
- param_error = param_mode_conflict;
- break;
- }
- behavior=PHP_MODE_CLI_DIRECT;
- exec_direct=optarg;
- break;
-
- case 'R':
- if (behavior == PHP_MODE_PROCESS_STDIN) {
- if (exec_run || script_file) {
- param_error = "You can use -R or -F only once.\n";
- break;
- }
- } else if (behavior != PHP_MODE_STANDARD) {
- param_error = param_mode_conflict;
- break;
- }
- behavior=PHP_MODE_PROCESS_STDIN;
- exec_run=optarg;
- break;
-
- case 'B':
- if (behavior == PHP_MODE_PROCESS_STDIN) {
- if (exec_begin) {
- param_error = "You can use -B only once.\n";
- break;
- }
- } else if (behavior != PHP_MODE_STANDARD) {
- param_error = param_mode_conflict;
- break;
- }
- behavior=PHP_MODE_PROCESS_STDIN;
- exec_begin=optarg;
- break;
-
- case 'E':
- if (behavior == PHP_MODE_PROCESS_STDIN) {
- if (exec_end) {
- param_error = "You can use -E only once.\n";
- break;
- }
- } else if (behavior != PHP_MODE_STANDARD) {
- param_error = param_mode_conflict;
- break;
- }
- scan_input = 1;
- behavior=PHP_MODE_PROCESS_STDIN;
- exec_end=optarg;
- break;
-
- case 's': /* generate highlighted HTML from source */
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
- param_error = "Source highlighting only works for files.\n";
- break;
- }
- behavior=PHP_MODE_HIGHLIGHT;
- break;
-
- case 'v': /* show php version & quit */
- no_headers = 1;
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- goto err;
- }
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
- php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2003 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
- case 'w':
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
- param_error = "Source stripping only works for files.\n";
- break;
- }
- behavior=PHP_MODE_STRIP;
- break;
-
- case 'z': /* load extension file */
- zend_load_extension(optarg);
- break;
- case 'H':
- hide_argv = 1;
- break;
-
- default:
- break;
- }
- }
-
- if (param_error) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- PUTS(param_error);
- exit(1);
- }
-
- CG(interactive) = interactive;
-
- /* only set script_file if not set already and not in direct mode and not at end of parameter list */
- if (argc > optind
- && !script_file
- && behavior!=PHP_MODE_CLI_DIRECT
- && behavior!=PHP_MODE_PROCESS_STDIN
- && strcmp(argv[optind-1],"--"))
- {
- no_headers = 1;
- script_file=argv[optind];
- optind++;
- }
- if (script_file) {
- if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) {
- goto err;
- }
- script_filename = script_file;
- } else {
- /* We could handle PHP_MODE_PROCESS_STDIN in a different manner */
- /* here but this would make things only more complicated. And it */
- /* is consitent with the way -R works where the stdin file handle*/
- /* is also accessible. */
- file_handle.filename = "-";
- file_handle.handle.fp = stdin;
- }
- file_handle.type = ZEND_HANDLE_FP;
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
- php_self = file_handle.filename;
-
- /* before registering argv to module exchange the *new* argv[0] */
- /* we can achieve this without allocating more memory */
- SG(request_info).argc=argc-optind+1;
- arg_excp = argv+optind-1;
- arg_free = argv[optind-1];
- SG(request_info).path_translated = file_handle.filename;
- argv[optind-1] = file_handle.filename;
- SG(request_info).argv=argv+optind-1;
-
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- *arg_excp = arg_free;
- fclose(file_handle.handle.fp);
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- php_request_shutdown((void *) 0);
- PUTS("Could not startup.\n");
- goto err;
- }
- CG(start_lineno) = lineno;
- *arg_excp = arg_free; /* reconstuct argv */
-
- if (hide_argv) {
- int i;
- for (i = 1; i < argc; i++) {
- memset(argv[i], 0, strlen(argv[i]));
- }
- }
-
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
-
- /* This actually destructs the elements of the list - ugly hack */
- zend_llist_apply(&global_vars, (llist_apply_func_t) php_register_command_line_global_vars TSRMLS_CC);
- zend_llist_destroy(&global_vars);
-
- switch (behavior) {
- case PHP_MODE_STANDARD:
- if (strcmp(file_handle.filename, "-")) {
- cli_register_file_handles(TSRMLS_C);
- }
- php_execute_script(&file_handle TSRMLS_CC);
- exit_status = EG(exit_status);
- break;
- case PHP_MODE_LINT:
- PG(during_request_startup) = 0;
- exit_status = php_lint_script(&file_handle TSRMLS_CC);
- if (exit_status==SUCCESS) {
- zend_printf("No syntax errors detected in %s\n", file_handle.filename);
- } else {
- zend_printf("Errors parsing %s\n", file_handle.filename);
- }
- break;
- case PHP_MODE_STRIP:
- if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {
- zend_strip(TSRMLS_C);
- fclose(file_handle.handle.fp);
- }
- goto out;
- break;
- case PHP_MODE_HIGHLIGHT:
- {
- zend_syntax_highlighter_ini syntax_highlighter_ini;
-
- if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {
- php_get_highlight_struct(&syntax_highlighter_ini);
- zend_highlight(&syntax_highlighter_ini TSRMLS_CC);
- fclose(file_handle.handle.fp);
- }
- goto out;
- }
- break;
-#if 0
- /* Zeev might want to do something with this one day */
- case PHP_MODE_INDENT:
- open_file_for_scanning(&file_handle TSRMLS_CC);
- zend_indent();
- fclose(file_handle.handle.fp);
- goto out;
- break;
-#endif
- case PHP_MODE_CLI_DIRECT:
- cli_register_file_handles(TSRMLS_C);
- if (zend_eval_string(exec_direct, NULL, "Command line code" TSRMLS_CC) == FAILURE) {
- exit_status=254;
- }
- break;
-
- case PHP_MODE_PROCESS_STDIN:
- {
- char *input;
- size_t len, index = 0;
- pval *argn, *argi;
-
- cli_register_file_handles(TSRMLS_C);
-
- if (exec_begin && zend_eval_string(exec_begin, NULL, "Command line begin code" TSRMLS_CC) == FAILURE) {
- exit_status=254;
- }
- ALLOC_ZVAL(argi);
- Z_TYPE_P(argi) = IS_LONG;
- Z_LVAL_P(argi) = index;
- INIT_PZVAL(argi);
- zend_hash_update(&EG(symbol_table), "argi", sizeof("argi"), &argi, sizeof(pval *), NULL);
- while (exit_status == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) {
- len = strlen(input);
- while (len-- && (input[len]=='\n' || input[len]=='\r')) {
- input[len] = '\0';
- }
- ALLOC_ZVAL(argn);
- Z_TYPE_P(argn) = IS_STRING;
- Z_STRLEN_P(argn) = ++len;
- Z_STRVAL_P(argn) = estrndup(input, len);
- INIT_PZVAL(argn);
- zend_hash_update(&EG(symbol_table), "argn", sizeof("argn"), &argn, sizeof(pval *), NULL);
- Z_LVAL_P(argi) = ++index;
- if (exec_run) {
- if (zend_eval_string(exec_run, NULL, "Command line run code" TSRMLS_CC) == FAILURE) {
- exit_status=254;
- }
- } else {
- if (script_file) {
- if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) {
- exit_status = 1;
- } else {
- CG(start_lineno) = lineno;
- php_execute_script(&file_handle TSRMLS_CC);
- exit_status = EG(exit_status);
- }
- }
- }
- efree(input);
- }
- if (exec_end && zend_eval_string(exec_end, NULL, "Command line end code" TSRMLS_CC) == FAILURE) {
- exit_status=254;
- }
-
- break;
- }
- }
-
- if (cli_sapi_module.php_ini_path_override) {
- free(cli_sapi_module.php_ini_path_override);
- }
-
- } zend_catch {
- exit_status = EG(exit_status);
- } zend_end_try();
-
-out:
- php_request_shutdown((void *) 0);
-out_err:
- if (module_started) {
- php_module_shutdown(TSRMLS_C);
- }
- sapi_shutdown();
-#ifdef ZTS
- tsrm_shutdown();
-#endif
-
- exit(exit_status);
-
-err:
- zend_ini_deactivate(TSRMLS_C);
- exit_status = 1;
- goto out_err;
-}
-/* }}} */
-
-/*
- * 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/cli/php_getopt.h b/sapi/cli/php_getopt.h
deleted file mode 100644
index 1e2355ff63..0000000000
--- a/sapi/cli/php_getopt.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Marcus Boerger <helly@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-#include "php.h"
-
-/* Define structure for one recognized option (both single char and long name).
- * If short_open is '-' this is the last option.
- */
-typedef struct _opt_struct {
- const char opt_char;
- const int need_param;
- const char * opt_name;
-} opt_struct;
-
-int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err);
diff --git a/sapi/embed/CREDITS b/sapi/embed/CREDITS
deleted file mode 100644
index a5227b4ea9..0000000000
--- a/sapi/embed/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-Embed
-Edin Kadribasic
diff --git a/sapi/embed/EXPERIMENTAL b/sapi/embed/EXPERIMENTAL
deleted file mode 100644
index 293159a693..0000000000
--- a/sapi/embed/EXPERIMENTAL
+++ /dev/null
@@ -1,5 +0,0 @@
-this module is experimental,
-its functions may change their names
-or move to extension all together
-so do not rely to much on them
-you have been warned!
diff --git a/sapi/embed/config.m4 b/sapi/embed/config.m4
deleted file mode 100644
index 80fed48d00..0000000000
--- a/sapi/embed/config.m4
+++ /dev/null
@@ -1,32 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for embedded SAPI library support)
-
-AC_ARG_ENABLE(embed,
-[ --enable-embed[=TYPE] EXPERIMENTAL: Enable building of embedded SAPI library
- TYPE is either 'shared' or 'static'. [TYPE=shared]],
-[
- case $enableval in
- yes|shared)
- PHP_EMBED_TYPE=shared
- INSTALL_IT="\$(mkinstalldirs) \$(INSTALL_ROOT)\$(prefix)/lib; \$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)\$(prefix)/lib"
- ;;
- static)
- PHP_EMBED_TYPE=static
- INSTALL_IT="\$(mkinstalldirs) \$(INSTALL_ROOT)\$(prefix)/lib; \$(INSTALL) -m 0644 $SAPI_STATIC \$(INSTALL_ROOT)\$(prefix)/lib"
- ;;
- *)
- PHP_EMBED_TYPE=no
- ;;
- esac
-],[
- PHP_EMBED_TYPE=no
-])
-
-AC_MSG_RESULT($PHP_EMBED_TYPE)
-
-if test "$PHP_EMBED_TYPE" != "no"; then
- PHP_SELECT_SAPI(embed, $PHP_EMBED_TYPE, php_embed.c)
-fi
diff --git a/sapi/embed/php4embed.dsp b/sapi/embed/php4embed.dsp
deleted file mode 100644
index d251fca04d..0000000000
--- a/sapi/embed/php4embed.dsp
+++ /dev/null
@@ -1,100 +0,0 @@
-# Microsoft Developer Studio Project File - Name="php4embed" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Static Library" 0x0104
-
-CFG=php4embed - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "php4embed.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 "php4embed.mak" CFG="php4embed - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php4embed - Win32 Debug_TS" (based on "Win32 (x86) Static Library")
-!MESSAGE "php4embed - Win32 Release_TS" (based on "Win32 (x86) Static Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "php4embed - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D ZEND_DEBUG=1 /YX /FD /GZ /c
-# ADD BASE RSC /l 0x406 /d "_DEBUG"
-# ADD RSC /l 0x406 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo /out:"..\..\Debug_TS\php4embed.lib"
-
-!ELSEIF "$(CFG)" == "php4embed - 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 Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D ZEND_DEBUG=0 /YX /FD /c
-# ADD BASE RSC /l 0x406 /d "NDEBUG"
-# ADD RSC /l 0x406 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo /out:"..\..\Release_TS\php4embed.lib"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php4embed - Win32 Debug_TS"
-# Name "php4embed - Win32 Release_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=php_embed.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=php_embed.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c
deleted file mode 100644
index fb76ff5aa0..0000000000
--- a/sapi/embed/php_embed.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Edin Kadribasic <edink@php.net> |
- +----------------------------------------------------------------------+
-*/
-/* $Id$ */
-
-#include "php_embed.h"
-
-#ifdef PHP_WIN32
-#include <io.h>
-#include <fcntl.h>
-#endif
-
-static char* php_embed_read_cookies(TSRMLS_D)
-{
- return NULL;
-}
-
-static int php_embed_deactivate(TSRMLS_D)
-{
- fflush(stdout);
- return SUCCESS;
-}
-
-static inline size_t php_embed_single_write(const char *str, uint str_length)
-{
-#ifdef PHP_WRITE_STDOUT
- long ret;
-
- ret = write(STDOUT_FILENO, str, str_length);
- if (ret <= 0) return 0;
- return ret;
-#else
- size_t ret;
-
- ret = fwrite(str, 1, MIN(str_length, 16384), stdout);
- return ret;
-#endif
-}
-
-
-static int php_embed_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- const char *ptr = str;
- uint remaining = str_length;
- size_t ret;
-
- while (remaining > 0) {
- ret = php_embed_single_write(ptr, remaining);
- if (!ret) {
- php_handle_aborted_connection();
- }
- ptr += ret;
- remaining -= ret;
- }
-
- return str_length;
-}
-
-static void php_embed_flush(void *server_context)
-{
- if (fflush(stdout)==EOF) {
- php_handle_aborted_connection();
- }
-}
-
-static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC)
-{
-}
-
-static void php_embed_log_message(char *message)
-{
- fprintf (stderr, "%s\n", message);
-}
-
-static void php_embed_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- php_import_environment_variables(track_vars_array TSRMLS_CC);
-}
-
-static int php_embed_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
- return FAILURE;
- }
- return SUCCESS;
-}
-
-sapi_module_struct php_embed_module = {
- "embed", /* name */
- "PHP Embedded Library", /* pretty name */
-
- php_embed_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- php_embed_deactivate, /* deactivate */
-
- php_embed_ub_write, /* unbuffered write */
- php_embed_flush, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error, /* error handler */
-
- NULL, /* header handler */
- NULL, /* send headers handler */
- php_embed_send_header, /* send header handler */
-
- NULL, /* read POST data */
- php_embed_read_cookies, /* read Cookies */
-
- php_embed_register_variables, /* register server variables */
- php_embed_log_message, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-/* }}} */
-
-int php_embed_init(int argc, char **argv PTSRMLS_DC)
-{
- zend_llist global_vars;
-#ifdef ZTS
- zend_compiler_globals *compiler_globals;
- zend_executor_globals *executor_globals;
- php_core_globals *core_globals;
- sapi_globals_struct *sapi_globals;
- void ***tsrm_ls;
-#endif
-
-#ifdef HAVE_SIGNAL_H
-#if defined(SIGPIPE) && defined(SIG_IGN)
- signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
- that sockets created via fsockopen()
- don't kill PHP if the remote site
- closes it. in apache|apxs mode apache
- does that for us! thies@thieso.net
- 20000419 */
-#endif
-#endif
-
-#ifdef PHP_WIN32
- _fmode = _O_BINARY; /*sets default for file streams to binary */
- setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */
- setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */
- setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
-#endif
-
-#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
-#endif
-
-#ifdef ZTS
- compiler_globals = ts_resource(compiler_globals_id);
- executor_globals = ts_resource(executor_globals_id);
- core_globals = ts_resource(core_globals_id);
- sapi_globals = ts_resource(sapi_globals_id);
- tsrm_ls = ts_resource(0);
- *ptsrm_ls = tsrm_ls;
-#endif
-
- sapi_startup(&php_embed_module);
-
- if (php_embed_module.startup(&php_embed_module)==FAILURE) {
- return FAILURE;
- }
-
- if (argv) {
- php_embed_module.executable_location = argv[0];
- }
-
- zend_llist_init(&global_vars, sizeof(char *), NULL, 0);
-
- /* Set some Embedded PHP defaults */
- SG(options) |= SAPI_OPTION_NO_CHDIR;
- zend_alter_ini_entry("register_argc_argv", 19, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("implicit_flush", 15, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
-
- SG(request_info).argc=argc;
- SG(request_info).argv=argv;
-
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- php_module_shutdown(TSRMLS_C);
- return FAILURE;
- }
-
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- php_register_variable("PHP_SELF", "-", NULL TSRMLS_CC);
-
- return SUCCESS;
-}
-
-void php_embed_shutdown(TSRMLS_D)
-{
- php_request_shutdown((void *) 0);
- php_module_shutdown(TSRMLS_C);
-#ifdef ZTS
- tsrm_shutdown();
-#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/embed/php_embed.h b/sapi/embed/php_embed.h
deleted file mode 100644
index 2a0d88e1e7..0000000000
--- a/sapi/embed/php_embed.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Edin Kadribasic <edink@php.net> |
- +----------------------------------------------------------------------+
-*/
-/* $Id$ */
-
-#ifndef _PHP_EMBED_H_
-#define _PHP_EMBED_H_
-
-#include <main/php.h>
-#include <main/SAPI.h>
-#include <main/php_main.h>
-#include <main/php_variables.h>
-#include <main/php_ini.h>
-#include <zend_ini.h>
-
-#ifdef ZTS
-#define PTSRMLS_D void ****ptsrm_ls
-#define PTSRMLS_DC , PTSRMLS_D
-#define PTSRMLS_C &tsrm_ls
-#define PTSRMLS_CC , PTSRMLS_C
-#else
-#define PTSRMLS_D
-#define PTSRMLS_DC
-#define PTSRMLS_C
-#define PTSRMLS_CC
-#endif
-
-#define PHP_EMBED_START_BLOCK(x,y) { \
- void ***tsrm_ls; \
- php_embed_init(x, y PTSRMLS_CC); \
- zend_first_try {
-
-#define PHP_EMBED_END_BLOCK() \
- } zend_catch { \
- /* int exit_status = EG(exit_status); */ \
- } zend_end_try(); \
- php_embed_shutdown(TSRMLS_C); \
-}
-
-BEGIN_EXTERN_C()
-int php_embed_init(int argc, char **argv PTSRMLS_DC);
-void php_embed_shutdown(TSRMLS_D);
-extern sapi_module_struct php_embed_module;
-END_EXTERN_C()
-
-
-#endif /* _PHP_EMBED_H_ */
diff --git a/sapi/isapi/CREDITS b/sapi/isapi/CREDITS
deleted file mode 100644
index 11c6fdc73c..0000000000
--- a/sapi/isapi/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-ISAPI
-Andi Gutmans, Zeev Suraski
diff --git a/sapi/isapi/config.m4 b/sapi/isapi/config.m4
deleted file mode 100644
index ece730cef9..0000000000
--- a/sapi/isapi/config.m4
+++ /dev/null
@@ -1,27 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-RESULT=no
-AC_MSG_CHECKING(for Zeus ISAPI support)
-AC_ARG_WITH(isapi,
-[ --with-isapi=DIR Build PHP as an ISAPI module for use with Zeus.],
-[
- if test "$withval" = "yes"; then
- ZEUSPATH=/usr/local/zeus # the default
- else
- ZEUSPATH=$withval
- fi
- test -f "$ZEUSPATH/web/include/httpext.h" || AC_MSG_ERROR(Unable to find httpext.h in $ZEUSPATH/web/include)
- PHP_BUILD_THREAD_SAFE
- AC_DEFINE(WITH_ZEUS,1,[ ])
- PHP_ADD_INCLUDE($ZEUSPATH/web/include)
- PHP_SELECT_SAPI(isapi, shared, php4isapi.c)
- INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$ZEUSPATH/web/bin/"
- RESULT=yes
-])
-AC_MSG_RESULT($RESULT)
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
diff --git a/sapi/isapi/php.sym b/sapi/isapi/php.sym
deleted file mode 100644
index 34b50b851c..0000000000
--- a/sapi/isapi/php.sym
+++ /dev/null
@@ -1,5 +0,0 @@
-GetFilterVersion
-HttpFilterProc
-GetExtensionVersion
-HttpExtensionProc
-ZSLMain
diff --git a/sapi/isapi/php4isapi.c b/sapi/isapi/php4isapi.c
deleted file mode 100644
index 71090bcc5e..0000000000
--- a/sapi/isapi/php4isapi.c
+++ /dev/null
@@ -1,925 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Zeev Suraski <zeev@zend.com> |
- | Ben Mansell <ben@zeus.com> (Zeus Support) |
- +----------------------------------------------------------------------+
- */
-
-#include "php.h"
-#include <httpext.h>
-#include <httpfilt.h>
-#include <httpext.h>
-#include "php_main.h"
-#include "SAPI.h"
-#include "php_globals.h"
-#include "ext/standard/info.h"
-#include "php_variables.h"
-#include "php_ini.h"
-
-#ifdef PHP_WIN32
-# include <process.h>
-#else
-# define __try
-# define __except(val)
-# define __declspec(foo)
-#endif
-
-
-#ifdef WITH_ZEUS
-# include "httpext.h"
-# include <errno.h>
-# define GetLastError() errno
-#endif
-
-#ifdef PHP_WIN32
-#define PHP_ENABLE_SEH
-#endif
-
-/*
-uncomment the following lines to turn off
-exception trapping when running under a debugger
-
-#ifdef _DEBUG
-#undef PHP_ENABLE_SEH
-#endif
-*/
-
-#define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION")
-#define ISAPI_SERVER_VAR_BUF_SIZE 1024
-#define ISAPI_POST_DATA_BUF 1024
-
-static zend_bool bFilterLoaded=0;
-static zend_bool bTerminateThreadsOnError=0;
-
-static char *isapi_special_server_variable_names[] = {
- "ALL_HTTP",
- "HTTPS",
-#ifndef WITH_ZEUS
- "SCRIPT_NAME",
-#endif
- NULL
-};
-
-#define NUM_SPECIAL_VARS (sizeof(isapi_special_server_variable_names)/sizeof(char *))
-#define SPECIAL_VAR_ALL_HTTP 0
-#define SPECIAL_VAR_HTTPS 1
-#define SPECIAL_VAR_PHP_SELF 2
-
-static char *isapi_server_variable_names[] = {
- "AUTH_PASSWORD",
- "AUTH_TYPE",
- "AUTH_USER",
- "CONTENT_LENGTH",
- "CONTENT_TYPE",
- "PATH_TRANSLATED",
- "QUERY_STRING",
- "REMOTE_ADDR",
- "REMOTE_HOST",
- "REMOTE_USER",
- "REQUEST_METHOD",
- "SERVER_NAME",
- "SERVER_PORT",
- "SERVER_PROTOCOL",
- "SERVER_SOFTWARE",
-#ifndef WITH_ZEUS
- "APPL_MD_PATH",
- "APPL_PHYSICAL_PATH",
- "INSTANCE_ID",
- "INSTANCE_META_PATH",
- "LOGON_USER",
- "REQUEST_URI",
- "URL",
-#else
- "DOCUMENT_ROOT",
-#endif
- NULL
-};
-
-
-static char *isapi_secure_server_variable_names[] = {
- "CERT_COOKIE",
- "CERT_FLAGS",
- "CERT_ISSUER",
- "CERT_KEYSIZE",
- "CERT_SECRETKEYSIZE",
- "CERT_SERIALNUMBER",
- "CERT_SERVER_ISSUER",
- "CERT_SERVER_SUBJECT",
- "CERT_SUBJECT",
- "HTTPS_KEYSIZE",
- "HTTPS_SECRETKEYSIZE",
- "HTTPS_SERVER_ISSUER",
- "HTTPS_SERVER_SUBJECT",
- "SERVER_PORT_SECURE",
-#ifdef WITH_ZEUS
- "SSL_CLIENT_CN",
- "SSL_CLIENT_EMAIL",
- "SSL_CLIENT_OU",
- "SSL_CLIENT_O",
- "SSL_CLIENT_L",
- "SSL_CLIENT_ST",
- "SSL_CLIENT_C",
- "SSL_CLIENT_I_CN",
- "SSL_CLIENT_I_EMAIL",
- "SSL_CLIENT_I_OU",
- "SSL_CLIENT_I_O",
- "SSL_CLIENT_I_L",
- "SSL_CLIENT_I_ST",
- "SSL_CLIENT_I_C",
-#endif
- NULL
-};
-
-
-static void php_info_isapi(ZEND_MODULE_INFO_FUNC_ARGS)
-{
- char **p;
- char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
- DWORD variable_len;
- char **all_variables[] = {
- isapi_server_variable_names,
- isapi_special_server_variable_names,
- isapi_secure_server_variable_names,
- NULL
- };
- char ***server_variable_names;
- LPEXTENSION_CONTROL_BLOCK lpECB;
-
- lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
-
- php_info_print_table_start();
- php_info_print_table_header(2, "Server Variable", "Value");
- server_variable_names = all_variables;
- while (*server_variable_names) {
- p = *server_variable_names;
- while (*p) {
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len)
- && variable_buf[0]) {
- php_info_print_table_row(2, *p, variable_buf);
- } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
- char *tmp_variable_buf;
-
- tmp_variable_buf = (char *) emalloc(variable_len);
- if (lpECB->GetServerVariable(lpECB->ConnID, *p, tmp_variable_buf, &variable_len)
- && variable_buf[0]) {
- php_info_print_table_row(2, *p, tmp_variable_buf);
- }
- efree(tmp_variable_buf);
- }
- p++;
- }
- server_variable_names++;
- }
- php_info_print_table_end();
-}
-
-
-static zend_module_entry php_isapi_module = {
- STANDARD_MODULE_HEADER,
- "ISAPI",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- php_info_isapi,
- NULL,
- STANDARD_MODULE_PROPERTIES
-};
-
-
-static int sapi_isapi_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- DWORD num_bytes = str_length;
- LPEXTENSION_CONTROL_BLOCK ecb;
-
- ecb = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
- if (ecb->WriteClient(ecb->ConnID, (char *) str, &num_bytes, HSE_IO_SYNC) == FALSE) {
- php_handle_aborted_connection();
- }
- return num_bytes;
-}
-
-
-static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- return SAPI_HEADER_ADD;
-}
-
-
-
-static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length TSRMLS_DC)
-{
- *total_length += sapi_header->header_len+2;
-}
-
-
-static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr TSRMLS_DC)
-{
- memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len);
- *combined_headers_ptr += sapi_header->header_len;
- **combined_headers_ptr = '\r';
- (*combined_headers_ptr)++;
- **combined_headers_ptr = '\n';
- (*combined_headers_ptr)++;
-}
-
-
-static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- uint total_length = 2; /* account for the trailing \r\n */
- char *combined_headers, *combined_headers_ptr;
- LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
- HSE_SEND_HEADER_EX_INFO header_info;
- char status_buf[MAX_STATUS_LENGTH];
- sapi_header_struct default_content_type;
-
- /* Obtain headers length */
- if (SG(sapi_headers).send_default_content_type) {
- sapi_get_default_content_type_header(&default_content_type TSRMLS_CC);
- accumulate_header_length(&default_content_type, (void *) &total_length TSRMLS_CC);
- }
- zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) accumulate_header_length, (void *) &total_length TSRMLS_CC);
-
- /* Generate headers */
- combined_headers = (char *) emalloc(total_length+1);
- combined_headers_ptr = combined_headers;
- if (SG(sapi_headers).send_default_content_type) {
- concat_header(&default_content_type, (void *) &combined_headers_ptr TSRMLS_CC);
- sapi_free_header(&default_content_type); /* we no longer need it */
- }
- zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) concat_header, (void *) &combined_headers_ptr TSRMLS_CC);
- *combined_headers_ptr++ = '\r';
- *combined_headers_ptr++ = '\n';
- *combined_headers_ptr = 0;
-
- switch (SG(sapi_headers).http_response_code) {
- case 200:
- header_info.pszStatus = "200 OK";
- break;
- case 302:
- header_info.pszStatus = "302 Moved Temporarily";
- break;
- case 401:
- header_info.pszStatus = "401 Authorization Required";
- break;
- default:
- snprintf(status_buf, MAX_STATUS_LENGTH, "%d Undescribed", SG(sapi_headers).http_response_code);
- header_info.pszStatus = status_buf;
- break;
- }
- header_info.cchStatus = strlen(header_info.pszStatus);
- header_info.pszHeader = combined_headers;
- header_info.cchHeader = total_length;
- header_info.fKeepConn = FALSE;
- lpECB->dwHttpStatusCode = SG(sapi_headers).http_response_code;
-
- lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL);
-
- efree(combined_headers);
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-
-static int php_isapi_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, &php_isapi_module, 1)==FAILURE) {
- return FAILURE;
- } else {
- bTerminateThreadsOnError = (zend_bool) INI_INT("isapi.terminate_threads_on_error");
- return SUCCESS;
- }
-}
-
-
-
-static int sapi_isapi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
- LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
- DWORD read_from_buf=0;
- DWORD read_from_input=0;
- DWORD total_read=0;
-
- if ((DWORD) SG(read_post_bytes) < lpECB->cbAvailable) {
- read_from_buf = MIN(lpECB->cbAvailable-SG(read_post_bytes), count_bytes);
- memcpy(buffer, lpECB->lpbData+SG(read_post_bytes), read_from_buf);
- total_read += read_from_buf;
- }
- if (read_from_buf<count_bytes
- && (SG(read_post_bytes)+read_from_buf) < lpECB->cbTotalBytes) {
- DWORD cbRead=0, cbSize;
-
- read_from_input = MIN(count_bytes-read_from_buf, lpECB->cbTotalBytes-SG(read_post_bytes)-read_from_buf);
- while (cbRead < read_from_input) {
- cbSize = read_from_input - cbRead;
- if (!lpECB->ReadClient(lpECB->ConnID, buffer+read_from_buf+cbRead, &cbSize) || cbSize==0) {
- break;
- }
- cbRead += cbSize;
- }
- total_read += cbRead;
- }
- return total_read;
-}
-
-
-static char *sapi_isapi_read_cookies(TSRMLS_D)
-{
- LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
- char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
- DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
-
- if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", variable_buf, &variable_len)) {
- return estrndup(variable_buf, variable_len);
- } else if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) {
- char *tmp_variable_buf = (char *) emalloc(variable_len+1);
-
- if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", tmp_variable_buf, &variable_len)) {
- tmp_variable_buf[variable_len] = 0;
- return tmp_variable_buf;
- } else {
- efree(tmp_variable_buf);
- }
- }
- return NULL;
-}
-
-
-#ifdef WITH_ZEUS
-
-static void sapi_isapi_register_zeus_ssl_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array TSRMLS_DC)
-{
- char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
- DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- char static_cons_buf[ISAPI_SERVER_VAR_BUF_SIZE];
- /*
- * We need to construct the /C=.../ST=...
- * DN's for SSL_CLIENT_DN and SSL_CLIENT_I_DN
- */
- strcpy( static_cons_buf, "/C=" );
- if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_C", static_variable_buf, &variable_len ) && static_variable_buf[0] ) {
- strcat( static_cons_buf, static_variable_buf );
- }
- strcat( static_cons_buf, "/ST=" );
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_ST", static_variable_buf, &variable_len ) && static_variable_buf[0] ) {
- strcat( static_cons_buf, static_variable_buf );
- }
- php_register_variable( "SSL_CLIENT_DN", static_cons_buf, track_vars_array TSRMLS_CC );
-
- strcpy( static_cons_buf, "/C=" );
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_I_C", static_variable_buf, &variable_len ) && static_variable_buf[0] ) {
- strcat( static_cons_buf, static_variable_buf );
- }
- strcat( static_cons_buf, "/ST=" );
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_I_ST", static_variable_buf, &variable_len ) && static_variable_buf[0] ) {
- strcat( static_cons_buf, static_variable_buf );
- }
- php_register_variable( "SSL_CLIENT_I_DN", static_cons_buf, track_vars_array TSRMLS_CC );
-}
-
-static void sapi_isapi_register_zeus_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array TSRMLS_DC)
-{
- char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
- DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- DWORD scriptname_len = ISAPI_SERVER_VAR_BUF_SIZE;
- DWORD pathinfo_len = 0;
- char *strtok_buf = NULL;
-
- /* Get SCRIPT_NAME, we use this to work out which bit of the URL
- * belongs in PHP's version of PATH_INFO
- */
- lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &scriptname_len);
-
- /* Adjust Zeus' version of PATH_INFO, set PHP_SELF,
- * and generate REQUEST_URI
- */
- if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_INFO", static_variable_buf, &variable_len) && static_variable_buf[0] ) {
-
- /* PHP_SELF is just PATH_INFO */
- php_register_variable( "PHP_SELF", static_variable_buf, track_vars_array TSRMLS_CC );
-
- /* Chop off filename to get just the 'real' PATH_INFO' */
- pathinfo_len = variable_len - scriptname_len;
- php_register_variable( "PATH_INFO", static_variable_buf + scriptname_len - 1, track_vars_array TSRMLS_CC );
- /* append query string to give url... extra byte for '?' */
- if ( strlen(lpECB->lpszQueryString) + variable_len + 1 < ISAPI_SERVER_VAR_BUF_SIZE ) {
- /* append query string only if it is present... */
- if ( strlen(lpECB->lpszQueryString) ) {
- static_variable_buf[ variable_len - 1 ] = '?';
- strcpy( static_variable_buf + variable_len, lpECB->lpszQueryString );
- }
- php_register_variable( "URL", static_variable_buf, track_vars_array TSRMLS_CC );
- php_register_variable( "REQUEST_URI", static_variable_buf, track_vars_array TSRMLS_CC );
- }
- }
-
- /* Get and adjust PATH_TRANSLATED to what PHP wants */
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_TRANSLATED", static_variable_buf, &variable_len) && static_variable_buf[0] ) {
- static_variable_buf[ variable_len - pathinfo_len - 1 ] = '\0';
- php_register_variable( "PATH_TRANSLATED", static_variable_buf, track_vars_array TSRMLS_CC );
- }
-
- /* Bring in the AUTHENTICATION stuff as needed */
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if ( lpECB->GetServerVariable(lpECB->ConnID, "AUTH_USER", static_variable_buf, &variable_len) && static_variable_buf[0] ) {
- php_register_variable( "PHP_AUTH_USER", static_variable_buf, track_vars_array TSRMLS_CC );
- }
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if ( lpECB->GetServerVariable(lpECB->ConnID, "AUTH_PASSWORD", static_variable_buf, &variable_len) && static_variable_buf[0] ) {
- php_register_variable( "PHP_AUTH_PW", static_variable_buf, track_vars_array TSRMLS_CC );
- }
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if ( lpECB->GetServerVariable(lpECB->ConnID, "AUTH_TYPE", static_variable_buf, &variable_len) && static_variable_buf[0] ) {
- php_register_variable( "PHP_AUTH_TYPE", static_variable_buf, track_vars_array TSRMLS_CC );
- }
-
- /* And now, for the SSL variables (if applicable) */
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if ( lpECB->GetServerVariable(lpECB->ConnID, "CERT_COOKIE", static_variable_buf, &variable_len) && static_variable_buf[0] ) {
- sapi_isapi_register_zeus_ssl_variables( lpECB, track_vars_array TSRMLS_CC );
- }
- /* Copy some of the variables we need to meet Apache specs */
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if ( lpECB->GetServerVariable(lpECB->ConnID, "SERVER_SOFTWARE", static_variable_buf, &variable_len) && static_variable_buf[0] ) {
- php_register_variable( "SERVER_SIGNATURE", static_variable_buf, track_vars_array TSRMLS_CC );
- }
-}
-#else
-
-static void sapi_isapi_register_iis_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array TSRMLS_DC)
-{
- char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
- char path_info_buf[ISAPI_SERVER_VAR_BUF_SIZE];
- DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- DWORD scriptname_len = ISAPI_SERVER_VAR_BUF_SIZE;
- DWORD pathinfo_len = 0;
- HSE_URL_MAPEX_INFO humi;
-
- /* Get SCRIPT_NAME, we use this to work out which bit of the URL
- * belongs in PHP's version of PATH_INFO
- */
- lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &scriptname_len);
-
- /* Adjust Zeus' version of PATH_INFO, set PHP_SELF,
- * and generate REQUEST_URI
- */
- if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_INFO", static_variable_buf, &variable_len) && static_variable_buf[0] ) {
-
- /* Chop off filename to get just the 'real' PATH_INFO' */
- pathinfo_len = variable_len - scriptname_len;
- strncpy(path_info_buf, static_variable_buf + scriptname_len - 1, sizeof(path_info_buf)-1);
- php_register_variable( "PATH_INFO", path_info_buf, track_vars_array TSRMLS_CC );
- /* append query string to give url... extra byte for '?' */
- if ( strlen(lpECB->lpszQueryString) + variable_len + 1 < ISAPI_SERVER_VAR_BUF_SIZE ) {
- /* append query string only if it is present... */
- if ( strlen(lpECB->lpszQueryString) ) {
- static_variable_buf[ variable_len - 1 ] = '?';
- strcpy( static_variable_buf + variable_len, lpECB->lpszQueryString );
- }
- php_register_variable( "URL", static_variable_buf, track_vars_array TSRMLS_CC );
- php_register_variable( "REQUEST_URI", static_variable_buf, track_vars_array TSRMLS_CC );
- }
- }
-
- /* Get and adjust PATH_TRANSLATED to what PHP wants */
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_TRANSLATED", static_variable_buf, &variable_len) && static_variable_buf[0] ) {
- static_variable_buf[ variable_len - pathinfo_len - 1 ] = '\0';
- php_register_variable( "SCRIPT_FILENAME", static_variable_buf, track_vars_array TSRMLS_CC );
- efree(SG(request_info).path_translated);
- SG(request_info).path_translated = estrdup(static_variable_buf);
- if (pathinfo_len) {
- char *t = strrchr(static_variable_buf,'\\');
- if (t) *t = 0;
- strncat(static_variable_buf, path_info_buf, sizeof(static_variable_buf)-1);
- } else {
- static_variable_buf[0]=0;
- }
- php_register_variable( "PATH_TRANSLATED", static_variable_buf, track_vars_array TSRMLS_CC );
- }
-
- static_variable_buf[0] = '/';
- static_variable_buf[1] = 0;
- variable_len = 2;
- if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, static_variable_buf, &variable_len, (LPDWORD) &humi)) {
- /* Remove trailing \ */
- if (humi.lpszPath[variable_len-2] == '\\') {
- humi.lpszPath[variable_len-2] = 0;
- }
- php_register_variable("DOCUMENT_ROOT", humi.lpszPath, track_vars_array TSRMLS_CC);
- }
-
- if (!SG(request_info).auth_user || !SG(request_info).auth_password ||
- !SG(request_info).auth_user[0] || !SG(request_info).auth_password[0]) {
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_AUTHORIZATION", static_variable_buf, &variable_len)
- && static_variable_buf[0]) {
- php_handle_auth_data(static_variable_buf TSRMLS_CC);
- }
- }
-
- if (SG(request_info).auth_user) {
- php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, track_vars_array TSRMLS_CC );
- }
- if (SG(request_info).auth_password) {
- php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, track_vars_array TSRMLS_CC );
- }
-}
-#endif
-
-static void sapi_isapi_register_server_variables2(char **server_variables, LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array, char **recorded_values TSRMLS_DC)
-{
- char **p=server_variables;
- DWORD variable_len;
- char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
- char *variable_buf;
-
- while (*p) {
- variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if (lpECB->GetServerVariable(lpECB->ConnID, *p, static_variable_buf, &variable_len)
- && static_variable_buf[0]) {
- php_register_variable(*p, static_variable_buf, track_vars_array TSRMLS_CC);
- if (recorded_values) {
- recorded_values[p-server_variables] = estrndup(static_variable_buf, variable_len);
- }
- } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
- variable_buf = (char *) emalloc(variable_len+1);
- if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len)
- && variable_buf[0]) {
- php_register_variable(*p, variable_buf, track_vars_array TSRMLS_CC);
- }
- if (recorded_values) {
- recorded_values[p-server_variables] = variable_buf;
- } else {
- efree(variable_buf);
- }
- }
- p++;
- }
-}
-
-
-static void sapi_isapi_register_server_variables(zval *track_vars_array TSRMLS_DC)
-{
- DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
- char *variable;
- char *strtok_buf = NULL;
- char *isapi_special_server_variables[NUM_SPECIAL_VARS];
- LPEXTENSION_CONTROL_BLOCK lpECB;
-
- lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
-
- /* Register the special ISAPI variables */
- memset(isapi_special_server_variables, 0, sizeof(isapi_special_server_variables));
- sapi_isapi_register_server_variables2(isapi_special_server_variable_names, lpECB, track_vars_array, isapi_special_server_variables TSRMLS_CC);
- if (SG(request_info).cookie_data) {
- php_register_variable("HTTP_COOKIE", SG(request_info).cookie_data, track_vars_array TSRMLS_CC);
- }
-
- /* Register the standard ISAPI variables */
- sapi_isapi_register_server_variables2(isapi_server_variable_names, lpECB, track_vars_array, NULL TSRMLS_CC);
-
- if (isapi_special_server_variables[SPECIAL_VAR_HTTPS]
- && atoi(isapi_special_server_variables[SPECIAL_VAR_HTTPS])) {
- /* Register SSL ISAPI variables */
- sapi_isapi_register_server_variables2(isapi_secure_server_variable_names, lpECB, track_vars_array, NULL TSRMLS_CC);
- }
-
- if (isapi_special_server_variables[SPECIAL_VAR_HTTPS]) {
- efree(isapi_special_server_variables[SPECIAL_VAR_HTTPS]);
- }
-
-
-#ifdef WITH_ZEUS
- sapi_isapi_register_zeus_variables(lpECB, track_vars_array TSRMLS_CC);
-#else
- sapi_isapi_register_iis_variables(lpECB, track_vars_array TSRMLS_CC);
-#endif
-
- /* PHP_SELF support */
- if (isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]) {
- php_register_variable("PHP_SELF", isapi_special_server_variables[SPECIAL_VAR_PHP_SELF], track_vars_array TSRMLS_CC);
- efree(isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]);
- }
-
- if (isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP]) {
- /* Register the internal bits of ALL_HTTP */
- variable = php_strtok_r(isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP], "\r\n", &strtok_buf);
- while (variable) {
- char *colon = strchr(variable, ':');
-
- if (colon) {
- char *value = colon+1;
-
- while (*value==' ') {
- value++;
- }
- *colon = 0;
- php_register_variable(variable, value, track_vars_array TSRMLS_CC);
- *colon = ':';
- }
- variable = php_strtok_r(NULL, "\r\n", &strtok_buf);
- }
- efree(isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP]);
- }
-}
-
-
-static sapi_module_struct isapi_sapi_module = {
- "isapi", /* name */
- "ISAPI", /* pretty name */
-
- php_isapi_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- sapi_isapi_ub_write, /* unbuffered write */
- NULL, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error, /* error handler */
-
- sapi_isapi_header_handler, /* header handler */
- sapi_isapi_send_headers, /* send headers handler */
- NULL, /* send header handler */
-
- sapi_isapi_read_post, /* read POST data */
- sapi_isapi_read_cookies, /* read Cookies */
-
- sapi_isapi_register_server_variables, /* register server variables */
- NULL, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-
-BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pFilterVersion)
-{
- bFilterLoaded = 1;
- pFilterVersion->dwFilterVersion = HTTP_FILTER_REVISION;
- strcpy(pFilterVersion->lpszFilterDesc, isapi_sapi_module.pretty_name);
- pFilterVersion->dwFlags= (SF_NOTIFY_AUTHENTICATION | SF_NOTIFY_PREPROC_HEADERS);
- return TRUE;
-}
-
-
-DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LPVOID pvNotification)
-{
- TSRMLS_FETCH();
-
- switch (notificationType) {
- case SF_NOTIFY_PREPROC_HEADERS:
- SG(request_info).auth_user = NULL;
- SG(request_info).auth_password = NULL;
- break;
- case SF_NOTIFY_AUTHENTICATION: {
- char *auth_user = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszUser;
- char *auth_password = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszPassword;
-
- if (auth_user && auth_user[0]) {
- SG(request_info).auth_user = estrdup(auth_user);
- }
- if (auth_password && auth_password[0]) {
- SG(request_info).auth_password = estrdup(auth_password);
- }
- return SF_STATUS_REQ_HANDLED_NOTIFICATION;
- }
- break;
- }
- return SF_STATUS_REQ_NEXT_NOTIFICATION;
-}
-
-
-static void init_request_info(LPEXTENSION_CONTROL_BLOCK lpECB TSRMLS_DC)
-{
- SG(request_info).request_method = lpECB->lpszMethod;
- SG(request_info).query_string = lpECB->lpszQueryString;
- SG(request_info).path_translated = estrdup(lpECB->lpszPathTranslated);
- SG(request_info).request_uri = lpECB->lpszPathInfo;
- SG(request_info).content_type = lpECB->lpszContentType;
- SG(request_info).content_length = lpECB->cbTotalBytes;
- SG(sapi_headers).http_response_code = 200; /* I think dwHttpStatusCode is invalid at this stage -RL */
- if (!bFilterLoaded) { /* we don't have valid ISAPI Filter information */
- SG(request_info).auth_user = SG(request_info).auth_password = NULL;
- }
-}
-
-
-static void php_isapi_report_exception(char *message, int message_len TSRMLS_DC)
-{
- if (!SG(headers_sent)) {
- HSE_SEND_HEADER_EX_INFO header_info;
- LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
-
- header_info.pszStatus = "500 Internal Server Error";
- header_info.cchStatus = strlen(header_info.pszStatus);
- header_info.pszHeader = "Content-Type: text/html\r\n\r\n";
- header_info.cchHeader = strlen(header_info.pszHeader);
-
- lpECB->dwHttpStatusCode = 500;
- lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL);
- SG(headers_sent)=1;
- }
- sapi_isapi_ub_write(message, message_len TSRMLS_CC);
-}
-
-
-BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer)
-{
- pVer->dwExtensionVersion = HSE_VERSION;
-#ifdef WITH_ZEUS
- strncpy( pVer->lpszExtensionDesc, isapi_sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN);
-#else
- lstrcpyn(pVer->lpszExtensionDesc, isapi_sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN);
-#endif
- return TRUE;
-}
-
-
-static void my_endthread()
-{
-#ifdef PHP_WIN32
- if (bTerminateThreadsOnError) {
- _endthread();
- }
-#endif
-}
-
-#ifdef PHP_WIN32
-/* ep is accessible only in the context of the __except expression,
- * so we have to call this function to obtain it.
- */
-BOOL exceptionhandler(LPEXCEPTION_POINTERS *e, LPEXCEPTION_POINTERS ep)
-{
- *e=ep;
- return TRUE;
-}
-#endif
-
-DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
-{
- zend_file_handle file_handle;
- zend_bool stack_overflown=0;
-#ifdef PHP_ENABLE_SEH
- LPEXCEPTION_POINTERS e;
-#endif
- TSRMLS_FETCH();
-
- zend_first_try {
-#ifdef PHP_ENABLE_SEH
- __try {
-#endif
- init_request_info(lpECB TSRMLS_CC);
- SG(server_context) = lpECB;
-
- php_request_startup(TSRMLS_C);
-#ifdef WITH_ZEUS
- /* PATH_TRANSLATED can contain extra PATH_INFO stuff after the
- * file being loaded, so we must use SCRIPT_FILENAME instead
- */
- file_handle.filename = (char *)emalloc( ISAPI_SERVER_VAR_BUF_SIZE );
- file_handle.free_filename = 1;
- {
- DWORD filename_len = ISAPI_SERVER_VAR_BUF_SIZE;
- if( !lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_FILENAME", file_handle.filename, &filename_len) || file_handle.filename[ 0 ] == '\0' ) {
- /* If we're running on an earlier version of Zeus, this
- * variable won't be present, so fall back to old behaviour.
- */
- efree( file_handle.filename );
- file_handle.filename = SG(request_info).path_translated;
- file_handle.free_filename = 0;
- }
- }
-#else
- file_handle.filename = SG(request_info).path_translated;
- file_handle.free_filename = 0;
-#endif
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.opened_path = NULL;
-
-
- php_execute_script(&file_handle TSRMLS_CC);
- if (SG(request_info).cookie_data) {
- efree(SG(request_info).cookie_data);
- }
- efree(SG(request_info).path_translated);
-#ifdef PHP_ENABLE_SEH
- } __except(exceptionhandler(&e, GetExceptionInformation())) {
- char buf[1024];
- if (_exception_code()==EXCEPTION_STACK_OVERFLOW) {
- LPBYTE lpPage;
- static SYSTEM_INFO si;
- static MEMORY_BASIC_INFORMATION mi;
- static DWORD dwOldProtect;
-
- GetSystemInfo(&si);
-
- /* Get page ESP is pointing to */
- _asm mov lpPage, esp;
-
- /* Get stack allocation base */
- VirtualQuery(lpPage, &mi, sizeof(mi));
-
- /* Go to the page below the current page */
- lpPage = (LPBYTE) (mi.BaseAddress) - si.dwPageSize;
-
- /* Free pages below current page */
- if (!VirtualFree(mi.AllocationBase, (LPBYTE)lpPage - (LPBYTE) mi.AllocationBase, MEM_DECOMMIT)) {
- _endthread();
- }
-
- /* Restore the guard page */
- if (!VirtualProtect(lpPage, si.dwPageSize, PAGE_GUARD | PAGE_READWRITE, &dwOldProtect)) {
- _endthread();
- }
-
- CG(unclean_shutdown)=1;
- _snprintf(buf, sizeof(buf)-1,"PHP has encountered a Stack overflow");
- php_isapi_report_exception(buf, strlen(buf) TSRMLS_CC);
- } else if (_exception_code()==EXCEPTION_ACCESS_VIOLATION) {
- _snprintf(buf, sizeof(buf)-1,"PHP has encountered an Access Violation at %p", e->ExceptionRecord->ExceptionAddress);
- php_isapi_report_exception(buf, strlen(buf) TSRMLS_CC);
- my_endthread();
- } else {
- _snprintf(buf, sizeof(buf)-1,"PHP has encountered an Unhandled Exception Code %d at %p", e->ExceptionRecord->ExceptionCode , e->ExceptionRecord->ExceptionAddress);
- php_isapi_report_exception(buf, strlen(buf) TSRMLS_CC);
- my_endthread();
- }
- }
-#endif
-#ifdef PHP_ENABLE_SEH
- __try {
- php_request_shutdown(NULL);
- } __except(EXCEPTION_EXECUTE_HANDLER) {
- my_endthread();
- }
-#else
- php_request_shutdown(NULL);
-#endif
- } zend_catch {
- zend_try {
- php_request_shutdown(NULL);
- } zend_end_try();
- return HSE_STATUS_ERROR;
- } zend_end_try();
-
- return HSE_STATUS_SUCCESS;
-}
-
-
-
-__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
-{
- switch (fdwReason) {
- case DLL_PROCESS_ATTACH:
-#ifdef WITH_ZEUS
- tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "TSRM.log");
-#else
- tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "C:\\TSRM.log");
-#endif
- sapi_startup(&isapi_sapi_module);
- if (isapi_sapi_module.startup) {
- isapi_sapi_module.startup(&sapi_module);
- }
- break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- ts_free_thread();
- break;
- case DLL_PROCESS_DETACH:
- if (isapi_sapi_module.shutdown) {
- isapi_sapi_module.shutdown(&sapi_module);
- }
- tsrm_shutdown();
- break;
- }
- return TRUE;
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/sapi/isapi/php4isapi.def b/sapi/isapi/php4isapi.def
deleted file mode 100644
index 596023ef55..0000000000
--- a/sapi/isapi/php4isapi.def
+++ /dev/null
@@ -1,5 +0,0 @@
-EXPORTS
-HttpFilterProc
-GetFilterVersion
-HttpExtensionProc
-GetExtensionVersion
diff --git a/sapi/isapi/php4isapi.dsp b/sapi/isapi/php4isapi.dsp
deleted file mode 100644
index 7913ec6fad..0000000000
--- a/sapi/isapi/php4isapi.dsp
+++ /dev/null
@@ -1,165 +0,0 @@
-# Microsoft Developer Studio Project File - Name="php4isapi" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php4isapi - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "php4isapi.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "php4isapi.mak" CFG="php4isapi - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php4isapi - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4isapi - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4isapi - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4isapi - Win32 Release_TSDbg" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "php4isapi - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "_DEBUG" /D "COMPILE_LIBZEND" /D ZEND_DEBUG=1 /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "_DEBUG"
-# ADD RSC /l 0x40d /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 wsock32.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 php4ts_debug.lib /nologo /version:4.0 /dll /debug /machine:I386 /nodefaultlib:"libcmt" /pdbtype:sept /libpath:"..\..\Debug_TS"
-
-!ELSEIF "$(CFG)" == "php4isapi - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS"
-# PROP BASE Intermediate_Dir "Release_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"..\..\Release_TS"
-
-!ELSEIF "$(CFG)" == "php4isapi - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php4isapi___Win32_Release_TS_inline"
-# PROP BASE Intermediate_Dir "php4isapi___Win32_Release_TS_inline"
-# PROP BASE Ignore_Export_Lib 0
-# 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 /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "WIN32" /D "_MBCS" /D ZEND_DEBUG=0 /FR /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386 /libpath:"..\..\Release_TS"
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"..\..\Release_TS_inline"
-
-!ELSEIF "$(CFG)" == "php4isapi - Win32 Release_TSDbg"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php4isapi___Win32_Release_TSDbg"
-# PROP BASE Intermediate_Dir "php4isapi___Win32_Release_TSDbg"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Release_TSDbg"
-# PROP Intermediate_Dir "Release_TSDbg"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /Zi /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"..\..\Release_TS"
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /version:4.0 /dll /debug /machine:I386 /libpath:"..\..\Release_TSDbg"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php4isapi - Win32 Debug_TS"
-# Name "php4isapi - Win32 Release_TS"
-# Name "php4isapi - Win32 Release_TS_inline"
-# Name "php4isapi - Win32 Release_TSDbg"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\php4isapi.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\php4isapi.def
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# End Group
-# End Target
-# End Project
diff --git a/sapi/isapi/stresstest/getopt.c b/sapi/isapi/stresstest/getopt.c
deleted file mode 100644
index 57faa0f890..0000000000
--- a/sapi/isapi/stresstest/getopt.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/* Borrowed from Apache NT Port */
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
-#include "getopt.h"
-#define OPTERRCOLON (1)
-#define OPTERRNF (2)
-#define OPTERRARG (3)
-
-
-char *ap_optarg;
-int ap_optind = 1;
-static int ap_opterr = 1;
-static int ap_optopt;
-
-static int
-ap_optiserr(int argc, char * const *argv, int oint, const char *optstr,
- int optchr, int err)
-{
- if (ap_opterr)
- {
- fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1);
- switch(err)
- {
- case OPTERRCOLON:
- fprintf(stderr, ": in flags\n");
- break;
- case OPTERRNF:
- fprintf(stderr, "option not found %c\n", argv[oint][optchr]);
- break;
- case OPTERRARG:
- fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]);
- break;
- default:
- fprintf(stderr, "unknown\n");
- break;
- }
- }
- ap_optopt = argv[oint][optchr];
- return('?');
-}
-
-int ap_getopt(int argc, char* const *argv, const char *optstr)
-{
- static int optchr = 0;
- static int dash = 0; /* have already seen the - */
-
- char *cp;
-
- if (ap_optind >= argc)
- return(EOF);
- if (!dash && (argv[ap_optind][0] != '-'))
- return(EOF);
- if (!dash && (argv[ap_optind][0] == '-') && !argv[ap_optind][1])
- {
- /*
- * use to specify stdin. Need to let pgm process this and
- * the following args
- */
- return(EOF);
- }
- if ((argv[ap_optind][0] == '-') && (argv[ap_optind][1] == '-'))
- {
- /* -- indicates end of args */
- ap_optind++;
- return(EOF);
- }
- if (!dash)
- {
- assert((argv[ap_optind][0] == '-') && argv[ap_optind][1]);
- dash = 1;
- optchr = 1;
- }
-
- /* Check if the guy tries to do a -: kind of flag */
- assert(dash);
- if (argv[ap_optind][optchr] == ':')
- {
- dash = 0;
- ap_optind++;
- return(ap_optiserr(argc, argv, ap_optind-1, optstr, optchr, OPTERRCOLON));
- }
- if (!(cp = strchr(optstr, argv[ap_optind][optchr])))
- {
- int errind = ap_optind;
- int errchr = optchr;
-
- if (!argv[ap_optind][optchr+1])
- {
- dash = 0;
- ap_optind++;
- }
- else
- optchr++;
- return(ap_optiserr(argc, argv, errind, optstr, errchr, OPTERRNF));
- }
- if (cp[1] == ':')
- {
- /* Check for cases where the value of the argument
- is in the form -<arg> <val> or in the form -<arg><val> */
- dash = 0;
- if(!argv[ap_optind][2]) {
- ap_optind++;
- if (ap_optind == argc)
- return(ap_optiserr(argc, argv, ap_optind-1, optstr, optchr, OPTERRARG));
- ap_optarg = argv[ap_optind++];
- }
- else
- {
- ap_optarg = &argv[ap_optind][2];
- ap_optind++;
- }
- return(*cp);
- }
- else
- {
- if (!argv[ap_optind][optchr+1])
- {
- dash = 0;
- ap_optind++;
- }
- else
- optchr++;
- return(*cp);
- }
- assert(0);
- return(0);
-}
-
-#ifdef TESTGETOPT
-int
- main (int argc, char **argv)
- {
- int c;
- extern char *ap_optarg;
- extern int ap_optind;
- int aflg = 0;
- int bflg = 0;
- int errflg = 0;
- char *ofile = NULL;
-
- while ((c = ap_getopt(argc, argv, "abo:")) != EOF)
- switch (c) {
- case 'a':
- if (bflg)
- errflg++;
- else
- aflg++;
- break;
- case 'b':
- if (aflg)
- errflg++;
- else
- bflg++;
- break;
- case 'o':
- ofile = ap_optarg;
- (void)printf("ofile = %s\n", ofile);
- break;
- case '?':
- errflg++;
- }
- if (errflg) {
- (void)fprintf(stderr,
- "usage: cmd [-a|-b] [-o <filename>] files...\n");
- exit (2);
- }
- for ( ; ap_optind < argc; ap_optind++)
- (void)printf("%s\n", argv[ap_optind]);
- return 0;
- }
-
-#endif /* TESTGETOPT */
diff --git a/sapi/isapi/stresstest/getopt.h b/sapi/isapi/stresstest/getopt.h
deleted file mode 100644
index a3e278e3a6..0000000000
--- a/sapi/isapi/stresstest/getopt.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/* Borrowed from Apache NT Port */
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern char *ap_optarg;
-extern int ap_optind;
-
-int ap_getopt(int argc, char* const *argv, const char *optstr);
-
-#ifdef __cplusplus
-}
-#endif \ No newline at end of file
diff --git a/sapi/isapi/stresstest/notes.txt b/sapi/isapi/stresstest/notes.txt
deleted file mode 100644
index 2bab38dd07..0000000000
--- a/sapi/isapi/stresstest/notes.txt
+++ /dev/null
@@ -1,56 +0,0 @@
-This stress test program is for debugging threading issues with the ISAPI
-module.
-
-2 ways to use it:
-
-1: test any php script file on multiple threads
-2: run the php test scripts bundled with the source code
-
-
-
-GLOBAL SETTINGS
-===============
-
-If you need to set special environement variables, in addition to your
-regular environment, create a file that contains them, one setting per line:
-
-MY_ENV_VAR=XXXXXXXX
-
-This can be used to simulate ISAPI environment variables if need be.
-
-By default, stress test uses 10 threads. To change this, change the define
-NUM_THREADS in stresstest.cpp.
-
-
-
-1: Test any php script file on multiple threads
-===============================================
-
-Create a file that contains a list of php script files, one per line. If
-you need to provide input, place the GET data, or Query String, after the
-filename. File contents would look like:
-
-e:\inetpub\pages\index.php
-e:\inetpub\pages\info.php
-e:\inetpub\pages\test.php a=1&b=2
-
-Run: stresstest L files.txt
-
-
-
-2: Run the php test scripts bundled with the source code
-========================================================
-
-supply the path to the parent of the "tests" directory (expect a couple
-long pauses for a couple of the larger tests)
-
-Run: stresstest T c:\php4-source
-
-
-
-TODO:
-
-* Make more options configurable: number of threads, iterations, etc.
-* Improve stdout output to make it more useful
-* Implement support for SKIPIF
-* Improve speed of CompareFile function (too slow on big files).
diff --git a/sapi/isapi/stresstest/stresstest.cpp b/sapi/isapi/stresstest/stresstest.cpp
deleted file mode 100644
index bf268f4e23..0000000000
--- a/sapi/isapi/stresstest/stresstest.cpp
+++ /dev/null
@@ -1,936 +0,0 @@
-/*
- * ======================================================================= *
- * File: stress .c *
- * stress tester for isapi dll's *
- * based on cgiwrap *
- * ======================================================================= *
- *
-*/
-#define WIN32_LEAN_AND_MEAN
-#include <afx.h>
-#include <afxtempl.h>
-#include <winbase.h>
-#include <winerror.h>
-#include <httpext.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "getopt.h"
-
-// These are things that go out in the Response Header
-//
-#define HTTP_VER "HTTP/1.0"
-#define SERVER_VERSION "Http-Srv-Beta2/1.0"
-
-//
-// Simple wrappers for the heap APIS
-//
-#define xmalloc(s) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (s))
-#define xfree(s) HeapFree(GetProcessHeap(), 0, (s))
-
-//
-// The mandatory exports from the ISAPI DLL
-//
-DWORD numThreads = 1;
-DWORD iterations = 1;
-
-HANDLE StartNow;
-// quick and dirty environment
-typedef CMapStringToString TEnvironment;
-TEnvironment IsapiEnvironment;
-
-typedef struct _TResults {
- LONG ok;
- LONG bad;
-} TResults;
-
-CStringArray IsapiFileList; // list of filenames
-CStringArray TestNames; // --TEST--
-CStringArray IsapiGetData; // --GET--
-CStringArray IsapiPostData; // --POST--
-CStringArray IsapiMatchData; // --EXPECT--
-CArray<TResults, TResults> Results;
-
-typedef struct _TIsapiContext {
- HANDLE in;
- HANDLE out;
- DWORD tid;
- TEnvironment env;
- HANDLE waitEvent;
-} TIsapiContext;
-
-//
-// Prototypes of the functions this sample implements
-//
-extern "C" {
-HINSTANCE hDll;
-typedef BOOL (WINAPI *VersionProc)(HSE_VERSION_INFO *) ;
-typedef DWORD (WINAPI *HttpExtProc)(EXTENSION_CONTROL_BLOCK *);
-typedef BOOL (WINAPI *TerminateProc) (DWORD);
-BOOL WINAPI FillExtensionControlBlock(EXTENSION_CONTROL_BLOCK *, TIsapiContext *) ;
-BOOL WINAPI GetServerVariable(HCONN, LPSTR, LPVOID, LPDWORD );
-BOOL WINAPI ReadClient(HCONN, LPVOID, LPDWORD);
-BOOL WINAPI WriteClient(HCONN, LPVOID, LPDWORD, DWORD);
-BOOL WINAPI ServerSupportFunction(HCONN, DWORD, LPVOID, LPDWORD, LPDWORD);
-VersionProc IsapiGetExtensionVersion;
-HttpExtProc IsapiHttpExtensionProc;
-TerminateProc TerminateExtensionProc;
-HSE_VERSION_INFO version_info;
-}
-
-char * MakeDateStr(VOID);
-char * GetEnv(char *);
-
-
-
-
-DWORD CALLBACK IsapiThread(void *);
-int stress_main(const char *filename,
- const char *arg,
- const char *postfile,
- const char *matchdata);
-
-
-
-BOOL bUseTestFiles = FALSE;
-char temppath[MAX_PATH];
-
-void stripcrlf(char *line)
-{
- DWORD l = strlen(line)-1;
- if (line[l]==10 || line[l]==13) line[l]=0;
- l = strlen(line)-1;
- if (line[l]==10 || line[l]==13) line[l]=0;
-}
-
-#define COMPARE_BUF_SIZE 1024
-
-BOOL CompareFiles(const char*f1, const char*f2)
-{
- FILE *fp1, *fp2;
- bool retval;
- char buf1[COMPARE_BUF_SIZE], buf2[COMPARE_BUF_SIZE];
- int length1, length2;
-
- if ((fp1=fopen(f1, "r"))==NULL) {
- return FALSE;
- }
-
- if ((fp2=fopen(f2, "r"))==NULL) {
- fclose(fp1);
- return FALSE;
- }
-
- retval = TRUE; // success oriented
- while (true) {
- length1 = fread(buf1, 1, sizeof(buf1), fp1);
- length2 = fread(buf2, 1, sizeof(buf2), fp2);
-
- // check for end of file
- if (feof(fp1)) {
- if (!feof(fp2)) {
- retval = FALSE;
- }
- break;
- } else if (feof(fp2)) {
- if (!feof(fp1)) {
- retval = FALSE;
- }
- break;
- }
-
- // compare data
- if (length1!=length2
- || memcmp(buf1, buf2, length1)!=0) {
- retval = FALSE;
- break;
- }
- }
- fclose(fp1);
- fclose(fp2);
-
- return retval;
-}
-
-
-BOOL CompareStringWithFile(const char *filename, const char *str, unsigned int str_length)
-{
- FILE *fp;
- bool retval;
- char buf[COMPARE_BUF_SIZE];
- unsigned int offset=0, readbytes;
- fprintf(stderr, "test %s\n",filename);
- if ((fp=fopen(filename, "rb"))==NULL) {
- fprintf(stderr, "Error opening %s\n",filename);
- return FALSE;
- }
-
- retval = TRUE; // success oriented
- while (true) {
- readbytes = fread(buf, 1, sizeof(buf), fp);
-
- // check for end of file
-
- if (offset+readbytes > str_length
- || memcmp(buf, str+offset, readbytes)!=NULL) {
- fprintf(stderr, "File missmatch %s\n",filename);
- retval = FALSE;
- break;
- }
- if (feof(fp)) {
- if (!retval) fprintf(stderr, "File zero length %s\n",filename);
- break;
- }
- }
- fclose(fp);
-
- return retval;
-}
-
-
-BOOL ReadGlobalEnvironment(const char *environment)
-{
- if (environment) {
- FILE *fp = fopen(environment, "r");
- DWORD i=0;
- if (fp) {
- char line[2048];
- while (fgets(line, sizeof(line)-1, fp)) {
- // file.php arg1 arg2 etc.
- char *p = strchr(line, '=');
- if (p) {
- *p=0;
- IsapiEnvironment[line]=p+1;
- }
- }
- fclose(fp);
- return IsapiEnvironment.GetCount() > 0;
- }
- }
- return FALSE;
-}
-
-BOOL ReadFileList(const char *filelist)
-{
- FILE *fp = fopen(filelist, "r");
- if (!fp) {
- printf("Unable to open %s\r\n", filelist);
- }
- char line[2048];
- int i=0;
- while (fgets(line, sizeof(line)-1, fp)) {
- // file.php arg1 arg2 etc.
- stripcrlf(line);
- if (strlen(line)>3) {
- char *p = strchr(line, ' ');
- if (p) {
- *p = 0;
- // get file
-
- IsapiFileList.Add(line);
- IsapiGetData.Add(p+1);
- } else {
- // just a filename is all
- IsapiFileList.Add(line);
- IsapiGetData.Add("");
- }
- }
-
- // future use
- IsapiPostData.Add("");
- IsapiMatchData.Add("");
- TestNames.Add("");
-
- i++;
- }
- Results.SetSize(TestNames.GetSize());
-
- fclose(fp);
- return IsapiFileList.GetSize() > 0;
-}
-
-void DoThreads() {
-
- if (IsapiFileList.GetSize() == 0) {
- printf("No Files to test\n");
- return;
- }
-
- printf("Starting Threads...\n");
- // loop creating threads
- DWORD tid;
- HANDLE *threads = new HANDLE[numThreads];
- DWORD i;
- for (i=0; i< numThreads; i++) {
- threads[i]=CreateThread(NULL, 0, IsapiThread, NULL, CREATE_SUSPENDED, &tid);
- }
- for (i=0; i< numThreads; i++) {
- if (threads[i]) ResumeThread(threads[i]);
- }
- // wait for threads to finish
- WaitForMultipleObjects(numThreads, threads, TRUE, INFINITE);
- for (i=0; i< numThreads; i++) {
- CloseHandle(threads[i]);
- }
- delete threads;
-}
-
-void DoFileList(const char *filelist, const char *environment)
-{
- // read config files
-
- if (!ReadFileList(filelist)) {
- printf("No Files to test!\r\n");
- return;
- }
-
- ReadGlobalEnvironment(environment);
-
- DoThreads();
-}
-
-
-/**
- * ParseTestFile
- * parse a single phpt file and add it to the arrays
- */
-BOOL ParseTestFile(const char *path, const char *fn)
-{
- // parse the test file
- char filename[MAX_PATH];
- _snprintf(filename, sizeof(filename)-1, "%s\\%s", path, fn);
- char line[1024];
- memset(line, 0, sizeof(line));
- CString cTest, cSkipIf, cPost, cGet, cFile, cExpect;
- printf("Reading %s\r\n", filename);
-
- enum state {none, test, skipif, post, get, file, expect} parsestate = none;
-
- FILE *fp = fopen(filename, "rb");
- char *tn = _tempnam(temppath,"pht.");
- char *en = _tempnam(temppath,"exp.");
- FILE *ft = fopen(tn, "wb+");
- FILE *fe = fopen(en, "wb+");
- if (fp && ft && fe) {
- while (fgets(line, sizeof(line)-1, fp)) {
- if (line[0]=='-') {
- if (_strnicmp(line, "--TEST--", 8)==0) {
- parsestate = test;
- continue;
- } else if (_strnicmp(line, "--SKIPIF--", 10)==0) {
- parsestate = skipif;
- continue;
- } else if (_strnicmp(line, "--POST--", 8)==0) {
- parsestate = post;
- continue;
- } else if (_strnicmp(line, "--GET--", 7)==0) {
- parsestate = get;
- continue;
- } else if (_strnicmp(line, "--FILE--", 8)==0) {
- parsestate = file;
- continue;
- } else if (_strnicmp(line, "--EXPECT--", 10)==0) {
- parsestate = expect;
- continue;
- }
- }
- switch (parsestate) {
- case test:
- stripcrlf(line);
- cTest = line;
- break;
- case skipif:
- cSkipIf += line;
- break;
- case post:
- cPost += line;
- break;
- case get:
- cGet += line;
- break;
- case file:
- fputs(line, ft);
- break;
- case expect:
- fputs(line, fe);
- break;
- }
- }
-
- fclose(fp);
- fclose(ft);
- fclose(fe);
-
- if (!cTest.IsEmpty()) {
- IsapiFileList.Add(tn);
- TestNames.Add(cTest);
- IsapiGetData.Add(cGet);
- IsapiPostData.Add(cPost);
- IsapiMatchData.Add(en);
- free(tn);
- free(en);
- return TRUE;
- }
- }
- free(tn);
- free(en);
- return FALSE;
-}
-
-
-/**
- * GetTestFiles
- * Recurse through the path and subdirectories, parse each phpt file
- */
-BOOL GetTestFiles(const char *path)
-{
- // find all files .phpt under testpath\tests
- char FindPath[MAX_PATH];
- WIN32_FIND_DATA fd;
- memset(&fd, 0, sizeof(WIN32_FIND_DATA));
-
- _snprintf(FindPath, sizeof(FindPath)-1, "%s\\*.*", path);
- HANDLE fh = FindFirstFile(FindPath, &fd);
- if (fh != INVALID_HANDLE_VALUE) {
- do {
- if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
- !strchr(fd.cFileName, '.')) {
- // subdirectory, recurse into it
- char NewFindPath[MAX_PATH];
- _snprintf(NewFindPath, sizeof(NewFindPath)-1, "%s\\%s", path, fd.cFileName);
- GetTestFiles(NewFindPath);
- } else if (strstr(fd.cFileName, ".phpt")) {
- // got test file, parse it now
- if (ParseTestFile(path, fd.cFileName)) {
- printf("Test File Added: %s\\%s\r\n", path, fd.cFileName);
- }
- }
- memset(&fd, 0, sizeof(WIN32_FIND_DATA));
- } while (FindNextFile(fh, &fd) != 0);
- FindClose(fh);
- }
- return IsapiFileList.GetSize() > 0;
-}
-
-void DeleteTempFiles(const char *mask)
-{
- char FindPath[MAX_PATH];
- WIN32_FIND_DATA fd;
- memset(&fd, 0, sizeof(WIN32_FIND_DATA));
-
- _snprintf(FindPath, sizeof(FindPath)-1, "%s\\%s", temppath, mask);
- HANDLE fh = FindFirstFile(FindPath, &fd);
- if (fh != INVALID_HANDLE_VALUE) {
- do {
- char NewFindPath[MAX_PATH];
- _snprintf(NewFindPath, sizeof(NewFindPath)-1, "%s\\%s", temppath, fd.cFileName);
- DeleteFile(NewFindPath);
- memset(&fd, 0, sizeof(WIN32_FIND_DATA));
- } while (FindNextFile(fh, &fd) != 0);
- FindClose(fh);
- }
-}
-
-void DoTestFiles(const char *filelist, const char *environment)
-{
- if (!GetTestFiles(filelist)) {
- printf("No Files to test!\r\n");
- return;
- }
-
- Results.SetSize(IsapiFileList.GetSize());
-
- ReadGlobalEnvironment(environment);
-
- DoThreads();
-
- printf("\r\nRESULTS:\r\n");
- // show results:
- DWORD r = Results.GetSize();
- for (DWORD i=0; i< r; i++) {
- TResults result = Results.GetAt(i);
- printf("%s\r\nOK: %d FAILED: %d\r\n", TestNames.GetAt(i), result.ok, result.bad);
- }
-
- // delete temp files
- printf("Deleting Temp Files\r\n");
- DeleteTempFiles("exp.*");
- DeleteTempFiles("pht.*");
- printf("Done\r\n");
-}
-
-#define OPTSTRING "m:f:d:h:t:i:"
-static void _usage(char *argv0)
-{
- char *prog;
-
- prog = strrchr(argv0, '/');
- if (prog) {
- prog++;
- } else {
- prog = "stresstest";
- }
-
- printf("Usage: %s -m <isapi.dll> -d|-l <file> [-t <numthreads>] [-i <numiterations>]\n"
- " -m path to isapi dll\n"
- " -d <directory> php directory (to run php test files).\n"
- " -f <file> file containing list of files to run\n"
- " -t number of threads to use (default=1)\n"
- " -i number of iterations per thread (default=1)\n"
- " -h This help\n", prog);
-}
-int main(int argc, char* argv[])
-{
- LPVOID lpMsgBuf;
- char *filelist=NULL, *environment=NULL, *module=NULL;
- int c = NULL;
- while ((c=ap_getopt(argc, argv, OPTSTRING))!=-1) {
- switch (c) {
- case 'd':
- bUseTestFiles = TRUE;
- filelist = strdup(ap_optarg);
- break;
- case 'f':
- bUseTestFiles = FALSE;
- filelist = strdup(ap_optarg);
- break;
- case 'e':
- environment = strdup(ap_optarg);
- break;
- case 't':
- numThreads = atoi(ap_optarg);
- break;
- case 'i':
- iterations = atoi(ap_optarg);
- break;
- case 'm':
- module = strdup(ap_optarg);
- break;
- case 'h':
- _usage(argv[0]);
- exit(0);
- break;
- }
- }
- if (!module || !filelist) {
- _usage(argv[0]);
- exit(0);
- }
-
- GetTempPath(sizeof(temppath), temppath);
- hDll = LoadLibrary(module); // Load our DLL
-
- if (!hDll) {
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR) &lpMsgBuf,
- 0,
- NULL
- );
- fprintf(stderr,"Error: Dll 'php4isapi.dll' not found -%d\n%s\n", GetLastError(), lpMsgBuf);
- free (module);
- free(filelist);
- LocalFree( lpMsgBuf );
- return -1;
- }
-
- //
- // Find the exported functions
-
- IsapiGetExtensionVersion = (VersionProc)GetProcAddress(hDll,"GetExtensionVersion");
- if (!IsapiGetExtensionVersion) {
- fprintf(stderr,"Can't Get Extension Version %d\n", GetLastError());
- free (module);
- free(filelist);
- return -1;
- }
- IsapiHttpExtensionProc = (HttpExtProc)GetProcAddress(hDll,"HttpExtensionProc");
- if (!IsapiHttpExtensionProc) {
- fprintf(stderr,"Can't Get Extension proc %d\n", GetLastError());
- free (module);
- free(filelist);
- return -1;
- }
- TerminateExtensionProc = (TerminateProc) GetProcAddress(hDll,
- "TerminateExtension");
-
- // This should really check if the version information matches what we
- // expect.
- //
- if (!IsapiGetExtensionVersion(&version_info) ) {
- fprintf(stderr,"Fatal: GetExtensionVersion failed\n");
- free (module);
- free(filelist);
- return -1;
- }
-
- if (bUseTestFiles) {
- char TestPath[MAX_PATH];
- if (filelist != NULL)
- _snprintf(TestPath, sizeof(TestPath)-1, "%s\\tests", filelist);
- else strcpy(TestPath, "tests");
- DoTestFiles(TestPath, environment);
- } else {
- DoFileList(filelist, environment);
- }
-
- // cleanup
- if (TerminateExtensionProc) TerminateExtensionProc(0);
-
- // We should really free memory (e.g., from GetEnv), but we'll be dead
- // soon enough
-
- FreeLibrary(hDll);
- free (module);
- free(filelist);
- return 0;
-}
-
-
-DWORD CALLBACK IsapiThread(void *p)
-{
- DWORD filecount = IsapiFileList.GetSize();
-
- for (DWORD j=0; j<iterations; j++) {
- for (DWORD i=0; i<filecount; i++) {
- // execute each file
- CString testname = TestNames.GetAt(i);
- BOOL ok = FALSE;
- if (stress_main(IsapiFileList.GetAt(i),
- IsapiGetData.GetAt(i),
- IsapiPostData.GetAt(i),
- IsapiMatchData.GetAt(i))) {
- InterlockedIncrement(&Results[i].ok);
- ok = TRUE;
- } else {
- InterlockedIncrement(&Results[i].bad);
- ok = FALSE;
- }
-
- if (testname.IsEmpty()) {
- printf("Thread %d File %s\n", GetCurrentThreadId(), IsapiFileList.GetAt(i));
- } else {
- printf("tid %d: %s %s\n", GetCurrentThreadId(), testname, ok?"OK":"FAIL");
- }
- Sleep(10);
- }
- }
- printf("Thread ending...\n");
- return 0;
-}
-
-/*
- * ======================================================================= *
- * In the startup of this program, we look at our executable name and *
- * replace the ".EXE" with ".DLL" to find the ISAPI DLL we need to load. *
- * This means that the executable need only be given the same "name" as *
- * the DLL to load. There is no recompilation required. *
- * ======================================================================= *
-*/
-BOOL stress_main(const char *filename,
- const char *arg,
- const char *postdata,
- const char *matchdata)
-{
-
- EXTENSION_CONTROL_BLOCK ECB;
- DWORD rc;
- TIsapiContext context;
-
- // open output and input files
- context.tid = GetCurrentThreadId();
- CString fname;
- fname.Format("%08X.out", context.tid);
-
- context.out = CreateFile(fname, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
- if (context.out==INVALID_HANDLE_VALUE) {
- printf("failed to open output file %s\n", fname);
- return 0;
- }
-
- // not using post files
- context.in = INVALID_HANDLE_VALUE;
-
- //
- // Fill the ECB with the necessary information
- //
- if (!FillExtensionControlBlock(&ECB, &context) ) {
- fprintf(stderr,"Fill Ext Block Failed\n");
- return -1;
- }
-
- // check for command line argument,
- // first arg = filename
- // this is added for testing php from command line
-
- context.env.RemoveAll();
- context.env["PATH_TRANSLATED"]= filename;
- context.env["SCRIPT_MAP"]= filename;
- context.env["CONTENT_TYPE"]= "";
- context.env["CONTENT_LENGTH"]= "";
- context.env["QUERY_STRING"]= arg;
- context.env["METHOD"]="GET";
- context.env["PATH_INFO"] = "";
- context.waitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- char buf[MAX_PATH];
- if (postdata && *postdata !=0) {
- ECB.cbAvailable = strlen(postdata);
- ECB.cbTotalBytes = ECB.cbAvailable;
- ECB.lpbData = (unsigned char *)postdata;
- context.env["METHOD"]="POST";
-
- _snprintf(buf, sizeof(buf)-1, "%d", ECB.cbTotalBytes);
- context.env["CONTENT_LENGTH"]=buf;
-
- context.env["CONTENT_TYPE"]="application/x-www-form-urlencoded";
- }
- ECB.lpszMethod = strdup(context.env["METHOD"]);
- ECB.lpszPathTranslated = strdup(filename);
- ECB.lpszQueryString = strdup(arg);
- ECB.lpszPathInfo = strdup(context.env["PATH_INFO"]);
-
-
- // Call the DLL
- //
- rc = IsapiHttpExtensionProc(&ECB);
- if (rc == HSE_STATUS_PENDING) {
- // We will exit in ServerSupportFunction
- WaitForSingleObject(context.waitEvent, INFINITE);
- }
- CloseHandle(context.waitEvent);
- //Sleep(75);
- free(ECB.lpszPathTranslated);
- free(ECB.lpszQueryString);
- free(ECB.lpszMethod);
- free(ECB.lpszPathInfo);
-
- BOOL ok = TRUE;
-
- if (context.out != INVALID_HANDLE_VALUE) CloseHandle(context.out);
-
- // compare the output with the EXPECT section
- if (matchdata && *matchdata != 0) {
- ok = CompareFiles(fname, matchdata);
- }
-
- DeleteFile(fname);
-
- return ok;
-
-}
-//
-// GetServerVariable() is how the DLL calls the main program to figure out
-// the environment variables it needs. This is a required function.
-//
-BOOL WINAPI GetServerVariable(HCONN hConn, LPSTR lpszVariableName,
- LPVOID lpBuffer, LPDWORD lpdwSize){
-
- DWORD rc;
- CString value;
- TIsapiContext *c = (TIsapiContext *)hConn;
- if (!c) return FALSE;
-
- if (IsapiEnvironment.Lookup(lpszVariableName, value)) {
- rc = value.GetLength();
- strncpy((char *)lpBuffer, value, *lpdwSize-1);
- } else if (c->env.Lookup(lpszVariableName, value)) {
- rc = value.GetLength();
- strncpy((char *)lpBuffer, value, *lpdwSize-1);
- } else
- rc = GetEnvironmentVariable(lpszVariableName, (char *)lpBuffer, *lpdwSize) ;
-
- if (!rc) { // return of 0 indicates the variable was not found
- SetLastError(ERROR_NO_DATA);
- return FALSE;
- }
-
- if (rc > *lpdwSize) {
- SetLastError(ERROR_INSUFFICIENT_BUFFER);
- return FALSE;
- }
-
- *lpdwSize =rc + 1 ; // GetEnvironmentVariable does not count the NULL
-
- return TRUE;
-
-}
-//
-// Again, we don't have an HCONN, so we simply wrap ReadClient() to
-// ReadFile on stdin. The semantics of the two functions are the same
-//
-BOOL WINAPI ReadClient(HCONN hConn, LPVOID lpBuffer, LPDWORD lpdwSize) {
- TIsapiContext *c = (TIsapiContext *)hConn;
- if (!c) return FALSE;
-
- if (c->in != INVALID_HANDLE_VALUE)
- return ReadFile(c->in, lpBuffer, (*lpdwSize), lpdwSize, NULL);
-
- return FALSE;
-}
-//
-// ditto for WriteClient()
-//
-BOOL WINAPI WriteClient(HCONN hConn, LPVOID lpBuffer, LPDWORD lpdwSize,
- DWORD dwReserved) {
- TIsapiContext *c = (TIsapiContext *)hConn;
- if (!c) return FALSE;
-
- if (c->out != INVALID_HANDLE_VALUE)
- return WriteFile(c->out, lpBuffer, *lpdwSize, lpdwSize, NULL);
- return FALSE;
-}
-//
-// This is a special callback function used by the DLL for certain extra
-// functionality. Look at the API help for details.
-//
-BOOL WINAPI ServerSupportFunction(HCONN hConn, DWORD dwHSERequest,
- LPVOID lpvBuffer, LPDWORD lpdwSize, LPDWORD lpdwDataType){
-
- TIsapiContext *c = (TIsapiContext *)hConn;
- char *lpszRespBuf;
- char * temp = NULL;
- DWORD dwBytes;
- BOOL bRet = TRUE;
-
- switch(dwHSERequest) {
- case (HSE_REQ_SEND_RESPONSE_HEADER) :
- lpszRespBuf = (char *)xmalloc(*lpdwSize);//+ 80);//accomodate our header
- if (!lpszRespBuf)
- return FALSE;
- wsprintf(lpszRespBuf,"%s",
- //HTTP_VER,
-
- /* Default response is 200 Ok */
-
- //lpvBuffer?lpvBuffer:"200 Ok",
-
- /* Create a string for the time. */
- //temp=MakeDateStr(),
-
- //SERVER_VERSION,
-
- /* If this exists, it is a pointer to a data buffer to
- be sent. */
- lpdwDataType?(char *)lpdwDataType:NULL);
-
- if (temp) xfree(temp);
-
- dwBytes = strlen(lpszRespBuf);
- bRet = WriteClient(0, lpszRespBuf, &dwBytes, 0);
- xfree(lpszRespBuf);
-
- break;
- //
- // A real server would do cleanup here
- case (HSE_REQ_DONE_WITH_SESSION):
- SetEvent(c->waitEvent);
- //ExitThread(0);
- break;
-
- //
- // This sends a redirect (temporary) to the client.
- // The header construction is similar to RESPONSE_HEADER above.
- //
- case (HSE_REQ_SEND_URL_REDIRECT_RESP):
- lpszRespBuf = (char *)xmalloc(*lpdwSize +80) ;
- if (!lpszRespBuf)
- return FALSE;
- wsprintf(lpszRespBuf,"%s %s %s\r\n",
- HTTP_VER,
- "302 Moved Temporarily",
- (lpdwSize > 0)?lpvBuffer:0);
- xfree(temp);
- dwBytes = strlen(lpszRespBuf);
- bRet = WriteClient(0, lpszRespBuf, &dwBytes, 0);
- xfree(lpszRespBuf);
- break;
- default:
- return FALSE;
- break;
- }
- return bRet;
-
-}
-//
-// Makes a string of the date and time from GetSystemTime().
-// This is in UTC, as required by the HTTP spec.`
-//
-char * MakeDateStr(void){
- SYSTEMTIME systime;
- char *szDate= (char *)xmalloc(64);
-
- char * DaysofWeek[] = {"Sun","Mon","Tue","Wed","Thurs","Fri","Sat"};
- char * Months[] = {"NULL","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
- "Sep","Oct","Nov","Dec"};
-
- GetSystemTime(&systime);
-
- wsprintf(szDate,"%s, %d %s %d %d:%d.%d", DaysofWeek[systime.wDayOfWeek],
- systime.wDay,
- Months[systime.wMonth],
- systime.wYear,
- systime.wHour, systime.wMinute,
- systime.wSecond );
-
- return szDate;
-}
-//
-// Fill the ECB up
-//
-BOOL WINAPI FillExtensionControlBlock(EXTENSION_CONTROL_BLOCK *ECB, TIsapiContext *context) {
-
- char * temp;
- ECB->cbSize = sizeof(EXTENSION_CONTROL_BLOCK);
- ECB->dwVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
- ECB->ConnID = (void *)context;
- //
- // Pointers to the functions the DLL will call.
- //
- ECB->GetServerVariable = GetServerVariable;
- ECB->ReadClient = ReadClient;
- ECB->WriteClient = WriteClient;
- ECB->ServerSupportFunction = ServerSupportFunction;
-
- //
- // Fill in the standard CGI environment variables
- //
- ECB->lpszMethod = GetEnv("REQUEST_METHOD");
- if (!ECB->lpszMethod) ECB->lpszMethod = "GET";
-
- ECB->lpszQueryString = GetEnv("QUERY_STRING");
- ECB->lpszPathInfo = GetEnv("PATH_INFO");
- ECB->lpszPathTranslated = GetEnv("PATH_TRANSLATED");
- ECB->cbTotalBytes=( (temp=GetEnv("CONTENT_LENGTH")) ? (atoi(temp)): 0);
- ECB->cbAvailable = 0;
- ECB->lpbData = (unsigned char *)"";
- ECB->lpszContentType = GetEnv("CONTENT_TYPE");
- return TRUE;
-
-}
-
-//
-// Works like _getenv(), but uses win32 functions instead.
-//
-char *GetEnv(LPSTR lpszEnvVar)
-{
-
- char *var, dummy;
- DWORD dwLen;
-
- if (!lpszEnvVar)
- return "";
-
- dwLen =GetEnvironmentVariable(lpszEnvVar, &dummy, 1);
-
- if (dwLen == 0)
- return "";
-
- var = (char *)xmalloc(dwLen);
- if (!var)
- return "";
- (void)GetEnvironmentVariable(lpszEnvVar, var, dwLen);
-
- return var;
-}
diff --git a/sapi/isapi/stresstest/stresstest.dsp b/sapi/isapi/stresstest/stresstest.dsp
deleted file mode 100644
index fb82303e3d..0000000000
--- a/sapi/isapi/stresstest/stresstest.dsp
+++ /dev/null
@@ -1,108 +0,0 @@
-# Microsoft Developer Studio Project File - Name="stresstest" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=stresstest - Win32 Debug
-!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 "stresstest.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 "stresstest.mak" CFG="stresstest - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "stresstest - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "stresstest - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "stresstest - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 2
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /FD /c
-# SUBTRACT CPP /YX /Yc /Yu
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL"
-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 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 /subsystem:console /machine:I386
-# ADD LINK32 /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "stresstest - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 2
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "c:\php-fcgi"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /FD /GZ /c
-# SUBTRACT CPP /YX /Yc /Yu
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL"
-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 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 /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "stresstest - Win32 Release"
-# Name "stresstest - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\getopt.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\getopt.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\stresstest.cpp
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\notes.txt
-# End Source File
-# End Target
-# End Project
diff --git a/sapi/milter/CREDITS b/sapi/milter/CREDITS
deleted file mode 100644
index cd00d6774b..0000000000
--- a/sapi/milter/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-Sendmail Milter
-Harald Radi
diff --git a/sapi/milter/EXPERIMENTAL b/sapi/milter/EXPERIMENTAL
deleted file mode 100644
index 293159a693..0000000000
--- a/sapi/milter/EXPERIMENTAL
+++ /dev/null
@@ -1,5 +0,0 @@
-this module is experimental,
-its functions may change their names
-or move to extension all together
-so do not rely to much on them
-you have been warned!
diff --git a/sapi/milter/Makefile.frag b/sapi/milter/Makefile.frag
deleted file mode 100644
index 8dbdf7a8fd..0000000000
--- a/sapi/milter/Makefile.frag
+++ /dev/null
@@ -1,2 +0,0 @@
-$(SAPI_MILTER_PATH): $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
- $(BUILD_MILTER)
diff --git a/sapi/milter/TODO b/sapi/milter/TODO
deleted file mode 100644
index 4a427ea131..0000000000
--- a/sapi/milter/TODO
+++ /dev/null
@@ -1,5 +0,0 @@
-threaded version still leaks mem, don't know why
-extensions aren't loaded
-stdout to syslog
-testing
-documentation \ No newline at end of file
diff --git a/sapi/milter/config.m4 b/sapi/milter/config.m4
deleted file mode 100644
index 4194d4f2cf..0000000000
--- a/sapi/milter/config.m4
+++ /dev/null
@@ -1,39 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for Milter support)
-AC_ARG_WITH(milter,
-[ --with-milter=DIR Build PHP as Milter application],[
- if test "$withval" = "yes"; then
- if test -f /usr/lib/libmilter.a ; then
- MILTERPATH=/usr/lib
- else
- if test -f /usr/lib/libmilter/libmilter.a ; then
- MILTERPATH=/usr/lib/libmilter
- else
- AC_MSG_ERROR(Unable to find libmilter.a)
- fi
- fi
- else
- MILTERPATH=$withval
- fi
-
- SAPI_MILTER_PATH=sapi/milter/php-milter
- PHP_SUBST(SAPI_MILTER_PATH)
- PHP_BUILD_THREAD_SAFE
- PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/milter/Makefile.frag)
-
- PHP_SELECT_SAPI(milter, program, php_milter.c getopt.c,,'$(SAPI_MILTER_PATH)')
- PHP_ADD_LIBRARY_WITH_PATH(milter, $MILTERPATH,)
-
- BUILD_MILTER="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_MILTER_PATH)"
-
- INSTALL_IT="\$(INSTALL) -m 0755 \$(SAPI_MILTER_PATH) \$(bindir)/php-milter"
- RESULT=yes
-
- PHP_SUBST(BUILD_MILTER)
-],[
- RESULT=no
-])
-AC_MSG_RESULT($RESULT)
diff --git a/sapi/milter/getopt.c b/sapi/milter/getopt.c
deleted file mode 100644
index f5874d577e..0000000000
--- a/sapi/milter/getopt.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/* Borrowed from Apache NT Port */
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
-#include "php_getopt.h"
-#define OPTERRCOLON (1)
-#define OPTERRNF (2)
-#define OPTERRARG (3)
-
-
-char *ap_php_optarg;
-int ap_php_optind = 1;
-static int ap_php_opterr = 1;
-
-static int
-ap_php_optiserr(int argc, char * const *argv, int oint, const char *optstr,
- int optchr, int err)
-{
- if (ap_php_opterr)
- {
- fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1);
- switch(err)
- {
- case OPTERRCOLON:
- fprintf(stderr, ": in flags\n");
- break;
- case OPTERRNF:
- fprintf(stderr, "option not found %c\n", argv[oint][optchr]);
- break;
- case OPTERRARG:
- fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]);
- break;
- default:
- fprintf(stderr, "unknown\n");
- break;
- }
- }
- return('?');
-}
-
-int ap_php_getopt(int argc, char* const *argv, const char *optstr)
-{
- static int optchr = 0;
- static int dash = 0; /* have already seen the - */
-
- char *cp;
-
- if (ap_php_optind >= argc)
- return(EOF);
- if (!dash && (argv[ap_php_optind][0] != '-'))
- return(EOF);
- if (!dash && (argv[ap_php_optind][0] == '-') && !argv[ap_php_optind][1])
- {
- /*
- * use to specify stdin. Need to let pgm process this and
- * the following args
- */
- return(EOF);
- }
- if ((argv[ap_php_optind][0] == '-') && (argv[ap_php_optind][1] == '-'))
- {
- /* -- indicates end of args */
- ap_php_optind++;
- return(EOF);
- }
- if (!dash)
- {
- assert((argv[ap_php_optind][0] == '-') && argv[ap_php_optind][1]);
- dash = 1;
- optchr = 1;
- }
-
- /* Check if the guy tries to do a -: kind of flag */
- assert(dash);
- if (argv[ap_php_optind][optchr] == ':')
- {
- dash = 0;
- ap_php_optind++;
- return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRCOLON));
- }
- if (!(cp = strchr(optstr, argv[ap_php_optind][optchr])))
- {
- int errind = ap_php_optind;
- int errchr = optchr;
-
- if (!argv[ap_php_optind][optchr+1])
- {
- dash = 0;
- ap_php_optind++;
- }
- else
- optchr++;
- return(ap_php_optiserr(argc, argv, errind, optstr, errchr, OPTERRNF));
- }
- if (cp[1] == ':')
- {
- /* Check for cases where the value of the argument
- is in the form -<arg> <val> or in the form -<arg><val> */
- dash = 0;
- if(!argv[ap_php_optind][2]) {
- ap_php_optind++;
- if (ap_php_optind == argc)
- return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRARG));
- ap_php_optarg = argv[ap_php_optind++];
- }
- else
- {
- ap_php_optarg = &argv[ap_php_optind][2];
- ap_php_optind++;
- }
- return(*cp);
- }
- else
- {
- if (!argv[ap_php_optind][optchr+1])
- {
- dash = 0;
- ap_php_optind++;
- }
- else
- optchr++;
- return(*cp);
- }
- assert(0);
- return(0); /* never reached */
-}
-
-#ifdef TESTGETOPT
-int
- main (int argc, char **argv)
- {
- int c;
- extern char *ap_php_optarg;
- extern int ap_php_optind;
- int aflg = 0;
- int bflg = 0;
- int errflg = 0;
- char *ofile = NULL;
-
- while ((c = ap_php_getopt(argc, argv, "abo:")) != EOF)
- switch (c) {
- case 'a':
- if (bflg)
- errflg++;
- else
- aflg++;
- break;
- case 'b':
- if (aflg)
- errflg++;
- else
- bflg++;
- break;
- case 'o':
- ofile = ap_php_optarg;
- (void)printf("ofile = %s\n", ofile);
- break;
- case '?':
- errflg++;
- }
- if (errflg) {
- (void)fprintf(stderr,
- "usage: cmd [-a|-b] [-o <filename>] files...\n");
- exit (2);
- }
- for ( ; ap_php_optind < argc; ap_php_optind++)
- (void)printf("%s\n", argv[ap_php_optind]);
- return 0;
- }
-
-#endif /* TESTGETOPT */
diff --git a/sapi/milter/milter.php b/sapi/milter/milter.php
deleted file mode 100644
index 0878f2a4d9..0000000000
--- a/sapi/milter/milter.php
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-/**
- * example milter script
- *
- * run: php-milter -D -p /path/to/sock milter.php
- *
- * for details on how to set up sendmail and configure the milter see
- * http://www.sendmail.com/partner/resources/development/milter_api/
- *
- * for api details see
- * http://www.sendmail.com/partner/resources/development/milter_api/api.html
- *
- * below is a list of all callbacks, that are available through the milter sapi,
- * if you leave one or more out they simply won't get called (e.g. if you secify an
- * empty php file, the milter would do nothing :)
- */
-
-/**
- * this function is called once on sapi startup,
- * here you can specify the actions the filter may take
- *
- * see http://www.sendmail.com/partner/resources/development/milter_api/smfi_register.html#flags
- */
-
-function milter_log($msg)
-{
- $GLOBALS['log'] = fopen("/tmp/milter.log", "a");
- fwrite($GLOBALS['log'], date("[H:i:s d.m.Y]") . "\t{$msg}\n");
- fclose($GLOBALS['log']);
-}
-
-function milter_init() {
- milter_log("-- startup --");
- milter_log("milter_init()");
- smfi_setflags(SMFIF_ADDHDRS);
-}
-
-/**
- * is called once, at the start of each SMTP connection
- */
-function milter_connect($connect)
-{
- milter_log("milter_connect('$connect')");
-}
-
-/**
- * is called whenever the client sends a HELO/EHLO command.
- * It may therefore be called between zero and three times.
- */
-function milter_helo($helo)
-{
- milter_log("milter_helo('$helo')");
-}
-
-/**
- * is called once at the beginning of each message,
- * before milter_envrcpt.
- */
-function milter_envfrom($args)
-{
- milter_log("milter_envfrom(args[])");
- foreach ($args as $ix => $arg) {
- milter_log("\targs[$ix] = $arg");
- }
-}
-
-/**
- * is called once per recipient, hence one or more times per message,
- * immediately after milter_envfrom
- */
-function milter_envrcpt($args)
-{
- milter_log("milter_envrcpt(args[])");
- foreach ($args as $ix => $arg) {
- milter_log("\targs[$ix] = $arg");
- }
-}
-
-/**
- * is called zero or more times between milter_envrcpt and milter_eoh,
- * once per message header
- */
-function milter_header($header, $value)
-{
- milter_log("milter_header('$header', '$value')");
-}
-
-/**
- * is called once after all headers have been sent and processed.
- */
-function milter_eoh()
-{
- milter_log("milter_eoh()");
-}
-
-/**
- * is called zero or more times between milter_eoh and milter_eom.
- */
-function milter_body($bodypart)
-{
- milter_log("milter_body('$bodypart')");
-}
-
-/**
- * is called once after all calls to milter_body for a given message.
- * most of the api functions, that alter the message can only be called
- * within this callback.
- */
-function milter_eom()
-{
- milter_log("milter_eom()");
- /* add PHP header to the message */
- smfi_addheader("X-PHP", phpversion());
-}
-
-/**
- * may be called at any time during message processing
- * (i.e. between some message-oriented routine and milter_eom).
- */
-function milter_abort()
-{
- milter_log("milter_abort()");
-}
-
-/**
- * is always called once at the end of each connection.
- */
-function milter_close()
-{
- milter_log("milter_close()");
-}
-?>
diff --git a/sapi/milter/php_getopt.h b/sapi/milter/php_getopt.h
deleted file mode 100644
index 40da432b59..0000000000
--- a/sapi/milter/php_getopt.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* Borrowed from Apache NT Port */
-#include "php.h"
-
-extern char *ap_php_optarg;
-extern int ap_php_optind;
-
-int ap_php_getopt(int argc, char* const *argv, const char *optstr);
diff --git a/sapi/milter/php_milter.c b/sapi/milter/php_milter.c
deleted file mode 100644
index 112a645983..0000000000
--- a/sapi/milter/php_milter.c
+++ /dev/null
@@ -1,1139 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Harald Radi <phanto@php.net> |
- | Parts based on CGI SAPI Module by |
- | Rasmus Lerdorf, Stig Bakken and Zeev Suraski |
- +----------------------------------------------------------------------+
-*/
-
-
-#include "php.h"
-#include "php_globals.h"
-#include "php_variables.h"
-#include "zend_modules.h"
-
-#ifndef ZTS
-#error SRM sapi module is only useable in thread-safe mode
-#endif
-
-#include "SAPI.h"
-
-#include <stdio.h>
-#include "php.h"
-#if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-#if HAVE_SETLOCALE
-#include <locale.h>
-#endif
-#include "zend.h"
-#include "zend_extensions.h"
-#include "php_ini.h"
-#include "php_globals.h"
-#include "php_main.h"
-#include "fopen_wrappers.h"
-#include "ext/standard/php_standard.h"
-
-#ifdef __riscos__
-#include <unixlib/local.h>
-#endif
-
-#include "zend_compile.h"
-#include "zend_execute.h"
-#include "zend_highlight.h"
-#include "zend_indent.h"
-
-#include "libmilter/mfapi.h"
-
-#define OPTSTRING "ac:d:Def:hnp:vVz:?"
-#define MG(v) TSRMG(milter_globals_id, zend_milter_globals *, v)
-
-#define IS_NONE "%s(): This function must not be called outside of a milter callback function's scope"
-#define NOT_EOM "%s(): This function can only be used inside the milter_eom callback's scope"
-#define NOT_INIT "%s(): This function can only be used inside the milter_init callback's scope"
-
-#define MLFI_NONE 0
-#define MLFI_CONNECT 1
-#define MLFI_HELO 2
-#define MLFI_ENVFROM 3
-#define MLFI_ENVRCPT 4
-#define MLFI_HEADER 5
-#define MLFI_EOH 6
-#define MLFI_BODY 7
-#define MLFI_EOM 8
-#define MLFI_ABORT 9
-#define MLFI_CLOSE 10
-#define MLFI_INIT 11
-
-/* {{{ globals
- */
-extern char *ap_php_optarg;
-extern int ap_php_optind;
-
-static int flag_debug=0;
-static char *filename;
-
-/* per thread */
-ZEND_BEGIN_MODULE_GLOBALS(milter)
- SMFICTX *ctx;
- int state;
- int initialized;
-ZEND_END_MODULE_GLOBALS(milter)
-
-ZEND_DECLARE_MODULE_GLOBALS(milter)
-/* }}} */
-
-/* this method is called only once when the milter starts */
-/* {{{ Init Milter
-*/
-static int mlfi_init()
-{
- int ret = 0;
- zend_file_handle file_handle;
- zval function_name, retval;
- TSRMLS_FETCH();
-
- /* request startup */
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- php_request_shutdown((void *) 0);
-
- return -1;
- }
-
- /* disable headers */
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
-
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = filename;
- file_handle.free_filename = 0;
- file_handle.opened_path = NULL;
-
- php_execute_script(&file_handle TSRMLS_CC);
-
- /* call userland */
- INIT_ZVAL(function_name);
-
- ZVAL_STRING(&function_name, "milter_init", 0);
-
- /* set the milter context for possible use in API functions */
- MG(state) = MLFI_INIT;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
- MG(initialized) = 1;
-
- if (Z_TYPE(retval) == IS_LONG) {
- ret = Z_LVAL(retval);
- }
-
- php_request_shutdown((void *) 0);
-
- return ret;
-}
-/* }}} */
-
-/* {{{ Milter callback functions
- */
-
-/* connection info filter, is called whenever sendmail connects to the milter */
-/* {{{ mlfi_connect()
-*/
-static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
-{
- zend_file_handle file_handle;
- zval function_name, retval, *param[1];
- TSRMLS_FETCH();
-
- /* request startup */
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- php_request_shutdown((void *) 0);
-
- return SMFIS_TEMPFAIL;
- }
-
- /* disable headers */
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
-
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = filename;
- file_handle.free_filename = 0;
- file_handle.opened_path = NULL;
-
- php_execute_script(&file_handle TSRMLS_CC);
-
- /* call userland */
- INIT_ZVAL(function_name);
-
- ALLOC_ZVAL(param[0]);
- INIT_PZVAL(param[0]);
-
- ZVAL_STRING(&function_name, "milter_connect", 0);
- ZVAL_STRING(param[0], hostname, 1);
-
- /* set the milter context for possible use in API functions */
- MG(ctx) = ctx;
- MG(state) = MLFI_CONNECT;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
-
- if (Z_TYPE(retval) == IS_LONG) {
- return Z_LVAL(retval);
- }
-
- return SMFIS_CONTINUE;
-}
-/* }}} */
-
-/* SMTP HELO command filter */
-/* {{{ mlfi_helo()
-*/
-static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost)
-{
- zval function_name, retval, *param[1];
- TSRMLS_FETCH();
-
- /* call userland */
- INIT_ZVAL(function_name);
-
- ALLOC_ZVAL(param[0]);
- INIT_PZVAL(param[0]);
-
- ZVAL_STRING(&function_name, "milter_helo", 0);
- ZVAL_STRING(param[0], helohost, 1);
-
- /* set the milter context for possible use in API functions */
- MG(ctx) = ctx;
- MG(state) = MLFI_HELO;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
-
- FREE_ZVAL(param[0]);
-
- if (Z_TYPE(retval) == IS_LONG) {
- return Z_LVAL(retval);
- }
-
- return SMFIS_CONTINUE;
-}
-/* }}} */
-
-/* envelope sender filter */
-/* {{{ mlfi_envform()
-*/
-static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv)
-{
- zval function_name, retval, *param[1];
- TSRMLS_FETCH();
-
- /* call userland */
- INIT_ZVAL(function_name);
-
- ALLOC_ZVAL(param[0]);
- INIT_PZVAL(param[0]);
-
- ZVAL_STRING(&function_name, "milter_envfrom", 0);
- array_init(param[0]);
-
- while (*argv) {
- add_next_index_string(param[0], *argv, 1);
- argv++;
- }
-
- /* set the milter context for possible use in API functions */
- MG(ctx) = ctx;
- MG(state) = MLFI_ENVFROM;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
-
- FREE_ZVAL(param[0]);
-
- if (Z_TYPE(retval) == IS_LONG) {
- return Z_LVAL(retval);
- }
-
- return SMFIS_CONTINUE;
-}
-/* }}} */
-
-/* envelope recipient filter */
-/* {{{ mlfi_envrcpt()
-*/
-static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv)
-{
- zval function_name, retval, *param[1];
- TSRMLS_FETCH();
-
- /* call userland */
- INIT_ZVAL(function_name);
-
- ALLOC_ZVAL(param[0]);
- INIT_PZVAL(param[0]);
-
- ZVAL_STRING(&function_name, "milter_envrcpt", 0);
- array_init(param[0]);
-
- while (*argv) {
- add_next_index_string(param[0], *argv, 1);
- argv++;
- }
-
- /* set the milter context for possible use in API functions */
- MG(ctx) = ctx;
- MG(state) = MLFI_ENVRCPT;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
-
- FREE_ZVAL(param[0]);
-
- if (Z_TYPE(retval) == IS_LONG) {
- return Z_LVAL(retval);
- }
-
- return SMFIS_CONTINUE;
-}
-/* }}} */
-
-/* header filter */
-/* {{{ mlfi_header()
-*/
-static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv)
-{
- zval function_name, retval, *param[2];
- TSRMLS_FETCH();
-
- /* call userland */
- INIT_ZVAL(function_name);
-
- ALLOC_ZVAL(param[0]);
- ALLOC_ZVAL(param[1]);
- INIT_PZVAL(param[0]);
- INIT_PZVAL(param[1]);
-
- ZVAL_STRING(&function_name, "milter_header", 0);
- ZVAL_STRING(param[0], headerf, 1);
- ZVAL_STRING(param[1], headerv, 1);
-
- /* set the milter context for possible use in API functions */
- MG(ctx) = ctx;
- MG(state) = MLFI_HEADER;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 2, param TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
-
- FREE_ZVAL(param[0]);
- FREE_ZVAL(param[1]);
-
- if (Z_TYPE(retval) == IS_LONG) {
- return Z_LVAL(retval);
- }
-
- return SMFIS_CONTINUE;
-}
-/* }}} */
-
-/* end of header */
-/* {{{ mlfi_eoh()
-*/
-static sfsistat mlfi_eoh(SMFICTX *ctx)
-{
- zval function_name, retval;
- TSRMLS_FETCH();
-
- /* call userland */
- INIT_ZVAL(function_name);
- ZVAL_STRING(&function_name, "milter_eoh", 0);
-
- /* set the milter context for possible use in API functions */
- MG(ctx) = ctx;
- MG(state) = MLFI_EOH;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
-
- if (Z_TYPE(retval) == IS_LONG) {
- return Z_LVAL(retval);
- }
-
- return SMFIS_CONTINUE;
-}
-/* }}} */
-
-/* body block */
-/* {{{ mlfi_body()
-*/
-static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
-{
- zval function_name, retval, *param[1];
- TSRMLS_FETCH();
-
- /* call userland */
- INIT_ZVAL(function_name);
-
- ALLOC_ZVAL(param[0]);
- INIT_PZVAL(param[0]);
-
- ZVAL_STRING(&function_name, "milter_body", 0);
- ZVAL_STRINGL(param[0], bodyp, len, 1);
-
- /* set the milter context for possible use in API functions */
- MG(ctx) = ctx;
- MG(state) = MLFI_BODY;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
-
- FREE_ZVAL(param[0]);
-
- if (Z_TYPE(retval) == IS_LONG) {
- return Z_LVAL(retval);
- }
-
- return SMFIS_CONTINUE;
-}
-/* }}} */
-
-/* end of message */
-/* {{{ mlfi_eom()
-*/
-static sfsistat mlfi_eom(SMFICTX *ctx)
-{
- zval function_name, retval;
- TSRMLS_FETCH();
-
- /* call userland */
- INIT_ZVAL(function_name);
- ZVAL_STRING(&function_name, "milter_eom", 0);
-
- /* set the milter context for possible use in API functions */
- MG(ctx) = ctx;
- MG(state) = MLFI_EOM;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
-
- if (Z_TYPE(retval) == IS_LONG) {
- return Z_LVAL(retval);
- }
-
- return SMFIS_CONTINUE;
-}
-/* }}} */
-
-/* message aborted */
-/* {{{ mlfi_abort()
-*/
-static sfsistat mlfi_abort(SMFICTX *ctx)
-{
- zval function_name, retval;
- TSRMLS_FETCH();
-
- /* call userland */
- INIT_ZVAL(function_name);
- ZVAL_STRING(&function_name, "milter_abort", 0);
-
- /* set the milter context for possible use in API functions */
- MG(ctx) = ctx;
- MG(state) = MLFI_ABORT;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
-
- if (Z_TYPE(retval) == IS_LONG) {
- return Z_LVAL(retval);
- }
-
- return SMFIS_CONTINUE;
-}
-/* }}} */
-
-/* connection cleanup */
-/* {{{ mlfi_close()
-*/
-static sfsistat mlfi_close(SMFICTX *ctx)
-{
- int ret = SMFIS_CONTINUE;
- zval function_name, retval;
- TSRMLS_FETCH();
-
- /* call userland */
- INIT_ZVAL(function_name);
- ZVAL_STRING(&function_name, "milter_close", 0);
-
- /* set the milter context for possible use in API functions */
- MG(ctx) = ctx;
- MG(state) = MLFI_CLOSE;
-
- call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);
-
- MG(state) = MLFI_NONE;
-
- if (Z_TYPE(retval) == IS_LONG) {
- ret = Z_LVAL(retval);
- }
-
- php_request_shutdown((void *) 0);
-
- return ret;
-}
-/* }}} */
-/* }}} */
-
-/* {{{ Milter entry struct
- */
-struct smfiDesc smfilter = {
- "php-milter", /* filter name */
- SMFI_VERSION, /* version code -- leave untouched */
- 0, /* flags */
- mlfi_connect, /* info filter callback */
- mlfi_helo, /* HELO filter callback */
- mlfi_envfrom, /* envelope filter callback */
- mlfi_envrcpt, /* envelope recipient filter callback */
- mlfi_header, /* header filter callback */
- mlfi_eoh, /* end of header callback */
- mlfi_body, /* body filter callback */
- mlfi_eom, /* end of message callback */
- mlfi_abort, /* message aborted callback */
- mlfi_close, /* connection cleanup callback */
-};
-/* }}} */
-
-/* {{{ PHP Milter API
- */
-
-/* {{{ proto string smfi_setflags(long flags)
- Sets the flags describing the actions the filter may take. */
-PHP_FUNCTION(smfi_setflags)
-{
- long flags;
-
- /* valid only in the init callback */
- if (MG(state) != MLFI_INIT) {
- php_error(E_WARNING, NOT_INIT, get_active_function_name(TSRMLS_C));
- } else if (zend_parse_parameters(1 TSRMLS_CC, "l", &flags) == SUCCESS) {
- flags = flags & SMFIF_ADDHDRS|SMFIF_CHGHDRS|SMFIF_CHGBODY|SMFIF_ADDRCPT|SMFIF_DELRCPT;
- smfilter.xxfi_flags = flags;
- }
-}
-/* }}} */
-
-/* {{{ proto string smfi_settimeout(long timeout)
- Sets the number of seconds libmilter will wait for an MTA connection before timing out a socket. */
-PHP_FUNCTION(smfi_settimeout)
-{
- long timeout;
-
- /* valid only in the init callback */
- if (MG(state) != MLFI_INIT) {
- php_error(E_WARNING, NOT_INIT, get_active_function_name(TSRMLS_C));
- } else if (zend_parse_parameters(1 TSRMLS_CC, "l", &timeout) == SUCCESS) {
- smfi_settimeout(timeout);
- }
-}
-/* }}} */
-
-/* {{{ proto string smfi_getsymval(string macro)
- Returns the value of the given macro or NULL if the macro is not defined. */
-PHP_FUNCTION(smfi_getsymval)
-{
- char *symname, *ret;
- int len;
-
- /* valid in any callback */
- if (MG(state) == MLFI_NONE) {
- php_error(E_WARNING, IS_NONE, get_active_function_name(TSRMLS_C));
- } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &symname, &len) == SUCCESS) {
- if ((ret = smfi_getsymval(MG(ctx), symname)) != NULL) {
- RETVAL_STRING(ret, 1);
- }
- }
-
- RETVAL_NULL();
-}
-/* }}} */
-
-/* {{{ proto string smfi_setreply(string rcode, string xcode, string message)
- Directly set the SMTP error reply code for this connection.
- This code will be used on subsequent error replies resulting from actions taken by this filter. */
-PHP_FUNCTION(smfi_setreply)
-{
- char *rcode, *xcode, *message;
- int len;
-
- /* valid in any callback */
- if (MG(state) == MLFI_NONE) {
- php_error(E_WARNING, IS_NONE, get_active_function_name(TSRMLS_C));
- } else if (zend_parse_parameters(3 TSRMLS_CC, "sss", &rcode, &len, &xcode, &len, &message, &len) == SUCCESS) {
- if (smfi_setreply(MG(ctx), rcode, xcode, message) == MI_SUCCESS) {
- RETVAL_TRUE;
- }
- }
-
- RETVAL_FALSE;
-}
-/* }}} */
-
-/* {{{ proto string smfi_addheader(string headerf, string headerv)
- Adds a header to the current message. */
-PHP_FUNCTION(smfi_addheader)
-{
- char *f, *v;
- int len;
-
- /* valid only in milter_eom */
- if (MG(state) != MLFI_EOM) {
- php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C));
- } else if (zend_parse_parameters(2 TSRMLS_CC, "ss", &f, &len, &v, &len) == SUCCESS) {
- if (smfi_addheader(MG(ctx), f, v) == MI_SUCCESS) {
- RETVAL_TRUE;
- }
- }
-
- RETVAL_FALSE;
-}
-/* }}} */
-
-/* {{{ proto string smfi_chgheader(string headerf, string headerv)
- Changes a header's value for the current message. */
-PHP_FUNCTION(smfi_chgheader)
-{
- char *f, *v;
- long idx;
- int len;
-
- /* valid only in milter_eom */
- if (MG(state) != MLFI_EOM) {
- php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C));
- } else if (zend_parse_parameters(3 TSRMLS_CC, "sls", &f, &len, &idx, &v, &len) == SUCCESS) {
- if (smfi_chgheader(MG(ctx), f, idx, v) == MI_SUCCESS) {
- RETVAL_TRUE;
- }
- }
-
- RETVAL_FALSE;
-}
-/* }}} */
-
-/* {{{ proto string smfi_addrcpt(string rcpt)
- Add a recipient to the message envelope. */
-PHP_FUNCTION(smfi_addrcpt)
-{
- char *rcpt;
- int len;
-
- /* valid only in milter_eom */
- if (MG(state) != MLFI_EOM) {
- php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C));
- } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) {
- if (smfi_addrcpt(MG(ctx), rcpt) == MI_SUCCESS) {
- RETVAL_TRUE;
- }
- }
-
- RETVAL_FALSE;
-}
-/* }}} */
-
-/* {{{ proto string smfi_delrcpt(string rcpt)
- Removes the named recipient from the current message's envelope. */
-PHP_FUNCTION(smfi_delrcpt)
-{
- char *rcpt;
- int len;
-
- /* valid only in milter_eom */
- if (MG(state) != MLFI_EOM) {
- php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C));
- } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) {
- if (smfi_delrcpt(MG(ctx), rcpt) == MI_SUCCESS) {
- RETVAL_TRUE;
- }
- }
-
- RETVAL_FALSE;
-}
-/* }}} */
-
-/* {{{ proto string smfi_replacebody(string body)
- Replaces the body of the current message. If called more than once,
- subsequent calls result in data being appended to the new body. */
-PHP_FUNCTION(smfi_replacebody)
-{
- char *body;
- int len;
-
- /* valid only in milter_eom */
- if (MG(state) != MLFI_EOM) {
- php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C));
- } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &body, &len) == SUCCESS) {
- if (smfi_replacebody(MG(ctx), body, len) == MI_SUCCESS) {
- RETVAL_TRUE;
- }
- }
-
- RETVAL_FALSE;
-}
-/* }}} */
-
-/* {{{ PHP_MINIT_FUNCTION
- */
-PHP_MINIT_FUNCTION(milter)
-{
- REGISTER_LONG_CONSTANT("SMFIS_CONTINUE", SMFIS_CONTINUE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SMFIS_REJECT", SMFIS_REJECT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SMFIS_DISCARD", SMFIS_DISCARD, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SMFIS_ACCEPT", SMFIS_ACCEPT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SMFIS_TEMPFAIL", SMFIS_TEMPFAIL, CONST_CS | CONST_PERSISTENT);
-
- REGISTER_LONG_CONSTANT("SMFIF_ADDHDRS", SMFIF_ADDHDRS, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SMFIF_CHGHDRS", SMFIF_CHGHDRS, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SMFIF_CHGBODY", SMFIF_CHGBODY, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SMFIF_ADDRCPT", SMFIF_ADDRCPT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SMFIF_DELRCPT", SMFIF_DELRCPT, CONST_CS | CONST_PERSISTENT);
-
- ZEND_INIT_MODULE_GLOBALS(milter, NULL, NULL);
-
- MG(state) = MLFI_NONE;
- MG(initialized) = 0;
-}
-/* }}} */
-
-/* {{{ PHP_MINFO_FUNCTION
- */
-PHP_MINFO_FUNCTION(milter)
-{
- php_info_print_table_start();
- php_info_print_table_header(2, "Milter support", "enabled");
- php_info_print_table_end();
-}
-/* }}} */
-/* }}} */
-
-/* {{{ milter_functions[]
-*/
-static function_entry milter_functions[] = {
- PHP_FE(smfi_setflags, NULL)
- PHP_FE(smfi_settimeout, NULL)
- PHP_FE(smfi_getsymval, NULL)
- PHP_FE(smfi_setreply, NULL)
- PHP_FE(smfi_addheader, NULL)
- PHP_FE(smfi_chgheader, NULL)
- PHP_FE(smfi_addrcpt, NULL)
- PHP_FE(smfi_delrcpt, NULL)
- PHP_FE(smfi_replacebody, NULL)
- { NULL, NULL, NULL }
-};
-/* }}} */
-
-/* {{{ Zend module entry
-*/
-static zend_module_entry php_milter_module = {
- STANDARD_MODULE_HEADER,
- "Milter",
- milter_functions,
- PHP_MINIT(milter),
- NULL,
- NULL,
- NULL,
- PHP_MINFO(milter),
- "0.1.0",
- STANDARD_MODULE_PROPERTIES
-};
-/* }}} */
-
-/* {{{ Milter SAPI
-*/
-static int sapi_milter_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- return str_length;
-}
-
-static void sapi_milter_flush(void *server_context)
-{
-}
-
-static void sapi_milter_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- php_register_variable ("SERVER_SOFTWARE", "Sendmail Milter", track_vars_array TSRMLS_CC);
-}
-
-static int sapi_milter_post_read(char *buf, uint count_bytes TSRMLS_DC)
-{
- return 0;
-}
-
-static char* sapi_milter_read_cookies(TSRMLS_D)
-{
- return NULL;
-}
-
-static int sapi_milter_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-static int php_milter_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, &php_milter_module, 1) == FAILURE) {
- return FAILURE;
- }
- return SUCCESS;
-}
-/* }}} */
-
-/* {{{ sapi_module_struct milter_sapi_module
-*/
-static sapi_module_struct milter_sapi_module = {
- "milter", /* name */
- "Sendmail Milter SAPI", /* pretty name */
-
- php_milter_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- sapi_milter_ub_write, /* unbuffered write */
- sapi_milter_flush, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error, /* error handler */
-
- NULL, /* header handler */
- sapi_milter_send_headers, /* send headers handler */
- NULL, /* send header handler */
-
- sapi_milter_post_read, /* read POST data */
- sapi_milter_read_cookies, /* read Cookies */
-
- sapi_milter_register_variables, /* register server variables */
- NULL, /* Log message */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-/* }}} */
-
-/****
-* ripped from cli, has to be cleaned up !
-*/
-
-/* {{{ php_milter_usage
-*/
-static void php_milter_usage(char *argv0)
-{
- char *prog;
-
- prog = strrchr(argv0, '/');
- if (prog) {
- prog++;
- } else {
- prog = "php-milter";
- }
-
- printf( "Usage: %s [options] [-f] <file> [args...]\n"
- " %s [options] -r <code> [args...]\n"
- " %s [options] [-- args...]\n"
- " -a Run interactively\n"
- " -c <path>|<file> Look for php.ini file in this directory\n"
- " -n No php.ini file will be used\n"
- " -d foo[=bar] Define INI entry foo with value 'bar'\n"
- " -D run as daemon\n"
- " -e Generate extended information for debugger/profiler\n"
- " -f <file> Parse <file>.\n"
- " -h This help\n"
- " -p <socket> path to create socket\n"
- " -v Version number\n"
- " -V <n> set debug level to n (1 or 2).\n"
- " -z <file> Load Zend extension <file>.\n"
- " args... Arguments passed to script. Use -- args when first argument \n"
- " starts with - or script is read from stdin\n"
- , prog, prog, prog);
-}
-/* }}} */
-
-static void define_command_line_ini_entry(char *arg)
-{
- char *name, *value;
-
- name = arg;
- value = strchr(arg, '=');
- if (value) {
- *value = 0;
- value++;
- } else {
- value = "1";
- }
- zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
-}
-
-/* {{{ main
-*/
-int main(int argc, char *argv[])
-{
- char *sock = NULL;
- int dofork = 0;
-
- int exit_status = SUCCESS;
- int c;
-/* temporary locals */
- int orig_optind=ap_php_optind;
- char *orig_optarg=ap_php_optarg;
- char *arg_free=NULL, **arg_excp=&arg_free;
- int interactive=0;
- char *exec_direct=NULL;
- char *param_error=NULL;
-/* end of temporary locals */
-
- void ***tsrm_ls;
-
-#ifdef HAVE_SIGNAL_H
-#if defined(SIGPIPE) && defined(SIG_IGN)
- signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
- that sockets created via fsockopen()
- don't kill PHP if the remote site
- closes it. in apache|apxs mode apache
- does that for us! thies@thieso.net
- 20000419 */
-#endif
-#endif
-
-
- tsrm_startup(1, 1, 0, NULL);
- sapi_startup(&milter_sapi_module);
-
- while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
- switch (c) {
- case 'c':
- milter_sapi_module.php_ini_path_override = strdup(ap_php_optarg);
- break;
- case 'n':
- milter_sapi_module.php_ini_ignore = 1;
- break;
- }
- }
- ap_php_optind = orig_optind;
- ap_php_optarg = orig_optarg;
-
- milter_sapi_module.executable_location = argv[0];
-
- tsrm_ls = ts_resource(0);
-
- sapi_module.startup(&milter_sapi_module);
-
- zend_first_try {
- while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
- switch (c) {
- case '?':
- php_output_startup();
- php_output_activate(TSRMLS_C);
- SG(headers_sent) = 1;
- php_milter_usage(argv[0]);
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
- }
- }
- ap_php_optind = orig_optind;
- ap_php_optarg = orig_optarg;
-
- /* Set some CLI defaults */
- SG(options) |= SAPI_OPTION_NO_CHDIR;
- zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
-
- zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */
-
- if (milter_sapi_module.php_ini_path_override && milter_sapi_module.php_ini_ignore) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- PUTS("You cannot use both -n and -c switch. Use -h for help.\n");
- exit(1);
- }
-
- while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) {
- switch (c) {
-
- case 'a': /* interactive mode */
- printf("Interactive mode enabled\n\n");
- interactive=1;
- break;
-
- case 'C': /* don't chdir to the script directory */
- /* This is default so NOP */
- break;
- case 'd': /* define ini entries on command line */
- define_command_line_ini_entry(ap_php_optarg);
- break;
-
- case 'D': /* daemon */
- dofork = 1;
- break;
-
- case 'e': /* enable extended info output */
- CG(extended_info) = 1;
- break;
-
- case 'f': /* parse file */
- filename = ap_php_optarg;
- break;
-
- case 'h': /* help & quit */
- case '?':
- php_output_startup();
- php_output_activate(TSRMLS_C);
- SG(headers_sent) = 1;
- php_milter_usage(argv[0]);
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
- case 'p': /* socket */
- sock = strdup(ap_php_optarg);
- break;
-
- case 'v': /* show php version & quit */
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- zend_ini_deactivate(TSRMLS_C);
- php_module_shutdown(TSRMLS_C);
- sapi_shutdown();
- tsrm_shutdown();
-
- exit(1);
- }
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2003 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
- case 'V': /* verbose */
- flag_debug = atoi(ap_php_optarg);
- break;
-
- case 'z': /* load extension file */
- zend_load_extension(ap_php_optarg);
- break;
-
- default:
- break;
- }
- }
-
- if (param_error) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- PUTS(param_error);
- exit(1);
- }
-
- CG(interactive) = interactive;
-
- /* only set script_file if not set already and not in direct mode and not at end of parameter list */
- if (argc > ap_php_optind && !filename) {
- filename=argv[ap_php_optind];
- ap_php_optind++;
- }
-
- // check if file exists, exit else
-
- if (dofork) {
- switch(fork()) {
- case -1: /* Uh-oh, we have a problem forking. */
- fprintf(stderr, "Uh-oh, couldn't fork!\n");
- exit(errno);
- break;
- case 0: /* Child */
- break;
- default: /* Parent */
- exit(0);
- }
- }
-
- {
- struct stat junk;
- if (stat(sock,&junk) == 0) unlink(sock);
- }
-
- openlog("php-milter", LOG_PID, LOG_MAIL);
-
- if (exit_status = mlfi_init()) {
- syslog(1, "mlfi_init failed.");
- exit(exit_status);
- }
-
- smfi_setconn(sock);
- if (smfi_register(smfilter) == MI_FAILURE) {
- syslog(1, "smfi_register failed.");
- fprintf(stderr, "smfi_register failed\n");
- } else {
- exit_status = smfi_main();
- }
-
- closelog();
-
- if (milter_sapi_module.php_ini_path_override) {
- free(milter_sapi_module.php_ini_path_override);
- }
-
- } zend_catch {
- exit_status = EG(exit_status);
- } zend_end_try();
-
- php_module_shutdown(TSRMLS_C);
- sapi_shutdown();
- tsrm_shutdown();
-
- exit(exit_status);
-}
-/* }}} */
-
-/*
- * 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/milter/php_milter.h b/sapi/milter/php_milter.h
deleted file mode 100644
index 72d7ac51ee..0000000000
--- a/sapi/milter/php_milter.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef PHP_MILTER_H
-#define PHP_MILTER_H
-
-#include "libmilter/mfapi.h"
-
-#define MLFI_NONE 0
-#define MLFI_CONNECT 1
-#define MLFI_HELO 2
-#define MLFI_ENVFROM 3
-#define MLFI_ENVRCPT 4
-#define MLFI_HEADER 5
-#define MLFI_EOH 6
-#define MLFI_BODY 7
-#define MLFI_EOM 8
-#define MLFI_ABORT 9
-#define MLFI_CLOSE 10
-#define MLFI_INIT 11
-
-#define MG(v) TSRMG(milter_globals_id, zend_milter_globals *, v)
-
-typedef struct {
- pthread_t thread;
- MUTEX_T receiver;
- MUTEX_T sender;
- SMFICTX *ctx;
- sfsistat retval;
- int message;
- void **args;
-} worker_thread;
-
-#endif
diff --git a/sapi/nsapi/CREDITS b/sapi/nsapi/CREDITS
deleted file mode 100644
index c41a7bf583..0000000000
--- a/sapi/nsapi/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-NSAPI
-Jayakumar Muthukumarasamy
diff --git a/sapi/nsapi/config.m4 b/sapi/nsapi/config.m4
deleted file mode 100644
index 6a556dbe6f..0000000000
--- a/sapi/nsapi/config.m4
+++ /dev/null
@@ -1,45 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for NSAPI support)
-AC_ARG_WITH(nsapi,
-[ --with-nsapi=DIR Build PHP as NSAPI module for use with iPlanet.],[
- PHP_NSAPI=$withval
-],[
- PHP_NSAPI=no
-])
-AC_MSG_RESULT($PHP_NSAPI)
-
-if test "$PHP_NSAPI" != "no"; then
- if test ! -d $PHP_NSAPI/bin ; then
- AC_MSG_ERROR(Please specify the path to the root of your Netscape server using --with-nsapi=DIR)
- fi
- AC_MSG_CHECKING(for NSAPI include files)
- if test -d $PHP_NSAPI/include ; then
- NSAPI_INCLUDE=$PHP_NSAPI/include
- AC_MSG_RESULT(Netscape-Enterprise/3.x style)
- AC_CHECK_HEADERS([$NSAPI_INCLUDE/nsapi.h])
- fi
- if test -d $PHP_NSAPI/plugins/include ; then
- test -n "$NSAPI_INCLUDE" && NSAPI_INC_DIR="-I$NSAPI_INCLUDE"
- NSAPI_INCLUDE="$PHP_NSAPI/plugins/include"
- AC_MSG_RESULT(iPlanet/4.x style)
- AC_CHECK_HEADERS([$NSAPI_INCLUDE/nsapi.h])
- NSAPI_INCLUDE="$NSAPI_INC_DIR -I$NSAPI_INCLUDE"
- fi
- if test "$NSAPI_INCLUDE" = ""; then
- AC_MSG_ERROR(Please check you have nsapi.h in either $PHP_NSAPI/include or $PHP_NSAPI/plugins/include)
- fi
-
- PHP_EVAL_INCLINE($NSAPI_INCLUDE)
- PHP_BUILD_THREAD_SAFE
- AC_DEFINE(HAVE_NSAPI,1,[Whether you have a Netscape Server])
- PHP_SELECT_SAPI(nsapi, shared, nsapi.c)
- INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PHP_NSAPI/bin/"
-fi
-
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
diff --git a/sapi/nsapi/nsapi-readme.txt b/sapi/nsapi/nsapi-readme.txt
deleted file mode 100644
index 61e7dc8254..0000000000
--- a/sapi/nsapi/nsapi-readme.txt
+++ /dev/null
@@ -1,76 +0,0 @@
-Configuration of your Netscape or iPlanet Web Server for PHP4
--------------------------------------------------------------
-
-These instructions are targetted at Netscape Enterprise Web Server and
-SUN/Netscape Alliance iPlanet Web Server. On other web servers your
-milage may vary.
-
-Firstly you may need to add some paths to the LD_LIBRARY_PATH
-environment for Netscape to find all the shared libs. This is best done
-in the start script for your Netscape server. Windows users can
-probably skip this step. The start script is located in:
-
- <path-to-netscape-server>/https-servername/start
-
-
-Netscape config files are located in:
-
- <path-to-netscape-server>/https-servername/config
-
-
-Add the following line to mime.types:
-
- type=magnus-internal/x-httpd-php exts=php
-
-
-Add the following to obj.conf, shlib will vary depending on your OS, for
-Unix it will be something like:
-
- "<path-to-netscape-server>/bin/libphp4.so".
-
-
-Note! Place following two lines after mime.types init:
-
- Init fn="load-modules" funcs="php4_init,php4_close,php4_execute,php4_auth_trans" shlib="/php4/nsapiPHP4.dll"
- Init fn=php4_init errorString="Failed to initialize PHP!"
-
- <Object name="default">
- .
- .
- .
- # NOTE this next line should happen after all 'ObjectType' and before
- # all 'AddLog' lines
-
- Service fn="php4_execute" type="magnus-internal/x-httpd-php"
- .
- .
- </Object>
-
- <Object name="x-httpd-php">
- ObjectType fn="force-type" type="magnus-internal/x-httpd-php"
- Service fn=php4_execute
- </Object>
-
-
-Authentication configuration
-----------------------------
-
-PHP authentication cannot be used with any other authentication. ALL
-AUTHENTICATION IS PASSED TO YOUR PHP SCRIPT. To configure PHP
-Authentication for the entire server, add the following line:
-
- <Object name="default">
- AuthTrans fn=php4_auth_trans
- .
- .
- .
- .
- </Object>
-
-
-To use PHP Authentication on a single directory, add the following:
-
- <Object ppath="d:\path\to\authenticated\dir\*">
- AuthTrans fn=php4_auth_trans
- </Object>
-
diff --git a/sapi/nsapi/nsapi.c b/sapi/nsapi/nsapi.c
deleted file mode 100644
index 155d812aec..0000000000
--- a/sapi/nsapi/nsapi.c
+++ /dev/null
@@ -1,599 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Jayakumar Muthukumarasamy <jk@kasenna.com> |
- | Uwe Schindler <uwe@thetaphi.de> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-/*
- * PHP includes
- */
-#define NSAPI 1
-
-#include "php.h"
-#include "php_variables.h"
-#include "ext/standard/info.h"
-#include "php_ini.h"
-#include "php_globals.h"
-#include "SAPI.h"
-#include "php_main.h"
-#include "php_version.h"
-#include "TSRM.h"
-#include "ext/standard/php_standard.h"
-
-/*
- * If neither XP_UNIX not XP_WIN32 is defined, try to guess which one.
- * Ideally, this should be done by the configure script.
- */
-#if !defined(XP_UNIX) && !defined(XP_WIN32)
-#if defined(WIN32)
-#define XP_WIN32
-#else
-#define XP_UNIX
-#endif
-#endif
-
-/*
- * NSAPI includes
- */
-#include "nsapi.h"
-#include "base/pblock.h"
-#include "base/session.h"
-#include "frame/req.h"
-#include "frame/protocol.h" /* protocol_start_response */
-#include "base/util.h" /* is_mozilla, getline */
-#include "frame/log.h" /* log_error */
-
-/*
- * Timeout for net_read(). This should probably go into php.ini
- */
-#define NSAPI_READ_TIMEOUT 60 /* 60 seconds */
-
-#define NSLS_D struct nsapi_request_context *request_context
-#define NSLS_DC , NSLS_D
-#define NSLS_C request_context
-#define NSLS_CC , NSLS_C
-#define NSG(v) (request_context->v)
-
-#define NS_BUF_SIZE 2048
-
-/*
- * ZTS needs to be defined for NSAPI to work
- */
-#if !defined(ZTS)
-#error "NSAPI module needs ZTS to be defined"
-#endif
-
-/*
- * Structure to encapsulate the NSAPI request in SAPI
- */
-typedef struct nsapi_request_context {
- pblock *pb;
- Session *sn;
- Request *rq;
- int read_post_bytes;
-} nsapi_request_context;
-
-/*
- * Mappings between NSAPI names and environment variables. This
- * mapping was obtained from the sample programs at the iplanet
- * website.
- */
-typedef struct nsapi_equiv {
- const char *env_var;
- const char *nsapi_eq;
-} nsapi_equiv;
-
-static nsapi_equiv nsapi_headers[] = {
- { "CONTENT_LENGTH", "content-length" },
- { "CONTENT_TYPE", "content-type" }
-};
-static size_t nsapi_headers_size = sizeof(nsapi_headers)/sizeof(nsapi_headers[0]);
-
-static nsapi_equiv nsapi_reqpb[] = {
- { "QUERY_STRING", "query" },
- { "REQUEST_LINE", "clf-request" },
- { "REQUEST_METHOD", "method" },
- { "PHP_SELF", "uri" },
- { "SERVER_PROTOCOL", "protocol" }
-};
-static size_t nsapi_reqpb_size = sizeof(nsapi_reqpb)/sizeof(nsapi_reqpb[0]);
-
-static nsapi_equiv nsapi_vars[] = {
- { "PATH_INFO", "path-info" },
- { "SCRIPT_FILENAME", "path" },
- { "AUTH_TYPE", "auth-type" },
- { "CLIENT_CERT", "auth-cert" },
- { "REMOTE_USER", "auth-user" }
-};
-static size_t nsapi_vars_size = sizeof(nsapi_vars)/sizeof(nsapi_vars[0]);
-
-static nsapi_equiv nsapi_client[] = {
- { "HTTPS_KEYSIZE", "keysize" },
- { "HTTPS_SECRETSIZE", "secret-keysize" },
- { "REMOTE_ADDR", "ip" },
- { "REMOTE_HOST", "ip" }
-};
-static size_t nsapi_client_size = sizeof(nsapi_client)/sizeof(nsapi_client[0]);
-
-static char *nsapi_strdup(char *str)
-{
- if (str != NULL) {
- return STRDUP(str);
- }
- return NULL;
-}
-
-static void nsapi_free(void *addr)
-{
- if (addr != NULL) {
- FREE(addr);
- }
-}
-
-static int sapi_nsapi_ub_write(const char *str, unsigned int str_length TSRMLS_DC)
-{
- int retval;
- nsapi_request_context *rc;
-
- rc = (nsapi_request_context *)SG(server_context);
- retval = net_write(rc->sn->csd, (char *)str, str_length);
- if (retval == IO_ERROR /* -1 */ || retval == IO_EOF /* 0 */) {
- php_handle_aborted_connection();
- }
- return retval;
-}
-
-static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- char *header_name, *header_content, *p;
- nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
-
- header_name = sapi_header->header;
- header_content = p = strchr(header_name, ':');
- if (p == NULL) {
- efree(sapi_header->header);
- return 0;
- }
-
- *p = 0;
- do {
- header_content++;
- } while (*header_content == ' ');
-
- if (!strcasecmp(header_name, "Content-Type")) {
- param_free(pblock_remove("content-type", rc->rq->srvhdrs));
- pblock_nvinsert("content-type", header_content, rc->rq->srvhdrs);
- } else if (!strcasecmp(header_name, "Set-Cookie")) {
- pblock_nvinsert("set-cookie", header_content, rc->rq->srvhdrs);
- } else {
- pblock_nvinsert(header_name, header_content, rc->rq->srvhdrs);
- }
-
- *p = ':'; /* restore '*p' */
-
- efree(sapi_header->header);
-
- return 0; /* don't use the default SAPI mechanism, NSAPI duplicates this functionality */
-}
-
-static int sapi_nsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- int retval;
- nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
-
- /*
- * We could probably just do this in the header_handler. But, I
- * don't know what the implication of doing it there is.
- */
- if (SG(sapi_headers).send_default_content_type) {
- param_free(pblock_remove("content-type", rc->rq->srvhdrs));
- pblock_nvinsert("content-type", "text/html", rc->rq->srvhdrs);
- }
-
- protocol_status(rc->sn, rc->rq, SG(sapi_headers).http_response_code, NULL);
- retval = protocol_start_response(rc->sn, rc->rq);
-
- if (retval == REQ_PROCEED || retval == REQ_NOACTION) {
- return SAPI_HEADER_SENT_SUCCESSFULLY;
- } else {
- return SAPI_HEADER_SEND_FAILED;
- }
-}
-
-static int sapi_nsapi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
- nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
- char *read_ptr = buffer, *content_length_str = NULL;
- uint bytes_read = 0;
- int length, content_length = 0;
- netbuf *nbuf = rc->sn->inbuf;
-
- /*
- * Yesss!
- */
- count_bytes = MIN(count_bytes, SG(request_info).content_length-rc->read_post_bytes);
- content_length = SG(request_info).content_length;
-
-#if 0
- /*
- * Determine the content-length. This will tell us the limit we can read.
- */
- content_length_str = pblock_findval("content-length", rc->rq->headers);
- if (content_length_str != NULL) {
- content_length = strtol(content_length_str, 0, 0);
- }
-#endif
-
- if (content_length <= 0) {
- return 0;
- }
-
- /*
- * Gobble any pending data in the netbuf.
- */
- length = nbuf->cursize - nbuf->pos;
- length = MIN(count_bytes, length);
- if (length > 0) {
- memcpy(read_ptr, nbuf->inbuf + nbuf->pos, length);
- bytes_read += length;
- read_ptr += length;
- content_length -= length;
- nbuf->pos += length;
- }
-
- /*
- * Read the remaining from the socket.
- */
- while (content_length > 0 && bytes_read < count_bytes) {
- int bytes_to_read = count_bytes - bytes_read;
-
- if (content_length < bytes_to_read) {
- bytes_to_read = content_length;
- }
-
- length = net_read(rc->sn->csd, read_ptr, bytes_to_read, NSAPI_READ_TIMEOUT);
-
- if (length == IO_ERROR || length == IO_EOF) {
- break;
- }
-
- bytes_read += length;
- read_ptr += length;
- content_length -= length;
- }
-
- if ( bytes_read > 0 ) {
- rc->read_post_bytes += bytes_read;
- }
- return bytes_read;
-}
-
-static char *sapi_nsapi_read_cookies(TSRMLS_D)
-{
- char *cookie_string;
- nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
-
- cookie_string = pblock_findval("cookie", rc->rq->headers);
- return cookie_string;
-}
-
-static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_DC)
-{
- nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
- register size_t i;
- char *value,*p;
- char buf[NS_BUF_SIZE + 1];
- struct pb_entry *entry;
-
- for (i = 0; i < nsapi_reqpb_size; i++) {
- value = pblock_findval(nsapi_reqpb[i].nsapi_eq, rc->rq->reqpb);
- if (value) {
- php_register_variable((char *)nsapi_reqpb[i].env_var, value, track_vars_array TSRMLS_CC);
- }
- }
-
- for (i = 0; i < nsapi_headers_size; i++) {
- value = pblock_findval(nsapi_headers[i].nsapi_eq, rc->rq->headers);
- if (value) {
- php_register_variable((char *)nsapi_headers[i].env_var, value, track_vars_array TSRMLS_CC);
- }
- }
-
- for (i=0; i < rc->rq->headers->hsize; i++) {
- entry=rc->rq->headers->ht[i];
- while (entry) {
- snprintf(buf, NS_BUF_SIZE, "HTTP_%s", entry->param->name);
- for(p = buf + 5; *p; p++) {
- *p = toupper(*p);
- if (*p < 'A' || *p > 'Z') {
- *p = '_';
- }
- }
- php_register_variable(buf, entry->param->value, track_vars_array TSRMLS_CC);
- entry=entry->next;
- }
- }
-
- for (i = 0; i < nsapi_vars_size; i++) {
- value = pblock_findval(nsapi_vars[i].nsapi_eq, rc->rq->vars);
- if (value) {
- php_register_variable((char *)nsapi_vars[i].env_var, value, track_vars_array TSRMLS_CC);
- }
- }
-
- for (i = 0; i < nsapi_client_size; i++) {
- value = pblock_findval(nsapi_client[i].nsapi_eq, rc->sn->client);
- if (value) {
- php_register_variable((char *)nsapi_client[i].env_var, value, track_vars_array TSRMLS_CC);
- }
- }
-
- if (value = session_dns(rc->sn)) {
- php_register_variable("REMOTE_HOST", value, track_vars_array TSRMLS_CC);
- nsapi_free(value);
- }
-
- sprintf(buf, "%d", conf_getglobals()->Vport);
- php_register_variable("SERVER_PORT", buf, track_vars_array TSRMLS_CC);
- php_register_variable("SERVER_NAME", conf_getglobals()->Vserver_hostname, track_vars_array TSRMLS_CC);
-
- value = http_uri2url_dynamic("", "", rc->sn, rc->rq);
- php_register_variable("SERVER_URL", value, track_vars_array TSRMLS_CC);
- nsapi_free(value);
-
- php_register_variable("SERVER_SOFTWARE", system_version(), track_vars_array TSRMLS_CC);
- php_register_variable("HTTPS", (security_active ? "ON" : "OFF"), track_vars_array TSRMLS_CC);
- php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array TSRMLS_CC);
-
- /* DOCUMENT_ROOT */
- if (value = request_translate_uri("/", rc->sn)) {
- value[strlen(value) - 1] = 0;
- php_register_variable("DOCUMENT_ROOT", value, track_vars_array TSRMLS_CC);
- nsapi_free(value);
- }
-
- /* PATH_TRANSLATED */
- if (value = pblock_findval("path-info", rc->rq->vars)) {
- if (value = request_translate_uri(value, rc->sn)) {
- php_register_variable("PATH_TRANSLATED", value, track_vars_array TSRMLS_CC);
- nsapi_free(value);
- }
- }
-
- /* Create full Request-URI */
- if (value = pblock_findval("uri", rc->rq->reqpb)) {
- snprintf(buf,NS_BUF_SIZE, "%s", value);
- if (value = pblock_findval("query", rc->rq->reqpb)) {
- p = strchr(buf, 0);
- snprintf(p, NS_BUF_SIZE-(p-buf), "?%s", value);
- }
- php_register_variable("REQUEST_URI", buf, track_vars_array TSRMLS_CC);
- }
-
- /* Create Script-Name */
- if (value = pblock_findval("uri", rc->rq->reqpb)) {
- snprintf(buf,NS_BUF_SIZE, "%s", value);
- if (value = pblock_findval("path-info", rc->rq->vars)) {
- buf[strlen(buf) - strlen(value)] = 0;
- }
- php_register_variable("SCRIPT_NAME", buf, track_vars_array TSRMLS_CC);
- }
-}
-
-static void nsapi_log_message(char *message)
-{
- TSRMLS_FETCH();
- nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
-
- log_error(LOG_INFORM, "PHP module", rc->sn, rc->rq, "%s", message);
-}
-
-static int php_nsapi_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
- return FAILURE;
- }
- return SUCCESS;
-}
-
-
-static sapi_module_struct nsapi_sapi_module = {
- "nsapi", /* name */
- "NSAPI", /* pretty name */
-
- php_nsapi_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- sapi_nsapi_ub_write, /* unbuffered write */
- NULL, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error, /* error handler */
-
- sapi_nsapi_header_handler, /* header handler */
- sapi_nsapi_send_headers, /* send headers handler */
- NULL, /* send header handler */
-
- sapi_nsapi_read_post, /* read POST data */
- sapi_nsapi_read_cookies, /* read Cookies */
-
- sapi_nsapi_register_server_variables, /* register server variables */
- nsapi_log_message, /* Log message */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-
-static void nsapi_request_ctor(NSLS_D TSRMLS_DC)
-{
- char *query_string = pblock_findval("query", NSG(rq)->reqpb);
- char *uri = pblock_findval("uri", NSG(rq)->reqpb);
- char *path_info = pblock_findval("path-info", NSG(rq)->vars);
- char *request_method = pblock_findval("method", NSG(rq)->reqpb);
- char *content_type = pblock_findval("content-type", NSG(rq)->headers);
- char *content_length = pblock_findval("content-length", NSG(rq)->headers);
- char *path_translated = pblock_findval("path", NSG(rq)->vars);;
-
-#if defined(NSAPI_DEBUG)
- log_error(LOG_INFORM, "nsapi_request_ctor", NSG(sn), NSG(rq),
- "query_string = %s, "
- "uri = %s, "
- "path_info = %s, "
- "path_translated = %s, "
- "request_method = %s, "
- "content_type = %s, "
- "content_length = %s",
- query_string,
- uri,
- path_info,
- path_translated,
- request_method,
- content_type,
- content_length);
-#endif
-
- SG(request_info).query_string = nsapi_strdup(query_string);
- SG(request_info).request_uri = nsapi_strdup(uri);
- SG(request_info).request_method = nsapi_strdup(request_method);
- SG(request_info).path_translated = nsapi_strdup(path_translated);
- SG(request_info).content_type = nsapi_strdup(content_type);
- SG(request_info).content_length = (content_length == NULL) ? 0 : strtoul(content_length, 0, 0);
- SG(sapi_headers).http_response_code = 200;
-}
-
-static void nsapi_request_dtor(NSLS_D TSRMLS_DC)
-{
- nsapi_free(SG(request_info).query_string);
- nsapi_free(SG(request_info).request_uri);
- nsapi_free(SG(request_info).request_method);
- nsapi_free(SG(request_info).path_translated);
- nsapi_free(SG(request_info).content_type);
-}
-
-int nsapi_module_main(NSLS_D TSRMLS_DC)
-{
- zend_file_handle file_handle;
-
- if (php_request_startup(TSRMLS_C) == FAILURE) {
- return FAILURE;
- }
-
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = SG(request_info).path_translated;
- file_handle.free_filename = 0;
- file_handle.opened_path = NULL;
-
-#if defined(NSAPI_DEBUG)
- log_error(LOG_INFORM, "nsapi_module_main", NSG(sn), NSG(rq), "Parsing [%s]", SG(request_info).path_translated);
-#endif
-
- php_execute_script(&file_handle TSRMLS_CC);
- php_request_shutdown(NULL);
-
-#if defined(NSAPI_DEBUG)
- log_error(LOG_INFORM, "nsapi_module_main", NSG(sn), NSG(rq), "PHP request finished Ok");
-#endif
-
- return SUCCESS;
-}
-
-void NSAPI_PUBLIC php4_close(void *vparam)
-{
- if (nsapi_sapi_module.shutdown) {
- nsapi_sapi_module.shutdown(&nsapi_sapi_module);
- }
- tsrm_shutdown();
-}
-
-int NSAPI_PUBLIC php4_init(pblock *pb, Session *sn, Request *rq)
-{
- php_core_globals *core_globals;
-
- tsrm_startup(1, 1, 0, NULL);
- core_globals = ts_resource(core_globals_id);
-
- sapi_startup(&nsapi_sapi_module);
- nsapi_sapi_module.startup(&nsapi_sapi_module);
-
- log_error(LOG_INFORM, "php4_init", sn, rq, "Initialized PHP Module\n");
- return REQ_PROCEED;
-}
-
-int NSAPI_PUBLIC php4_execute(pblock *pb, Session *sn, Request *rq)
-{
- int retval;
- nsapi_request_context *request_context;
- TSRMLS_FETCH();
-
- request_context = (nsapi_request_context *)MALLOC(sizeof(nsapi_request_context));
- request_context->pb = pb;
- request_context->sn = sn;
- request_context->rq = rq;
- request_context->read_post_bytes = 0;
-
- SG(server_context) = request_context;
-
- nsapi_request_ctor(NSLS_C TSRMLS_CC);
- retval = nsapi_module_main(NSLS_C TSRMLS_CC);
- nsapi_request_dtor(NSLS_C TSRMLS_CC);
-
- FREE(request_context);
-
- return (retval == SUCCESS) ? REQ_PROCEED : REQ_EXIT;
-}
-
-/*********************************************************
-/ authentication
-/
-/ we have to make a 'fake' authenticator for netscape so it
-/ will pass authentication through to php, and allow us to
-/ check authentication with our scripts.
-/
-/ php4_auth_trans
-/ main function called from netscape server to authenticate
-/ a line in obj.conf:
-/ funcs=php4_auth_trans shlib="path/to/this/phpnsapi.dll"
-/ and:
-/ <Object ppath="path/to/be/authenticated/by/php/*">
-/ AuthTrans fn="php4_auth_trans"
-/*********************************************************/
-int NSAPI_PUBLIC php4_auth_trans(pblock * pb, Session * sn, Request * rq)
-{
- /* This is a DO NOTHING function that allows authentication
- * information
- * to be passed through to PHP scripts.
- */
- return REQ_PROCEED;
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
- \ No newline at end of file
diff --git a/sapi/nsapi/php4nsapi.dsp b/sapi/nsapi/php4nsapi.dsp
deleted file mode 100644
index 9b0b8c9a56..0000000000
--- a/sapi/nsapi/php4nsapi.dsp
+++ /dev/null
@@ -1,135 +0,0 @@
-# Microsoft Developer Studio Project File - Name="php4nsapi" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php4nsapi - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "php4nsapi.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 "php4nsapi.mak" CFG="php4nsapi - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php4nsapi - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4nsapi - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4nsapi - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "php4nsapi - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php4nsapi___Win32_Release_TS"
-# PROP BASE Intermediate_Dir "php4nsapi___Win32_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 "php4nsapi_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /I "..\..\..\php_build\nsapi30\include\\" /I "..\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\tsrm" /D ZEND_DEBUG=0 /D "NDEBUG" /D "XP_WIN32" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "php4nsapi_EXPORTS" /D "WIN32" /D "_MBCS" /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 ns-httpd30.lib php4ts.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:"0x62000000" /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\nsapi30\lib\\" /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS"
-
-!ELSEIF "$(CFG)" == "php4nsapi - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php4nsapi___Win32_Release_TS_inline"
-# PROP BASE Intermediate_Dir "php4nsapi___Win32_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 "php4nsapi_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /I "..\..\..\php_build\nsapi30\include\\" /I "..\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\tsrm" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "NDEBUG" /D "XP_WIN32" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "php4nsapi_EXPORTS" /D "WIN32" /D "_MBCS" /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 ns-httpd30.lib php4ts.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:"0x62000000" /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\nsapi30\lib\\" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"
-
-!ELSEIF "$(CFG)" == "php4nsapi - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "php4nsapi___Win32_Debug_TS"
-# PROP BASE Intermediate_Dir "php4nsapi___Win32_Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "php4nsapi_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /I "..\..\..\php_build\nsapi30\include\\" /I "..\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\tsrm" /D "_Debug_TS" /D ZEND_DEBUG=1 /D "_DEBUG" /D "XP_WIN32" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "php4nsapi_EXPORTS" /D "WIN32" /D "_MBCS" /FR /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 ns-httpd30.lib php4ts_debug.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:"0x62000000" /version:4.0 /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\php_build\nsapi30\lib\\" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php4nsapi - Win32 Release_TS"
-# Name "php4nsapi - Win32 Release_TS_inline"
-# Name "php4nsapi - Win32 Debug_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\nsapi.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# 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/phttpd/CREDITS b/sapi/phttpd/CREDITS
deleted file mode 100644
index 134cc54825..0000000000
--- a/sapi/phttpd/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-phttpd
-Thies C. Arntzen
diff --git a/sapi/phttpd/README b/sapi/phttpd/README
deleted file mode 100644
index cdb6f7c381..0000000000
--- a/sapi/phttpd/README
+++ /dev/null
@@ -1,5 +0,0 @@
-phttpd sapi module.
-
-THIS IS BY NO MEANS COMPLETE NOR USABLE RIGHT NOW!
-
-thies@thieso.net 03.01.2000
diff --git a/sapi/phttpd/config.m4 b/sapi/phttpd/config.m4
deleted file mode 100644
index 75c6d66891..0000000000
--- a/sapi/phttpd/config.m4
+++ /dev/null
@@ -1,25 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-RESULT=no
-AC_MSG_CHECKING(for PHTTPD support)
-AC_ARG_WITH(phttpd,
-[ --with-phttpd=DIR Build PHP as phttpd module],
-[
- if test ! -d $withval ; then
- AC_MSG_ERROR(You did not specify a directory)
- fi
- PHP_BUILD_THREAD_SAFE
- PHTTPD_DIR=$withval
- PHP_ADD_INCLUDE($PHTTPD_DIR/include)
- AC_DEFINE(HAVE_PHTTPD,1,[Whether you have phttpd])
- PHP_SELECT_SAPI(phttpd, shared, phttpd.c)
- INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PHTTPD_DIR/modules/"
- RESULT=yes
-])
-AC_MSG_RESULT($RESULT)
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
diff --git a/sapi/phttpd/php.sym b/sapi/phttpd/php.sym
deleted file mode 100644
index f10b883a99..0000000000
--- a/sapi/phttpd/php.sym
+++ /dev/null
@@ -1,4 +0,0 @@
-pm_init
-pm_exit
-pm_request
-
diff --git a/sapi/phttpd/php_phttpd.h b/sapi/phttpd/php_phttpd.h
deleted file mode 100644
index c82c852c54..0000000000
--- a/sapi/phttpd/php_phttpd.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Thies C. Arntzen <thies@thieso.net> |
- +----------------------------------------------------------------------+
-*/
-
-#ifndef PHP_PHTTPD_H
-#define PHP_PHTTPD_H
-
-#include <phttpd.h>
-
-#endif
diff --git a/sapi/phttpd/phttpd.c b/sapi/phttpd/phttpd.c
deleted file mode 100644
index 886fc09936..0000000000
--- a/sapi/phttpd/phttpd.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Thies C. Arntzen <thies@thieso.net> |
- | Based on aolserver SAPI by Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-#include "php.h"
-#include "SAPI.h"
-#include "php_main.h"
-
-#ifdef HAVE_PHTTPD
-
-#include "ext/standard/info.h"
-
-#ifndef ZTS
-#error PHTTPD module is only useable in thread-safe mode
-#endif
-
-#include "php_phttpd.h"
-
-typedef struct {
- struct connectioninfo *cip;
- struct stat sb;
-} phttpd_globals_struct;
-
-static int ph_globals_id;
-
-#define PHG(v) TSRMG(ph_globals_id, phttpd_globals_struct *, v)
-
-static int
-php_phttpd_startup(sapi_module_struct *sapi_module)
-{
- fprintf(stderr,"***php_phttpd_startup\n");
-
- if (php_module_startup(sapi_module, NULL, 0)) {
- return FAILURE;
- } else {
- return SUCCESS;
- }
-}
-
-static int
-php_phttpd_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- int sent_bytes;
-
- sent_bytes = fd_write(PHG(cip)->fd, str, str_length);
-
- if (sent_bytes == -1) {
- php_handle_aborted_connection();
- }
-
- return sent_bytes;
-}
-
-static int
-php_phttpd_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- char *header_name, *header_content;
- char *p;
- TSRMLS_FETCH();
-
- http_sendheaders(PHG(cip)->fd, PHG(cip), SG(sapi_headers).http_response_code, NULL);
-
- header_name = sapi_header->header;
- header_content = p = strchr(header_name, ':');
-
- if (p) {
- *p = '\0';
- do {
- header_content++;
- } while (*header_content == ' ');
-
- fd_printf(PHG(cip)->fd,"%s: %s\n", header_name, header_content);
-
- *p = ':';
- }
-
- sapi_free_header(sapi_header);
-
- return 0;
-}
-
-static int
-php_phttpd_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- TSRMLS_FETCH();
-
- if (SG(sapi_headers).send_default_content_type) {
- fd_printf(PHG(cip)->fd,"Content-Type: text/html\n");
- }
-
- fd_putc('\n', PHG(cip)->fd);
-
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-static char *
-php_phttpd_sapi_read_cookies(TSRMLS_D)
-{
-
-/*
- int i;
- char *http_cookie = NULL;
- NTSRMLS_FETCH();
-
- i = Ns_SetIFind(NSG(conn->headers), "cookie");
- if(i != -1) {
- http_cookie = Ns_SetValue(NSG(conn->headers), i);
- }
-
- return http_cookie;
-*/
- fprintf(stderr,"***php_phttpd_sapi_read_cookies\n");
-
- return 0;
-}
-
-static int
-php_phttpd_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC)
-{
-/*
- uint max_read;
- uint total_read = 0;
- NTSRMLS_FETCH();
-
- max_read = MIN(NSG(data_avail), count_bytes);
-
- total_read = Ns_ConnRead(NSG(conn), buf, max_read);
-
- if(total_read == NS_ERROR) {
- total_read = -1;
- } else {
- NSG(data_avail) -= total_read;
- }
-
- return total_read;
-*/
- fprintf(stderr,"***php_phttpd_sapi_read_post\n");
- return 0;
-}
-
-static sapi_module_struct phttpd_sapi_module = {
- "phttpd",
- "PHTTPD",
-
- php_phttpd_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- php_phttpd_sapi_ub_write, /* unbuffered write */
- NULL, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error, /* error handler */
-
- php_phttpd_sapi_header_handler, /* header handler */
- php_phttpd_sapi_send_headers, /* send headers handler */
- NULL, /* send header handler */
-
- php_phttpd_sapi_read_post, /* read POST data */
- php_phttpd_sapi_read_cookies, /* read Cookies */
-
- NULL, /* register server variables */
- NULL, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-static void
-php_phttpd_request_ctor(TSRMLS_D TSRMLS_DC)
-{
- memset(&SG(request_info), 0, sizeof(sapi_globals_struct)); /* pfusch! */
-
- SG(request_info).query_string = PHG(cip)->hip->request;
- SG(request_info).request_method = PHG(cip)->hip->method;
- SG(request_info).path_translated = malloc(MAXPATHLEN);
- SG(sapi_headers).http_response_code = 200;
- if (url_expand(PHG(cip)->hip->url, SG(request_info).path_translated, MAXPATHLEN, &PHG(sb), NULL, NULL) == NULL) {
- /* handle error */
- }
-
-#if 0
- char *server;
- Ns_DString ds;
- char *root;
- int index;
- char *tmp;
-
- server = Ns_ConnServer(NSG(conn));
-
- Ns_DStringInit(&ds);
- Ns_UrlToFile(&ds, server, NSG(conn->request->url));
-
- /* path_translated is the absolute path to the file */
- SG(request_info).path_translated = strdup(Ns_DStringValue(&ds));
- Ns_DStringFree(&ds);
- root = Ns_PageRoot(server);
- SG(request_info).request_uri = SG(request_info).path_translated + strlen(root);
- SG(request_info).content_length = Ns_ConnContentLength(NSG(conn));
- index = Ns_SetIFind(NSG(conn)->headers, "content-type");
- SG(request_info).content_type = index == -1 ? NULL :
- Ns_SetValue(NSG(conn)->headers, index);
-
- tmp = Ns_ConnAuthUser(NSG(conn));
- if(tmp) {
- tmp = estrdup(tmp);
- }
- SG(request_info).auth_user = tmp;
-
- tmp = Ns_ConnAuthPasswd(NSG(conn));
- if(tmp) {
- tmp = estrdup(tmp);
- }
- SG(request_info).auth_password = tmp;
-
- NSG(data_avail) = SG(request_info).content_length;
-#endif
-}
-
-static void
-php_phttpd_request_dtor(TSRMLS_D TSRMLS_DC)
-{
- free(SG(request_info).path_translated);
-}
-
-
-int php_doit(TSRMLS_D TSRMLS_DC)
-{
- struct stat sb;
- zend_file_handle file_handle;
- struct httpinfo *hip = PHG(cip)->hip;
- TSRMLS_FETCH();
-
- if (php_request_startup(TSRMLS_C) == FAILURE) {
- return -1;
- }
-
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = SG(request_info).path_translated;
- file_handle.free_filename = 0;
-
-/*
- php_phttpd_hash_environment(TSRMLS_C);
-*/
- php_execute_script(&file_handle TSRMLS_CC);
- php_request_shutdown(NULL);
-
- return SG(sapi_headers).http_response_code;
-}
-
-int pm_init(const char **argv)
-{
- tsrm_startup(1, 1, 0, NULL);
- sapi_startup(&phttpd_sapi_module);
- phttpd_sapi_module.startup(&phttpd_sapi_module);
-
- ts_allocate_id(&ph_globals_id, sizeof(phttpd_globals_struct), NULL, NULL);
-
- return 0;
-}
-
-void pm_exit(void)
-{
- fprintf(stderr,"***pm_exit\n");
-}
-
-int pm_request(struct connectioninfo *cip)
-{
- struct httpinfo *hip = cip->hip;
- int status;
- TSRMLS_FETCH();
-
- if (strcasecmp(hip->method, "GET") == 0 ||
- strcasecmp(hip->method, "HEAD") == 0 ||
- strcasecmp(hip->method, "POST") == 0) {
- PHG(cip) = cip;
-
- php_phttpd_request_ctor(TSRMLS_C);
- status = php_doit(TSRMLS_C);
- php_phttpd_request_dtor(TSRMLS_C);
-
- return status;
- } else {
- return -2;
- }
-}
-
-#endif
diff --git a/sapi/pi3web/CREDITS b/sapi/pi3web/CREDITS
deleted file mode 100644
index c4541f89da..0000000000
--- a/sapi/pi3web/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-pi3web
-Holger Zimmermann
diff --git a/sapi/pi3web/README b/sapi/pi3web/README
deleted file mode 100644
index 8d7e9dc274..0000000000
--- a/sapi/pi3web/README
+++ /dev/null
@@ -1,50 +0,0 @@
-PHP4 Module
-==========
-This module requires PHP4 as thread safe shared library. Have a look
-into the INSTALL file which accompanies that distribution.
-
-If you distribute this software bundled with the PHP software in source
-or binary form, then you must adhere to the PHP copyright conditions -
-the terms are reasonable.
-
-You should have checked out and built the PHP4 source package from the
-PHP CVS tree into the Pi3Web source directory called 'PHP4' first. Then
-build PHP4 as Pi3Web module and after that build the Pi3Web PHP4 wrapper:
-
-1. Checkout PHP4
-================
-cvs -d :pserver:cvsread@cvs.php.net:/repository login
-The required password is phpfi
-
-cvs -z3 -d :pserver:cvsread@cvs.php.net:/repository co php4
-
-You must also checkout the TSRM and the ZEND module from the ZEND cvs tree
-into the PHP4 root directory
-
-cvs -d :pserver:cvsread@cvs.zend.com:/repository login
-The required password is zend
-
-cvs -z3 -d :pserver:cvsread@cvs.zend.com:/repository co Zend TSRM
-
-2. Build PHP4
-=============
-2.1 POSIX
----------
-cd ./php4
-./buildconf
-./configure --with-pi3web
-make
-
-2.2 Win32
----------
-other required downloads from the php website
- - bison 1.25
- - bindlib32
- - number4.tar.gz
-nmake php4dllts.mak
-
-3. Build Pi3Web PHP4 wrapper
-============================
-Run make in the Pi3Web /Source/PHP4 directory.
-
-For further information refer to http://www.php.net/version4/
diff --git a/sapi/pi3web/config.m4 b/sapi/pi3web/config.m4
deleted file mode 100644
index 5b1ec78140..0000000000
--- a/sapi/pi3web/config.m4
+++ /dev/null
@@ -1,35 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-RESULT=no
-AC_MSG_CHECKING(for Pi3Web support)
-
-AC_ARG_WITH(pi3web,
-[ --with-pi3web=DIR Build PHP as Pi3Web module],
-[
-if test "$withval" != "no"; then
- if test "$withval" = "yes"; then
- PI3PATH=../.. # the default
- else
- PI3PATH=$withval
- fi
- test -f "$PI3PATH/PiAPI/PiAPI.h" || AC_MSG_ERROR(Unable to find PiAPI.h in $PI3PATH/PiAPI)
- PHP_BUILD_THREAD_SAFE
- AC_DEFINE(WITH_PI3WEB,1,[whether you want Pi3Web support])
- PHP_ADD_INCLUDE($PI3PATH/PiAPI)
- PHP_ADD_INCLUDE($PI3PATH/Pi2API)
- PHP_ADD_INCLUDE($PI3PATH/Pi3API)
- PHP_ADD_INCLUDE($PI3PATH/PHP4)
- PHP_SELECT_SAPI(pi3web, shared, pi3web_sapi.c)
- INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PI3PATH/bin/"
- RESULT=yes
-else
- RESULT=no
-fi
-])
-AC_MSG_RESULT($RESULT)
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
diff --git a/sapi/pi3web/php.sym b/sapi/pi3web/php.sym
deleted file mode 100644
index e69de29bb2..0000000000
--- a/sapi/pi3web/php.sym
+++ /dev/null
diff --git a/sapi/pi3web/php4pi3web.dsp b/sapi/pi3web/php4pi3web.dsp
deleted file mode 100644
index ec1c2806a3..0000000000
--- a/sapi/pi3web/php4pi3web.dsp
+++ /dev/null
@@ -1,136 +0,0 @@
-# Microsoft Developer Studio Project File - Name="php4pi3web" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php4pi3web - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "php4pi3web.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 "php4pi3web.mak" CFG="php4pi3web - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php4pi3web - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4pi3web - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php4pi3web - 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)" == "php4pi3web - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "php4pi3web_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "_WINDOWS" /D "_USRDLL" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "_DEBUG"
-# ADD RSC /l 0x40d /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 php4ts_debug.lib kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib PiAPI.lib Pi2API.lib Pi3API.lib /nologo /version:4.0 /dll /debug /machine:I386 /nodefaultlib:"libcmt" /nodefaultlib:"libc" /pdbtype:sept /libpath:"..\..\Debug_TS"
-
-!ELSEIF "$(CFG)" == "php4pi3web - 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 "php4pi3web_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "_WINDOWS" /D "_USRDLL" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 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 php4ts.lib kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib PiAPI.lib Pi2API.lib Pi3API.lib /nologo /version:4.0 /dll /machine:I386 /nodefaultlib:"libc.lib" /nodefaultlib:"libcmt.lib" /libpath:"..\..\Release_TS"
-
-!ELSEIF "$(CFG)" == "php4pi3web - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php4pi3web___Win32_Release_TS_inline"
-# PROP BASE Intermediate_Dir "php4pi3web___Win32_Release_TS_inline"
-# PROP BASE Ignore_Export_Lib 0
-# 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 /MD /W3 /GX /O2 /I ".." /I "..\main" /I "..\regex" /I "..\..\bindlib_w32" /I "..\Zend" /I "..\TSRM" /I "..\ext\mysql\libmysql" /I "..\..\..\PiAPI" /I "..\..\..\Pi2API" /I "..\..\..\Pi3API" /D "NDEBUG" /D ZEND_DEBUG=0 /D "_WINDOWS" /D "_USRDLL" /D "PHP4DLLTS_EXPORTS" /D "PHP_EXPORTS" /D "LIBZEND_EXPORTS" /D "TSRM_EXPORTS" /D "SAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "_WINDOWS" /D "_USRDLL" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /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 wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ZendTS.lib TSRM.lib resolv.lib libmysql.lib PiAPI.lib Pi2API.lib Pi3API.lib /nologo /version:4.0 /dll /machine:I386 /nodefaultlib:"libc.lib" /nodefaultlib:"libcmt.lib" /out:"..\Release_TS\php4ts.dll" /libpath:"..\TSRM\Release_TS" /libpath:"..\Zend\Release_TS" /libpath:"..\..\bindlib_w32\Release" /libpath:"..\ext\mysql\libmysql\Release_TS" /libpath:"Release_TS" /libpath:"..\..\..\PiAPI" /libpath:"..\..\..\Pi2API" /libpath:"..\..\..\Pi3API"
-# ADD LINK32 php4ts.lib kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib PiAPI.lib Pi2API.lib Pi3API.lib /nologo /version:4.0 /dll /machine:I386 /nodefaultlib:"libc.lib" /nodefaultlib:"libcmt.lib" /libpath:"..\..\Release_TS_inline"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php4pi3web - Win32 Debug_TS"
-# Name "php4pi3web - Win32 Release_TS"
-# Name "php4pi3web - Win32 Release_TS_inline"
-# Begin Group "Source Files"
-
-# PROP Default_Filter ".c"
-# Begin Source File
-
-SOURCE=.\pi3web_sapi.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter ".h"
-# Begin Source File
-
-SOURCE=.\pi3web_sapi.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/sapi/pi3web/pi3web_sapi.c b/sapi/pi3web/pi3web_sapi.c
deleted file mode 100644
index f11d59338d..0000000000
--- a/sapi/pi3web/pi3web_sapi.c
+++ /dev/null
@@ -1,482 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Pi3Web version 2.0 |
- +----------------------------------------------------------------------+
- | This file is committed by the Pi3 development group. |
- | (pi3web.sourceforge.net) |
- | |
- | Author: Holger Zimmermann (zimpel@users.sourceforge.net) |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
-
-#include "pi3web_sapi.h"
-#include "php.h"
-#include "php_main.h"
-#include "php_variables.h"
-#include "SAPI.h"
-#include "php_globals.h"
-#include "ext/standard/info.h"
-#include "zend_highlight.h"
-#include "zend_indent.h"
-#include "zend_alloc.h"
-#include "ext/standard/basic_functions.h"
-#include "TSRM/TSRM.h"
-#include "PiAPI.h"
-#include "Pi3API.h"
-
-#define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION")
-#define PI3WEB_SERVER_VAR_BUF_SIZE 1024
-#define PI3WEB_POST_DATA_BUF 1024
-
-int IWasLoaded=0;
-
-static char *pi3web_server_variables[] = {
- "ALL_HTTP",
- "AUTH_TYPE",
- "CONTENT_LENGTH",
- "CONTENT_TYPE",
- "GATEWAY_INTERFACE",
- "PATH_INFO",
- "PATH_TRANSLATED",
- "QUERY_STRING",
- "REQUEST_METHOD",
- "REMOTE_ADDR",
- "REMOTE_HOST",
- "REMOTE_USER",
- "SCRIPT_NAME",
- "SERVER_NAME",
- "SERVER_PORT",
- "SERVER_PROTOCOL",
- "SERVER_SOFTWARE",
- NULL
-};
-
-
-static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS)
-{
- char **p = pi3web_server_variables;
- char variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE];
- DWORD variable_len;
- LPCONTROL_BLOCK lpCB;
-
- lpCB = (LPCONTROL_BLOCK) SG(server_context);
-
- PUTS("<table border=0 cellpadding=3 cellspacing=1 width=600 align=center>\n");
- PUTS("<tr><th colspan=2 bgcolor=\"" PHP_HEADER_COLOR "\">Pi3Web Server Information</th></tr>\n");
- php_info_print_table_header(2, "Information Field", "Value");
- php_info_print_table_row(2, "Pi3Web SAPI module version", "$Id$");
- php_info_print_table_row(2, "Server Name Stamp", HTTPCore_getServerStamp());
- snprintf(variable_buf, 511, "%d", HTTPCore_debugEnabled());
- php_info_print_table_row(2, "Debug Enabled", variable_buf);
- PIPlatform_getCurrentDirectory( variable_buf, PI3WEB_SERVER_VAR_BUF_SIZE);
- php_info_print_table_row(2, "Current Path", variable_buf);
- if (lpCB->GetServerVariable(lpCB->ConnID, "SERVER_NAME", variable_buf, &variable_len)
- && variable_buf[0]) {
- php_info_print_table_row(2, "Main Virtual Hostname", variable_buf);
- };
- snprintf(variable_buf, 511, "%d", PIPlatform_getProcessId());
- php_info_print_table_row(2, "Server PID", variable_buf);
- php_info_print_table_row(2, "Server Platform", PIPlatform_getDescription());
-
- PUTS("</table><br />");
-
- PUTS("<table border=0 cellpadding=3 cellspacing=1 width=600 align=center>\n");
- PUTS("<tr><th colspan=2 bgcolor=\"" PHP_HEADER_COLOR "\">HTTP Request Information</th></tr>\n");
- php_info_print_table_row(2, "HTTP Request Line", lpCB->lpszReq);
- PUTS("<tr><th colspan=2 bgcolor=\"" PHP_HEADER_COLOR "\">HTTP Headers</th></tr>\n");
- php_info_print_table_header(2, "Server Variable", "Value");
- while (*p) {
- variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
- if (lpCB->GetServerVariable(lpCB->ConnID, *p, variable_buf, &variable_len)
- && variable_buf[0]) {
- php_info_print_table_row(2, *p, variable_buf);
- } else if (PIPlatform_getLastError() == PIAPI_EINVAL) {
- char *tmp_variable_buf;
-
- tmp_variable_buf = (char *) emalloc(variable_len);
- if (lpCB->GetServerVariable(lpCB->ConnID, *p, tmp_variable_buf, &variable_len)
- && variable_buf[0]) {
- php_info_print_table_row(2, *p, tmp_variable_buf);
- }
- efree(tmp_variable_buf);
- }
- p++;
- }
-
- PUTS("</table>");
-}
-
-
-static zend_module_entry php_pi3web_module = {
- STANDARD_MODULE_HEADER,
- "PI3WEB",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- php_info_pi3web,
- NULL,
- STANDARD_MODULE_PROPERTIES
-};
-
-
-static int zend_pi3web_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- DWORD num_bytes = str_length;
- LPCONTROL_BLOCK cb;
-
- cb = (LPCONTROL_BLOCK) SG(server_context);
-
- if ( !IWasLoaded ) return 0;
- cb->WriteClient(cb->ConnID, (char *) str, &num_bytes, 0 );
-
- if (num_bytes != str_length)
- php_handle_aborted_connection();
- return num_bytes;
-}
-
-
-static int sapi_pi3web_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- return SAPI_HEADER_ADD;
-}
-
-
-static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length TSRMLS_DC)
-{
- *total_length += sapi_header->header_len+2;
-}
-
-
-static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr TSRMLS_DC)
-{
- memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len);
- *combined_headers_ptr += sapi_header->header_len;
- **combined_headers_ptr = '\r';
- (*combined_headers_ptr)++;
- **combined_headers_ptr = '\n';
- (*combined_headers_ptr)++;
-}
-
-
-static int sapi_pi3web_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- uint total_length = 2; /* account for the trailing \r\n */
- char *combined_headers, *combined_headers_ptr;
- LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context);
- sapi_header_struct default_content_type;
-
- if ( !IWasLoaded ) return SAPI_HEADER_SENT_SUCCESSFULLY;
-
-
- if (SG(sapi_headers).send_default_content_type) {
- sapi_get_default_content_type_header(&default_content_type TSRMLS_CC);
- accumulate_header_length(&default_content_type, (void *) &total_length TSRMLS_CC);
- }
- zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) accumulate_header_length, (void *) &total_length TSRMLS_CC);
-
- /* Generate headers */
- combined_headers = (char *) emalloc(total_length+1);
- combined_headers_ptr = combined_headers;
- if (SG(sapi_headers).send_default_content_type) {
- concat_header(&default_content_type, (void *) &combined_headers_ptr TSRMLS_CC);
- sapi_free_header(&default_content_type); /* we no longer need it */
- }
- zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) concat_header, (void *) &combined_headers_ptr TSRMLS_CC);
- *combined_headers_ptr++ = '\r';
- *combined_headers_ptr++ = '\n';
- *combined_headers_ptr = 0;
-
- lpCB->dwHttpStatusCode = SG(sapi_headers).http_response_code;
- lpCB->SendHeaderFunction(lpCB->ConnID, &total_length, (LPDWORD) combined_headers);
-
- efree(combined_headers);
- if (SG(sapi_headers).http_status_line) {
- efree(SG(sapi_headers).http_status_line);
- SG(sapi_headers).http_status_line = 0;
- }
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-
-static int php_pi3web_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, &php_pi3web_module, 1)==FAILURE) {
- return FAILURE;
- } else {
- return SUCCESS;
- }
-}
-
-
-static int sapi_pi3web_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
- LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context);
- DWORD read_from_buf=0;
- DWORD read_from_input=0;
- DWORD total_read=0;
-
- if (SG(read_post_bytes) < lpCB->cbAvailable) {
- read_from_buf = MIN(lpCB->cbAvailable-SG(read_post_bytes), count_bytes);
- memcpy(buffer, lpCB->lpbData+SG(read_post_bytes), read_from_buf);
- total_read += read_from_buf;
- }
- if (read_from_buf<count_bytes
- && (SG(read_post_bytes)+read_from_buf) < lpCB->cbTotalBytes) {
- DWORD cbRead=0, cbSize;
-
- read_from_input = MIN(count_bytes-read_from_buf, lpCB->cbTotalBytes-SG(read_post_bytes)-read_from_buf);
- while (cbRead < read_from_input) {
- cbSize = read_from_input - cbRead;
- if (!lpCB->ReadClient(lpCB->ConnID, buffer+read_from_buf+cbRead, &cbSize) || cbSize==0) {
- break;
- }
- cbRead += cbSize;
- }
- total_read += cbRead;
- }
- SG(read_post_bytes) += total_read;
- return total_read;
-}
-
-
-static char *sapi_pi3web_read_cookies(TSRMLS_D)
-{
- LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context);
- char variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE];
- DWORD variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
-
- if (lpCB->GetServerVariable(lpCB->ConnID, "HTTP_COOKIE", variable_buf, &variable_len)) {
- return estrndup(variable_buf, variable_len);
- } else if (PIPlatform_getLastError()==PIAPI_EINVAL) {
- char *tmp_variable_buf = (char *) emalloc(variable_len+1);
-
- if (lpCB->GetServerVariable(lpCB->ConnID, "HTTP_COOKIE", tmp_variable_buf, &variable_len)) {
- tmp_variable_buf[variable_len] = 0;
- return tmp_variable_buf;
- } else {
- efree(tmp_variable_buf);
- }
- }
- return NULL;
-}
-
-static void init_request_info(LPCONTROL_BLOCK lpCB TSRMLS_DC)
-{
- SG(server_context) = lpCB;
- SG(request_info).request_method = lpCB->lpszMethod;
- SG(request_info).query_string = lpCB->lpszQueryString;
- SG(request_info).path_translated = lpCB->lpszPathTranslated;
- SG(request_info).request_uri = lpCB->lpszUri;
- SG(request_info).content_type = lpCB->lpszContentType;
- SG(request_info).content_length = lpCB->cbTotalBytes;
- SG(request_info).auth_user = (lpCB->lpszUser) ? (char *)estrdup((const char *)(lpCB->lpszUser)) : 0;
- SG(request_info).auth_password = (lpCB->lpszPassword) ? (char *)estrdup((const char *)(lpCB->lpszPassword)) : 0;
- SG(sapi_headers).http_response_code = 200;
-}
-
-static void sapi_pi3web_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- char static_variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE];
- char *variable_buf;
- DWORD variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
- char *variable;
- char *strtok_buf = NULL;
- LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context);
- char **p = pi3web_server_variables;
- p++; // Jump over ALL_HTTP;
-
- /* Register the standard server variables */
- while (*p) {
- variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
- if (lpCB->GetServerVariable(lpCB->ConnID, *p, static_variable_buf, &variable_len)
- && (variable_len > 1)) {
- php_register_variable(*p, static_variable_buf, track_vars_array TSRMLS_CC);
- } else if (PIPlatform_getLastError()==PIAPI_EINVAL) {
- variable_buf = (char *) emalloc(variable_len);
- if (lpCB->GetServerVariable(lpCB->ConnID, *p, variable_buf, &variable_len)) {
- php_register_variable(*p, variable_buf, track_vars_array TSRMLS_CC);
- }
- efree(variable_buf);
- }
- p++;
- }
-
- /* PHP_SELF support */
- variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
- if (lpCB->GetServerVariable(lpCB->ConnID, "SCRIPT_NAME", static_variable_buf, &variable_len)
- && (variable_len > 1)) {
- php_register_variable("PHP_SELF", static_variable_buf, track_vars_array TSRMLS_CC);
- }
-
- variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
- if (lpCB->GetServerVariable(lpCB->ConnID, "ALL_HTTP", static_variable_buf, &variable_len)
- && (variable_len > 1)) {
- variable_buf = static_variable_buf;
- } else {
- if (PIPlatform_getLastError()==PIAPI_EINVAL) {
- variable_buf = (char *) emalloc(variable_len);
- if (!lpCB->GetServerVariable(lpCB->ConnID, "ALL_HTTP", variable_buf, &variable_len)) {
- efree(variable_buf);
- return;
- }
- } else {
- return;
- }
- }
- variable = php_strtok_r(variable_buf, "\r\n", &strtok_buf);
- while (variable) {
- char *colon = strchr(variable, ':');
-
- if (colon) {
- char *value = colon+1;
- while (*value==' ') {
- value++;
- }
- *colon = 0;
- php_register_variable(variable, value, track_vars_array TSRMLS_CC);
- *colon = ':';
- }
- variable = php_strtok_r(NULL, "\r\n", &strtok_buf);
- }
- if (variable_buf!=static_variable_buf) {
- efree(variable_buf);
- }
-}
-
-static sapi_module_struct pi3web_sapi_module = {
- "pi3web", /* name */
- "PI3WEB", /* pretty name */
-
- php_pi3web_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
- NULL, /* activate */
- NULL, /* deactivate */
- zend_pi3web_ub_write, /* unbuffered write */
- NULL, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
- php_error, /* error handler */
- sapi_pi3web_header_handler, /* header handler */
- sapi_pi3web_send_headers, /* send headers handler */
- NULL, /* send header handler */
- sapi_pi3web_read_post, /* read POST data */
- sapi_pi3web_read_cookies, /* read Cookies */
- sapi_pi3web_register_variables, /* register server variables */
- NULL, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-DWORD PHP4_wrapper(LPCONTROL_BLOCK lpCB)
-{
- zend_file_handle file_handle;
- int iRet = PIAPI_COMPLETED;
- TSRMLS_FETCH();
-
- zend_first_try {
- file_handle.filename = lpCB->lpszFileName;
- file_handle.free_filename = 0;
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.opened_path = NULL;
-
- init_request_info(lpCB TSRMLS_CC);
- php_request_startup(TSRMLS_C);
-
- switch ( lpCB->dwBehavior ) {
- case PHP_MODE_STANDARD:
- iRet = ( php_execute_script( &file_handle TSRMLS_CC ) ) ?
- PIAPI_COMPLETED : PIAPI_ERROR;
- break;
- case PHP_MODE_HIGHLIGHT: {
- zend_syntax_highlighter_ini syntax_highlighter_ini;
- if ( open_file_for_scanning( &file_handle TSRMLS_CC ) == SUCCESS )
- {
- php_get_highlight_struct( &syntax_highlighter_ini );
- zend_highlight( &syntax_highlighter_ini TSRMLS_CC );
- }
- else
- {
- iRet = PIAPI_ERROR;
- };
- };
- break;
- case PHP_MODE_INDENT: {
- sapi_header_line ctr = {0};
-
- ctr.line = "Content-Type: text/plain";
- ctr.line_len = strlen(ctr.line);
-
- sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
- }
- if ( open_file_for_scanning( &file_handle TSRMLS_CC ) == SUCCESS )
- {
- zend_indent();
- }
- else
- {
- iRet = PIAPI_ERROR;
- };
- break;
- case PHP_MODE_LINT:
- iRet = (php_lint_script(&file_handle TSRMLS_CC) == SUCCESS) ?
- PIAPI_COMPLETED : PIAPI_ERROR;
- break;
- default:
- iRet = PIAPI_ERROR;;
- }
-
- if (SG(request_info).cookie_data) {
- efree(SG(request_info).cookie_data);
- };
-
- php_request_shutdown(NULL);
- } zend_catch {
- iRet = PIAPI_ERROR;
- } zend_end_try();
- return iRet;
-}
-
-BOOL PHP4_startup() {
- tsrm_startup(1, 1, 0, NULL);
- sapi_startup(&pi3web_sapi_module);
- if (pi3web_sapi_module.startup) {
- pi3web_sapi_module.startup(&pi3web_sapi_module);
- };
- IWasLoaded = 1;
- return IWasLoaded;
-};
-
-BOOL PHP4_shutdown() {
- if (pi3web_sapi_module.shutdown) {
- pi3web_sapi_module.shutdown(&pi3web_sapi_module);
- };
- sapi_shutdown();
- tsrm_shutdown();
- IWasLoaded = 0;
- return !IWasLoaded;
-};
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/sapi/pi3web/pi3web_sapi.h b/sapi/pi3web/pi3web_sapi.h
deleted file mode 100644
index 36e08e7982..0000000000
--- a/sapi/pi3web/pi3web_sapi.h
+++ /dev/null
@@ -1,95 +0,0 @@
-#ifndef _PI3WEB_SAPI_H_
-#define _PI3WEB_SAPI_H_
-
-#ifdef PHP_WIN32
-# include <windows.h>
-# include <httpext.h>
-# ifdef SAPI_EXPORTS
-# define MODULE_API __declspec(dllexport)
-# else
-# define MODULE_API __declspec(dllimport)
-# endif
-#else
-# define far
-# define MODULE_API
-
- typedef int BOOL;
- typedef void far *LPVOID;
- typedef LPVOID HCONN;
- typedef unsigned long DWORD;
- typedef DWORD far *LPDWORD;
- typedef char CHAR;
- typedef CHAR *LPSTR;
- typedef unsigned char BYTE;
- typedef BYTE far *LPBYTE;
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define PHP_MODE_STANDARD 1
-#define PHP_MODE_HIGHLIGHT 2
-#define PHP_MODE_INDENT 3
-#define PHP_MODE_LINT 4
-
-//
-// passed to the procedure on a new request
-//
-typedef struct _CONTROL_BLOCK {
- DWORD cbSize; // size of this struct.
- HCONN ConnID; // Context number not to be modified!
- DWORD dwHttpStatusCode; // HTTP Status code
- CHAR lpszLogData[80]; // null terminated log info
-
- LPSTR lpszMethod; // REQUEST_METHOD
- LPSTR lpszQueryString; // QUERY_STRING
- LPSTR lpszPathInfo; // PATH_INFO
- LPSTR lpszPathTranslated; // PATH_TRANSLATED
- LPSTR lpszFileName; // FileName to PHP3 physical file
- LPSTR lpszUri; // The request URI
- LPSTR lpszReq; // The whole HTTP request line
- LPSTR lpszUser; // The authenticated user
- LPSTR lpszPassword; // The authenticated password
-
- DWORD cbTotalBytes; // Total bytes indicated from client
- DWORD cbAvailable; // Available number of bytes
- LPBYTE lpbData; // pointer to cbAvailable bytes
-
- LPSTR lpszContentType; // Content type of client data
- DWORD dwBehavior; // PHP behavior (standard, highlight, intend
-
- BOOL (* GetServerVariable) ( HCONN hConn,
- LPSTR lpszVariableName,
- LPVOID lpvBuffer,
- LPDWORD lpdwSize );
-
- BOOL (* WriteClient) ( HCONN ConnID,
- LPVOID Buffer,
- LPDWORD lpdwBytes,
- DWORD dwReserved );
-
- BOOL (* ReadClient) ( HCONN ConnID,
- LPVOID lpvBuffer,
- LPDWORD lpdwSize );
-
- BOOL (* SendHeaderFunction)( HCONN hConn,
- LPDWORD lpdwSize,
- LPDWORD lpdwDataType );
-
-} CONTROL_BLOCK, *LPCONTROL_BLOCK;
-
-DWORD PHP4_wrapper(LPCONTROL_BLOCK lpCB);
-BOOL PHP4_startup();
-BOOL PHP4_shutdown();
-
-// the following type declaration is for the server side
-typedef DWORD ( * PFN_WRAPPERFUNC )( CONTROL_BLOCK *pCB );
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // end definition _PI3WEB_SAPI_H_
diff --git a/sapi/roxen/README b/sapi/roxen/README
deleted file mode 100644
index c6ec30d272..0000000000
--- a/sapi/roxen/README
+++ /dev/null
@@ -1,18 +0,0 @@
-Roxen PHP support. Early version. Don't expect to be able to get it to
-work. Requires Pike 0.7.79 and Roxen 1.4. Anything less won't work.
-
-The module is now thread safe, in a couple of different modes. First
-mode, the default, uses a process global PHP lock in the Roxen
-module. This means that all PHP-requests are serialized (ie only one
-script is executed at any one time). The second option is using ZTS
-(Zend Thread Safe mode). Unless --enable-roxen-zts is specified, this
-won't be used.
-
-This solution now works fine and is recommended. Multiple PHP4
-requests will be run in parallell. The maximum number of parallell
-PHP4-execution is limited to the number of handle threads Roxen is
-started with.
-
-Support for this module is lacking. Please contact Roxen Internet
-Software for support and help. See http://www.roxen.com/company/contact/
-for contact information.
diff --git a/sapi/roxen/TODO b/sapi/roxen/TODO
deleted file mode 100644
index 4ba171accc..0000000000
--- a/sapi/roxen/TODO
+++ /dev/null
@@ -1,33 +0,0 @@
-BUGS:
-
-- fix backtraces
-- exit in PHP exits Roxen
-- POST newline added?
-- Rewriting header handling so that more than one header with the same
- name can be set (most importantly, cookies).
-- Recursive mutex lock problem:
-
- And another error (when trying to include a class)
-
- Recursive mutex locks!
- /Usr/local/pike/7.0.54/lib/modules/PHP4.so.Interpreter:
- run("/home/www/www.tx.pl/news/test.php",mapping[3],modules/scripting/php4.pike.PHPScript(),modules/scripting/php4.pike.PHPScript.done)
- modules/scripting/php4.pike:169: run()
- base_server/roxen.pike:569: handler_thread(3).
-
- And after this every access to any php script (on other virtual sites
- also) ends (of course there is no proper output) with this error:
-
- Php4.Interpreter->run: Tried to run a PHP-script from a PHP
- callback!/usr/local/pike/7.0.54/lib/modules/PHP4.so.Interpreter:
- run("/home/www/biall.com.pl/index.php3",mapping[2],modules/scripting/php4.pike.PHPScript(),modules/scripting/php4.pike.PHPScript.done)
- modules/scripting/php4.pike:169: run()
- base_server/roxen.pike:569: handler_thread(3).
-
-
-ADDITIONS:
-
-- use th_farm
-- change cwd in single threaded mode
-- per-virtual-server configuration
-
diff --git a/sapi/roxen/config.m4 b/sapi/roxen/config.m4
deleted file mode 100644
index cf2726b51b..0000000000
--- a/sapi/roxen/config.m4
+++ /dev/null
@@ -1,60 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-RESULT=no
-AC_MSG_CHECKING(for Roxen/Pike support)
-AC_ARG_WITH(roxen,
-[ --with-roxen=DIR Build PHP as a Pike module. DIR is the base Roxen
- directory, normally /usr/local/roxen/server.],
-[
- if test ! -d $withval ; then
- AC_MSG_ERROR(You did not specify a directory)
- fi
- if test -f $withval/bin/roxen; then
- PIKE=$withval/bin/roxen
- elif test -f $withval/bin/pike; then
- PIKE=$withval/bin/pike
- else
- AC_MSG_ERROR(Couldn't find a pike in $withval/bin/)
- fi
- if $PIKE -e 'float v; catch(v = __VERSION__ + (__BUILD__/10000.0)); if(v < 0.7079) exit(1); exit(0);'; then
- PIKE_MODULE_DIR=`$PIKE --show-paths 2>&1| grep '^Module' | sed -e 's/.*: //'`
- PIKE_INCLUDE_DIR=`echo $PIKE_MODULE_DIR | sed -e 's,lib/pike/modules,include/pike,' -e 's,lib/modules,include/pike,'`
- if test -z "$PIKE_INCLUDE_DIR" -o -z "$PIKE_MODULE_DIR"; then
- AC_MSG_ERROR(Failed to figure out Pike module and include directories)
- fi
- else
- AC_MSG_ERROR(Roxen/PHP requires Pike 0.7.79 or newer)
- fi
-
- PHP_ADD_INCLUDE($PIKE_INCLUDE_DIR)
- AC_DEFINE(HAVE_ROXEN,1,[Whether you use Roxen])
- PHP_SELECT_SAPI(roxen, shared, roxen.c)
- INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PIKE_MODULE_DIR/PHP4.so"
- RESULT="yes
- Pike binary used: $PIKE
- Pike include dir: $PIKE_INCLUDE_DIR
- Pike module directory: $PIKE_MODULE_DIR"
- PIKE_INCLUDE_DIR=" -I$PIKE_INCLUDE_DIR "
-])
-AC_MSG_RESULT($RESULT)
-
-if test "$RESULT" != "no" ; then
- RESULT=no
- AC_MSG_CHECKING(if Roxen should use ZTS)
- AC_ARG_ENABLE(roxen-zts,
- [ --enable-roxen-zts Build the Roxen module using Zend Thread Safety.],
- [
- PHP_BUILD_THREAD_SAFE
- AC_DEFINE(ROXEN_USE_ZTS,1,[Whether to use Roxen in ZTS mode])
- RESULT=yes
-
- ])
- AC_MSG_RESULT($RESULT)
-fi
-
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
-
diff --git a/sapi/roxen/roxen.c b/sapi/roxen/roxen.c
deleted file mode 100644
index 9002040959..0000000000
--- a/sapi/roxen/roxen.c
+++ /dev/null
@@ -1,725 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: David Hedbor <neotron@php.net> |
- | Based on aolserver SAPI by Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-#ifdef HAVE_ROXEN
-
-#include "php_ini.h"
-#include "php_globals.h"
-#include "SAPI.h"
-#include "php_main.h"
-#include "ext/standard/info.h"
-
-#include "php_version.h"
-
-#ifndef ZTS
-/* Only valid if thread safety is enabled. */
-#undef ROXEN_USE_ZTS
-#endif
-
-
-/* Pike Include Files
- *
- * conflicts with pike avoided by only using long names. Requires a new
- * Pike 0.7 since it was implemented for this interface only.
- *
- */
-#define NO_PIKE_SHORTHAND
-
-#include <fdlib.h>
-#include <program.h>
-#include <pike_types.h>
-#include <interpret.h>
-#include <module_support.h>
-#include <error.h>
-#include <array.h>
-#include <backend.h>
-#include <stralloc.h>
-#include <mapping.h>
-#include <object.h>
-#include <threads.h>
-#include <builtin_functions.h>
-#include <operators.h>
-
-#undef HIDE_GLOBAL_VARIABLES
-#undef REVEAL_GLOBAL_VARIABLES
-#define HIDE_GLOBAL_VARIABLES()
-#define REVEAL_GLOBAL_VARIABLES()
-
-/* php_roxen_request is per-request object storage */
-
-typedef struct
-{
- struct mapping *request_data;
- struct object *my_fd_obj;
- int my_fd;
- char *filename;
-} php_roxen_request;
-
-
-/* Defines to get to the data supplied when the script is started. */
-
-#ifdef ROXEN_USE_ZTS
-
-/* ZTS does work now, but it seems like it's faster using the "serialization"
- * method I previously used. Thus it's not used unless ROXEN_USE_ZTS is defined.
- */
-
-/* Per thread storage area id... */
-static int roxen_globals_id;
-
-# define GET_THIS() php_roxen_request *_request = ts_resource(roxen_globals_id)
-# define THIS _request
-#else
-static php_roxen_request *current_request = NULL;
-
-# define GET_THIS() current_request = ((php_roxen_request *)Pike_fp->current_storage)
-# define THIS current_request
-#endif
-
-/* File descriptor integer. Used to write directly to the FD without
- * passing Pike
- */
-#define MY_FD (THIS->my_fd)
-
-/* FD object. Really a PHPScript object from Pike which implements a couple
- * of functions to handle headers, writing and buffering.
- */
-#define MY_FD_OBJ ((struct object *)(THIS->my_fd_obj))
-
-/* Mapping with data supplied from the calling Roxen module. Contains
- * a mapping with headers, an FD object etc.
- */
-#define REQUEST_DATA ((struct mapping *)(THIS->request_data))
-
-
-#if defined(_REENTRANT) && !defined(ROXEN_USE_ZTS)
-/* Lock used to serialize the PHP execution. If ROXEN_USE_ZTS is defined, we
- * are using the PHP thread safe mechanism instead.
- */
-static PIKE_MUTEX_T roxen_php_execution_lock;
-# define PHP_INIT_LOCK() mt_init(&roxen_php_execution_lock)
-# define PHP_LOCK(X) THREADS_ALLOW();mt_lock(&roxen_php_execution_lock);THREADS_DISALLOW()
-# define PHP_UNLOCK(X) mt_unlock(&roxen_php_execution_lock);
-# define PHP_DESTROY() mt_destroy(&roxen_php_execution_lock)
-#else /* !_REENTRANT */
-# define PHP_INIT_LOCK()
-# define PHP_LOCK(X)
-# define PHP_UNLOCK(X)
-# define PHP_DESTROY()
-#endif /* _REENTRANT */
-
-extern int fd_from_object(struct object *o);
-static unsigned char roxen_php_initialized;
-
-/* This allows calling of pike functions from the PHP callbacks,
- * which requires the Pike interpreter to be locked.
- */
-#define THREAD_SAFE_RUN(COMMAND, what) do {\
- struct thread_state *state;\
- if((state = thread_state_for_id(th_self()))!=NULL) {\
- if(!state->swapped) {\
- COMMAND;\
- } else {\
- mt_lock(&interpreter_lock);\
- SWAP_IN_THREAD(state);\
- COMMAND;\
- SWAP_OUT_THREAD(state);\
- mt_unlock(&interpreter_lock);\
- }\
- }\
-} while(0)
-
-struct program *php_program;
-
-
-/* To avoid executing a PHP script from a PHP callback, which would
- * create a deadlock, a global thread id is used. If the thread calling the
- * php-script is the same as the current thread, it fails.
- */
-static int current_thread = -1;
-
-
-/* Low level header lookup. Basically looks for the named header in the mapping
- * headers in the supplied options mapping.
- */
-
-static INLINE struct svalue *lookup_header(char *headername)
-{
- struct svalue *headers, *value;
- struct pike_string *sind;
-#ifdef ROXEN_USE_ZTS
- GET_THIS();
-#endif
- sind = make_shared_string("env");
- headers = low_mapping_string_lookup(REQUEST_DATA, sind);
- free_string(sind);
- if(!headers || headers->type != PIKE_T_MAPPING) return NULL;
- sind = make_shared_string(headername);
- value = low_mapping_string_lookup(headers->u.mapping, sind);
- free_string(sind);
- if(!value) return NULL;
- return value;
-}
-
-/* Lookup a header in the mapping and return the value as a string, or
- * return the default if it's missing
- */
-INLINE static char *lookup_string_header(char *headername, char *default_value)
-{
- struct svalue *head = NULL;
- THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup");
- if(!head || head->type != PIKE_T_STRING)
- return default_value;
- return head->u.string->str;
-}
-
-/* Lookup a header in the mapping and return the value as if it's an integer
- * and otherwise return the default.
- */
-INLINE static int lookup_integer_header(char *headername, int default_value)
-{
- struct svalue *head = NULL;
- THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup");
- if(!head || head->type != PIKE_T_INT)
- return default_value;
- return head->u.integer;
-}
-
-/*
- * php_roxen_low_ub_write() writes data to the client connection. Might be
- * rewritten to do more direct IO to save CPU and the need to lock the *
- * interpreter for better threading.
- */
-
-static int
-php_roxen_low_ub_write(const char *str, uint str_length TSRMLS_DC) {
- int sent_bytes = 0;
- struct pike_string *to_write = NULL;
-#ifdef ROXEN_USE_ZTS
- GET_THIS();
-#endif
-
- if(!MY_FD_OBJ->prog) {
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- zend_bailout();
- return -1;
- }
- to_write = make_shared_binary_string(str, str_length);
- push_string(to_write);
- safe_apply(MY_FD_OBJ, "write", 1);
- if(Pike_sp[-1].type == PIKE_T_INT)
- sent_bytes = Pike_sp[-1].u.integer;
- pop_stack();
- if(sent_bytes != str_length) {
- /* This means the connection is closed. Dead. Gone. *sniff* */
- php_handle_aborted_connection();
- }
- return sent_bytes;
-}
-
-/*
- * php_roxen_sapi_ub_write() calls php_roxen_low_ub_write in a Pike thread
- * safe manner.
- */
-
-static int
-php_roxen_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
-#ifdef ROXEN_USE_ZTS
- GET_THIS();
-#endif
-
- int sent_bytes = 0, fd = MY_FD;
- if(fd)
- {
- for(sent_bytes=0;sent_bytes < str_length;)
- {
- int written;
- written = fd_write(fd, str + sent_bytes, str_length - sent_bytes);
- if(written < 0)
- {
- switch(errno)
- {
- default:
- /* This means the connection is closed. Dead. Gone. *sniff* */
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- zend_bailout();
- return sent_bytes;
- case EINTR:
- case EWOULDBLOCK:
- continue;
- }
-
- } else {
- sent_bytes += written;
- }
- }
- } else {
- THREAD_SAFE_RUN(sent_bytes = php_roxen_low_ub_write(str, str_length TSRMLS_CC),
- "write");
- }
- return sent_bytes;
-}
-
-/* php_roxen_set_header() sets a header in the header mapping. Called in a
- * thread safe manner from php_roxen_sapi_header_handler.
- */
-static void php_roxen_set_header(char *header_name, char *value, char *p)
-{
- struct svalue hsval;
- struct pike_string *hval, *ind, *hind;
- struct mapping *headermap;
- struct svalue *s_headermap;
-#ifdef ROXEN_USE_ZTS
- GET_THIS();
-#endif
- hval = make_shared_string(value);
- ind = make_shared_string(" _headers");
- hind = make_shared_binary_string(header_name,
- (int)(p - header_name));
-
- s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind);
- if(!s_headermap)
- {
- struct svalue mappie;
- mappie.type = PIKE_T_MAPPING;
- headermap = allocate_mapping(1);
- mappie.u.mapping = headermap;
- mapping_string_insert(REQUEST_DATA, ind, &mappie);
- free_mapping(headermap);
- } else
- headermap = s_headermap->u.mapping;
-
- hsval.type = PIKE_T_STRING;
- hsval.u.string = hval;
- mapping_string_insert(headermap, hind, &hsval);
-
- free_string(hval);
- free_string(ind);
- free_string(hind);
-}
-
-/*
- * php_roxen_sapi_header_handler() sets a HTTP reply header to be
- * sent to the client.
- */
-static int
-php_roxen_sapi_header_handler(sapi_header_struct *sapi_header,
- sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- char *header_name, *header_content, *p;
- header_name = sapi_header->header;
- header_content = p = strchr(header_name, ':');
-
- if(p) {
- do {
- header_content++;
- } while(*header_content == ' ');
- THREAD_SAFE_RUN(php_roxen_set_header(header_name, header_content, p), "header handler");
- }
- sapi_free_header(sapi_header);
- return 0;
-}
-
-/*
- * php_roxen_sapi_send_headers() flushes the headers to the client.
- * Called before real content is sent by PHP.
- */
-
-static int
-php_roxen_low_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- struct pike_string *ind;
- struct svalue *s_headermap;
-#ifdef ROXEN_USE_ZTS
- GET_THIS();
-#endif
-
- if(!MY_FD_OBJ->prog) {
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- zend_bailout();
- return SAPI_HEADER_SEND_FAILED;
- }
- ind = make_shared_string(" _headers");
- s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind);
- free_string(ind);
-
- push_int(SG(sapi_headers).http_response_code);
- if(s_headermap && s_headermap->type == PIKE_T_MAPPING)
- ref_push_mapping(s_headermap->u.mapping);
- else
- push_int(0);
- safe_apply(MY_FD_OBJ, "send_headers", 2);
- pop_stack();
-
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-static int
-php_roxen_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- int res = 0;
- THREAD_SAFE_RUN(res = php_roxen_low_send_headers(sapi_headers TSRMLS_CC), "send headers");
- return res;
-}
-
-/*
- * php_roxen_sapi_read_post() reads a specified number of bytes from
- * the client. Used for POST/PUT requests.
- */
-
-INLINE static int php_roxen_low_read_post(char *buf, uint count_bytes)
-{
- uint total_read = 0;
-#ifdef ROXEN_USE_ZTS
- GET_THIS();
-#endif
- TSRMLS_FETCH();
-
- if(!MY_FD_OBJ->prog)
- {
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- zend_bailout();
- return -1;
- }
- push_int(count_bytes);
- safe_apply(MY_FD_OBJ, "read_post", 1);
- if(Pike_sp[-1].type == PIKE_T_STRING) {
- MEMCPY(buf, Pike_sp[-1].u.string->str,
- (total_read = Pike_sp[-1].u.string->len));
- buf[total_read] = '\0';
- } else
- total_read = 0;
- pop_stack();
- return total_read;
-}
-
-static int
-php_roxen_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC)
-{
- uint total_read = 0;
- THREAD_SAFE_RUN(total_read = php_roxen_low_read_post(buf, count_bytes), "read post");
- return total_read;
-}
-
-/*
- * php_roxen_sapi_read_cookies() returns the Cookie header from
- * the HTTP request header
- */
-
-static char *
-php_roxen_sapi_read_cookies(TSRMLS_D)
-{
- char *cookies;
- cookies = lookup_string_header("HTTP_COOKIE", NULL);
- return cookies;
-}
-
-static void php_info_roxen(ZEND_MODULE_INFO_FUNC_ARGS)
-{
- /* char buf[512]; */
- php_info_print_table_start();
- php_info_print_table_row(2, "SAPI module version", "$Id$");
- /* php_info_print_table_row(2, "Build date", Ns_InfoBuildDate());
- php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile());
- php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog());
- php_info_print_table_row(2, "Installation path", Ns_InfoHomePath());
- php_info_print_table_row(2, "Hostname of server", Ns_InfoHostname());
- php_info_print_table_row(2, "Source code label", Ns_InfoLabel());
- php_info_print_table_row(2, "Server platform", Ns_InfoPlatform());
- snprintf(buf, 511, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion());
- php_info_print_table_row(2, "Server version", buf);
- snprintf(buf, 511, "%d day(s), %02d:%02d:%02d",
- uptime / 86400,
- (uptime / 3600) % 24,
- (uptime / 60) % 60,
- uptime % 60);
- php_info_print_table_row(2, "Server uptime", buf);
- */
- php_info_print_table_end();
-}
-
-static zend_module_entry php_roxen_module = {
- STANDARD_MODULE_HEADER,
- "Roxen",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- php_info_roxen,
- NULL,
- STANDARD_MODULE_PROPERTIES
-};
-
-static int php_roxen_startup(sapi_module_struct *sapi_module)
-{
- if(php_module_startup(sapi_module, &php_roxen_module, 1) == FAILURE) {
- return FAILURE;
- } else {
- return SUCCESS;
- }
-}
-
-/* this structure is static (as in "it does not change") */
-
-static sapi_module_struct roxen_sapi_module = {
- "roxen",
- "Roxen",
- php_roxen_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
- NULL, /* activate */
- NULL, /* deactivate */
- php_roxen_sapi_ub_write, /* unbuffered write */
- NULL, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
- php_error, /* error handler */
- php_roxen_sapi_header_handler, /* header handler */
- php_roxen_sapi_send_headers, /* send headers handler */
- NULL, /* send header handler */
- php_roxen_sapi_read_post, /* read POST data */
- php_roxen_sapi_read_cookies, /* read Cookies */
- NULL, /* register server variables */
- NULL, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-/*
- * php_roxen_hash_environment() populates the php script environment
- * with a number of variables. HTTP_* variables are created for
- * the HTTP header data, so that a script can access these.
- */
-#define ADD_STRING(name) \
- MAKE_STD_ZVAL(pval); \
- pval->type = IS_STRING; \
- pval->value.str.len = strlen(buf); \
- pval->value.str.val = estrndup(buf, pval->value.str.len); \
- zend_hash_update(&EG(symbol_table), name, sizeof(name), \
- &pval, sizeof(zval *), NULL)
-
-static void
-php_roxen_hash_environment(TSRMLS_D)
-{
- int i;
- char buf[512];
- zval *pval;
- struct svalue *headers;
- struct pike_string *sind;
- struct array *indices;
- struct svalue *ind, *val;
-#ifdef ROXEN_USE_ZTS
- GET_THIS();
-#endif
- sind = make_shared_string("env");
- headers = low_mapping_string_lookup(REQUEST_DATA, sind);
- free_string(sind);
- if(headers && headers->type == PIKE_T_MAPPING) {
- indices = mapping_indices(headers->u.mapping);
- for(i = 0; i < indices->size; i++) {
- ind = &indices->item[i];
- val = low_mapping_lookup(headers->u.mapping, ind);
- if(ind && ind->type == PIKE_T_STRING &&
- val && val->type == PIKE_T_STRING) {
- int buf_len;
- buf_len = MIN(511, ind->u.string->len);
- strncpy(buf, ind->u.string->str, buf_len);
- buf[buf_len] = '\0'; /* Terminate correctly */
- MAKE_STD_ZVAL(pval);
- pval->type = IS_STRING;
- pval->value.str.len = val->u.string->len;
- pval->value.str.val = estrndup(val->u.string->str, pval->value.str.len);
-
- zend_hash_update(&EG(symbol_table), buf, buf_len + 1, &pval, sizeof(zval *), NULL);
- }
- }
- free_array(indices);
- }
-
- /*
- MAKE_STD_ZVAL(pval);
- pval->type = IS_LONG;
- pval->value.lval = Ns_InfoBootTime();
- zend_hash_update(&EG(symbol_table), "SERVER_BOOTTIME", sizeof("SERVER_BOOTTIME"), &pval, sizeof(zval *), NULL);
- */
-}
-
-/*
- * php_roxen_module_main() is called by the per-request handler and
- * "executes" the script
- */
-
-static int php_roxen_module_main(TSRMLS_D)
-{
- int res, len;
- char *dir;
- zend_file_handle file_handle;
-#ifdef ROXEN_USE_ZTS
- GET_THIS();
-#endif
-
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = THIS->filename;
- file_handle.free_filename = 0;
- file_handle.opened_path = NULL;
-
- THREADS_ALLOW();
- res = php_request_startup(TSRMLS_C);
- THREADS_DISALLOW();
- if(res == FAILURE) {
- return 0;
- }
- php_roxen_hash_environment(TSRMLS_C);
- THREADS_ALLOW();
- php_execute_script(&file_handle TSRMLS_CC);
- php_request_shutdown(NULL);
- THREADS_DISALLOW();
- return 1;
-}
-
-/*
- * The php_roxen_request_handler() is called per request and handles
- * everything for one request.
- */
-
-void f_php_roxen_request_handler(INT32 args)
-{
- struct object *my_fd_obj;
- struct mapping *request_data;
- struct svalue *done_callback, *raw_fd;
- struct pike_string *script, *ind;
- int status = 1;
-#ifdef ROXEN_USE_ZTS
- GET_THIS();
-#endif
- TSRMLS_FETCH();
-
- if(current_thread == th_self())
- php_error(E_WARNING, "PHP4.Interpreter->run: Tried to run a PHP-script from a PHP "
- "callback!");
- get_all_args("PHP4.Interpreter->run", args, "%S%m%O%*", &script,
- &request_data, &my_fd_obj, &done_callback);
- if(done_callback->type != PIKE_T_FUNCTION)
- php_error(E_WARNING, "PHP4.Interpreter->run: Bad argument 4, expected function.\n");
- PHP_LOCK(THIS); /* Need to lock here or reusing the same object might cause
- * problems in changing stuff in that object */
-#ifndef ROXEN_USE_ZTS
- GET_THIS();
-#endif
- THIS->request_data = request_data;
- THIS->my_fd_obj = my_fd_obj;
- THIS->filename = script->str;
- current_thread = th_self();
- SG(request_info).query_string = lookup_string_header("QUERY_STRING", 0);
- SG(server_context) = (void *)1; /* avoid server_context == NULL */
-
- /* path_translated is apparently the absolute path to the file, not
- the translated PATH_INFO
- */
- SG(request_info).path_translated =
- lookup_string_header("SCRIPT_FILENAME", NULL);
- SG(request_info).request_uri = lookup_string_header("DOCUMENT_URI", NULL);
- if(!SG(request_info).request_uri)
- SG(request_info).request_uri = lookup_string_header("SCRIPT_NAME", NULL);
- SG(request_info).request_method = lookup_string_header("REQUEST_METHOD", "GET");
- SG(request_info).content_length = lookup_integer_header("HTTP_CONTENT_LENGTH", 0);
- SG(request_info).content_type = lookup_string_header("HTTP_CONTENT_TYPE", NULL);
- SG(sapi_headers).http_response_code = 200;
-
- /* FIXME: Check for auth stuff needs to be fixed... */
- SG(request_info).auth_user = NULL;
- SG(request_info).auth_password = NULL;
-
- ind = make_shared_binary_string("my_fd", 5);
- raw_fd = low_mapping_string_lookup(THIS->request_data, ind);
- if(raw_fd && raw_fd->type == PIKE_T_OBJECT)
- {
- int fd = fd_from_object(raw_fd->u.object);
- if(fd == -1)
- php_error(E_WARNING, "PHP4.Interpreter->run: my_fd object not open or not an FD.\n");
- THIS->my_fd = fd;
- } else
- THIS->my_fd = 0;
-
- status = php_roxen_module_main(TSRMLS_C);
- current_thread = -1;
-
- apply_svalue(done_callback, 0);
- pop_stack();
- pop_n_elems(args);
- push_int(status);
- PHP_UNLOCK(THIS);
-}
-
-
-/* Clear the object global struct */
-static void clear_struct(struct object *o)
-{
- MEMSET(Pike_fp->current_storage, 0, sizeof(php_roxen_request));
-}
-
-
-/*
- * pike_module_init() is called by Pike once at startup
- *
- * This functions allocates basic structures
- */
-
-void pike_module_init( void )
-{
- if (!roxen_php_initialized) {
-#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
-#ifdef ROXEN_USE_ZTS
- ts_allocate_id(&roxen_globals_id, sizeof(php_roxen_request), NULL, NULL);
-#endif
-#endif
- sapi_startup(&roxen_sapi_module);
- /*php_roxen_startup(&roxen_sapi_module); removed - should be called from SAPI activation*/
- roxen_php_initialized = 1;
- PHP_INIT_LOCK();
- }
- start_new_program(); /* Text */
- ADD_STORAGE(php_roxen_request);
- set_init_callback(clear_struct);
- pike_add_function("run", f_php_roxen_request_handler,
- "function(string, mapping, object, function:int)", 0);
- add_program_constant("Interpreter", (php_program = end_program()), 0);
-}
-
-/*
- * pike_module_exit() performs the last steps before the
- * server exists. Shutdowns basic services and frees memory
- */
-
-void pike_module_exit(void)
-{
- roxen_php_initialized = 0;
- roxen_sapi_module.shutdown(&roxen_sapi_module);
- if(php_program) free_program(php_program);
-#ifdef ZTS
- tsrm_shutdown();
-#endif
- PHP_DESTROY();
-}
-#endif
diff --git a/sapi/servlet/CREDITS b/sapi/servlet/CREDITS
deleted file mode 100644
index ae4e83e1e2..0000000000
--- a/sapi/servlet/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-Java Servlet
-Sam Ruby
diff --git a/sapi/servlet/EXPERIMENTAL b/sapi/servlet/EXPERIMENTAL
deleted file mode 100644
index 293159a693..0000000000
--- a/sapi/servlet/EXPERIMENTAL
+++ /dev/null
@@ -1,5 +0,0 @@
-this module is experimental,
-its functions may change their names
-or move to extension all together
-so do not rely to much on them
-you have been warned!
diff --git a/sapi/servlet/Makefile.frag b/sapi/servlet/Makefile.frag
deleted file mode 100644
index 3ad40f86ac..0000000000
--- a/sapi/servlet/Makefile.frag
+++ /dev/null
@@ -1,19 +0,0 @@
-
-sapi/servlet/java.c : sapi/servlet/../../ext/java/java.c sapi/servlet/phpsrvlt.jar
- @cp sapi/servlet/../../ext/java/java.c sapi/servlet
-
-sapi/servlet/phpsrvlt.jar : sapi/servlet/servlet.java sapi/servlet/../../ext/java/reflect.java
- $(mkinstalldirs) sapi/servlet/net/php
- @echo library=php4 > sapi/servlet/net/php/reflect.properties
- @echo library=php4 > sapi/servlet/net/php/servlet.properties
- @cp sapi/servlet/formatter.java sapi/servlet/net/php
- @cp sapi/servlet/servlet.java sapi/servlet/net/php
- @cp sapi/servlet/../../ext/java/reflect.java sapi/servlet/net/php
- cd sapi/servlet && javac net/php/reflect.java
- @test ! -f sapi/servlet/reflect.class || mv sapi/servlet/reflect.class sapi/servlet/net/php # bug in KJC javac
- cd sapi/servlet && javac -classpath .:$(SERVLET_CLASSPATH):$(CLASSPATH):. net/php/servlet.java
- @test ! -f sapi/servlet/servlet.class || mv sapi/servlet/servlet.class sapi/servlet/net/php # bug in KJC javac
- cd sapi/servlet && javac -classpath .:$(SERVLET_CLASSPATH):$(CLASSPATH):. net/php/formatter.java
- @test ! -f sapi/servlet/formatter.class || mv sapi/servlet/formatter.class sapi/servlet/net/php # bug in KJC javac
- cd sapi/servlet/ && $(JAVA_JAR) phpsrvlt.jar net/php/*.class net/php/*.properties
- @rm -rf sapi/servlet/net
diff --git a/sapi/servlet/README b/sapi/servlet/README
deleted file mode 100644
index be874d28c1..0000000000
--- a/sapi/servlet/README
+++ /dev/null
@@ -1,113 +0,0 @@
-Java Servlet SAPI Module for PHP 4
-
-
- Introduction
-
- The Java Servlet SAPI Module allows for the execution of PHP 4 as
- a Servlet from within a Java Servlet Engine, such as Apache's
- Jakarta Tomcat [1]. It builds upon the mechanism defined by PHP's
- Java Extension, which can be found in /php4/ext/java.
-
- The primary advantage of this from a PHP perspective is that web
- servers which support servlets typically take great care in
- pooling and reusing Java Virtual Machines (JVMs).
-
- PHP may also be bridged with the Apache Cocoon XML Publishing
- Framework. [2]
-
- A suitably configured system will invoke the PHP binaries through
- JNI and the output of the page will be processed through the
- configured XML parser and placed into the pipeline for processing
- by such filters as XSLT. This enables PHP developers to access the
- powers of Cocoon to separate their content, style, and logic
- without requiring them to write a single line of Java code.
-
- While this code is intended to be able to run on any servlet
- engine, it has only been tested on Apache's Jakarta Tomcat to
- date. Bug reports, success stories and/or patches required to get
- this code to run on other engines would be appreciated; please
- send them to the PHP Development Mailinglist [3].
-
- Note: PHP has a habit of changing the working directory. The Java
- Servlet SAPI Module will eventually change it back, but while PHP
- is running the servlet engine may not be able to load any classes
- from the CLASSPATH which are specified using a relative directory
- syntax, or find the work directory used for administration and JSP
- compilation tasks.
-
-
- Installing PHP as a Servlet into Apache's Jakarta Tomcat [*]
-
- 1.) Build the PHP 4 Java Servlet SAPI Module
-
- The javax.servlet package should be in your CLASSPATH. If you're
- using Tomcat, adding servlet.jar to your CLASSPATH is sufficient.
-
- UNIX
-
- o ./configure --with-servlet --with-java
-
- o Add directory containing libphp4.so to LD_LIBRARY_PATH.
-
- Windows
-
- o Build ext/java/java.dsp, copy php_java.dll to your
- extension_dir directory and enable the extension in the
- php.ini.
-
- o Build sapi/servlet/servlet.dsp.
-
- o Add the directory containing php4ts.dll and phpsrvlt.dll to
- the PATH environment variable.
-
- 2.) Copy phpsrvlt.jar into your $TOMCAT_HOME/shared/lib directory.
-
- 3.) Merge the configuration directives from web.xml file that
- comes with the Java Servlet SAPI Module into your
- $TOMCAT_HOME/conf/web.xml configuration file.
-
- Make sure that the element ordering of the web.xml is legal
- with Tomcat and put all the <servlet> declarations first,
- followed by all the <servlet-mapping> declarations.
-
- Add
-
- <welcome-file>index.php</welcome-file>
-
- to the
-
- <welcome-file-list>
- ...
- </welcome-file-list>
-
- block of your $TOMCAT_HOME/conf/web.xml configuration file.
-
- 4.) Test your installation by creating a test.php file in your
- $TOMCAT_HOME/webapps/ROOT directory with
-
- <?php phpinfo(); ?>
-
- in it.
-
- Access this file in your browser at
-
- http://localhost:8080/test.php
-
- and you should see the familiar output of phpinfo().
-
-
- Installing PHP as a Generator into Apache's Cocoon2 Framework
-
- 1.) Build the Java Servlet SAPI Module as described above.
-
- 2.) Get the Cocoon2 source tree, either by CVS or from a release
- archive; a binary distribution does not suffice. Copy the
- phpsrvlet.jar file into your xml-cocoon2/lib/optional directory
- and build Cocoon.
-
---
- [*] The instructions herein have been tested with Tomcat 4.1.12.
-
- [1] http://jakarta.apache.org/tomcat/
- [2] http://xml.apache.org/cocoon2/
- [3] http://www.php.net/support.php
diff --git a/sapi/servlet/config.m4 b/sapi/servlet/config.m4
deleted file mode 100644
index 05ebd70fad..0000000000
--- a/sapi/servlet/config.m4
+++ /dev/null
@@ -1,54 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for Servlet support)
-AC_ARG_WITH(servlet,
-[ --with-servlet[=DIR] Include servlet support. DIR is the base install
- directory for the JSDK. This SAPI prereqs the
- java extension must be built as a shared dl.],
-[
- if test "$withval" != "no"; then
-
- if test "$withval" = "yes"; then
- SERVLET_CLASSPATH=.
- else
- if test -f $withval/lib/servlet.jar; then
- SERVLET_CLASSPATH=$withval/lib/servlet.jar
- fi
-
- if test -f $withval/lib/jsdk.jar; then
- SERVLET_CLASSPATH=$withval/lib/jsdk.jar
- fi
-
- if test -d $withval/javax; then
- SERVLET_CLASSPATH=$withval
- fi
-
- if test -z "$SERVLET_CLASSPATH"; then
- AC_MSG_RESULT(no)
- AC_MSG_ERROR(unable to find servlet libraries)
- fi
- fi
-
- AC_DEFINE(SAPI_SERVLET, 1, [Whether you use Servlet])
-
- INSTALL_IT="\$(mkinstalldirs) \$(libdir)"
- INSTALL_IT="$INSTALL_IT; \$(INSTALL) -m 0755 \$(top_srcdir)/sapi/servlet/phpsrvlt.jar \$(libdir)"
- INSTALL_IT="$INSTALL_IT; \$(INSTALL) -m 0755 $SAPI_SHARED \$(libdir)"
- PHP_SAPI=servlet
- PHP_BUILD_THREAD_SAFE
- EXTRA_INCLUDES="$EXTRA_INCLUDES \$(JAVA_INCLUDE)"
- PHP_SELECT_SAPI(servlet, shared, servlet.c)
- PHP_ADD_SOURCES(/sapi/servlet, java.c,, sapi)
- PHP_ADD_MAKEFILE_FRAGMENT(sapi/servlet/Makefile.frag)
-
- AC_MSG_RESULT(yes)
- else
- AC_MSG_RESULT(no)
- fi
-],[
- AC_MSG_RESULT(no)
-])
-
-PHP_SUBST(SERVLET_CLASSPATH)
diff --git a/sapi/servlet/cookies.php b/sapi/servlet/cookies.php
deleted file mode 100644
index bcc4c40aae..0000000000
--- a/sapi/servlet/cookies.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<html>
-<body bgcolor="white">
-<head>
-<title>Cookies Example</title>
-</head>
-<body>
-<h3>Cookies Example</h3>
-
-<?
- $cookies = $request->cookies;
-
- // print out cookies
-
- if (!current($cookies)) {
- echo "Your browser isn't sending any cookies\n";
- } else {
- echo "Your browser is sending the following cookies:<br>\n";
-
- foreach ($cookies as $cookie) {
- echo "Cookie Name: $cookie->name<br>Cookie value: $cookie->value<br>\n";
- }
- }
-
- // set a cookie
-
- if ($cookieName) {
- $response->addCookie(new Java("javax.servlet.http.Cookie", $cookieName, $cookieValue));
- echo "<p>You just sent the following cookie to your browser:<br>\n";
- echo "Name: $cookieName<br>Value: $cookieValue<P>\n";
- }
-
-?>
-<P>
-Create a cookie to send to your browser<br>
-<form action="<?PHP echo $PHP_SELF ?>" method=POST>
-Name: <input type=text length=20 name=cookieName><br>
-Value: <input type=text length=20 name=cookieValue><br>
-<input type=submit></form>
-</body>
-</html>
-
diff --git a/sapi/servlet/date.php b/sapi/servlet/date.php
deleted file mode 100644
index 1146d31fab..0000000000
--- a/sapi/servlet/date.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<html>
-<!--
- Copyright (c) 1999 The Apache Software Foundation. All rights
- reserved.
--->
-
-<body bgcolor="white">
-<?php $clock=new Java("dates.JspCalendar"); ?>
-
-<font size=4>
-<ul>
-<li> Day of month: is <?php echo $clock->dayOfMonth ?>
-<li> Year: is <?php echo $clock->year ?>
-<li> Month: is <?php echo $clock->month ?>
-<li> Time: is <?php echo $clock->time ?>
-<li> Date: is <?php echo $clock->date ?>
-<li> Day: is <?php echo $clock->day ?>
-<li> Day Of Year: is <?php echo $clock->dayOfYear ?>
-<li> Week Of Year: is <?php echo $clock->weekOfYear ?>
-<li> era: is <?php echo $clock->era ?>
-<li> DST Offset: is <?php echo $clock->dSTOffset ?>
-<li> Zone Offset: is <?php echo $clock->zoneOffset ?>
-</ul>
-</font>
-
-</body>
-</html>
-
diff --git a/sapi/servlet/formatter.java b/sapi/servlet/formatter.java
deleted file mode 100644
index 46c8c3a6e1..0000000000
--- a/sapi/servlet/formatter.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2002 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sam Ruby (rubys@us.ibm.com) |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-package net.php;
-
-import javax.servlet.*;
-import javax.servlet.http.*;
-
-public class formatter extends servlet {
- public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {
- display_source_mode = true;
- super.service(request, response);
- }
-}
diff --git a/sapi/servlet/jinfo.php b/sapi/servlet/jinfo.php
deleted file mode 100644
index f20bbfb27d..0000000000
--- a/sapi/servlet/jinfo.php
+++ /dev/null
@@ -1,5 +0,0 @@
-<?
-
- phpinfo();
-
-?>
diff --git a/sapi/servlet/jver.php b/sapi/servlet/jver.php
deleted file mode 100644
index e5e029c6e4..0000000000
--- a/sapi/servlet/jver.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<html>
-<?
-
- $system = new Java("java.lang.System");
- print "Java version=".$system->getProperty("java.version")." <br>\n";
- print "Java vendor=".$system->getProperty("java.vendor")." <p>\n\n";
- print "OS=".$system->getProperty("os.name")." ".
- $system->getProperty("os.version")." on ".
- $system->getProperty("os.arch")." <br>\n";
-
- $formatter = new Java("java.text.SimpleDateFormat",
- "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");
-
- print $formatter->format(new Java("java.util.Date"))."\n";
-
-?>
-</html>
diff --git a/sapi/servlet/reqheaders.php b/sapi/servlet/reqheaders.php
deleted file mode 100644
index db04aed3dc..0000000000
--- a/sapi/servlet/reqheaders.php
+++ /dev/null
@@ -1,24 +0,0 @@
-<html>
-<body bgcolor="white">
-<head>
-<title>Request Header Example</title>
-</head>
-<body>
-<h3>Request Header Example</h3>
-<table border=0>
-
-<?php
-
- $e = $request->headerNames;
- while ($e->hasMoreElements()) {
- $name = $e->nextElement();
- $value = $request->getHeader($name);
- print "<tr><td bgcolor=\"#CCCCCC\">$name\n";
- print "</td><td>$value</td></tr>\n";
- }
-
-?>
-
-</table>
-</body>
-</html>
diff --git a/sapi/servlet/reqinfo.php b/sapi/servlet/reqinfo.php
deleted file mode 100644
index 37d453baf9..0000000000
--- a/sapi/servlet/reqinfo.php
+++ /dev/null
@@ -1,29 +0,0 @@
-<html>
-<body>
-<head>
-<title>Request Information Example</title>
-</head>
-<body bgcolor="white">
-<h3>Request Information Example</h3>
-<table border=0><tr><td>
-Method:
-</td><td>
-<?php print $request->method ?>
-</td></tr><tr><td>
-Request URI:
-</td><td>
-<?php print $request->requestURI ?>
-</td></tr><tr><td>
-Protocol:
-</td><td>
-<?php print $request->protocol ?>
-</td></tr><tr><td>
-Path Info:
-</td><td>
-<?php print $request->pathInfo ?>
-</td></tr><tr><td>
-Remote Address:
-</td><td>
-<?php print $request->remoteAddr ?>
-</table>
-
diff --git a/sapi/servlet/reqparams.php b/sapi/servlet/reqparams.php
deleted file mode 100644
index f968b2753d..0000000000
--- a/sapi/servlet/reqparams.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<html>
-<body>
-<head>
-<title>Request Parameters Example</title>
-</head>
-<body bgcolor="white">
-<h3>Request Parameters Example</h3>
-Parameters in this request:<br>
-<?php
- $e = $request->getParameterNames();
-
- if (!$e->hasMoreElements()) {
- echo "No Parameters, Please enter some";
- }
-
- while ($e->hasMoreElements()) {
- $name = $e->nextElement();
- $value = $request->getParameter($name);
- echo "$name = $value<br>\n";
- }
-
-?>
-<P>
-<form action="<?php echo $PHP_SELF ?>" method=POST>
-First Name:
-<input type=text size=20 name=firstname>
-<br>
-Last Name:
-<input type=text size=20 name=lastname>
-<br>
-<input type=submit>
-</form>
-</body>
-</html>
-
diff --git a/sapi/servlet/servlet.c b/sapi/servlet/servlet.c
deleted file mode 100644
index 6635f64085..0000000000
--- a/sapi/servlet/servlet.c
+++ /dev/null
@@ -1,397 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sam Ruby (rubys@us.ibm.com) |
- +----------------------------------------------------------------------+
-*/
-
-#include <jni.h>
-
-#include "php.h"
-#include "php_globals.h"
-
-#include "SAPI.h"
-
-#include <stdio.h>
-#include "php.h"
-#ifdef PHP_WIN32
-#include "win32/time.h"
-#include "win32/signal.h"
-#include <process.h>
-#endif
-#if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-#if HAVE_SETLOCALE
-#include <locale.h>
-#endif
-#include "zend.h"
-#include "php_ini.h"
-#include "php_globals.h"
-#include "php_main.h"
-#include "fopen_wrappers.h"
-#include "ext/standard/php_standard.h"
-#include "ext/standard/php_dir.h"
-#ifdef PHP_WIN32
-#include <io.h>
-#include <fcntl.h>
-#include "win32/php_registry.h"
-#endif
-
-#include "zend_compile.h"
-#include "zend_execute.h"
-#include "zend_highlight.h"
-#include "zend_indent.h"
-
-JNIEXPORT void JNICALL Java_net_php_reflect_setEnv
- (JNIEnv *newJenv, jclass self TSRMLS_DC);
-
-typedef struct {
- JNIEnv *jenv;
- jobject servlet;
- char *cookies;
-} servlet_request;
-
-extern zend_module_entry java_module_entry;
-
-/***************************************************************************/
-
-/*
- * JNI convenience utilities
- */
-
-#define SETSTRING(target, source) \
- { const char *UTFString; \
- if (source) { \
- UTFString = (*jenv)->GetStringUTFChars(jenv, source, 0); \
- target = estrdup(UTFString); \
- (*jenv)->ReleaseStringUTFChars(jenv, source, UTFString); \
- } else { \
- target = 0; \
- } }
-
-#define FREESTRING(target) \
- { if (target) { efree(target); target=0; } }
-
-void ThrowIOException (JNIEnv *jenv, char *msg) {
- jclass iox = (*jenv)->FindClass (jenv, "java/io/IOException");
- (*jenv)->ThrowNew (jenv, iox, (msg?msg:"null") );
-}
-
-void ThrowServletException (JNIEnv *jenv, char *msg) {
- jclass sx = (*jenv)->FindClass (jenv, "javax/servlet/ServletException");
- (*jenv)->ThrowNew (jenv, sx, msg);
-}
-
-/***************************************************************************/
-
-/*
- * sapi callbacks
- */
-
-static int sapi_servlet_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- if (!SG(server_context)) {
- fprintf(stderr, str);
- return 0;
- }
-
- {
- JNIEnv *jenv = ((servlet_request*)SG(server_context))->jenv;
- jobject servlet = ((servlet_request*)SG(server_context))->servlet;
-
- jclass servletClass = (*jenv)->GetObjectClass(jenv, servlet);
- jmethodID write = (*jenv)->GetMethodID(jenv, servletClass, "write",
- "(Ljava/lang/String;)V");
- char *copy = malloc(str_length+1);
- jstring arg;
- memcpy(copy, str, str_length);
- copy[str_length] = 0;
- arg=(*jenv)->NewStringUTF(jenv, copy);
- free(copy);
- (*jenv)->CallVoidMethod(jenv, servlet, write, arg);
- (*jenv)->DeleteLocalRef(jenv, arg);
- return str_length;
- }
-}
-
-
-static void sapi_servlet_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC)
-{
- if (!sapi_header) return;
- if (!SG(server_context)) return;
-
- {
- JNIEnv *jenv = ((servlet_request*)SG(server_context))->jenv;
- jobject servlet = ((servlet_request*)SG(server_context))->servlet;
-
- jclass servletClass = (*jenv)->GetObjectClass(jenv, servlet);
- jmethodID header = (*jenv)->GetMethodID(jenv, servletClass, "header",
- "(Ljava/lang/String;)V");
- jstring arg=(*jenv)->NewStringUTF(jenv, sapi_header->header);
- (*jenv)->CallVoidMethod(jenv, servlet, header, arg);
- (*jenv)->DeleteLocalRef(jenv, arg);
- }
-}
-
-
-static int sapi_servlet_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
- if (count_bytes == 0) {
- return 0;
- } else {
- JNIEnv *jenv = ((servlet_request*)SG(server_context))->jenv;
- jobject servlet = ((servlet_request*)SG(server_context))->servlet;
-
- jclass servletClass = (*jenv)->GetObjectClass(jenv, servlet);
- jmethodID readPost = (*jenv)->GetMethodID(jenv, servletClass,
- "readPost", "(I)Ljava/lang/String;");
- jstring post = (*jenv)->CallObjectMethod(jenv, servlet, readPost,
- count_bytes);
-
- const char *postAsUTF = (*jenv)->GetStringUTFChars(jenv, post, 0);
- uint read_bytes=(*jenv)->GetStringLength(jenv, post);
- if (read_bytes>count_bytes) read_bytes=count_bytes;
-
- memcpy(buffer, postAsUTF, read_bytes);
- if (read_bytes<count_bytes) buffer[read_bytes]=0;
-
- (*jenv)->ReleaseStringUTFChars(jenv, post, postAsUTF);
-
- return read_bytes;
- }
-}
-
-
-static char *sapi_servlet_read_cookies(TSRMLS_D)
-{
- JNIEnv *jenv = ((servlet_request*)SG(server_context))->jenv;
- jobject servlet = ((servlet_request*)SG(server_context))->servlet;
-
- jclass servletClass = (*jenv)->GetObjectClass(jenv, servlet);
- jmethodID readCookies = (*jenv)->GetMethodID(jenv, servletClass,
- "readCookies", "()Ljava/lang/String;");
- jstring cookies = (*jenv)->CallObjectMethod(jenv, servlet, readCookies);
-
- SETSTRING( ((servlet_request*)SG(server_context))->cookies, cookies);
-
- return ((servlet_request*)SG(server_context))->cookies;
-}
-
-/***************************************************************************/
-
-
-/*
- * sapi maintenance
- */
-
-static int php_servlet_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
- return FAILURE;
- } else {
- return SUCCESS;
- }
-}
-
-static sapi_module_struct servlet_sapi_module = {
- "java_servlet", /* name */
- "Java Servlet", /* pretty name */
-
- php_servlet_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- sapi_servlet_ub_write, /* unbuffered write */
- NULL, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error, /* error handler */
-
- NULL, /* header handler */
- NULL, /* send headers handler */
- sapi_servlet_send_header, /* send header handler */
-
- sapi_servlet_read_post, /* read POST data */
- sapi_servlet_read_cookies, /* read Cookies */
-
- NULL, /* register server variables */
- NULL, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-
-JNIEXPORT void JNICALL Java_net_php_servlet_startup
- (JNIEnv *jenv, jobject self)
-{
-
-#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
-#endif
-
- sapi_startup(&servlet_sapi_module);
-
- if (php_module_startup(&servlet_sapi_module, &java_module_entry, 1)==FAILURE) {
- ThrowServletException(jenv,"module startup failure");
- return;
- }
-}
-
-
-JNIEXPORT void JNICALL Java_net_php_servlet_shutdown
- (JNIEnv *jenv, jobject self)
-{
- TSRMLS_FETCH();
-
- php_module_shutdown(TSRMLS_C);
-#ifdef ZTS
- tsrm_shutdown();
-#endif
- return;
-}
-
-/***************************************************************************/
-
-/*
- * define a Java object to PHP
- */
-
-JNIEXPORT jlong JNICALL Java_net_php_servlet_define
- (JNIEnv *jenv, jobject self, jstring name)
-{
- pval *pzval;
- jlong addr = 0;
- const char *nameAsUTF = (*jenv)->GetStringUTFChars(jenv, name, 0);
- TSRMLS_FETCH();
-
- MAKE_STD_ZVAL(pzval);
- addr = (jlong)(long) pzval;
-
- zend_hash_add(&EG(symbol_table), (char*)nameAsUTF,
- strlen(nameAsUTF)+1, &pzval, sizeof(pval *), NULL);
- (*jenv)->ReleaseStringUTFChars(jenv, name, nameAsUTF);
-
- return addr;
-}
-
-/*
- * execute a script
- */
-
-JNIEXPORT void JNICALL Java_net_php_servlet_send
- (JNIEnv *jenv, jobject self,
- jstring requestMethod, jstring queryString,
- jstring requestURI, jstring pathTranslated,
- jstring contentType, jint contentLength,
- jstring authUser, jboolean display_source_mode)
-{
- zend_file_handle file_handle;
- int retval;
-#ifndef VIRTUAL_DIR
- char cwd[MAXPATHLEN];
-#endif
- TSRMLS_FETCH();
-
- zend_first_try {
- SG(server_context) = emalloc(sizeof(servlet_request));
- ((servlet_request*)SG(server_context))->jenv=jenv;
- ((servlet_request*)SG(server_context))->servlet=self;
- ((servlet_request*)SG(server_context))->cookies=0;
-
- /*
- * Initialize the request
- */
-
- SETSTRING( SG(request_info).auth_user, authUser );
- SETSTRING( SG(request_info).request_method, requestMethod );
- SETSTRING( SG(request_info).query_string, queryString );
- SETSTRING( SG(request_info).request_uri, requestURI );
- SETSTRING( SG(request_info).content_type, contentType );
- SG(sapi_headers).http_response_code = 200;
- SG(request_info).content_length = contentLength;
- SG(request_info).auth_password = NULL;
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- ThrowServletException(jenv,"request startup failure");
- return;
- }
-
- /*
- * Parse the file
- */
- SETSTRING( SG(request_info).path_translated, pathTranslated );
-#ifdef VIRTUAL_DIR
- retval = php_fopen_primary_script(&file_handle TSRMLS_CC);
-#else
- /*
- * The java runtime doesn't like the working directory to be
- * changed, so save it and change it back as quickly as possible
- * in the hopes that Java doesn't notice.
- */
- getcwd(cwd, MAXPATHLEN);
- retval = php_fopen_primary_script(&file_handle TSRMLS_CC);
- chdir(cwd);
-#endif
-
- if (retval == FAILURE) {
- php_request_shutdown((void *) 0);
- php_module_shutdown(TSRMLS_C);
- ThrowIOException(jenv, file_handle.filename);
- return;
- }
-
- /*
- * Execute the request
- */
- Java_net_php_reflect_setEnv(jenv, 0 TSRMLS_CC);
-
- if (display_source_mode) {
- zend_syntax_highlighter_ini syntax_highlighter_ini;
-
- if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {
- php_get_highlight_struct(&syntax_highlighter_ini);
- sapi_send_headers(TSRMLS_C);
- zend_highlight(&syntax_highlighter_ini TSRMLS_CC);
- }
- } else {
- php_execute_script(&file_handle TSRMLS_CC);
- php_header(); /* Make sure headers have been sent */
- }
-
- /*
- * Clean up
- */
-
- FREESTRING(SG(request_info).query_string);
- FREESTRING(SG(request_info).request_uri);
- FREESTRING(SG(request_info).path_translated);
- FREESTRING(((servlet_request*)SG(server_context))->cookies);
- efree(SG(server_context));
- SG(server_context)=0;
-
- if (!display_source_mode) php_request_shutdown((void *) 0);
- } zend_catch {
- ThrowServletException(jenv,"bailout");
- } zend_end_try();
-}
-
diff --git a/sapi/servlet/servlet.dsp b/sapi/servlet/servlet.dsp
deleted file mode 100644
index 4691b87e31..0000000000
--- a/sapi/servlet/servlet.dsp
+++ /dev/null
@@ -1,286 +0,0 @@
-# Microsoft Developer Studio Project File - Name="servlet" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=servlet - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "servlet.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "servlet.mak" CFG="servlet - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "servlet - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "servlet - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "servlet - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "servlet - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "servlet - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "..\..\Release"
-# PROP BASE Intermediate_Dir "..\..\Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\main" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "NDEBUG" /D ZEND_DEBUG=0 /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 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 /out:"..\..\Release/phpsrvlt.dll" /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Release"
-
-!ELSEIF "$(CFG)" == "servlet - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "..\..\Debug"
-# PROP BASE Intermediate_Dir "..\..\Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\main" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "_DEBUG" /D ZEND_DEBUG=1 /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /FR /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "_DEBUG"
-# ADD RSC /l 0x40d /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /dll /debug /machine:I386 /out:"..\..\Debug/phpsrvlt.dll" /pdbtype:sept /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Debug"
-
-!ELSEIF "$(CFG)" == "servlet - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "..\..\Debug_TS"
-# PROP BASE Intermediate_Dir "..\..\Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\..\Zend" /I "..\..\main" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "_DEBUG" /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /FR /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\TSRM" /I "..\..\Zend" /I "..\..\main" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "_DEBUG" /D ZEND_DEBUG=1 /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /D "ZTS" /FR /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "_DEBUG"
-# ADD RSC /l 0x40d /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 php4ts_debug.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 /debug /machine:I386 /out:"..\..\Debug_TS/phpsrvlt.dll" /pdbtype:sept /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Debug_TS"
-
-!ELSEIF "$(CFG)" == "servlet - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "..\..\Release_TS"
-# PROP BASE Intermediate_Dir "..\..\Release_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\..\Zend" /I "..\..\main" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "NDEBUG" /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\TSRM" /I "..\..\Zend" /I "..\..\main" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "NDEBUG" /D ZEND_DEBUG=0 /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /D "ZTS" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php4ts.lib 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 /out:"..\..\Release_TS/phpsrvlt.dll" /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-
-!ENDIF
-
-# Begin Target
-
-# Name "servlet - Win32 Release"
-# Name "servlet - Win32 Debug"
-# Name "servlet - Win32 Debug_TS"
-# Name "servlet - Win32 Release_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=..\..\ext\rpc\java\java.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\servlet.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# End Group
-# Begin Group "Java Files"
-
-# PROP Default_Filter "java"
-# Begin Source File
-
-SOURCE=.\servlet.java
-
-!IF "$(CFG)" == "servlet - Win32 Release"
-
-USERDEP__SERVL="..\..\ext\rpc\java\reflect.java"
-# Begin Custom Build
-OutDir=.\..\..\Release
-InputPath=.\servlet.java
-
-"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- if not exist net mkdir net
- if not exist net\php mkdir net\php
- copy *.java net\php > nul
- copy ..\..\ext\rpc\java\reflect.java net\php > nul
- echo library=phpsrvlt>net/php/reflect.properties
- echo library=phpsrvlt>net/php/servlet.properties
- cd net\php
- $(JAVA_HOME)\bin\javac -O *.java
- cd ..\..
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties
- erase net\php\servlet.*
- erase net\php\formatter.*
- erase net\php\reflect.*
- rmdir net\php
- rmdir net
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "servlet - Win32 Debug"
-
-USERDEP__SERVL="..\..\ext\rpc\java\reflect.java"
-# Begin Custom Build
-OutDir=.\..\..\Debug
-InputPath=.\servlet.java
-
-"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- if not exist net mkdir net
- if not exist net\php mkdir net\php
- copy *.java net\php > nul
- copy ..\..\ext\rpc\java\reflect.java net\php > nul
- echo library=phpsrvlt>net/php/reflect.properties
- echo library=phpsrvlt>net/php/servlet.properties
- cd net\php
- $(JAVA_HOME)\bin\javac -g *.java
- cd ..\..
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties
- erase net\php\servlet.*
- erase net\php\formatter.*
- erase net\php\reflect.*
- rmdir net\php
- rmdir net
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "servlet - Win32 Debug_TS"
-
-USERDEP__SERVL="..\..\ext\rpc\java\reflect.java"
-# Begin Custom Build
-OutDir=.\..\..\Debug_TS
-InputPath=.\servlet.java
-
-"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- if not exist net mkdir net
- if not exist net\php mkdir net\php
- copy *.java net\php > nul
- copy ..\..\ext\rpc\java\reflect.java net\php > nul
- echo library=phpsrvlt>net/php/reflect.properties
- echo library=phpsrvlt>net/php/servlet.properties
- cd net\php
- $(JAVA_HOME)\bin\javac -g *.java
- cd ..\..
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties
- erase net\php\servlet.*
- erase net\php\formatter.*
- erase net\php\reflect.*
- rmdir net\php
- rmdir net
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "servlet - Win32 Release_TS"
-
-USERDEP__SERVL="..\..\ext\rpc\java\reflect.java"
-# Begin Custom Build
-OutDir=.\..\..\Release_TS
-InputPath=.\servlet.java
-
-"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- if not exist net mkdir net
- if not exist net\php mkdir net\php
- copy *.java net\php > nul
- copy ..\..\ext\rpc\java\reflect.java net\php > nul
- echo library=phpsrvlt>net/php/reflect.properties
- echo library=phpsrvlt>net/php/servlet.properties
- cd net\php
- $(JAVA_HOME)\bin\javac -O *.java
- cd ..\..
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties
- erase net\php\servlet.*
- erase net\php\formatter.*
- erase net\php\reflect.*
- rmdir net\php
- rmdir net
-
-# End Custom Build
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\servlet.java
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\jtest.php
-# End Source File
-# End Target
-# End Project
diff --git a/sapi/servlet/servlet.java b/sapi/servlet/servlet.java
deleted file mode 100644
index 8cfbc29406..0000000000
--- a/sapi/servlet/servlet.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2002 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sam Ruby (rubys@us.ibm.com) |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-package net.php;
-
-import java.io.IOException;
-import java.net.URLEncoder;
-import java.util.Enumeration;
-import javax.servlet.*;
-import javax.servlet.http.*;
-
-import java.lang.reflect.Method;
-
-public class servlet extends HttpServlet {
- char slash = System.getProperty("file.separator").charAt(0);
-
- HttpServletRequest request;
- HttpServletResponse response;
- ServletInputStream stream;
-
- static int startup_count = 0;
-
- protected boolean display_source_mode = false;
- private Method addHeader;
-
- // Native methods
-
- public native void startup();
- public native long define(String name);
- public native void send(String requestMethod,
- String queryString,
- String pathInfo,
- String pathTranslated,
- String contentType,
- int contentLength,
- String authUser,
- boolean display_source_mode
- );
- public native void shutdown();
-
- // SAPI Callbacks
-
- public String readPost(int bytes) {
- String result;
-
- if (!request.getMethod().equals("POST")) {
- result = request.getQueryString();
- } else {
- Enumeration enum = request.getParameterNames();
- String concat = "";
- result = "";
-
- while (enum.hasMoreElements()) {
- String name = (String)enum.nextElement();
- String value = request.getParameter(name);
-
- try {
- result += concat + name + "=" + URLEncoder.encode(value, "UTF-8");
- }
-
- catch (Exception e) {
- e.printStackTrace(System.err);
- }
-
- concat = "&";
- }
- }
-
- if (result == null) return "";
-
- return result;
- }
-
- public String readCookies() {
- reflect.setResult(define("request"), request);
- reflect.setResult(define("response"), response);
- reflect.setResult(define("PHP_SELF"), request.getRequestURI());
-
- return request.getHeader("cookie");
- }
-
- public void header(String data) {
- // try to send the header using the most specific servlet API
- // as possible (some servlet engines will add a content type
- // header unless the setContentType method is called).
- try {
- if (data.startsWith("Content-type: ")) {
- response.setContentType(data.substring(data.indexOf(" ") + 1));
- }
-
- else if (data.startsWith("Location: ")) {
- response.sendRedirect(data.substring(data.indexOf(" ") + 1));
- } else if (data.startsWith("HTTP/1")) {
- return; // this one is added from servlet container (Tomcat 4.1), we have to check for others
- }
-
- else {
- int colon = data.indexOf(": ");
-
- if (colon > 0) {
- try {
- addHeader.invoke(response, new Object[]
- { data.substring(0, colon), data.substring(colon + 2) } );
- }
-
- catch (Exception e) {
- e.printStackTrace(System.err);
- }
- }
-
- else {
- write(data);
- }
- }
- }
-
- catch (IOException e) {
- e.printStackTrace(System.err);
- }
- }
-
- public void write(String data) {
- try {
- response.getWriter().print(data);
- }
-
- catch (IOException e) {
- e.printStackTrace(System.err);
- }
- }
-
- // Servlet interface
-
- public void init(ServletConfig config)
- throws ServletException {
- super.init(config);
-
- // first time in, initialize native code
- if (0 == startup_count++) {
- reflect.loadLibrary("servlet");
- startup();
- }
-
- // try to find the addHeader method (added in the servlet API 2.2)
- // otherwise settle for the setHeader method
-
- try {
- Class c = Class.forName("javax.servlet.http.HttpServletResponse");
- Method method[] = c.getDeclaredMethods();
-
- for (int i = 0; i < method.length; i++) {
- if (method[i].getName().equals("addHeader")) {
- addHeader = method[i];
- break;
- }
-
- if (method[i].getName().equals("setHeader")) {
- addHeader = method[i];
- }
- }
- }
-
- catch (Exception e) {
- e.printStackTrace(System.err);
- }
- }
-
- public void service(HttpServletRequest request, HttpServletResponse response, String contextPath)
- throws ServletException {
- this.request = request;
- this.response = response;
-
- send(request.getMethod(),
- request.getQueryString(),
- request.getRequestURI(),
- contextPath,
- request.getContentType(),
- request.getContentLength(),
- request.getRemoteUser(),
- display_source_mode
- );
-
- try {
- if (stream != null) stream.close();
- }
-
- catch (IOException e) {
- throw new ServletException(e.toString());
- }
- }
-
- public void service(HttpServletRequest request, HttpServletResponse response)
- throws ServletException {
- String servletPath = request.getServletPath();
- String contextPath = getServletContext().getRealPath(servletPath);
-
- service(request, response, contextPath);
- }
-
- public void destroy() {
- if (0 == --startup_count) shutdown();
- super.destroy();
- }
-}
diff --git a/sapi/servlet/sessions.php b/sapi/servlet/sessions.php
deleted file mode 100644
index 463b1b5e92..0000000000
--- a/sapi/servlet/sessions.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<html>
-<body bgcolor="white">
-<head>
-<title>Sessions Example</title>
-</head>
-<body>
-<h3>Sessions Example</h3>
-<?php
-
- // print session info
-
- $session = $request->session;
- $created = new Java("java.util.Date", $session->creationTime);
- $accessed = new Java("java.util.Date", $session->lastAccessedTime);
-
- print "Session ID: $session->id<br>\n";
- print "Created: " . $created->toString() . "<br>\n";
- print "Last Accessed: " . $accessed->toString() . "<br>\n";
-
- // set session info if needed
-
- if ($dataName) $session->setAttribute($dataName, $dataValue);
-
- // print session contents
-
- print "<P>\n";
- print "The following data is in your session:<br>\n";
- $e = $session->attributeNames;
- while ($e->hasMoreElements()) {
- $name = $e->nextElement();
- $value = $session->getAttribute($name);
- print "$name = $value<br>\n";
- }
-
-?>
-<P>
-<form action="<?php echo $PHP_SELF ?>" method=POST>
-Name of Session Attribute:
-<input type=text size=20 name=dataName>
-<br>
-Value of Session Attribute:
-<input type=text size=20 name=dataValue>
-<br>
-<input type=submit>
-</form>
-<P>GET based form:<br>
-<form action="<?php echo $PHP_SELF ?>" method=GET>
-Name of Session Attribute:
-<input type=text size=20 name=dataName>
-<br>
-Value of Session Attribute:
-<input type=text size=20 name=dataValue>
-<br>
-<input type=submit>
-</form>
-<p><a href="<?php echo $PHP_SELF ?>?dataName=foo&dataValue=bar" >URL encoded </a>
-</body>
-</html>
-</body>
-</html>
diff --git a/sapi/servlet/web.xml b/sapi/servlet/web.xml
deleted file mode 100644
index b0703a3614..0000000000
--- a/sapi/servlet/web.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-
-<!DOCTYPE web-app
- PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
- "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
-
-<web-app>
- <servlet>
- <servlet-name>
- php
- </servlet-name>
- <servlet-class>
- net.php.servlet
- </servlet-class>
- </servlet>
- <servlet>
- <servlet-name>
- php-formatter
- </servlet-name>
- <servlet-class>
- net.php.formatter
- </servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>
- php
- </servlet-name>
- <url-pattern>
- *.php
- </url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>
- php-formatter
- </servlet-name>
- <url-pattern>
- *.phps
- </url-pattern>
- </servlet-mapping>
-</web-app>
diff --git a/sapi/thttpd/CREDITS b/sapi/thttpd/CREDITS
deleted file mode 100644
index 8f02f36f4f..0000000000
--- a/sapi/thttpd/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-thttpd
-Sascha Schumann
diff --git a/sapi/thttpd/README b/sapi/thttpd/README
deleted file mode 100644
index 1e80a01956..0000000000
--- a/sapi/thttpd/README
+++ /dev/null
@@ -1,85 +0,0 @@
-README FOR THTTPD MODULE (by Sascha Schumann)
-($Date$)
-
- This is a SAPI module for PHP 4.x supporting thttpd, the tiny,
- turbo, throttling HTTP server by Jef Poskanzer.
-
- NOTE: All HTTP requests will be serialized. That means, one long running
- script will block all other requests. Choose another web server,
- if you want to execute arbitrarily long running scripts.
-
- The module contains a patch against version 2.21b of thttpd. The patch
- fixes a number of bugs and adds some functionality:
-
- - HTTP/1.1 Persistent Connection/Pipeline Support
- - PHP Scripting (**.php by default)
- - Highlighting PHP Scripts (**.phps by default)
- - Fast Accept Loop (unique to PHP)
- - Periodic Connection Expiring (unique to PHP)
- - Log to stdout (logfile=-)
- - Fixes the Host: header vulnerability (affects vhosts only)
- - Asynchronous request body handling (e.g. for POSTs)
- - Accept filter for Linux
- - Fix for non-blocking sending of thttpd-generated responses
-
- You can configure the filename extensions by creating a config file for
- thttpd and setting these entries:
-
- phppat=PATTERN
- phpspat=PATTERN
-
- The PATTERN has the same format as defined here:
-
- http://acme.com/software/thttpd/options.html#CGI_PATTERN
-
- "**.php" means: match any file ending in .php in any directory.
- Setting the pattern from the command line is not supported.
-
- NOTE: This version supports *only* thttpd 2.21b, no prior or later
- version.
-
- This is a functional and stable module (it runs a large application
- like IMP 2.2.0 without any problems). Its original intention was to
- demonstrate the ability of PHP to work in every web server environment.
-
-REQUIRED DOWNLOADS
-
- 1. thttpd 2.21b (2.20 or +2.22beta will _not_ work)
-
- Full Distribution:
- http://www.acme.com/software/thttpd/thttpd-2.21b.tar.gz
-
- 2. PHP 4.x
-
- Download:
- http://www.php.net/
-
- Snapshots from CVS:
- http://snaps.php.net/
-
-
-BUILD INSTRUCTIONS
-
- 1. Extract software packages
-
- $ gunzip -c thttpd-2.xx.tar.gz | tar xf -
- $ gunzip -c php-*.tar.gz | tar xf -
-
- 2. Prepare PHP
-
- $ cd php-*
- $ ./configure \
- --with-thttpd=../thttpd-2.xx \
- <further PHP options>
- $ make install
- $ cd ..
-
- You can see the list of valid PHP options by executing
-
- $ ./configure --help
-
- 3. Configure, compile, install thttpd
-
- Now follow the thttpd instructions. The Makefile template of
- thttpd was changed to automatically use the components
- required by PHP.
diff --git a/sapi/thttpd/config.m4 b/sapi/thttpd/config.m4
deleted file mode 100644
index 5cdb446f5e..0000000000
--- a/sapi/thttpd/config.m4
+++ /dev/null
@@ -1,33 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_ARG_WITH(thttpd,
-[ --with-thttpd=SRCDIR Build PHP as thttpd module],[
- if test ! -d $withval; then
- AC_MSG_RESULT(thttpd directory does not exist ($withval))
- fi
- if egrep thttpd.2.21b $withval/version.h >/dev/null; then
- :
- else
- AC_MSG_ERROR([This version only supports thttpd-2.21b])
- fi
- PHP_EXPAND_PATH($withval, THTTPD)
- PHP_TARGET_RDYNAMIC
- INSTALL_IT="\
- echo 'PHP_LIBS = -L. -lphp4 \$(PHP_LIBS) \$(EXTRA_LIBS)' > $THTTPD/php_makefile; \
- echo 'PHP_LDFLAGS = \$(NATIVE_RPATHS) \$(PHP_LDFLAGS)' >> $THTTPD/php_makefile; \
- echo 'PHP_CFLAGS = \$(COMMON_FLAGS) \$(CFLAGS_CLEAN) \$(CPPFLAGS) \$(EXTRA_CFLAGS)' >> $THTTPD/php_makefile; \
- \$(LN_S) $abs_srcdir/sapi/thttpd/thttpd.c $THTTPD/php_thttpd.c; \
- \$(LN_S) $abs_srcdir/sapi/thttpd/php_thttpd.h $abs_builddir/$SAPI_STATIC $THTTPD/;\
- test -f $THTTPD/php_patched || \
- (cd $THTTPD && patch < $abs_srcdir/sapi/thttpd/thttpd_patch && touch php_patched)"
- PHP_THTTPD="yes, using $THTTPD"
- PHP_ADD_INCLUDE($THTTPD)
- PHP_SELECT_SAPI(thttpd, static)
-],[
- PHP_THTTPD=no
-])
-
-AC_MSG_CHECKING(for thttpd)
-AC_MSG_RESULT($PHP_THTTPD)
diff --git a/sapi/thttpd/php.sym b/sapi/thttpd/php.sym
deleted file mode 100644
index 2214d3964d..0000000000
--- a/sapi/thttpd/php.sym
+++ /dev/null
@@ -1,3 +0,0 @@
-thttpd_php_request
-thttpd_php_init
-thttpd_php_shutdown
diff --git a/sapi/thttpd/php_thttpd.h b/sapi/thttpd/php_thttpd.h
deleted file mode 100644
index 3563961f80..0000000000
--- a/sapi/thttpd/php_thttpd.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-#ifndef PHP_THTTPD_H
-#define PHP_THTTPD_H
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <libhttpd.h>
-
-void thttpd_php_shutdown(void);
-void thttpd_php_init(void);
-off_t thttpd_php_request(httpd_conn *hc, int show_source);
-
-void thttpd_register_on_close(void (*)(int));
-void thttpd_closed_conn(int fd);
-int thttpd_get_fd(void);
-void thttpd_set_dont_close(void);
-
-#endif
diff --git a/sapi/thttpd/stub.c b/sapi/thttpd/stub.c
deleted file mode 100644
index e69de29bb2..0000000000
--- a/sapi/thttpd/stub.c
+++ /dev/null
diff --git a/sapi/thttpd/thttpd.c b/sapi/thttpd/thttpd.c
deleted file mode 100644
index 30d1cea798..0000000000
--- a/sapi/thttpd/thttpd.c
+++ /dev/null
@@ -1,747 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "SAPI.h"
-#include "php_main.h"
-#include "php_thttpd.h"
-#include "php_variables.h"
-#include "version.h"
-#include "php_ini.h"
-#include "zend_highlight.h"
-
-#include "ext/standard/php_smart_str.h"
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#ifdef HAVE_GETNAMEINFO
-#include <sys/socket.h>
-#include <netdb.h>
-#endif
-
-typedef struct {
- httpd_conn *hc;
- void (*on_close)(int);
-
- smart_str sbuf;
- int seen_cl;
- int seen_cn;
-} php_thttpd_globals;
-
-
-#ifdef ZTS
-static int thttpd_globals_id;
-#define TG(v) TSRMG(thttpd_globals_id, php_thttpd_globals *, v)
-#else
-static php_thttpd_globals thttpd_globals;
-#define TG(v) (thttpd_globals.v)
-#endif
-
-static int sapi_thttpd_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- int n;
- uint sent = 0;
-
- if (TG(sbuf).c != 0) {
- smart_str_appendl_ex(&TG(sbuf), str, str_length, 1);
- return str_length;
- }
-
- while (str_length > 0) {
- n = send(TG(hc)->conn_fd, str, str_length, 0);
-
- if (n == -1) {
- if (errno == EAGAIN) {
- smart_str_appendl_ex(&TG(sbuf), str, str_length, 1);
-
- return sent + str_length;
- } else
- php_handle_aborted_connection();
- }
-
- TG(hc)->bytes_sent += n;
- str += n;
- sent += n;
- str_length -= n;
- }
-
- return sent;
-}
-
-#define ADD_VEC(str,l) vec[n].iov_base=str;len += (vec[n].iov_len=l); n++
-#define COMBINE_HEADERS 30
-
-static int do_writev(struct iovec *vec, int nvec, int len TSRMLS_DC)
-{
- int n;
-
- /*
- * XXX: partial writevs are not handled
- * This can only cause problems, if the user tries to send
- * huge headers, so I consider this a void issue right now.
- * The maximum size depends on SO_SNDBUF and is usually
- * at least 16KB from my experience.
- */
-
- if (TG(sbuf).c == 0) {
- n = writev(TG(hc)->conn_fd, vec, nvec);
-
- if (n == -1) {
- if (errno == EAGAIN) {
- n = 0;
- } else {
- php_handle_aborted_connection();
- }
- }
-
-
- TG(hc)->bytes_sent += n;
- } else
- n = 0;
-
- if (n < len) {
- int i;
-
- /* merge all unwritten data into sbuf */
- for (i = 0; i < nvec; vec++, i++) {
- /* has this vector been written completely? */
- if (n >= vec->iov_len) {
- /* yes, proceed */
- n -= vec->iov_len;
- continue;
- }
-
- if (n > 0) {
- /* adjust vector */
- vec->iov_base = (char *) vec->iov_base + n;
- vec->iov_len -= n;
- n = 0;
- }
-
- smart_str_appendl_ex(&TG(sbuf), vec->iov_base, vec->iov_len, 1);
- }
- }
-
- return 0;
-}
-
-#define CL_TOKEN "Content-length: "
-#define CN_TOKEN "Connection: "
-#define KA_DO "Connection: keep-alive\r\n"
-#define KA_NO "Connection: close\r\n"
-#define DEF_CT "Content-Type: text/html\r\n"
-
-static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-{
- char buf[1024];
- struct iovec vec[COMBINE_HEADERS];
- int n = 0;
- zend_llist_position pos;
- sapi_header_struct *h;
- size_t len = 0;
-
- if (!SG(sapi_headers).http_status_line) {
- sprintf(buf, "HTTP/1.1 %d Code\r\n", /* SAFE */
- SG(sapi_headers).http_response_code);
- ADD_VEC(buf, strlen(buf));
- } else {
- ADD_VEC(SG(sapi_headers).http_status_line,
- strlen(SG(sapi_headers).http_status_line));
- ADD_VEC("\r\n", 2);
- }
- TG(hc)->status = SG(sapi_headers).http_response_code;
-
- if (SG(sapi_headers).send_default_content_type) {
- ADD_VEC(DEF_CT, strlen(DEF_CT));
- }
-
- h = zend_llist_get_first_ex(&sapi_headers->headers, &pos);
- while (h) {
-
- switch (h->header[0]) {
- case 'c': case 'C':
- if (!TG(seen_cl) && strncasecmp(h->header, CL_TOKEN, sizeof(CL_TOKEN)-1) == 0) {
- TG(seen_cl) = 1;
- } else if (!TG(seen_cn) && strncasecmp(h->header, CN_TOKEN, sizeof(CN_TOKEN)-1) == 0) {
- TG(seen_cn) = 1;
- }
- }
-
- ADD_VEC(h->header, h->header_len);
- if (n >= COMBINE_HEADERS - 1) {
- len = do_writev(vec, n, len TSRMLS_CC);
- n = 0;
- }
- ADD_VEC("\r\n", 2);
-
- h = zend_llist_get_next_ex(&sapi_headers->headers, &pos);
- }
-
- if (TG(seen_cl) && !TG(seen_cn) && TG(hc)->do_keep_alive) {
- ADD_VEC(KA_DO, sizeof(KA_DO)-1);
- } else {
- ADD_VEC(KA_NO, sizeof(KA_NO)-1);
- }
-
- ADD_VEC("\r\n", 2);
-
- do_writev(vec, n, len TSRMLS_CC);
-
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-/* to understand this, read cgi_interpose_input() in libhttpd.c */
-#define SIZEOF_UNCONSUMED_BYTES() (TG(hc)->read_idx - TG(hc)->checked_idx)
-#define CONSUME_BYTES(n) do { TG(hc)->checked_idx += (n); } while (0)
-
-
-static int sapi_thttpd_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
- size_t read_bytes = 0, tmp;
- int c;
- int n;
-
- c = SIZEOF_UNCONSUMED_BYTES();
- if (c > 0) {
- read_bytes = MIN(c, count_bytes);
- memcpy(buffer, TG(hc)->read_buf + TG(hc)->checked_idx, read_bytes);
- CONSUME_BYTES(read_bytes);
- count_bytes -= read_bytes;
- }
-
- return read_bytes;
-}
-
-static char *sapi_thttpd_read_cookies(TSRMLS_D)
-{
- return TG(hc)->cookie;
-}
-
-#define BUF_SIZE 512
-#define ADD_STRING(name) \
- php_register_variable(name, buf, track_vars_array TSRMLS_CC)
-
-static void sapi_thttpd_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- char buf[BUF_SIZE + 1];
- char *p;
- int xsa_len;
-
- php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array TSRMLS_CC);
- php_register_variable("SERVER_SOFTWARE", SERVER_SOFTWARE, track_vars_array TSRMLS_CC);
- php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array TSRMLS_CC);
- php_register_variable("REQUEST_METHOD", (char *) SG(request_info).request_method, track_vars_array TSRMLS_CC);
- php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array TSRMLS_CC);
- php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, track_vars_array TSRMLS_CC);
-
- if (TG(hc)->one_one) {
- php_register_variable("SERVER_PROTOCOL", "HTTP/1.1", track_vars_array TSRMLS_CC);
- } else {
- php_register_variable("SERVER_PROTOCOL", "HTTP/1.0", track_vars_array TSRMLS_CC);
- }
-
-#ifdef HAVE_GETNAMEINFO
- switch (TG(hc)->client_addr.sa.sa_family) {
- case AF_INET: xsa_len = sizeof(struct sockaddr_in); break;
- case AF_INET6: xsa_len = sizeof(struct sockaddr_in6); break;
- default: xsa_len = 0;
- }
-
- if (getnameinfo(&TG(hc)->client_addr.sa, xsa_len, buf, sizeof(buf), 0, 0, NI_NUMERICHOST) == 0) {
-#else
- p = inet_ntoa(TG(hc)->client_addr.sa_in.sin_addr);
-
- /* string representation of IPs are never larger than 512 bytes */
- if (p) {
- memcpy(buf, p, strlen(p) + 1);
-#endif
- ADD_STRING("REMOTE_ADDR");
- ADD_STRING("REMOTE_HOST");
- }
-
- snprintf(buf, BUF_SIZE, "%d", TG(hc)->hs->port);
- ADD_STRING("SERVER_PORT");
-
- snprintf(buf, BUF_SIZE, "/%s", TG(hc)->pathinfo);
- ADD_STRING("PATH_INFO");
-
- snprintf(buf, BUF_SIZE, "/%s", TG(hc)->origfilename);
- ADD_STRING("SCRIPT_NAME");
-
-#define CONDADD(name, field) \
- if (TG(hc)->field[0]) { \
- php_register_variable(#name, TG(hc)->field, track_vars_array TSRMLS_CC); \
- }
-
- CONDADD(QUERY_STRING, query);
- CONDADD(HTTP_HOST, hdrhost);
- CONDADD(HTTP_REFERER, referer);
- CONDADD(HTTP_USER_AGENT, useragent);
- CONDADD(HTTP_ACCEPT, accept);
- CONDADD(HTTP_ACCEPT_LANGUAGE, acceptl);
- CONDADD(HTTP_ACCEPT_ENCODING, accepte);
- CONDADD(HTTP_COOKIE, cookie);
- CONDADD(CONTENT_TYPE, contenttype);
- CONDADD(REMOTE_USER, remoteuser);
- CONDADD(SERVER_PROTOCOL, protocol);
-
- if (TG(hc)->contentlength != -1) {
- sprintf(buf, "%ld", (long) TG(hc)->contentlength);
- ADD_STRING("CONTENT_LENGTH");
- }
-
- if (TG(hc)->authorization[0])
- php_register_variable("AUTH_TYPE", "Basic", track_vars_array TSRMLS_CC);
-}
-
-static PHP_MINIT_FUNCTION(thttpd)
-{
- return SUCCESS;
-}
-
-static zend_module_entry php_thttpd_module = {
- STANDARD_MODULE_HEADER,
- "thttpd",
- NULL,
- PHP_MINIT(thttpd),
- NULL,
- NULL,
- NULL,
- NULL, /* info */
- NULL,
- STANDARD_MODULE_PROPERTIES
-};
-
-static int php_thttpd_startup(sapi_module_struct *sapi_module)
-{
-#if PHP_API_VERSION >= 20020918
- if (php_module_startup(sapi_module, &php_thttpd_module, 1) == FAILURE) {
-#else
- if (php_module_startup(sapi_module) == FAILURE
- || zend_startup_module(&php_thttpd_module) == FAILURE) {
-#endif
- return FAILURE;
- }
- return SUCCESS;
-}
-
-static int sapi_thttpd_get_fd(int *nfd TSRMLS_DC)
-{
- if (nfd) *nfd = TG(hc)->conn_fd;
- return SUCCESS;
-}
-
-static sapi_module_struct thttpd_sapi_module = {
- "thttpd",
- "thttpd",
-
- php_thttpd_startup,
- php_module_shutdown_wrapper,
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- sapi_thttpd_ub_write,
- NULL,
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error,
-
- NULL,
- sapi_thttpd_send_headers,
- NULL,
- sapi_thttpd_read_post,
- sapi_thttpd_read_cookies,
-
- sapi_thttpd_register_variables,
- NULL, /* Log message */
-
- NULL, /* php.ini path override */
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- NULL,
- NULL,
- NULL,
- 0,
- sapi_thttpd_get_fd
-};
-
-static void thttpd_module_main(int show_source TSRMLS_DC)
-{
- zend_file_handle file_handle;
-
- if (php_request_startup(TSRMLS_C) == FAILURE) {
- return;
- }
-
- if (show_source) {
- zend_syntax_highlighter_ini syntax_highlighter_ini;
-
- php_get_highlight_struct(&syntax_highlighter_ini);
- highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC);
- } else {
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = SG(request_info).path_translated;
- file_handle.free_filename = 0;
- file_handle.opened_path = NULL;
-
- php_execute_script(&file_handle TSRMLS_CC);
- }
-
- php_request_shutdown(NULL);
-}
-
-static void thttpd_request_ctor(TSRMLS_D)
-{
- smart_str s = {0};
-
- TG(seen_cl) = 0;
- TG(seen_cn) = 0;
- TG(sbuf).c = 0;
- SG(request_info).query_string = TG(hc)->query?strdup(TG(hc)->query):NULL;
-
- smart_str_appends_ex(&s, TG(hc)->hs->cwd, 1);
- smart_str_appends_ex(&s, TG(hc)->expnfilename, 1);
- smart_str_0(&s);
- SG(request_info).path_translated = s.c;
-
- s.c = NULL;
- smart_str_appendc_ex(&s, '/', 1);
- smart_str_appends_ex(&s, TG(hc)->origfilename, 1);
- smart_str_0(&s);
- SG(request_info).request_uri = s.c;
- SG(request_info).request_method = httpd_method_str(TG(hc)->method);
- SG(sapi_headers).http_response_code = 200;
- if (TG(hc)->contenttype)
- SG(request_info).content_type = strdup(TG(hc)->contenttype);
- SG(request_info).content_length = TG(hc)->contentlength == -1 ? 0
- : TG(hc)->contentlength;
-
- php_handle_auth_data(TG(hc)->authorization TSRMLS_CC);
-}
-
-static void thttpd_request_dtor(TSRMLS_D)
-{
- smart_str_free_ex(&TG(sbuf), 1);
- if (SG(request_info).query_string)
- free(SG(request_info).query_string);
- free(SG(request_info).request_uri);
- free(SG(request_info).path_translated);
- if (SG(request_info).content_type)
- free(SG(request_info).content_type);
-}
-
-#ifdef ZTS
-
-#ifdef TSRM_ST
-#define thread_create_simple_detached(n) st_thread_create(n, NULL, 0, 0)
-#define thread_usleep(n) st_usleep(n)
-#define thread_exit() st_thread_exit(NULL)
-/* No preemption, simple operations are safe */
-#define thread_atomic_inc(n) (++n)
-#define thread_atomic_dec(n) (--n)
-#else
-#error No thread primitives available
-#endif
-
-/* We might want to replace this with a STAILQ */
-typedef struct qreq {
- httpd_conn *hc;
- struct qreq *next;
-} qreq_t;
-
-static MUTEX_T qr_lock;
-static qreq_t *queued_requests;
-static qreq_t *last_qr;
-static int nr_free_threads;
-static int nr_threads;
-static int max_threads = 50;
-
-#define HANDLE_STRINGS() { \
- HANDLE_STR(encodedurl); \
- HANDLE_STR(decodedurl); \
- HANDLE_STR(origfilename); \
- HANDLE_STR(expnfilename); \
- HANDLE_STR(pathinfo); \
- HANDLE_STR(query); \
- HANDLE_STR(referer); \
- HANDLE_STR(useragent); \
- HANDLE_STR(accept); \
- HANDLE_STR(accepte); \
- HANDLE_STR(acceptl); \
- HANDLE_STR(cookie); \
- HANDLE_STR(contenttype); \
- HANDLE_STR(authorization); \
- HANDLE_STR(remoteuser); \
- }
-
-static httpd_conn *duplicate_conn(httpd_conn *hc, httpd_conn *nhc)
-{
- memcpy(nhc, hc, sizeof(*nhc));
-
-#define HANDLE_STR(m) nhc->m = nhc->m ? strdup(nhc->m) : NULL
- HANDLE_STRINGS();
-#undef HANDLE_STR
-
- return nhc;
-}
-
-static void destroy_conn(httpd_conn *hc)
-{
-#define HANDLE_STR(m) if (hc->m) free(hc->m)
- HANDLE_STRINGS();
-#undef HANDLE_STR
-}
-
-static httpd_conn *dequeue_request(void)
-{
- httpd_conn *ret = NULL;
- qreq_t *m;
-
- tsrm_mutex_lock(qr_lock);
- if (queued_requests) {
- m = queued_requests;
- ret = m->hc;
- if (!(queued_requests = m->next))
- last_qr = NULL;
- free(m);
- }
- tsrm_mutex_unlock(qr_lock);
-
- return ret;
-}
-
-static void *worker_thread(void *);
-
-static void queue_request(httpd_conn *hc)
-{
- qreq_t *m;
- httpd_conn *nhc;
-
- /* Mark as long-running request */
- hc->file_address = (char *) 1;
-
- /*
- * We cannot synchronously revoke accesses to hc in the worker
- * thread, so we need to pass a copy of hc to the worker thread.
- */
- nhc = malloc(sizeof *nhc);
- duplicate_conn(hc, nhc);
-
- /* Allocate request queue container */
- m = malloc(sizeof *m);
- m->hc = nhc;
- m->next = NULL;
-
- tsrm_mutex_lock(qr_lock);
- /* Create new threads when reaching a certain threshhold */
- if (nr_threads < max_threads && nr_free_threads < 2) {
- nr_threads++; /* protected by qr_lock */
-
- thread_atomic_inc(nr_free_threads);
- thread_create_simple_detached(worker_thread);
- }
- /* Insert container into request queue */
- if (queued_requests)
- last_qr->next = m;
- else
- queued_requests = m;
- last_qr = m;
- tsrm_mutex_unlock(qr_lock);
-}
-
-static off_t thttpd_real_php_request(httpd_conn *hc, int TSRMLS_DC);
-
-static void *worker_thread(void *dummy)
-{
- int do_work = 50;
- httpd_conn *hc;
-
- while (do_work) {
- hc = dequeue_request();
-
- if (!hc) {
-/* do_work--; */
- thread_usleep(500000);
- continue;
- }
-/* do_work = 50; */
-
- thread_atomic_dec(nr_free_threads);
-
- thttpd_real_php_request(hc, 0 TSRMLS_CC);
- shutdown(hc->conn_fd, 0);
- destroy_conn(hc);
- free(hc);
-
- thread_atomic_inc(nr_free_threads);
- }
- thread_atomic_dec(nr_free_threads);
- thread_atomic_dec(nr_threads);
- thread_exit();
-}
-
-static void remove_dead_conn(int fd)
-{
- qreq_t *m, *prev = NULL;
-
- tsrm_mutex_lock(qr_lock);
- m = queued_requests;
- while (m) {
- if (m->hc->conn_fd == fd) {
- if (prev)
- if (!(prev->next = m->next))
- last_qr = prev;
- else
- if (!(queued_requests = m->next))
- last_qr = NULL;
- destroy_conn(m->hc);
- free(m->hc);
- free(m);
- break;
- }
- prev = m;
- m = m->next;
- }
- tsrm_mutex_unlock(qr_lock);
-}
-
-#endif
-
-static off_t thttpd_real_php_request(httpd_conn *hc, int show_source TSRMLS_DC)
-{
- TG(hc) = hc;
- hc->bytes_sent = 0;
-
- if (hc->method == METHOD_POST)
- hc->should_linger = 1;
-
- if (hc->contentlength > 0
- && SIZEOF_UNCONSUMED_BYTES() < hc->contentlength) {
- int missing = hc->contentlength - SIZEOF_UNCONSUMED_BYTES();
-
- hc->read_body_into_mem = 1;
- return 0;
- }
-
- thttpd_request_ctor(TSRMLS_C);
-
- thttpd_module_main(show_source TSRMLS_CC);
-
- /* disable kl, if no content-length was seen or Connection: was set */
- if (TG(seen_cl) == 0 || TG(seen_cn) == 1) {
- TG(hc)->do_keep_alive = TG(hc)->keep_alive = 0;
- }
-
- if (TG(sbuf).c != 0) {
- if (TG(hc)->response)
- free(TG(hc)->response);
-
- TG(hc)->response = TG(sbuf).c;
- TG(hc)->responselen = TG(sbuf).len;
-
- TG(sbuf).c = 0;
- TG(sbuf).len = 0;
- TG(sbuf).a = 0;
- }
-
- thttpd_request_dtor(TSRMLS_C);
-
- return 0;
-}
-
-off_t thttpd_php_request(httpd_conn *hc, int show_source)
-{
-#ifdef ZTS
- queue_request(hc);
-#else
- TSRMLS_FETCH();
- return thttpd_real_php_request(hc, show_source TSRMLS_CC);
-#endif
-}
-
-void thttpd_register_on_close(void (*arg)(int))
-{
- TSRMLS_FETCH();
- TG(on_close) = arg;
-}
-
-void thttpd_closed_conn(int fd)
-{
- TSRMLS_FETCH();
- if (TG(on_close)) TG(on_close)(fd);
-}
-
-int thttpd_get_fd(void)
-{
- TSRMLS_FETCH();
- return TG(hc)->conn_fd;
-}
-
-void thttpd_set_dont_close(void)
-{
- TSRMLS_FETCH();
- TG(hc)->file_address = (char *) 1;
-}
-
-
-void thttpd_php_init(void)
-{
- char *ini;
-
-#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
- ts_allocate_id(&thttpd_globals_id, sizeof(php_thttpd_globals), NULL, NULL);
- qr_lock = tsrm_mutex_alloc();
- thttpd_register_on_close(remove_dead_conn);
-#endif
-
- if ((ini = getenv("PHP_INI_PATH"))) {
- thttpd_sapi_module.php_ini_path_override = ini;
- }
-
- sapi_startup(&thttpd_sapi_module);
- thttpd_sapi_module.startup(&thttpd_sapi_module);
-
- {
- TSRMLS_FETCH();
-
- SG(server_context) = (void *) 1;
- }
-}
-
-void thttpd_php_shutdown(void)
-{
- TSRMLS_FETCH();
-
- if (SG(server_context) != NULL) {
- thttpd_sapi_module.shutdown(&thttpd_sapi_module);
- sapi_shutdown();
-#ifdef ZTS
- tsrm_shutdown();
-#endif
- }
-}
diff --git a/sapi/thttpd/thttpd_patch b/sapi/thttpd/thttpd_patch
deleted file mode 100644
index 404686c13c..0000000000
--- a/sapi/thttpd/thttpd_patch
+++ /dev/null
@@ -1,1881 +0,0 @@
-diff -ur thttpd-2.21b/Makefile.in thttpd-2.21b-cool/Makefile.in
---- thttpd-2.21b/Makefile.in Thu Mar 29 20:36:21 2001
-+++ thttpd-2.21b-cool/Makefile.in Thu Feb 13 03:27:55 2003
-@@ -46,13 +46,15 @@
-
- # You shouldn't need to edit anything below here.
-
-+include php_makefile
-+
- CC = @CC@
- CCOPT = @V_CCOPT@
- DEFS = @DEFS@
- INCLS = -I.
- CFLAGS = $(CCOPT) $(DEFS) $(INCLS)
--LDFLAGS = @LDFLAGS@
--LIBS = @LIBS@
-+LDFLAGS = @LDFLAGS@ $(PHP_LDFLAGS)
-+LIBS = @LIBS@ $(PHP_LIBS)
- NETLIBS = @V_NETLIBS@
- INSTALL = @INSTALL@
-
-@@ -62,7 +64,7 @@
- @rm -f $@
- $(CC) $(CFLAGS) -c $*.c
-
--SRC = thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c syslog.c
-+SRC = thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c syslog.c php_thttpd.c
-
- OBJ = $(SRC:.c=.o) @LIBOBJS@
-
-@@ -77,7 +79,7 @@
- all: this subdirs
- this: $(ALL)
-
--thttpd: $(OBJ)
-+thttpd: $(OBJ) libphp4.a
- @rm -f $@
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(NETLIBS)
-
-@@ -151,6 +153,9 @@
-
- tags:
- ctags -wtd *.c *.h
-+
-+php_thttpd.o: php_thttpd.c
-+ $(CC) $(PHP_CFLAGS) $(CFLAGS) -c php_thttpd.c
-
- tar:
- @name=`sed -n -e '/SERVER_SOFTWARE/!d' -e 's,.*thttpd/,thttpd-,' -e 's, .*,,p' version.h` ; \
-diff -ur thttpd-2.21b/config.h thttpd-2.21b-cool/config.h
---- thttpd-2.21b/config.h Mon Apr 9 23:57:36 2001
-+++ thttpd-2.21b-cool/config.h Thu Feb 13 03:27:55 2003
-@@ -82,6 +82,11 @@
- */
- #define IDLE_READ_TIMELIMIT 60
-
-+/* CONFIGURE: How many seconds to allow for reading the subsequent requests
-+** on a keep-alive connection. Should be simiar to LINGER_TIME
-+*/
-+#define IDLE_KEEPALIVE_TIMELIMIT 2
-+
- /* CONFIGURE: How many seconds before an idle connection gets closed.
- */
- #define IDLE_SEND_TIMELIMIT 300
-@@ -316,7 +321,7 @@
- /* CONFIGURE: A list of index filenames to check. The files are searched
- ** for in this order.
- */
--#define INDEX_NAMES "index.html", "index.htm", "Default.htm", "index.cgi"
-+#define INDEX_NAMES "index.php", "index.html", "index.htm", "Default.htm", "index.cgi"
-
- /* CONFIGURE: If this is defined then thttpd will automatically generate
- ** index pages for directories that don't have an explicit index file.
-diff -ur thttpd-2.21b/configure thttpd-2.21b-cool/configure
---- thttpd-2.21b/configure Sat Apr 21 02:07:14 2001
-+++ thttpd-2.21b-cool/configure Thu Feb 13 03:27:55 2003
-@@ -1021,7 +1021,7 @@
- fi
- echo "$ac_t""$CPP" 1>&6
-
--for ac_hdr in fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h
-+for ac_hdr in fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h netinet/tcp.h
- do
- ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
- echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-diff -ur thttpd-2.21b/configure.in thttpd-2.21b-cool/configure.in
---- thttpd-2.21b/configure.in Sat Apr 21 02:06:23 2001
-+++ thttpd-2.21b-cool/configure.in Thu Feb 13 03:27:55 2003
-@@ -64,7 +64,7 @@
- AC_MSG_RESULT(no)
- fi
-
--AC_CHECK_HEADERS(fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h)
-+AC_CHECK_HEADERS(fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h netinet/tcp.h)
- AC_HEADER_TIME
- AC_HEADER_DIRENT
-
-diff -ur thttpd-2.21b/fdwatch.c thttpd-2.21b-cool/fdwatch.c
---- thttpd-2.21b/fdwatch.c Fri Apr 13 07:36:08 2001
-+++ thttpd-2.21b-cool/fdwatch.c Thu Feb 13 03:27:55 2003
-@@ -460,7 +460,7 @@
-
- ridx = 0;
- for ( i = 0; i < npollfds; ++i )
-- if ( pollfds[i].revents & ( POLLIN | POLLOUT ) )
-+ if ( pollfds[i].revents & ( POLLIN | POLLOUT | POLLERR | POLLHUP | POLLNVAL ) )
- poll_rfdidx[ridx++] = pollfds[i].fd;
-
- return r;
-@@ -472,8 +472,8 @@
- {
- switch ( fd_rw[fd] )
- {
-- case FDW_READ: return pollfds[poll_fdidx[fd]].revents & POLLIN;
-- case FDW_WRITE: return pollfds[poll_fdidx[fd]].revents & POLLOUT;
-+ case FDW_READ: return pollfds[poll_fdidx[fd]].revents & ( POLLIN | POLLERR | POLLHUP | POLLNVAL );
-+ case FDW_WRITE: return pollfds[poll_fdidx[fd]].revents & ( POLLOUT | POLLERR | POLLHUP | POLLNVAL );
- default: return 0;
- }
- }
-diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
---- thttpd-2.21b/libhttpd.c Tue Apr 24 00:42:40 2001
-+++ thttpd-2.21b-cool/libhttpd.c Thu Feb 13 03:27:55 2003
-@@ -56,6 +56,10 @@
- #include <unistd.h>
- #include <stdarg.h>
-
-+#ifdef HAVE_NETINET_TCP_H
-+#include <netinet/tcp.h>
-+#endif
-+
- #ifdef HAVE_OSRELDATE_H
- #include <osreldate.h>
- #endif /* HAVE_OSRELDATE_H */
-@@ -85,6 +89,12 @@
- #include "match.h"
- #include "tdate_parse.h"
-
-+#include "php_thttpd.h"
-+
-+#ifdef __CYGWIN__
-+# define timezone _timezone
-+#endif
-+
- #ifndef STDIN_FILENO
- #define STDIN_FILENO 0
- #endif
-@@ -242,6 +252,10 @@
- free( (void*) hs->cwd );
- if ( hs->cgi_pattern != (char*) 0 )
- free( (void*) hs->cgi_pattern );
-+ if ( hs->php_pattern != (char*) 0 )
-+ free( (void*) hs->php_pattern );
-+ if ( hs->phps_pattern != (char*) 0 )
-+ free( (void*) hs->phps_pattern );
- if ( hs->charset != (char*) 0 )
- free( (void*) hs->charset );
- if ( hs->url_pattern != (char*) 0 )
-@@ -249,6 +263,7 @@
- if ( hs->local_pattern != (char*) 0 )
- free( (void*) hs->local_pattern );
- free( (void*) hs );
-+ thttpd_php_shutdown();
- }
-
-
-@@ -257,7 +272,8 @@
- char* hostname, httpd_sockaddr* sa4P, httpd_sockaddr* sa6P, int port,
- char* cgi_pattern, char* charset, char* cwd, int no_log, FILE* logfp,
- int no_symlink, int vhost, int global_passwd, char* url_pattern,
-- char* local_pattern, int no_empty_referers )
-+ char* local_pattern, int no_empty_referers, char* php_pattern,
-+ char* phps_pattern )
- {
- httpd_server* hs;
- static char ghnbuf[256];
-@@ -312,6 +328,8 @@
- }
-
- hs->port = port;
-+ hs->php_pattern = strdup(php_pattern);
-+ hs->phps_pattern = strdup(phps_pattern);
- if ( cgi_pattern == (char*) 0 )
- hs->cgi_pattern = (char*) 0;
- else
-@@ -329,7 +347,7 @@
- while ( ( cp = strstr( hs->cgi_pattern, "|/" ) ) != (char*) 0 )
- (void) strcpy( cp + 1, cp + 2 );
- }
-- hs->charset = strdup( charset );
-+ hs->charset = strdup( charset );
- hs->cwd = strdup( cwd );
- if ( hs->cwd == (char*) 0 )
- {
-@@ -385,6 +403,8 @@
- return (httpd_server*) 0;
- }
-
-+ thttpd_php_init();
-+
- /* Done initializing. */
- if ( hs->binding_hostname == (char*) 0 )
- syslog( LOG_INFO, "%.80s starting on port %d", SERVER_SOFTWARE, hs->port );
-@@ -418,6 +438,11 @@
- }
- (void) fcntl( listen_fd, F_SETFD, 1 );
-
-+#if defined(TCP_DEFER_ACCEPT) && defined(SOL_TCP)
-+ on = 30; /* give clients 30s to send first data packet */
-+ setsockopt(listen_fd, SOL_TCP, TCP_DEFER_ACCEPT, &on, sizeof(on));
-+#endif
-+
- /* Allow reuse of local addresses. */
- on = 1;
- if ( setsockopt(
-@@ -582,6 +607,9 @@
- /* And send it, if necessary. */
- if ( hc->responselen > 0 )
- {
-+/*
-+printf("**RESPONSE [%d]** len = %d\n%*.*s\n", hc->conn_fd, hc->responselen, hc->responselen, hc->responselen, hc->response);
-+*/
- (void) write( hc->conn_fd, hc->response, hc->responselen );
- hc->responselen = 0;
- }
-@@ -657,9 +685,9 @@
- (void) my_snprintf(
- fixed_type, sizeof(fixed_type), type, hc->hs->charset );
- (void) my_snprintf( buf, sizeof(buf),
-- "%.20s %d %s\r\nServer: %s\r\nContent-Type: %s\r\nDate: %s\r\nLast-Modified: %s\r\nAccept-Ranges: bytes\r\nConnection: close\r\n",
-- hc->protocol, status, title, EXPOSED_SERVER_SOFTWARE, fixed_type,
-- nowbuf, modbuf );
-+ "HTTP/1.1 %d %s\r\nServer: %s\r\nContent-Type: %s\r\nDate: %s\r\nLast-Modified: %s\r\nAccept-Ranges: bytes\r\n",
-+ status, title, EXPOSED_SERVER_SOFTWARE, fixed_type,
-+ nowbuf, modbuf);
- add_response( hc, buf );
- if ( encodings[0] != '\0' )
- {
-@@ -681,6 +709,14 @@
- "Content-Length: %d\r\n", length );
- add_response( hc, buf );
- }
-+ else {
-+ hc->do_keep_alive = 0;
-+ }
-+ if (hc->do_keep_alive) {
-+ add_response( hc, "Connection: keep-alive\r\n" );
-+ } else {
-+ add_response( hc, "Connection: close\r\n" );
-+ }
- if ( extraheads[0] != '\0' )
- add_response( hc, extraheads );
- add_response( hc, "\r\n" );
-@@ -1603,6 +1639,70 @@
-
-
- int
-+httpd_request_reset(httpd_conn* hc, int preserve_read_buf )
-+{
-+ if (!preserve_read_buf) {
-+ hc->read_idx = 0;
-+ hc->checked_idx = 0;
-+ }
-+
-+ if (hc->read_buf_is_mmap) {
-+ hc->read_buf_is_mmap = 0;
-+ munmap(hc->read_buf, hc->read_size);
-+ hc->read_buf = NULL;
-+ hc->read_size = 0;
-+ httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 );
-+ }
-+ hc->checked_state = CHST_FIRSTWORD;
-+ hc->method = METHOD_UNKNOWN;
-+ hc->status = 0;
-+ hc->bytes_to_send = 0;
-+ hc->bytes_sent = 0;
-+ hc->encodedurl = "";
-+ hc->decodedurl[0] = '\0';
-+ hc->protocol = "UNKNOWN";
-+ hc->origfilename[0] = '\0';
-+ hc->expnfilename[0] = '\0';
-+ hc->encodings[0] = '\0';
-+ hc->pathinfo[0] = '\0';
-+ hc->query[0] = '\0';
-+ hc->referer = "";
-+ hc->useragent = "";
-+ hc->accept[0] = '\0';
-+ hc->accepte[0] = '\0';
-+ hc->acceptl = "";
-+ hc->cookie = "";
-+ hc->contenttype = "";
-+ hc->reqhost[0] = '\0';
-+ hc->hdrhost = "";
-+ hc->hostdir[0] = '\0';
-+ hc->authorization = "";
-+ hc->remoteuser[0] = '\0';
-+ hc->response[0] = '\0';
-+#ifdef TILDE_MAP_2
-+ hc->altdir[0] = '\0';
-+#endif /* TILDE_MAP_2 */
-+ hc->responselen = 0;
-+ hc->if_modified_since = (time_t) -1;
-+ hc->range_if = (time_t) -1;
-+ hc->contentlength = -1;
-+ hc->type = "";
-+ hc->hostname = (char*) 0;
-+ hc->mime_flag = 1;
-+ hc->one_one = 0;
-+ hc->got_range = 0;
-+ hc->tildemapped = 0;
-+ hc->init_byte_loc = 0;
-+ hc->end_byte_loc = -1;
-+ hc->keep_alive = 0;
-+ hc->do_keep_alive = 0;
-+ hc->should_linger = 0;
-+ hc->file_address = (char*) 0;
-+ hc->read_body_into_mem = 0;
-+ return GC_OK;
-+}
-+
-+int
- httpd_get_conn( httpd_server* hs, int listen_fd, httpd_conn* hc )
- {
- httpd_sockaddr sa;
-@@ -1612,6 +1712,7 @@
- {
- hc->read_size = 0;
- httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 );
-+ hc->read_buf_is_mmap = 0;
- hc->maxdecodedurl =
- hc->maxorigfilename = hc->maxexpnfilename = hc->maxencodings =
- hc->maxpathinfo = hc->maxquery = hc->maxaccept =
-@@ -1637,6 +1738,13 @@
- #endif /* TILDE_MAP_2 */
- hc->initialized = 1;
- }
-+ if (hc->read_buf_is_mmap) {
-+ hc->read_buf_is_mmap = 0;
-+ munmap(hc->read_buf, hc->read_size);
-+ hc->read_buf = NULL;
-+ hc->read_size = 0;
-+ httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 );
-+ }
-
- /* Accept the new connection. */
- sz = sizeof(sa);
-@@ -1657,53 +1765,12 @@
- hc->hs = hs;
- memset( &hc->client_addr, 0, sizeof(hc->client_addr) );
- memcpy( &hc->client_addr, &sa, sockaddr_len( &sa ) );
-- hc->read_idx = 0;
-- hc->checked_idx = 0;
-- hc->checked_state = CHST_FIRSTWORD;
-- hc->method = METHOD_UNKNOWN;
-- hc->status = 0;
-- hc->bytes_to_send = 0;
-- hc->bytes_sent = 0;
-- hc->encodedurl = "";
-- hc->decodedurl[0] = '\0';
-- hc->protocol = "UNKNOWN";
-- hc->origfilename[0] = '\0';
-- hc->expnfilename[0] = '\0';
-- hc->encodings[0] = '\0';
-- hc->pathinfo[0] = '\0';
-- hc->query[0] = '\0';
-- hc->referer = "";
-- hc->useragent = "";
-- hc->accept[0] = '\0';
-- hc->accepte[0] = '\0';
-- hc->acceptl = "";
-- hc->cookie = "";
-- hc->contenttype = "";
-- hc->reqhost[0] = '\0';
-- hc->hdrhost = "";
-- hc->hostdir[0] = '\0';
-- hc->authorization = "";
-- hc->remoteuser[0] = '\0';
-- hc->response[0] = '\0';
--#ifdef TILDE_MAP_2
-- hc->altdir[0] = '\0';
--#endif /* TILDE_MAP_2 */
-- hc->responselen = 0;
-- hc->if_modified_since = (time_t) -1;
-- hc->range_if = (time_t) -1;
-- hc->contentlength = -1;
-- hc->type = "";
-- hc->hostname = (char*) 0;
-- hc->mime_flag = 1;
-- hc->one_one = 0;
-- hc->got_range = 0;
-- hc->tildemapped = 0;
-- hc->init_byte_loc = 0;
-- hc->end_byte_loc = -1;
-- hc->keep_alive = 0;
-- hc->should_linger = 0;
-- hc->file_address = (char*) 0;
-- return GC_OK;
-+
-+/*
-+printf("doing httpd_get_con(%d)\n", hc->conn_fd);
-+*/
-+
-+ return httpd_request_reset(hc, 0);
- }
-
-
-@@ -1720,6 +1787,9 @@
- {
- char c;
-
-+/*
-+printf("**REQUEST [%d]**\n%*.*s\n", hc->conn_fd, hc->read_idx, hc->read_idx, hc->read_buf);
-+*/
- for ( ; hc->checked_idx < hc->read_idx; ++hc->checked_idx )
- {
- c = hc->read_buf[hc->checked_idx];
-@@ -1912,8 +1982,11 @@
- eol = strpbrk( protocol, " \t\n\r" );
- if ( eol != (char*) 0 )
- *eol = '\0';
-- if ( strcasecmp( protocol, "HTTP/1.0" ) != 0 )
-+ if ( strcasecmp( protocol, "HTTP/1.0" ) != 0 ) {
- hc->one_one = 1;
-+ hc->keep_alive = 1;
-+ hc->do_keep_alive = 1;
-+ }
- }
- }
- /* Check for HTTP/1.1 absolute URL. */
-@@ -2012,6 +2085,11 @@
- cp = strchr( hc->hdrhost, ':' );
- if ( cp != (char*) 0 )
- *cp = '\0';
-+ if ( hc->hdrhost[0] == '.' || strpbrk( hc->hdrhost, "/\\" ) != 0 )
-+ {
-+ httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
-+ return -1;
-+ }
- }
- else if ( strncasecmp( buf, "Accept:", 7 ) == 0 )
- {
-@@ -2129,6 +2207,7 @@
- cp = &buf[11];
- cp += strspn( cp, " \t" );
- if ( strcasecmp( cp, "keep-alive" ) == 0 )
-+ hc->do_keep_alive = 1;
- hc->keep_alive = 1;
- }
- #ifdef LOG_UNKNOWN_HEADERS
-@@ -2168,6 +2247,9 @@
- }
- }
-
-+/*
-+printf("one_one = %d keep_alive = %d\n", hc->one_one, hc->keep_alive);
-+*/
- if ( hc->one_one )
- {
- /* Check that HTTP/1.1 requests specify a host, as required. */
-@@ -2177,14 +2259,14 @@
- return -1;
- }
-
-- /* If the client wants to do keep-alives, it might also be doing
-- ** pipelining. There's no way for us to tell. Since we don't
-- ** implement keep-alives yet, if we close such a connection there
-- ** might be unread pipelined requests waiting. So, we have to
-- ** do a lingering close.
-+ /*
-+ ** Disable keep alive support for bad browsers,
-+ ** list taken from Apache 1.3.19
- */
-- if ( hc->keep_alive )
-- hc->should_linger = 1;
-+ if ( hc->do_keep_alive &&
-+ ( strstr(hc->useragent, "Mozilla/2") != NULL ||
-+ strstr(hc->useragent, "MSIE 4.0b2;") != NULL))
-+ hc->do_keep_alive = 0;
- }
-
- /* Ok, the request has been parsed. Now we resolve stuff that
-@@ -2349,15 +2431,24 @@
-
-
- void
--httpd_close_conn( httpd_conn* hc, struct timeval* nowP )
-- {
-- make_log_entry( hc, nowP );
-+httpd_complete_request( httpd_conn* hc, struct timeval* nowP, int logit )
-+{
-+ if (logit)
-+ make_log_entry( hc, nowP );
-
-- if ( hc->file_address != (char*) 0 )
-+ if ( hc->file_address == (char*) 1 )
-+ {
-+ thttpd_closed_conn(hc->conn_fd);
-+ } else if ( hc->file_address != (char*) 0 )
- {
- mmc_unmap( hc->file_address, &(hc->sb), nowP );
- hc->file_address = (char*) 0;
- }
-+ }
-+
-+void
-+httpd_close_conn( httpd_conn* hc, struct timeval* nowP )
-+{
- if ( hc->conn_fd >= 0 )
- {
- (void) close( hc->conn_fd );
-@@ -2370,7 +2461,12 @@
- {
- if ( hc->initialized )
- {
-- free( (void*) hc->read_buf );
-+
-+ if ( hc->read_buf_is_mmap ) {
-+ munmap( hc->read_buf, hc->read_size );
-+ } else {
-+ free( (void*) hc->read_buf );
-+ }
- free( (void*) hc->decodedurl );
- free( (void*) hc->origfilename );
- free( (void*) hc->expnfilename );
-@@ -3026,11 +3122,9 @@
- post_post_garbage_hack( httpd_conn* hc )
- {
- char buf[2];
-- int r;
-
-- r = recv( hc->conn_fd, buf, sizeof(buf), MSG_PEEK );
-- if ( r > 0 )
-- (void) read( hc->conn_fd, buf, r );
-+ fcntl(hc->conn_fd, F_SETFL, O_NONBLOCK);
-+ (void) read( hc->conn_fd, buf, 2 );
- }
-
-
-@@ -3313,6 +3407,11 @@
- int r;
- ClientData client_data;
-
-+ /*
-+ ** We are not going to leave the socket open after a CGI... too hard
-+ */
-+ hc->do_keep_alive = 0;
-+
- if ( hc->method == METHOD_GET || hc->method == METHOD_POST )
- {
- httpd_clear_ndelay( hc->conn_fd );
-@@ -3369,6 +3468,7 @@
- int expnlen, indxlen;
- char* cp;
- char* pi;
-+ int nocache = 0;
-
- expnlen = strlen( hc->expnfilename );
-
-@@ -3561,6 +3661,16 @@
- match( hc->hs->cgi_pattern, hc->expnfilename ) )
- return cgi( hc );
-
-+ if ( hc->hs->php_pattern != (char*) 0 &&
-+ match( hc->hs->php_pattern, hc->expnfilename)) {
-+ return thttpd_php_request( hc, 0 );
-+ }
-+
-+ if ( hc->hs->phps_pattern != (char*) 0 &&
-+ match( hc->hs->phps_pattern, hc->expnfilename)) {
-+ return thttpd_php_request( hc, 1 );
-+ }
-+
- /* It's not CGI. If it's executable or there's pathinfo, someone's
- ** trying to either serve or run a non-CGI file as CGI. Either case
- ** is prohibited.
-@@ -3594,6 +3704,8 @@
- hc->end_byte_loc = hc->sb.st_size - 1;
-
- figure_mime( hc );
-+ if ( strncmp(hc->decodedurl, "/nocache/", sizeof("/nocache/") - 1 ) == 0 )
-+ nocache = 1;
-
- if ( hc->method == METHOD_HEAD )
- {
-@@ -3601,7 +3713,7 @@
- hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,
- hc->sb.st_mtime );
- }
-- else if ( hc->if_modified_since != (time_t) -1 &&
-+ else if ( !nocache && hc->if_modified_since != (time_t) -1 &&
- hc->if_modified_since >= hc->sb.st_mtime )
- {
- hc->method = METHOD_HEAD;
-@@ -3611,14 +3723,25 @@
- }
- else
- {
-- hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP );
-+ char *extraheads = "";
-+
-+ if ( nocache )
-+ {
-+ extraheads = "Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n"
-+ "Cache-Control: no-store, no-cache, must-revalidate, "
-+ "post-check=0, pre-check=0\r\n"
-+ "Pragma: no-cache\r\n";
-+ }
-+
-+ hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP, nocache );
- if ( hc->file_address == (char*) 0 )
- {
- httpd_send_err( hc, 500, err500title, "", err500form, hc->encodedurl );
- return -1;
- }
-+
- send_mime(
-- hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,
-+ hc, 200, ok200title, hc->encodings, extraheads, hc->type, hc->sb.st_size,
- hc->sb.st_mtime );
- }
-
-diff -ur thttpd-2.21b/libhttpd.h thttpd-2.21b-cool/libhttpd.h
---- thttpd-2.21b/libhttpd.h Tue Apr 24 00:36:50 2001
-+++ thttpd-2.21b-cool/libhttpd.h Thu Feb 13 03:27:55 2003
-@@ -69,6 +69,8 @@
- char* server_hostname;
- int port;
- char* cgi_pattern;
-+ char* php_pattern;
-+ char* phps_pattern;
- char* charset;
- char* cwd;
- int listen4_fd, listen6_fd;
-@@ -88,6 +90,7 @@
- httpd_server* hs;
- httpd_sockaddr client_addr;
- char* read_buf;
-+ char read_buf_is_mmap;
- int read_size, read_idx, checked_idx;
- int checked_state;
- int method;
-@@ -132,11 +135,12 @@
- int got_range;
- int tildemapped; /* this connection got tilde-mapped */
- off_t init_byte_loc, end_byte_loc;
-- int keep_alive;
-+ int keep_alive, do_keep_alive;
- int should_linger;
- struct stat sb;
- int conn_fd;
- char* file_address;
-+ char read_body_into_mem;
- } httpd_conn;
-
- /* Methods. */
-@@ -168,7 +172,8 @@
- char* hostname, httpd_sockaddr* sa4P, httpd_sockaddr* sa6P, int port,
- char* cgi_pattern, char* charset, char* cwd, int no_log, FILE* logfp,
- int no_symlink, int vhost, int global_passwd, char* url_pattern,
-- char* local_pattern, int no_empty_referers );
-+ char* local_pattern, int no_empty_referers, char* php_pattern,
-+ char* phps_pattern );
-
- /* Change the log file. */
- extern void httpd_set_logfp( httpd_server* hs, FILE* logfp );
-@@ -229,6 +234,8 @@
- ** If you don't have a current timeval handy just pass in 0.
- */
- extern void httpd_close_conn( httpd_conn* hc, struct timeval* nowP );
-+void httpd_complete_request( httpd_conn* hc, struct timeval* nowP, int logit );
-+int httpd_request_reset(httpd_conn* hc,int );
-
- /* Call this to de-initialize a connection struct and *really* free the
- ** mallocced strings.
-diff -ur thttpd-2.21b/mime_encodings.txt thttpd-2.21b-cool/mime_encodings.txt
---- thttpd-2.21b/mime_encodings.txt Wed May 10 03:22:28 2000
-+++ thttpd-2.21b-cool/mime_encodings.txt Thu Feb 13 03:27:55 2003
-@@ -3,6 +3,6 @@
- # A list of file extensions followed by the corresponding MIME encoding.
- # Extensions not found in the table proceed to the mime_types table.
-
--Z x-compress
--gz x-gzip
-+Z compress
-+gz gzip
- uu x-uuencode
-diff -ur thttpd-2.21b/mime_types.txt thttpd-2.21b-cool/mime_types.txt
---- thttpd-2.21b/mime_types.txt Sat Apr 14 04:53:30 2001
-+++ thttpd-2.21b-cool/mime_types.txt Thu Feb 13 03:27:55 2003
-@@ -1,135 +1,138 @@
--# mime_types.txt
--#
--# A list of file extensions followed by the corresponding MIME type.
--# Extensions not found in the table are returned as text/plain.
--
--html text/html; charset=%s
--htm text/html; charset=%s
--txt text/plain; charset=%s
--rtx text/richtext
--etx text/x-setext
--tsv text/tab-separated-values
--css text/css
--xml text/xml
--dtd text/xml
--
--gif image/gif
--jpg image/jpeg
--jpeg image/jpeg
--jpe image/jpeg
--jfif image/jpeg
--tif image/tiff
--tiff image/tiff
--pbm image/x-portable-bitmap
--pgm image/x-portable-graymap
--ppm image/x-portable-pixmap
--pnm image/x-portable-anymap
--xbm image/x-xbitmap
--xpm image/x-xpixmap
--xwd image/x-xwindowdump
--ief image/ief
--png image/png
--
--au audio/basic
--snd audio/basic
--aif audio/x-aiff
--aiff audio/x-aiff
--aifc audio/x-aiff
--ra audio/x-pn-realaudio
--ram audio/x-pn-realaudio
--rm audio/x-pn-realaudio
--rpm audio/x-pn-realaudio-plugin
--wav audio/wav
--mid audio/midi
--midi audio/midi
--kar audio/midi
--mpga audio/mpeg
--mp2 audio/mpeg
--mp3 audio/mpeg
--
--mpeg video/mpeg
--mpg video/mpeg
--mpe video/mpeg
--qt video/quicktime
--mov video/quicktime
--avi video/x-msvideo
--movie video/x-sgi-movie
--mv video/x-sgi-movie
--vx video/x-rad-screenplay
--
--a application/octet-stream
-+ez application/andrew-inset
-+hqx application/mac-binhex40
-+cpt application/mac-compactpro
-+doc application/msword
- bin application/octet-stream
-+dms application/octet-stream
-+lha application/octet-stream
-+lzh application/octet-stream
- exe application/octet-stream
--dump application/octet-stream
--o application/octet-stream
--class application/java
--js application/x-javascript
-+class application/octet-stream
-+so application/octet-stream
-+dll application/octet-stream
-+oda application/oda
-+pdf application/pdf
- ai application/postscript
- eps application/postscript
- ps application/postscript
--dir application/x-director
-+smi application/smil
-+smil application/smil
-+mif application/vnd.mif
-+xls application/vnd.ms-excel
-+ppt application/vnd.ms-powerpoint
-+wbxml application/vnd.wap.wbxml
-+wmlc application/vnd.wap.wmlc
-+wmlsc application/vnd.wap.wmlscriptc
-+bcpio application/x-bcpio
-+vcd application/x-cdlink
-+pgn application/x-chess-pgn
-+cpio application/x-cpio
-+csh application/x-csh
- dcr application/x-director
-+dir application/x-director
- dxr application/x-director
--fgd application/x-director
--aam application/x-authorware-map
--aas application/x-authorware-seg
--aab application/x-authorware-bin
--fh4 image/x-freehand
--fh7 image/x-freehand
--fh5 image/x-freehand
--fhc image/x-freehand
--fh image/x-freehand
--spl application/futuresplash
--swf application/x-shockwave-flash
- dvi application/x-dvi
-+spl application/x-futuresplash
- gtar application/x-gtar
- hdf application/x-hdf
--hqx application/mac-binhex40
--iv application/x-inventor
-+js application/x-javascript
-+skp application/x-koan
-+skd application/x-koan
-+skt application/x-koan
-+skm application/x-koan
- latex application/x-latex
--man application/x-troff-man
--me application/x-troff-me
--mif application/x-mif
--ms application/x-troff-ms
--oda application/oda
--pdf application/pdf
--rtf application/rtf
--bcpio application/x-bcpio
--cpio application/x-cpio
--sv4cpio application/x-sv4cpio
--sv4crc application/x-sv4crc
--sh application/x-shar
-+nc application/x-netcdf
-+cdf application/x-netcdf
-+sh application/x-sh
- shar application/x-shar
-+swf application/x-shockwave-flash
- sit application/x-stuffit
-+sv4cpio application/x-sv4cpio
-+sv4crc application/x-sv4crc
- tar application/x-tar
-+tcl application/x-tcl
- tex application/x-tex
--texi application/x-texinfo
- texinfo application/x-texinfo
-+texi application/x-texinfo
-+t application/x-troff
- tr application/x-troff
- roff application/x-troff
- man application/x-troff-man
- me application/x-troff-me
- ms application/x-troff-ms
--zip application/x-zip-compressed
--tsp application/dsptype
--wsrc application/x-wais-source
- ustar application/x-ustar
--cdf application/x-netcdf
--nc application/x-netcdf
--doc application/msword
--ppt application/powerpoint
--
--crt application/x-x509-ca-cert
--crl application/x-pkcs7-crl
--
-+src application/x-wais-source
-+xhtml application/xhtml+xml
-+xht application/xhtml+xml
-+zip application/zip
-+au audio/basic
-+snd audio/basic
-+mid audio/midi
-+midi audio/midi
-+kar audio/midi
-+mpga audio/mpeg
-+mp2 audio/mpeg
-+mp3 audio/mpeg
-+aif audio/x-aiff
-+aiff audio/x-aiff
-+aifc audio/x-aiff
-+m3u audio/x-mpegurl
-+ram audio/x-pn-realaudio
-+rm audio/x-pn-realaudio
-+rpm audio/x-pn-realaudio-plugin
-+ra audio/x-realaudio
-+wav audio/x-wav
-+pdb chemical/x-pdb
-+xyz chemical/x-xyz
-+bmp image/bmp
-+gif image/gif
-+ief image/ief
-+jpeg image/jpeg
-+jpg image/jpeg
-+jpe image/jpeg
-+png image/png
-+tiff image/tiff
-+tif image/tiff
-+djvu image/vnd.djvu
-+djv image/vnd.djvu
-+wbmp image/vnd.wap.wbmp
-+ras image/x-cmu-raster
-+pnm image/x-portable-anymap
-+pbm image/x-portable-bitmap
-+pgm image/x-portable-graymap
-+ppm image/x-portable-pixmap
-+rgb image/x-rgb
-+xbm image/x-xbitmap
-+xpm image/x-xpixmap
-+xwd image/x-xwindowdump
-+igs model/iges
-+iges model/iges
-+msh model/mesh
-+mesh model/mesh
-+silo model/mesh
- wrl model/vrml
- vrml model/vrml
--mime message/rfc822
--
--pac application/x-ns-proxy-autoconfig
--
-+css text/css
-+html text/html; charset=%s
-+htm text/html; charset=%s
-+asc text/plain; charset=%s
-+txt text/plain; charset=%s
-+rtx text/richtext
-+rtf text/rtf
-+sgml text/sgml
-+sgm text/sgml
-+tsv text/tab-separated-values
- wml text/vnd.wap.wml
--wmlc application/vnd.wap.wmlc
- wmls text/vnd.wap.wmlscript
--wmlsc application/vnd.wap.wmlscriptc
--wbmp image/vnd.wap.wbmp
-+etx text/x-setext
-+xml text/xml
-+xsl text/xml
-+mpeg video/mpeg
-+mpg video/mpeg
-+mpe video/mpeg
-+qt video/quicktime
-+mov video/quicktime
-+mxu video/vnd.mpegurl
-+avi video/x-msvideo
-+movie video/x-sgi-movie
-+ice x-conference/x-cooltalk
-diff -ur thttpd-2.21b/mmc.c thttpd-2.21b-cool/mmc.c
---- thttpd-2.21b/mmc.c Fri Apr 13 23:02:15 2001
-+++ thttpd-2.21b-cool/mmc.c Thu Feb 13 03:27:55 2003
-@@ -70,6 +70,7 @@
- unsigned int hash;
- int hash_idx;
- struct MapStruct* next;
-+ char nocache;
- } Map;
-
-
-@@ -93,7 +94,7 @@
-
-
- void*
--mmc_map( char* filename, struct stat* sbP, struct timeval* nowP )
-+mmc_map( char* filename, struct stat* sbP, struct timeval* nowP, int nocache )
- {
- time_t now;
- struct stat sb;
-@@ -167,12 +168,13 @@
- m->ctime = sb.st_ctime;
- m->refcount = 1;
- m->reftime = now;
-+ m->nocache = (char) nocache;
-
- /* Avoid doing anything for zero-length files; some systems don't like
- ** to mmap them, other systems dislike mallocing zero bytes.
- */
- if ( m->size == 0 )
-- m->addr = (void*) 1; /* arbitrary non-NULL address */
-+ m->addr = (void*) 5; /* arbitrary non-NULL address */
- else
- {
- #ifdef HAVE_MMAP
-@@ -231,27 +233,32 @@
- void
- mmc_unmap( void* addr, struct stat* sbP, struct timeval* nowP )
- {
-- Map* m = (Map*) 0;
-+ Map* m = (Map*) 0, **mm = &maps;
-
- /* Find the Map entry for this address. First try a hash. */
- if ( sbP != (struct stat*) 0 )
- {
- m = find_hash( sbP->st_ino, sbP->st_dev, sbP->st_size, sbP->st_ctime );
-- if ( m != (Map*) 0 && m->addr != addr )
-+ if ( m != (Map*) 0 && ( m->addr != addr || m->nocache == 1 ) )
- m = (Map*) 0;
- }
- /* If that didn't work, try a full search. */
- if ( m == (Map*) 0 )
-- for ( m = maps; m != (Map*) 0; m = m->next )
-+ for ( m = maps; m != (Map*) 0; m = m->next ) {
- if ( m->addr == addr )
- break;
-+ mm = &m->next;
-+ }
- if ( m == (Map*) 0 )
- syslog( LOG_ERR, "mmc_unmap failed to find entry!" );
- else if ( m->refcount <= 0 )
- syslog( LOG_ERR, "mmc_unmap found zero or negative refcount!" );
- else
- {
-- --m->refcount;
-+ if ( --m->refcount == 0 && m->nocache == 1 ) {
-+ really_unmap( mm );
-+ return;
-+ }
- if ( nowP != (struct timeval*) 0 )
- m->reftime = nowP->tv_sec;
- else
-diff -ur thttpd-2.21b/mmc.h thttpd-2.21b-cool/mmc.h
---- thttpd-2.21b/mmc.h Fri Apr 13 07:36:54 2001
-+++ thttpd-2.21b-cool/mmc.h Thu Feb 13 03:27:55 2003
-@@ -31,8 +31,9 @@
- /* Returns an mmap()ed area for the given file, or (void*) 0 on errors.
- ** If you have a stat buffer on the file, pass it in, otherwise pass 0.
- ** Same for the current time.
-+** Set nocache to 1, if this entry is supposed to be removed quickly.
- */
--extern void* mmc_map( char* filename, struct stat* sbP, struct timeval* nowP );
-+extern void* mmc_map( char* filename, struct stat* sbP, struct timeval* nowP, int nocache );
-
- /* Done with an mmap()ed area that was returned by mmc_map().
- ** If you have a stat buffer on the file, pass it in, otherwise pass 0.
-diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
---- thttpd-2.21b/thttpd.c Tue Apr 24 00:41:57 2001
-+++ thttpd-2.21b-cool/thttpd.c Thu Feb 13 03:28:11 2003
-@@ -53,6 +53,10 @@
- #endif
- #include <unistd.h>
-
-+#include <sys/mman.h>
-+
-+#include <limits.h>
-+
- #include "fdwatch.h"
- #include "libhttpd.h"
- #include "mmc.h"
-@@ -66,6 +70,8 @@
- static char* dir;
- static int do_chroot, no_log, no_symlink, do_vhost, do_global_passwd;
- static char* cgi_pattern;
-+static char* php_pattern;
-+static char* phps_pattern;
- static char* url_pattern;
- static int no_empty_referers;
- static char* local_pattern;
-@@ -95,10 +101,10 @@
- httpd_conn* hc;
- int tnums[MAXTHROTTLENUMS]; /* throttle indexes */
- int numtnums;
-+ int keep_alive;
- long limit;
- time_t started_at;
-- Timer* idle_read_timer;
-- Timer* idle_send_timer;
-+ time_t last_io;
- Timer* wakeup_timer;
- Timer* linger_timer;
- long wouldblock_delay;
-@@ -106,17 +112,22 @@
- off_t bytes_sent;
- off_t bytes_to_send;
- } connecttab;
--static connecttab* connects;
-+static connecttab* connects, **free_connects;
-+static int next_free_connect;
- static int numconnects, maxconnects;
- static int httpd_conn_count;
-
- /* The connection states. */
--#define CNST_FREE 0
--#define CNST_READING 1
--#define CNST_SENDING 2
--#define CNST_PAUSING 3
--#define CNST_LINGERING 4
--
-+enum {
-+ CNST_FREE = 0,
-+ CNST_READING,
-+ CNST_SENDING,
-+ CNST_PAUSING,
-+ CNST_LINGERING,
-+ CNST_SENDING_RESP,
-+ CNST_READING_BODY,
-+ CNST_TOTAL_NR
-+};
-
- static httpd_server* hs = (httpd_server*) 0;
- int terminate = 0;
-@@ -140,14 +151,15 @@
- static int handle_newconnect( struct timeval* tvP, int listen_fd );
- static void handle_read( connecttab* c, struct timeval* tvP );
- static void handle_send( connecttab* c, struct timeval* tvP );
-+static void handle_send_resp( connecttab* c, struct timeval* tvP );
-+static void handle_read_body( connecttab* c, struct timeval* tvP );
- static void handle_linger( connecttab* c, struct timeval* tvP );
- static int check_throttles( connecttab* c );
-+static void timeout_conns( ClientData client_data, struct timeval* nowP );
- static void clear_throttles( connecttab* c, struct timeval* tvP );
- static void update_throttles( ClientData client_data, struct timeval* nowP );
--static void clear_connection( connecttab* c, struct timeval* tvP );
-+static void clear_connection( connecttab* c, struct timeval* tvP, int );
- static void really_clear_connection( connecttab* c, struct timeval* tvP );
--static void idle_read_connection( ClientData client_data, struct timeval* nowP );
--static void idle_send_connection( ClientData client_data, struct timeval* nowP );
- static void wakeup_connection( ClientData client_data, struct timeval* nowP );
- static void linger_clear_connection( ClientData client_data, struct timeval* nowP );
- static void occasional( ClientData client_data, struct timeval* nowP );
-@@ -156,7 +168,14 @@
- #endif /* STATS_TIME */
- static void logstats( struct timeval* nowP );
- static void thttpd_logstats( long secs );
-+static void boot_request(connecttab *c, struct timeval *tvP);
-+
-+typedef void (*handler_func)(connecttab*, struct timeval *);
-+
-+handler_func handler_array[CNST_TOTAL_NR] =
-+{NULL, handle_read, handle_send, NULL, handle_linger, handle_send_resp, handle_read_body};
-
-+#define RUN_HANDLER(type, c) if (handler_array[type]) handler_array[type](c, &tv)
-
- static void
- handle_term( int sig )
-@@ -177,7 +196,7 @@
- return;
-
- /* Re-open the log file. */
-- if ( logfile != (char*) 0 )
-+ if ( logfile != (char*) 0 && strcmp(logfile, "-") != 0)
- {
- logfp = fopen( logfile, "a" );
- if ( logfp == (FILE*) 0 )
-@@ -198,6 +217,8 @@
- }
-
-
-+static time_t httpd_time_now;
-+
- static void
- handle_usr2( int sig )
- {
-@@ -217,7 +238,6 @@
- int num_ready;
- int cnum, ridx;
- connecttab* c;
-- httpd_conn* hc;
- httpd_sockaddr sa4;
- httpd_sockaddr sa6;
- int gotv4, gotv6;
-@@ -270,7 +290,9 @@
- no_log = 1;
- logfp = (FILE*) 0;
- }
-- else
-+ else if (strcmp(logfile, "-") == 0) {
-+ logfp = stdout;
-+ } else
- {
- logfp = fopen( logfile, "a" );
- if ( logfp == (FILE*) 0 )
-@@ -420,7 +442,8 @@
- hostname,
- gotv4 ? &sa4 : (httpd_sockaddr*) 0, gotv6 ? &sa6 : (httpd_sockaddr*) 0,
- port, cgi_pattern, charset, cwd, no_log, logfp, no_symlink, do_vhost,
-- do_global_passwd, url_pattern, local_pattern, no_empty_referers );
-+ do_global_passwd, url_pattern, local_pattern, no_empty_referers,
-+ php_pattern, phps_pattern);
- if ( hs == (httpd_server*) 0 )
- exit( 1 );
-
-@@ -430,6 +453,12 @@
- syslog( LOG_CRIT, "tmr_create(occasional) failed" );
- exit( 1 );
- }
-+
-+ if (tmr_create(0, timeout_conns, JunkClientData, 30 * 1000, 1) == 0) {
-+ syslog(LOG_CRIT, "tmr_create(timeout_conns) failed");
-+ exit(1);
-+ }
-+
- if ( numthrottles > 0 )
- {
- /* Set up the throttles timer. */
-@@ -454,12 +483,14 @@
- /* If we're root, try to become someone else. */
- if ( getuid() == 0 )
- {
-+#ifndef __CYGWIN__
- /* Set aux groups to null. */
- if ( setgroups( 0, (const gid_t*) 0 ) < 0 )
- {
- syslog( LOG_CRIT, "setgroups - %m" );
- exit( 1 );
- }
-+#endif
- /* Set primary group. */
- if ( setgid( gid ) < 0 )
- {
-@@ -495,13 +526,17 @@
- }
- maxconnects -= SPARE_FDS;
- connects = NEW( connecttab, maxconnects );
-+ free_connects = malloc(sizeof(connecttab *) * maxconnects);
-+ next_free_connect = maxconnects;
- if ( connects == (connecttab*) 0 )
- {
- syslog( LOG_CRIT, "out of memory allocating a connecttab" );
- exit( 1 );
- }
-+
- for ( cnum = 0; cnum < maxconnects; ++cnum )
- {
-+ free_connects[cnum] = &connects[maxconnects - cnum - 1];
- connects[cnum].conn_state = CNST_FREE;
- connects[cnum].hc = (httpd_conn*) 0;
- }
-@@ -518,6 +553,8 @@
-
- /* Main loop. */
- (void) gettimeofday( &tv, (struct timezone*) 0 );
-+ httpd_time_now = tv.tv_sec;
-+
- while ( ( ! terminate ) || numconnects > 0 )
- {
- /* Do the fd watch. */
-@@ -565,16 +602,10 @@
- c = (connecttab*) fdwatch_get_client_data( ridx );
- if ( c == (connecttab*) 0 )
- continue;
-- hc = c->hc;
-- if ( c->conn_state == CNST_READING &&
-- fdwatch_check_fd( hc->conn_fd ) )
-- handle_read( c, &tv );
-- else if ( c->conn_state == CNST_SENDING &&
-- fdwatch_check_fd( hc->conn_fd ) )
-- handle_send( c, &tv );
-- else if ( c->conn_state == CNST_LINGERING &&
-- fdwatch_check_fd( hc->conn_fd ) )
-- handle_linger( c, &tv );
-+#if DO_UNNECESSARY_CHECK_FD
-+ fdwatch_check_fd(c->hc->conn_fd);
-+#endif
-+ RUN_HANDLER(c->conn_state, c);
- }
- tmr_run( &tv );
-
-@@ -627,6 +658,8 @@
- #else /* CGI_PATTERN */
- cgi_pattern = (char*) 0;
- #endif /* CGI_PATTERN */
-+ php_pattern = "**.php";
-+ phps_pattern = "**.phps";
- url_pattern = (char*) 0;
- no_empty_referers = 0;
- local_pattern = (char*) 0;
-@@ -833,6 +866,16 @@
- value_required( name, value );
- cgi_pattern = e_strdup( value );
- }
-+ else if ( strcasecmp( name, "phppat" ) == 0 )
-+ {
-+ value_required( name, value );
-+ php_pattern = e_strdup( value );
-+ }
-+ else if ( strcasecmp( name, "phpspat" ) == 0 )
-+ {
-+ value_required( name, value );
-+ phps_pattern = e_strdup( value );
-+ }
- else if ( strcasecmp( name, "urlpat" ) == 0 )
- {
- value_required( name, value );
-@@ -1196,8 +1239,10 @@
- logstats( &tv );
- for ( cnum = 0; cnum < maxconnects; ++cnum )
- {
-- if ( connects[cnum].conn_state != CNST_FREE )
-+ if ( connects[cnum].conn_state != CNST_FREE ) {
-+ httpd_complete_request( connects[cnum].hc, &tv, 1 );
- httpd_close_conn( connects[cnum].hc, &tv );
-+ }
- if ( connects[cnum].hc != (httpd_conn*) 0 )
- {
- httpd_destroy_conn( connects[cnum].hc );
-@@ -1214,6 +1259,7 @@
- }
- mmc_destroy();
- tmr_destroy();
-+ free( (void*) free_connects );
- free( (void*) connects );
- if ( throttles != (throttletab*) 0 )
- free( (void*) throttles );
-@@ -1234,7 +1280,7 @@
- for (;;)
- {
- /* Is there room in the connection table? */
-- if ( numconnects >= maxconnects )
-+ if ( numconnects >= maxconnects || next_free_connect == 0 )
- {
- /* Out of connection slots. Run the timers, then the
- ** existing connections, and maybe we'll free up a slot
-@@ -1245,10 +1291,10 @@
- return 0;
- }
- /* Find a free connection entry. */
-- for ( cnum = 0; cnum < maxconnects; ++cnum )
-- if ( connects[cnum].conn_state == CNST_FREE )
-- break;
-- c = &connects[cnum];
-+
-+ c = free_connects[--next_free_connect];
-+ free_connects[next_free_connect] = NULL;
-+
- /* Make the httpd_conn if necessary. */
- if ( c->hc == (httpd_conn*) 0 )
- {
-@@ -1267,24 +1313,18 @@
- {
- case GC_FAIL:
- case GC_NO_MORE:
-+ free_connects[next_free_connect++] = c;
- return 1;
- }
- c->conn_state = CNST_READING;
- ++numconnects;
- client_data.p = c;
-- c->idle_read_timer = tmr_create(
-- tvP, idle_read_connection, client_data, IDLE_READ_TIMELIMIT * 1000L,
-- 0 );
-- if ( c->idle_read_timer == (Timer*) 0 )
-- {
-- syslog( LOG_CRIT, "tmr_create(idle_read_connection) failed" );
-- exit( 1 );
-- }
-- c->idle_send_timer = (Timer*) 0;
- c->wakeup_timer = (Timer*) 0;
- c->linger_timer = (Timer*) 0;
- c->bytes_sent = 0;
- c->numtnums = 0;
-+ c->keep_alive = 0;
-+ c->last_io = httpd_time_now;
-
- /* Set the connection file descriptor to no-delay mode. */
- httpd_set_ndelay( c->hc->conn_fd );
-@@ -1297,12 +1337,79 @@
- }
- }
-
-+static void
-+setup_read_body(connecttab *c, struct timeval *tvP)
-+{
-+ httpd_conn *hc = c->hc;
-+ int already, missing, unused, nalloc;
-+
-+ c->conn_state = CNST_READING_BODY;
-+
-+ hc->read_body_into_mem = 0;
-+
-+ already = hc->read_idx - hc->checked_idx;
-+ missing = hc->contentlength - already;
-+ unused = hc->read_size - hc->read_idx;
-+ nalloc = missing - unused;
-+
-+ if (missing > 16384) {
-+ char filename[] = "/tmp/thttpd.upload.XXXXXX";
-+ int tmp = mkstemp(filename);
-+
-+ if (tmp >= 0) {
-+ void *p;
-+ size_t sz = hc->contentlength + hc->checked_idx + 10;
-+
-+ unlink(filename);
-+
-+ ftruncate(tmp, sz);
-+ p = mmap(NULL, sz,
-+ PROT_READ|PROT_WRITE, MAP_PRIVATE, tmp, 0);
-+
-+ if (p != MAP_FAILED) {
-+ memcpy(p, hc->read_buf, hc->read_idx);
-+ free(hc->read_buf);
-+ hc->read_size = sz;
-+ hc->read_buf = p;
-+ hc->read_buf_is_mmap = 1;
-+ }
-+ close(tmp);
-+ }
-+
-+ if (!hc->read_buf_is_mmap) {
-+ clear_connection( c, tvP, 0 );
-+ return;
-+ }
-+ } else {
-+ httpd_realloc_str(&hc->read_buf, &hc->read_size, hc->checked_idx + hc->contentlength + 10);
-+ }
-+
-+ fdwatch_del_fd( hc->conn_fd );
-+ fdwatch_add_fd( hc->conn_fd, c, FDW_READ );
-+}
-+
-+static void
-+setup_sending(connecttab *c, int state, struct timeval *tvP)
-+{
-+ httpd_conn *hc = c->hc;
-+ ClientData client_data;
-+
-+ c->conn_state = state;
-+ c->started_at = tvP->tv_sec;
-+ c->wouldblock_delay = 0;
-+ client_data.p = c;
-+
-+ fdwatch_del_fd( hc->conn_fd );
-+ fdwatch_add_fd( hc->conn_fd, c, FDW_WRITE );
-+}
-+
-+static void handle_request( connecttab *c, struct timeval *tvP);
-+
-
- static void
- handle_read( connecttab* c, struct timeval* tvP )
- {
- int sz;
-- ClientData client_data;
- httpd_conn* hc = c->hc;
-
- /* Is there room in our buffer to read more bytes? */
-@@ -1311,7 +1418,7 @@
- if ( hc->read_size > 5000 )
- {
- httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
-- clear_connection( c, tvP );
-+ clear_connection( c, tvP, 0 );
- return;
- }
- httpd_realloc_str(
-@@ -1327,14 +1434,53 @@
- ** EWOULDBLOCK; however, this apparently can happen if a packet gets
- ** garbled.
- */
-- if ( sz == 0 || ( sz < 0 && ( errno != EWOULDBLOCK ) ) )
-- {
-- httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
-- clear_connection( c, tvP );
-+ if ( sz == 0 ) {
-+ if (! c->keep_alive) {
-+ httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
-+ }
-+ clear_connection( c, tvP, 0 );
- return;
-+ } else if ( sz < 0 ) {
-+ if (errno != EWOULDBLOCK) {
-+ clear_connection( c, tvP, 0 );
-+ }
-+ return;
-+ }
-+
-+ /* If this is a persistent PHP connection, we must not receive
-+ ** any further requests on this connection. Some broken HTTP/1.1
-+ ** implementations (e.g. Mozilla 1.0.1) are known to do
-+ ** pipelining on a connection, although a prior response included
-+ ** Connection: close
-+ */
-+ if (c->hc->file_address == (char *) 1) {
-+ return;
- }
-- hc->read_idx += sz;
-+
-+ c->last_io = httpd_time_now;
-+ if (sz > 0) hc->read_idx += sz;
-+
-+ /*
-+ ** if we start getting new data on this socket, "promote" it
-+ ** to read timeout
-+ */
-+ if ( hc->keep_alive ) {
-+ ClientData client_data;
-+
-
-+ client_data.p = c;
-+
-+ hc->keep_alive = 0;
-+ }
-+ handle_request(c, tvP);
-+ }
-+
-+
-+static void
-+handle_request( connecttab *c, struct timeval *tvP)
-+{
-+ httpd_conn* hc = c->hc;
-+
- /* Do we have a complete request yet? */
- switch ( httpd_got_request( hc ) )
- {
-@@ -1342,14 +1488,14 @@
- return;
- case GR_BAD_REQUEST:
- httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
-- clear_connection( c, tvP );
-+ clear_connection( c, tvP, 0 );
- return;
- }
-
- /* Yes. Try parsing and resolving it. */
- if ( httpd_parse_request( hc ) < 0 )
- {
-- clear_connection( c, tvP );
-+ clear_connection( c, tvP, 0 );
- return;
- }
-
-@@ -1358,18 +1504,28 @@
- {
- httpd_send_err(
- hc, 503, httpd_err503title, "", httpd_err503form, hc->encodedurl );
-- clear_connection( c, tvP );
-+ clear_connection( c, tvP, 0 );
- return;
- }
-+ boot_request(c, tvP);
-+}
-
-+static void boot_request(connecttab *c, struct timeval *tvP)
-+{
-+ httpd_conn *hc = c->hc;
- /* Start the connection going. */
- if ( httpd_start_request( hc, tvP ) < 0 )
- {
- /* Something went wrong. Close down the connection. */
-- clear_connection( c, tvP );
-+ clear_connection( c, tvP, 0 );
- return;
- }
-
-+ if ( hc->read_body_into_mem ) {
-+ setup_read_body( c, tvP );
-+ return;
-+ }
-+
- /* Fill in bytes_to_send. */
- if ( hc->got_range )
- {
-@@ -1384,37 +1540,25 @@
- {
- /* No file address means someone else is handling it. */
- c->bytes_sent = hc->bytes_sent;
-- clear_connection( c, tvP );
-+ clear_connection( c, tvP, 1 );
- return;
- }
-+ if (hc->file_address == (char *) 1) {
-+ c->last_io = (time_t) LONG_MAX;
-+ c->wouldblock_delay = 0;
-+ return;
-+ }
- if ( c->bytes_sent >= c->bytes_to_send )
- {
- /* There's nothing to send. */
-- clear_connection( c, tvP );
-+ clear_connection( c, tvP, 1 );
- return;
- }
-
- /* Cool, we have a valid connection and a file to send to it. */
-- c->conn_state = CNST_SENDING;
-- c->started_at = tvP->tv_sec;
-- c->wouldblock_delay = 0;
-- client_data.p = c;
-- tmr_cancel( c->idle_read_timer );
-- c->idle_read_timer = (Timer*) 0;
-- c->idle_send_timer = tmr_create(
-- tvP, idle_send_connection, client_data, IDLE_SEND_TIMELIMIT * 1000L,
-- 0 );
-- if ( c->idle_send_timer == (Timer*) 0 )
-- {
-- syslog( LOG_CRIT, "tmr_create(idle_send_connection) failed" );
-- exit( 1 );
-- }
--
-- fdwatch_del_fd( hc->conn_fd );
-- fdwatch_add_fd( hc->conn_fd, c, FDW_WRITE );
-+ setup_sending(c, CNST_SENDING, tvP);
- }
-
--
- static void
- handle_send( connecttab* c, struct timeval* tvP )
- {
-@@ -1443,6 +1587,9 @@
- iv[1].iov_base = &(hc->file_address[c->bytes_sent]);
- iv[1].iov_len = MIN( c->bytes_to_send - c->bytes_sent, c->limit );
- sz = writev( hc->conn_fd, iv, 2 );
-+/*
-+printf("**RESPONSE2 [%d]** len = %d\n%*.*s\n", hc->conn_fd, hc->responselen, hc->responselen, hc->responselen, hc->response);
-+*/
- }
-
- if ( sz == 0 ||
-@@ -1486,12 +1633,12 @@
- */
- if ( errno != EPIPE && errno != EINVAL && errno != ECONNRESET )
- syslog( LOG_ERR, "write - %m sending %.80s", hc->encodedurl );
-- clear_connection( c, tvP );
-+ clear_connection( c, tvP, 0 );
- return;
- }
-
- /* Ok, we wrote something. */
-- tmr_reset( tvP, c->idle_send_timer );
-+ c->last_io = httpd_time_now;
- /* Was this a headers + file writev()? */
- if ( hc->responselen > 0 )
- {
-@@ -1500,7 +1647,7 @@
- {
- /* Yes; move the unwritten part to the front of the buffer. */
- int newlen = hc->responselen - sz;
-- (void) memcpy( hc->response, &(hc->response[sz]), newlen );
-+ (void) memmove( hc->response, &(hc->response[sz]), newlen );
- hc->responselen = newlen;
- sz = 0;
- }
-@@ -1519,7 +1666,7 @@
- if ( c->bytes_sent >= c->bytes_to_send )
- {
- /* This conection is finished! */
-- clear_connection( c, tvP );
-+ clear_connection( c, tvP, 1 );
- return;
- }
-
-@@ -1560,6 +1707,9 @@
- char buf[1024];
- int r;
-
-+/*
-+printf("*LINGER read\n");
-+*/
- /* In lingering-close mode we just read and ignore bytes. An error
- ** or EOF ends things, otherwise we go until a timeout.
- */
-@@ -1569,6 +1719,61 @@
- }
-
-
-+static void
-+handle_read_body(connecttab *c, struct timeval *tvP)
-+{
-+ httpd_conn *hc = c->hc;
-+ int n;
-+
-+ n = read(hc->conn_fd, hc->read_buf + hc->read_idx,
-+ hc->contentlength - (hc->read_idx - hc->checked_idx));
-+
-+ if (n <= 0) {
-+ if (errno == EAGAIN)
-+ return;
-+ clear_connection(c, tvP, 0);
-+ return;
-+ }
-+
-+ hc->read_idx += n;
-+
-+ if (hc->contentlength == hc->read_idx - hc->checked_idx) {
-+ boot_request(c, tvP);
-+ return;
-+ }
-+}
-+
-+static void
-+handle_send_resp(connecttab *c, struct timeval *tvP)
-+{
-+ httpd_conn* hc = c->hc;
-+ int n = send(hc->conn_fd, hc->response, hc->responselen, 0);
-+ int dokeep = 1;
-+
-+ if (n < 0) {
-+ if (errno == EAGAIN)
-+ return;
-+
-+ dokeep = 0;
-+ goto clear;
-+ }
-+
-+ c->last_io = httpd_time_now;
-+
-+ if (n == hc->responselen) {
-+clear:
-+ hc->response = realloc(hc->response, hc->maxresponse + 1);
-+ hc->responselen = 0;
-+
-+ clear_connection(c, tvP, dokeep);
-+ return;
-+ }
-+
-+ hc->responselen -= n;
-+
-+ memmove(hc->response, hc->response + n, hc->responselen);
-+}
-+
- static int
- check_throttles( connecttab* c )
- {
-@@ -1635,23 +1840,18 @@
-
-
- static void
--clear_connection( connecttab* c, struct timeval* tvP )
-+clear_connection( connecttab* c, struct timeval* tvP, int doKeep )
- {
- ClientData client_data;
-+ int linger;
-
- /* If we haven't actually sent the buffered response yet, do so now. */
-- httpd_write_response( c->hc );
-+ if (c->hc->responselen && c->conn_state != CNST_SENDING_RESP) {
-+ setup_sending(c, CNST_SENDING_RESP, tvP);
-
-- if ( c->idle_read_timer != (Timer*) 0 )
-- {
-- tmr_cancel( c->idle_read_timer );
-- c->idle_read_timer = 0;
-- }
-- if ( c->idle_send_timer != (Timer*) 0 )
-- {
-- tmr_cancel( c->idle_send_timer );
-- c->idle_send_timer = 0;
-+ return;
- }
-+
- if ( c->wakeup_timer != (Timer*) 0 )
- {
- tmr_cancel( c->wakeup_timer );
-@@ -1669,13 +1869,36 @@
- ** circumstances that make a lingering close necessary. If the flag
- ** isn't set we do the real close now.
- */
-- if ( c->hc->should_linger )
-+
-+ if ( c->hc->do_keep_alive && doKeep)
- {
-- c->conn_state = CNST_LINGERING;
-+ httpd_conn *hc = c->hc;
-+ c->conn_state = CNST_READING;
-+
-+ client_data.p = c;
-+ c->bytes_sent = 0;
-+ c->numtnums = 0;
-+ c->keep_alive = 1;
-+
-+ httpd_complete_request( c->hc, tvP, 1 );
-+
- fdwatch_del_fd( c->hc->conn_fd );
- fdwatch_add_fd( c->hc->conn_fd, c, FDW_READ );
-+
-+ httpd_request_reset( c->hc, 1 );
-+
-+ hc->read_idx -= hc->checked_idx;
-+ memmove(hc->read_buf, hc->read_buf + hc->checked_idx, hc->read_idx);
-+ hc->checked_idx = 0;
-+
- /* Make sure we are still in no-delay mode. */
- httpd_set_ndelay( c->hc->conn_fd );
-+ handle_request(c, tvP);
-+ }
-+ else if ( c->hc->should_linger )
-+ {
-+ c->conn_state = CNST_LINGERING;
-+
- client_data.p = c;
- c->linger_timer = tmr_create(
- tvP, linger_clear_connection, client_data, LINGER_TIME * 1000L, 0 );
-@@ -1684,9 +1907,19 @@
- syslog( LOG_CRIT, "tmr_create(linger_clear_connection) failed" );
- exit( 1 );
- }
-+
-+ httpd_complete_request( c->hc, tvP, 1 );
-+
-+ fdwatch_del_fd( c->hc->conn_fd );
-+ fdwatch_add_fd( c->hc->conn_fd, c, FDW_READ );
-+ /* Make sure we are still in no-delay mode. */
-+ httpd_set_ndelay( c->hc->conn_fd );
- }
-- else
-+ else
-+ {
-+ httpd_complete_request( c->hc, tvP, !c->keep_alive );
- really_clear_connection( c, tvP );
-+ }
- }
-
-
-@@ -1702,45 +1935,12 @@
- tmr_cancel( c->linger_timer );
- c->linger_timer = 0;
- }
-+ free_connects[next_free_connect++] = c;
- c->conn_state = CNST_FREE;
- --numconnects;
- }
-
-
--static void
--idle_read_connection( ClientData client_data, struct timeval* nowP )
-- {
-- connecttab* c;
--
-- c = (connecttab*) client_data.p;
-- c->idle_read_timer = (Timer*) 0;
-- if ( c->conn_state != CNST_FREE )
-- {
-- syslog( LOG_INFO,
-- "%.80s connection timed out reading",
-- httpd_ntoa( &c->hc->client_addr ) );
-- httpd_send_err( c->hc, 408, httpd_err408title, "", httpd_err408form, "" );
-- clear_connection( c, nowP );
-- }
-- }
--
--
--static void
--idle_send_connection( ClientData client_data, struct timeval* nowP )
-- {
-- connecttab* c;
--
-- c = (connecttab*) client_data.p;
-- c->idle_send_timer = (Timer*) 0;
-- if ( c->conn_state != CNST_FREE )
-- {
-- syslog( LOG_INFO,
-- "%.80s connection timed out sending",
-- httpd_ntoa( &c->hc->client_addr ) );
-- clear_connection( c, nowP );
-- }
-- }
--
-
- static void
- wakeup_connection( ClientData client_data, struct timeval* nowP )
-@@ -1826,3 +2026,41 @@
- stats_connections = stats_bytes = 0L;
- stats_simultaneous = 0;
- }
-+
-+static void
-+timeout_conns(ClientData client_data, struct timeval *nowP)
-+{
-+ connecttab *c = connects, *ce = c + maxconnects;
-+ time_t now = nowP->tv_sec;
-+ int r = 0, w = 0;
-+ int checked = 0;
-+
-+ while (c < ce) {
-+ switch (c->conn_state) {
-+ case CNST_SENDING:
-+ case CNST_SENDING_RESP:
-+ checked++;
-+ if ((now - c->last_io) > IDLE_SEND_TIMELIMIT) {
-+ clear_connection( c, nowP, 0 );
-+ w++;
-+ }
-+ break;
-+ case CNST_READING:
-+ checked++;
-+ if ((now - c->last_io) > IDLE_READ_TIMELIMIT) {
-+ clear_connection( c, nowP, 0 );
-+ r++;
-+ }
-+ break;
-+ case CNST_FREE: break;
-+ default: checked++; break;
-+ }
-+ c++;
-+ if (checked >= numconnects) break;
-+ }
-+
-+ if (r > 0 || w > 0) {
-+ syslog(LOG_INFO, "Expired %d/%d connections in read/write state", r, w);
-+ }
-+}
-+
diff --git a/sapi/tux/CREDITS b/sapi/tux/CREDITS
deleted file mode 100644
index 3b7aa70c01..0000000000
--- a/sapi/tux/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-tux
-Sascha Schumann
diff --git a/sapi/tux/README b/sapi/tux/README
deleted file mode 100644
index 167e52f3ca..0000000000
--- a/sapi/tux/README
+++ /dev/null
@@ -1,86 +0,0 @@
-README FOR THE TUX MODULE (by Sascha Schumann)
-($Date$)
-
- This is a SAPI module for the TUX web-server by Ingo Molnar.
-
- The special thing about TUX is that it is integrated into the Linux
- kernel and thus provides high-speed serving of static files.
-
- The web-server provides a user-space API which allows arbitrary
- plug-ins to be made available.
-
- All requests to the PHP userspace module are currently serialized.
-
- This module is of alpha quality. Due to incomplete APIs, HTTP
- authentication and handling of POST requests has not been
- implemented yet.
-
- SECURITY NOTE: PHP will happily run everything under the
- web-root through the parser; so be careful what you put
- there.
-
- Note that requests are served in a chroot'ed environment.
- The initialization of PHP does not take place in the chroot'ed
- environment, so that e.g. /usr/local/lib/php.ini is treated
- as usual.
-
-REQUIRED DOWNLOADS
-
- 1. TUX
-
- http://people.redhat.com/~mingo/TUX-patches/QuickStart-TUX.txt
-
- 2. PHP 4.0.x
-
- Download:
- http://www.php.net/
-
- Snapshots from CVS:
- http://snaps.php.net/
-
-
-BUILD INSTRUCTIONS
-
- 1. Install TUX as outlined in the QuickStart text.
- Create /tux-modules where modules will reside.
-
- 2. Prepare PHP
-
- $ cd php-*
- $ ./configure \
- --with-tux=/tux-modules \
- <further PHP options>
- # make install
-
- You can see the list of valid PHP options by executing
-
- $ ./configure --help
-
- 3. Touch a file in your web-root 'php4.tux'. This will
- cause requests to '/php4.tux' to be redirected to the
- userspace module php4.tux.
-
- 4. Start TUX with something like
-
- # tux -d -t 8 -r /www -m /tux-modules php4.tux
-
- (daemon mode, eight threads, web-root /www, modules in
- /tux-modules, load php4.tux)
-
- BEFORE running this command, the kernel side of TUX has to
- be properly setup.
-
- 5. Try to access
-
- http://yourserver/php4.tux?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000
-
- It should display the PHP credits page.
-
- To access a script /foo/bar.php, use
-
- http://yourserver/php4.tux?/foo/bar.php
-
- Parameters can be appended:
-
- http://yourserver/php4.tux?/foo/bar.php&var=value
-
diff --git a/sapi/tux/config.m4 b/sapi/tux/config.m4
deleted file mode 100644
index ea12e67c4b..0000000000
--- a/sapi/tux/config.m4
+++ /dev/null
@@ -1,18 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-PHP_TUX=no
-
-AC_ARG_WITH(tux,
-[ --with-tux=MODULEDIR Build PHP as a TUX module (Linux only)],[
- INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $withval/php4.tux.so"
- AC_CHECK_HEADERS(tuxmodule.h,[:],[AC_MSG_ERROR([Cannot find tuxmodule.h])])
- PHP_SELECT_SAPI(tux, shared, php_tux.c)
- PHP_TUX=yes
-])
-
-AC_MSG_CHECKING(for TUX)
-AC_MSG_RESULT($PHP_TUX)
-
-unset PHP_TUX
diff --git a/sapi/tux/php.sym b/sapi/tux/php.sym
deleted file mode 100644
index b968c5f5a2..0000000000
--- a/sapi/tux/php.sym
+++ /dev/null
@@ -1,2 +0,0 @@
-TUXAPI_handle_events
-TUXAPI_init
diff --git a/sapi/tux/php_tux.c b/sapi/tux/php_tux.c
deleted file mode 100644
index 7ea9d1fd6d..0000000000
--- a/sapi/tux/php_tux.c
+++ /dev/null
@@ -1,453 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-#include "php.h"
-#include "SAPI.h"
-#include "php_main.h"
-#include "php_variables.h"
-
-#include "ext/standard/php_smart_str.h"
-
-#include "tuxmodule.h"
-
-#include <sys/uio.h>
-
-#if 0
-#include <pthread.h>
-#endif
-
-void tux_closed_conn(int fd);
-
-enum {
- PHP_TUX_BACKGROUND_CONN = 1
-};
-
-typedef struct {
- user_req_t *req;
- void (*on_close)(int);
- int tux_action;
- struct iovec *header_vec;
- int number_vec;
-} php_tux_globals;
-
-static php_tux_globals tux_globals;
-
-#define TG(v) (tux_globals.v)
-
-static int sapi_tux_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- int n;
- int m;
- const char *estr;
-
- /* combine headers and body */
- if (TG(number_vec)) {
- struct iovec *vec = TG(header_vec);
-
- n = TG(number_vec);
- vec[n].iov_base = (void *) str;
- vec[n++].iov_len = str_length;
-
- /* XXX: this might need more complete error handling */
- if ((m = writev(TG(req)->sock, vec, n)) == -1 && errno == EPIPE)
- php_handle_aborted_connection();
-
- if (m > 0)
- TG(req)->bytes_sent += str_length;
-
- TG(number_vec) = 0;
- return str_length;
- }
-
- estr = str + str_length;
-
- while (str < estr) {
- n = send(TG(req)->sock, str, estr - str, 0);
-
- if (n == -1 && errno == EPIPE)
- php_handle_aborted_connection();
- if (n == -1 && errno == EAGAIN)
- continue;
- if (n <= 0)
- return n;
-
- str += n;
- }
-
- n = str_length - (estr - str);
-
- TG(req)->bytes_sent += n;
-
- return n;
-}
-
-static int sapi_tux_send_headers(sapi_headers_struct *sapi_headers)
-{
- char buf[1024];
- struct iovec *vec;
- int n;
- int max_headers;
- zend_llist_position pos;
- sapi_header_struct *h;
- size_t len;
- char *status_line;
- int locate_cl;
- TSRMLS_FETCH();
-
- max_headers = 30;
- n = 1;
-
- vec = malloc(sizeof(struct iovec) * max_headers);
- status_line = malloc(30);
-
- /* safe sprintf use */
- len = sprintf(status_line, "HTTP/1.1 %d NA\r\n", SG(sapi_headers).http_response_code);
-
- vec[0].iov_base = status_line;
- vec[0].iov_len = len;
-
- TG(req)->http_status = SG(sapi_headers).http_response_code;
-
- if (TG(tux_action) == TUX_ACTION_FINISH_CLOSE_REQ && TG(req)->http_version == HTTP_1_1)
- locate_cl = 1;
- else
- locate_cl = 0;
-
- h = zend_llist_get_first_ex(&sapi_headers->headers, &pos);
- while (h) {
- if (locate_cl
- && strncasecmp(h->header, "Content-length:", sizeof("Content-length:")-1) == 0) {
- TG(tux_action) = TUX_ACTION_FINISH_REQ;
- locate_cl = 0;
- }
-
- vec[n].iov_base = h->header;
- vec[n++].iov_len = h->header_len;
- if (n >= max_headers - 3) {
- max_headers *= 2;
- vec = realloc(vec, sizeof(struct iovec) * max_headers);
- }
- vec[n].iov_base = "\r\n";
- vec[n++].iov_len = 2;
-
- h = zend_llist_get_next_ex(&sapi_headers->headers, &pos);
- }
-
- vec[n].iov_base = "\r\n";
- vec[n++].iov_len = 2;
-
- TG(number_vec) = n;
- TG(header_vec) = vec;
-
-
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-static int sapi_tux_read_post(char *buffer, uint count_bytes)
-{
-#if 0
- int amount = 0;
- TSRMLS_FETCH();
-
- TG(req)->objectlen = count_bytes;
- TG(req)->object_addr = buffer;
- if (tux(TUX_ACTION_READ_POST_DATA, TG(req)))
- return 0;
-
- TG(read_post_data) = 1;
-
- return TG(req)->objectlen;
-#else
- return 0;
-#endif
-}
-
-static char *sapi_tux_read_cookies(void)
-{
- TSRMLS_FETCH();
-
- return TG(req)->cookies;
-}
-
-#define BUF_SIZE 512
-#define ADD_STRING(name) \
- php_register_variable(name, buf, track_vars_array TSRMLS_CC)
-
-static void sapi_tux_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- char buf[BUF_SIZE + 1];
- char *p;
- sapi_header_line ctr = {0};
-
- ctr.line = buf;
- ctr.line_len = sprintf(buf, "Server: %s", TUXAPI_version);
- sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
-
- php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array TSRMLS_CC);
- php_register_variable("SERVER_SOFTWARE", TUXAPI_version, track_vars_array TSRMLS_CC);
- php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array TSRMLS_CC);
- php_register_variable("REQUEST_METHOD", (char *) SG(request_info).request_method, track_vars_array TSRMLS_CC);
- php_register_variable("DOCUMENT_ROOT", TUXAPI_docroot, track_vars_array TSRMLS_CC);
- php_register_variable("SERVER_NAME", TUXAPI_servername, track_vars_array TSRMLS_CC);
- php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array TSRMLS_CC);
- php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, track_vars_array TSRMLS_CC);
-
- p = inet_ntoa(TG(req)->client_host);
- /* string representation of IPs are never larger than 512 bytes */
- if (p) {
- memcpy(buf, p, strlen(p) + 1);
- ADD_STRING("REMOTE_ADDR");
- ADD_STRING("REMOTE_HOST");
- }
-
- sprintf(buf, "%d", CGI_SERVER_PORT(TG(req)));
- ADD_STRING("SERVER_PORT");
-
-#if 0
- snprintf(buf, BUF_SIZE, "/%s", TG(hc)->pathinfo);
- ADD_STRING("PATH_INFO");
-
- snprintf(buf, BUF_SIZE, "/%s", TG(hc)->origfilename);
- ADD_STRING("SCRIPT_NAME");
-#endif
-
-#define CONDADD(name, field) \
- if (TG(req)->field[0]) { \
- php_register_variable(#name, TG(req)->field, track_vars_array TSRMLS_CC); \
- }
-
- CONDADD(HTTP_REFERER, referer);
- CONDADD(HTTP_USER_AGENT, user_agent);
- CONDADD(HTTP_ACCEPT, accept);
- CONDADD(HTTP_ACCEPT_ENCODING, accept_encoding);
- CONDADD(HTTP_ACCEPT_LANGUAGE, accept_language);
- CONDADD(HTTP_COOKIE, cookies);
- CONDADD(CONTENT_TYPE, content_type);
-
-#if 0
- if (TG(hc)->contentlength != -1) {
- sprintf(buf, "%ld", (long) TG(hc)->contentlength);
- ADD_STRING("CONTENT_LENGTH");
- }
-#endif
-
-#if 0
- if (TG(hc)->authorization[0])
- php_register_variable("AUTH_TYPE", "Basic", track_vars_array TSRMLS_CC);
-#endif
-}
-
-
-static int php_tux_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
- return FAILURE;
- } else {
- return SUCCESS;
- }
-}
-
-static sapi_module_struct tux_sapi_module = {
- "tux",
- "tux",
-
- php_tux_startup,
- php_module_shutdown_wrapper,
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- sapi_tux_ub_write,
- NULL,
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error,
-
- NULL,
- sapi_tux_send_headers,
- NULL,
- sapi_tux_read_post,
- sapi_tux_read_cookies,
-
- sapi_tux_register_variables,
- NULL, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-static void tux_module_main(TSRMLS_D)
-{
- zend_file_handle file_handle;
-
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = SG(request_info).path_translated;
- file_handle.free_filename = 0;
- file_handle.opened_path = NULL;
-
- if (php_request_startup(TSRMLS_C) == FAILURE) {
- return;
- }
-
- php_execute_script(&file_handle TSRMLS_CC);
- php_request_shutdown(NULL);
-}
-
-static void tux_request_ctor(TSRMLS_D)
-{
- char buf[1024];
- int offset;
- size_t filename_len;
- size_t cwd_len;
- smart_str s = {0};
- char *p;
-
- TG(number_vec) = 0;
- TG(header_vec) = NULL;
- SG(request_info).query_string = strdup(TG(req)->query);
-
- smart_str_appends_ex(&s, "/", 1);
- smart_str_appends_ex(&s, TG(req)->query, 1);
- smart_str_0(&s);
- p = strchr(s.c, '&');
- if (p)
- *p = '\0';
- SG(request_info).path_translated = s.c;
-
- s.c = NULL;
- smart_str_appendc_ex(&s, '/', 1);
- smart_str_appends_ex(&s, TG(req)->objectname, 1);
- smart_str_0(&s);
- SG(request_info).request_uri = s.c;
- SG(request_info).request_method = CGI_REQUEST_METHOD(TG(req));
- SG(sapi_headers).http_response_code = 200;
- SG(request_info).content_type = TG(req)->content_type;
- SG(request_info).content_length = 0; // TG(req)->contentlength;
-
-#if 0
- php_handle_auth_data(TG(hc)->authorization TSRMLS_CC);
-#endif
-}
-
-static void tux_request_dtor(TSRMLS_D)
-{
- if (TG(header_vec)) {
- /* free status_line */
- free(TG(header_vec)[0].iov_base);
- free(TG(header_vec));
- }
- if (SG(request_info).query_string)
- free(SG(request_info).query_string);
- free(SG(request_info).request_uri);
- free(SG(request_info).path_translated);
-}
-
-#if 0
-static void *separate_thread(void *bla)
-{
- int fd;
- int i = 0;
-
- fd = (int) bla;
-
- while (i++ < 5) {
- send(fd, "test<br />\n", 9, 0);
- sleep(1);
- }
-
- tux(TUX_ACTION_CONTINUE_REQ, (user_req_t *) fd);
- /* We HAVE to trigger some event on the fd. Otherwise
- fast_thread won't wake up, so that the eventloop
- won't be entered -> TUX hangs */
- shutdown(fd, 2);
- pthread_exit(NULL);
-}
-#endif
-
-int TUXAPI_handle_events(user_req_t *req)
-{
- TSRMLS_FETCH();
-
- if (req->event == PHP_TUX_BACKGROUND_CONN) {
- tux_closed_conn(req->sock);
- return tux(TUX_ACTION_FINISH_CLOSE_REQ, req);
- }
-
- TG(req) = req;
- TG(tux_action) = TUX_ACTION_FINISH_CLOSE_REQ;
-
- tux_request_ctor(TSRMLS_C);
-
- tux_module_main(TSRMLS_C);
-
- tux_request_dtor(TSRMLS_C);
-
- return tux(TG(tux_action), req);
-}
-
-void tux_register_on_close(void (*arg)(int))
-{
- TG(on_close) = arg;
-}
-
-void tux_closed_conn(int fd)
-{
- TSRMLS_FETCH();
-
- if (TG(on_close)) TG(on_close)(fd);
-}
-
-int tux_get_fd(void)
-{
- TSRMLS_FETCH();
-
- return TG(req)->sock;
-}
-
-void tux_set_dont_close(void)
-{
- TSRMLS_FETCH();
-
- TG(req)->event = PHP_TUX_BACKGROUND_CONN;
- tux(TUX_ACTION_POSTPONE_REQ, TG(req));
- TG(tux_action) = TUX_ACTION_EVENTLOOP;
-}
-
-void TUXAPI_init(void)
-{
- sapi_startup(&tux_sapi_module);
- tux_sapi_module.startup(&tux_sapi_module);
- SG(server_context) = (void *) 1;
-}
-
-void doesnotmatter_fini(void)
-{
- if (SG(server_context) != NULL) {
- tux_sapi_module.shutdown(&tux_sapi_module);
- sapi_shutdown();
- }
-}
-
-/*
- * 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/webjames/CREDITS b/sapi/webjames/CREDITS
deleted file mode 100644
index 73a7983e92..0000000000
--- a/sapi/webjames/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-WebJames
-Alex Waugh
diff --git a/sapi/webjames/README b/sapi/webjames/README
deleted file mode 100644
index 9a316efed7..0000000000
--- a/sapi/webjames/README
+++ /dev/null
@@ -1,28 +0,0 @@
-README for WebJames SAPI module
-by Alex Waugh <alex@alexwaugh.com>
-
-This is a SAPI module for the WebJames HTTP server, which runs on the
-RISC OS operating system.
-
-
-DOWNLOADS
-
-A recent (February 2002 or later) version of the GCCSDK cross compiler
-http://www.hard-mofo.dsvr.net/
-
-WebJames 0.35 or later
-http://www.webjames.alexwaugh.com/
-
-
-BUILDING
-
-$ cd php4
-$ ./configure \
- --host=arm-riscos-aof \
- --with-webjames=../webjames/src \
- --with-config-file-path=/Choices: \
- other PHP options
-$ make install
-$ cd ../webjames
-$ ./configure --enable-php
-$ make
diff --git a/sapi/webjames/config.m4 b/sapi/webjames/config.m4
deleted file mode 100644
index 10e0001680..0000000000
--- a/sapi/webjames/config.m4
+++ /dev/null
@@ -1,20 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_ARG_WITH(webjames,
-[ --with-webjames=SRCDIR Build PHP as a WebJames module (RISC OS only)],[
- PHP_EXPAND_PATH($withval, WEBJAMES)
- INSTALL_IT="\
- echo 'PHP_LIBS = -l$abs_srcdir/$SAPI_STATIC \$(PHP_LIBS) \$(EXTRA_LIBS)' > $WEBJAMES/build/php; \
- echo 'PHP_LDFLAGS = \$(NATIVE_RPATHS) \$(PHP_LDFLAGS)' >> $WEBJAMES/build/php; \
- echo 'PHP_CFLAGS = -DPHP \$(COMMON_FLAGS) \$(EXTRA_CFLAGS) -I$abs_srcdir/sapi/webjames' >> $WEBJAMES/build/php;"
- PHP_WEBJAMES="yes, using $WEBJAMES"
- PHP_ADD_INCLUDE($WEBJAMES)
- PHP_SELECT_SAPI(webjames, static, webjames.c)
-],[
- PHP_WEBJAMES="no"
-])
-
-AC_MSG_CHECKING(for webjames)
-AC_MSG_RESULT($PHP_WEBJAMES)
diff --git a/sapi/webjames/php_webjames.h b/sapi/webjames/php_webjames.h
deleted file mode 100644
index 62a74b0bd4..0000000000
--- a/sapi/webjames/php_webjames.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Alex Waugh <alex@alexwaugh.com> |
- +----------------------------------------------------------------------+
-*/
-
-#ifndef PHP_WEBJAMES_H
-#define PHP_WEBJAMES_H
-
-#include "webjames.h"
-
-void webjames_php_shutdown(void);
-int webjames_php_init(void);
-void webjames_php_request(struct connection *conn);
-
-#endif
diff --git a/sapi/webjames/webjames.c b/sapi/webjames/webjames.c
deleted file mode 100644
index beb8bca7a9..0000000000
--- a/sapi/webjames/webjames.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Alex Waugh <alex@alexwaugh.com> |
- +----------------------------------------------------------------------+
-*/
-
-
-#include "php.h"
-#include "SAPI.h"
-#include "php_main.h"
-#include "php_variables.h"
-
-#define WEBJAMES_PHP_ONLY
-#include "php_webjames.h"
-
-#include <unixlib/local.h>
-
-#define WEBJAMES_SAPI_VERSION "1.0.0"
-
-typedef struct {
- struct connection *conn; /*structure holding all the details of the current request*/
- int bodyread; /*amount of POST body read*/
- closefn oldclose; /*function to call to close the connection*/
-} php_webjames_globals;
-
-static php_webjames_globals webjames_globals;
-
-#define WG(v) (webjames_globals.v)
-
-static int sapi_webjames_ub_write(const char *str, uint str_length TSRMLS_DC)
-/*unbuffered write - send data straight out to socket*/
-{
- int bytes;
-
- bytes = webjames_writebuffer(WG(conn),str,str_length);
- if (bytes<0) {
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- if (!PG(ignore_user_abort)) {
- zend_bailout();
- }
- }
- return bytes;
-}
-
-static void sapi_webjames_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC)
-/*send an HTTP header*/
-{
- if (WG(conn)->flags.outputheaders) {
- if (sapi_header)
- webjames_writebuffer(WG(conn), sapi_header->header, sapi_header->header_len);
- webjames_writestring(WG(conn), "\r\n");
- }
-}
-
-static int sapi_webjames_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-/*read some of the post data*/
-{
- if (WG(conn)->body==NULL) return 0;
- if (count_bytes+WG(bodyread)>WG(conn)->bodysize) count_bytes=WG(conn)->bodysize-WG(bodyread);
- memcpy(buffer, WG(conn)->body+WG(bodyread), count_bytes);
- WG(bodyread)+=count_bytes;
- return count_bytes;
-}
-
-static char *sapi_webjames_read_cookies(TSRMLS_D)
-{
- return WG(conn)->cookie;
-}
-
-#define BUF_SIZE 512
-#define ADD_STRING(name,string)\
- php_register_variable(name, string, track_vars_array TSRMLS_CC)
-
-#define ADD_NUM(name,field) {\
- snprintf(buf, BUF_SIZE, "%d", WG(conn)->field);\
- php_register_variable(name, buf, track_vars_array TSRMLS_CC);\
-}
-
-#define ADD_FIELD(name, field) \
- if (WG(conn)->field) { \
- php_register_variable(name, WG(conn)->field, track_vars_array TSRMLS_CC); \
- }
-
-static void sapi_webjames_register_variables(zval *track_vars_array TSRMLS_DC)
-{
- char buf[BUF_SIZE + 1];
-
- buf[BUF_SIZE] = '\0';
-
- ADD_STRING("SERVER_SOFTWARE", configuration.server);
- ADD_STRING("SERVER_NAME", configuration.serverip);
- ADD_FIELD("SERVER_PROTOCOL", protocol);
- ADD_NUM("SERVER_PORT", port);
- ADD_STRING("SERVER_ADMIN",configuration.webmaster);
- ADD_STRING("GATEWAY_INTERFACE", "CGI/1.1");
- ADD_STRING("DOCUMENT_ROOT", configuration.site);
-
- ADD_FIELD("REQUEST_METHOD", methodstr);
- ADD_FIELD("REQUEST_URI", requesturi);
- ADD_STRING("PATH_TRANSLATED", SG(request_info).path_translated);
- ADD_FIELD("SCRIPT_NAME", uri);
- ADD_FIELD("PHP_SELF", uri);
- ADD_FIELD("QUERY_STRING", args);
-
-
- snprintf(buf, BUF_SIZE, "%d.%d.%d.%d", WG(conn)->ipaddr[0], WG(conn)->ipaddr[1], WG(conn)->ipaddr[2], WG(conn)->ipaddr[3]);
- ADD_STRING("REMOTE_ADDR", buf);
- if (WG(conn)->dnsstatus == DNS_OK) ADD_FIELD("REMOTE_HOST", host);
-
- if ((WG(conn)->method == METHOD_POST) || (WG(conn)->method == METHOD_PUT)) {
- ADD_NUM("CONTENT_LENGTH", bodysize);
- ADD_FIELD("CONTENT_TYPE", type);
- }
-
- if ((WG(conn)->method == METHOD_PUT) || (WG(conn)->method == METHOD_DELETE)) ADD_FIELD("ENTITY_PATH", requesturi);
-
- if (WG(conn)->pwd) {
- ADD_STRING("AUTH_TYPE", "basic");
- ADD_FIELD("REMOTE_USER", authorization);
- }
-
- ADD_FIELD("HTTP_COOKIE", cookie);
- ADD_FIELD("HTTP_USER_AGENT", useragent);
- ADD_FIELD("HTTP_REFERER", referer);
- ADD_FIELD("HTTP_ACCEPT", accept);
- ADD_FIELD("HTTP_ACCEPT_LANGUAGE", acceptlanguage);
- ADD_FIELD("HTTP_ACCEPT_CHARSET", acceptcharset);
- ADD_FIELD("HTTP_ACCEPT_ENCODING", acceptencoding);
-}
-
-static void webjames_module_main(TSRMLS_D)
-{
- zend_file_handle file_handle;
- FILE *fp=NULL;
- char *path;
-
- /* Convert filename to Unix format*/
- __riscosify_control|=__RISCOSIFY_DONT_CHECK_DIR;
- path = __unixify(WG(conn)->filename,0,NULL,1024,0);
- if (path) SG(request_info).path_translated = estrdup(path);
-
- SG(request_info).query_string = WG(conn)->args;
- SG(request_info).request_uri = WG(conn)->requesturi;
- SG(request_info).request_method = WG(conn)->methodstr;
- if (WG(conn)->method==METHOD_HEAD) {
- SG(request_info).headers_only = 1;
- } else {
- SG(request_info).headers_only = 0;
- }
- SG(sapi_headers).http_response_code = 200;
- SG(request_info).content_type = WG(conn)->type;
- SG(request_info).content_length = WG(conn)->bodysize;
-
- SG(request_info).auth_user = NULL;
- SG(request_info).auth_password = NULL;
- if (WG(conn)->authorization) {
- char *colon=strchr(WG(conn)->authorization,':');
- if (colon) {
- SG(request_info).auth_user = emalloc(colon-WG(conn)->authorization+1);
- if (SG(request_info).auth_user) {
- memcpy(SG(request_info).auth_user,WG(conn)->authorization,colon-WG(conn)->authorization);
- SG(request_info).auth_user[colon-WG(conn)->authorization]='\0';
- SG(request_info).auth_password = estrdup(colon+1);
- }
- }
- }
-
- /*ensure that syslog calls get logged separately from WebJames' main log */
- openlog("PHP",0,0);
-
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = SG(request_info).path_translated;
- file_handle.free_filename = 0;
- file_handle.opened_path = NULL;
-
- if (php_request_startup(TSRMLS_C) == FAILURE) {
- return;
- }
-
- php_execute_script(&file_handle TSRMLS_CC);
- php_request_shutdown(NULL);
-}
-
-static void webjames_php_close(struct connection *conn, int force)
-/*called by webjames if it wants to close the connection*/
-{
- TSRMLS_FETCH();
-
- php_request_shutdown(NULL);
- WG(oldclose)(conn,force);
-}
-
-void webjames_php_request(struct connection *conn)
-/*called by WebJames to start handler*/
-{
- TSRMLS_FETCH();
-
- WG(conn) = conn;
- WG(bodyread) = 0;
- WG(oldclose) = conn->close;
- conn->close=webjames_php_close;
-
- webjames_module_main(TSRMLS_C);
-
- WG(oldclose)(WG(conn), 0);
-}
-
-static void php_info_webjames(ZEND_MODULE_INFO_FUNC_ARGS)
-{
- php_info_print_table_start();
- php_info_print_table_row(2, "SAPI module version", WEBJAMES_SAPI_VERSION);
- php_info_print_table_row(2, "WebJames version", WEBJAMES_VERSION " (" WEBJAMES_DATE ")");
- php_info_print_table_end();
-}
-
-static zend_module_entry php_webjames_module = {
-#if ZEND_MODULE_API_NO >= 20010901
- STANDARD_MODULE_HEADER,
-#endif
- "WebJames",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- php_info_webjames,
-#if ZEND_MODULE_API_NO >= 20010901
- WEBJAMES_SAPI_VERSION,
-#endif
- STANDARD_MODULE_PROPERTIES
-};
-
-
-static int php_webjames_startup(sapi_module_struct *sapi_module)
-{
- if(php_module_startup(sapi_module, &php_webjames_module, 1) == FAILURE) {
- return FAILURE;
- } else {
- return SUCCESS;
- }
-}
-
-static sapi_module_struct sapi_module = {
- "webjames", /* name */
- "WebJames", /* pretty name */
-
- php_webjames_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- sapi_webjames_ub_write, /* unbuffered write */
- NULL, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error, /* error handler */
-
- NULL, /* header handler */
- NULL, /* send headers handler */
- sapi_webjames_send_header, /* send header handler */
- sapi_webjames_read_post, /* read POST data */
- sapi_webjames_read_cookies, /* read Cookies */
-
- sapi_webjames_register_variables, /* register server variables */
- NULL, /* Log message */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-int webjames_php_init(void)
-/*called when WebJames initialises*/
-{
- TSRMLS_FETCH();
- if (strcmp(configuration.webjames_h_revision,WEBJAMES_H_REVISION)!=0) {
- /*This file was compiled against a different revision of
- webjames.h than webjames was, which could be bad news*/
- webjames_writelog(0,"PHP module is compiled for WebJames (%s) and was linked with a different version (%s)",WEBJAMES_H_REVISION,configuration.webjames_h_revision);
- return 0; /*failed to initialise*/
- }
- sapi_startup(&sapi_module);
- sapi_module.startup(&sapi_module);
- SG(server_context) = (void *) 1;
- return 1; /*initialised correctly*/
-}
-
-void webjames_php_shutdown(void)
-/*called when WebJames is about to quit*/
-{
- sapi_module.shutdown(&sapi_module);
- sapi_shutdown();
-}