summaryrefslogtreecommitdiff
path: root/sapi
diff options
context:
space:
mode:
Diffstat (limited to 'sapi')
-rw-r--r--sapi/activescript/classfactory.cpp361
-rw-r--r--sapi/activescript/php4activescript.c156
-rw-r--r--sapi/activescript/php4activescript.def5
-rw-r--r--sapi/activescript/php4activescript.dsp185
-rw-r--r--sapi/activescript/php4activescript.h26
-rw-r--r--sapi/activescript/php4as_classfactory.h52
-rw-r--r--sapi/activescript/php4as_scriptengine.h234
-rw-r--r--sapi/activescript/scriptengine.cpp1813
-rw-r--r--sapi/aolserver/CREDITS2
-rw-r--r--sapi/aolserver/README69
-rw-r--r--sapi/aolserver/aolserver.c624
-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.m4237
-rw-r--r--sapi/apache/libphp4.module.in11
-rw-r--r--sapi/apache/mod_php4.c883
-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.c474
-rw-r--r--sapi/apache/php_apache_http.h34
-rw-r--r--sapi/apache/sapi_apache.c75
-rw-r--r--sapi/apache2filter/CREDITS2
-rw-r--r--sapi/apache2filter/README70
-rw-r--r--sapi/apache2filter/apache_config.c205
-rw-r--r--sapi/apache2filter/config.m494
-rw-r--r--sapi/apache2filter/php.sym1
-rw-r--r--sapi/apache2filter/php4apache2.dsp142
-rw-r--r--sapi/apache2filter/php_apache.h64
-rw-r--r--sapi/apache2filter/php_functions.c182
-rw-r--r--sapi/apache2filter/sapi_apache2.c570
-rw-r--r--sapi/caudium/CREDITS2
-rw-r--r--sapi/caudium/README16
-rw-r--r--sapi/caudium/TODO30
-rw-r--r--sapi/caudium/caudium.c784
-rw-r--r--sapi/caudium/config.m499
-rw-r--r--sapi/cgi/CREDITS2
-rw-r--r--sapi/cgi/cgi_main.c1119
-rw-r--r--sapi/cgi/config.m499
-rw-r--r--sapi/cgi/getopt.c175
-rw-r--r--sapi/cgi/libfcgi/LICENSE.TERMS28
-rw-r--r--sapi/cgi/libfcgi/fcgi_stdio.c801
-rw-r--r--sapi/cgi/libfcgi/fcgiapp.c2307
-rw-r--r--sapi/cgi/libfcgi/include/fastcgi.h136
-rw-r--r--sapi/cgi/libfcgi/include/fcgi_config.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.h626
-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.h136
-rw-r--r--sapi/cgi/libfcgi/os_unix.c1265
-rw-r--r--sapi/cgi/libfcgi/os_win32.c2076
-rw-r--r--sapi/cgi/libfcgi/strerror.c91
-rw-r--r--sapi/cgi/php.sym0
-rw-r--r--sapi/cgi/php_getopt.h7
-rw-r--r--sapi/cli/CREDITS2
-rw-r--r--sapi/cli/README19
-rw-r--r--sapi/cli/TODO6
-rw-r--r--sapi/cli/config.m422
-rw-r--r--sapi/cli/getopt.c173
-rw-r--r--sapi/cli/php_cli.c698
-rw-r--r--sapi/cli/php_getopt.h7
-rw-r--r--sapi/fastcgi/CREDITS4
-rw-r--r--sapi/fastcgi/README.Apache53
-rw-r--r--sapi/fastcgi/README.FastCGI91
-rw-r--r--sapi/fastcgi/config.m428
-rw-r--r--sapi/fastcgi/fastcgi.c621
-rw-r--r--sapi/fastcgi/fastcgi.dsp195
-rw-r--r--sapi/fastcgi/php.sym0
-rw-r--r--sapi/fastcgi/php_fastcgi.h28
-rw-r--r--sapi/fastcgi/windows.txt35
-rw-r--r--sapi/fhttpd/CREDITS2
-rw-r--r--sapi/fhttpd/fhttpd.c185
-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.c861
-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/nsapi/CREDITS2
-rw-r--r--sapi/nsapi/config.m438
-rw-r--r--sapi/nsapi/nsapi-readme.txt76
-rw-r--r--sapi/nsapi/nsapi.c542
-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.c312
-rw-r--r--sapi/pi3web/CREDITS2
-rw-r--r--sapi/pi3web/README50
-rw-r--r--sapi/pi3web/config.m427
-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.c728
-rw-r--r--sapi/servlet/CREDITS2
-rw-r--r--sapi/servlet/EXPERIMENTAL5
-rw-r--r--sapi/servlet/Makefile.frag19
-rw-r--r--sapi/servlet/README122
-rw-r--r--sapi/servlet/config.m452
-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.c404
-rw-r--r--sapi/servlet/servlet.dsp286
-rw-r--r--sapi/servlet/servlet.java219
-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/README59
-rw-r--r--sapi/thttpd/config.m427
-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.c651
-rw-r--r--sapi/thttpd/thttpd_patch240
-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.c444
-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.c324
149 files changed, 0 insertions, 28236 deletions
diff --git a/sapi/activescript/classfactory.cpp b/sapi/activescript/classfactory.cpp
deleted file mode 100644
index 3d4f256db6..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(&factory_count);
-}
-
-TPHPClassFactory::~TPHPClassFactory()
-{
- InterlockedDecrement(&factory_count);
-}
-
-void TPHPClassFactory::AddToObjectCount(void)
-{
- InterlockedIncrement(&object_count);
-}
-
-void TPHPClassFactory::RemoveFromObjectCount(void)
-{
- InterlockedDecrement(&object_count);
-}
-
-STDMETHODIMP_(DWORD) TPHPClassFactory::AddRef(void)
-{
- return InterlockedIncrement(&m_refcount);
-}
-
-STDMETHODIMP_(DWORD) TPHPClassFactory::Release(void)
-{
- DWORD ret = InterlockedDecrement(&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 eed1d7e52e..0000000000
--- a/sapi/activescript/php4activescript.c
+++ /dev/null
@@ -1,156 +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$ */
-
-#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) == FAILURE ||
- zend_startup_module(&php_activescript_module) == 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 */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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 423958fba0..0000000000
--- a/sapi/activescript/php4activescript.h
+++ /dev/null
@@ -1,26 +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$ */
-
-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 bc4d530c03..0000000000
--- a/sapi/activescript/php4as_classfactory.h
+++ /dev/null
@@ -1,52 +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 */
-
-#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 1d2314b5e2..0000000000
--- a/sapi/activescript/php4as_scriptengine.h
+++ /dev/null
@@ -1,234 +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$ */
-
-#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
-};
-
-struct php_active_script_get_dispatch_info {
- LPCOLESTR pstrItemName;
- LPSTREAM dispatch;
-};
-
-struct php_active_script_add_named_item_info {
- LPCOLESTR pstrName;
- DWORD dwFlags;
- IUnknown *punk;
- ITypeInfo *ptyp;
- IDispatch *pdisp;
- LPSTREAM 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;
- /* [out] */ IDispatch **ppdisp;
-};
-
-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 b0dc40dcb5..0000000000
--- a/sapi/activescript/scriptengine.cpp
+++ /dev/null
@@ -1,1813 +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.
- *
- * For talking to the site from engine thread, we use an invisible window:
- * the window processing is guaranteed to occur in the correct thread,
- * and the message queue provides a useful synchronization device.
- *
- * For talking to the engine from any other thread, the engine thread waits
- * for messages to arrive at it's message queue. Since the only API for
- * dealing with thread messages is asynchronous, we use a mutex to ensure
- * that only one thread can talk to the engine at a time, and an event
- * object to signal to it that the processing is complete.
- *
- * */
-
-#define _WIN32_DCOM
-
-#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/com/com.h"
-#include "ext/com/php_COM.h"
-#include "ext/com/conversion.h"
-}
-#include "php4as_scriptengine.h"
-#include "php4as_classfactory.h"
-#include <objbase.h>
-
-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));
-}
-
-
-
-/* {{{ 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";
- }
-}
-/* }}} */
-
-/* {{{ 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);
-}
-/* }}} */
-
-/* {{{ 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) { 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;
- }
-};
-/* }}} */
-
-/* {{{ 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(&m_refcount);
- }
-
- STDMETHODIMP_(DWORD) Release(void) {
- DWORD ret = InterlockedDecrement(&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;
-
- 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;
- }
-};
-/* }}} */
-
-/* {{{ 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();
- CoDisconnectObject((IUnknown*)disp, 0);
- 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);
-}
-
-/* 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");
- 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;
-
- }
- 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;
- char *itemname;
- unsigned int itemlen;
-
- if (info->pstrItemName != NULL) {
- zval **tmp;
-
- itemname = php_OLECHAR_to_char((OLECHAR*)info->pstrItemName, &itemlen, CP_ACP TSRMLS_CC);
-
- /* 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, itemlen+1, (void**)&tmp) == SUCCESS) {
- if (Z_TYPE_PP(tmp) == IS_OBJECT) {
- disp = php_COM_export_object(*tmp TSRMLS_CC);
- }
- }
- trace("%08x: GetScriptDispatch(%s --> %08x)\n", this, itemname, disp);
-
- efree(itemname);
-
- } else {
-#if 0
- zval *obj;
-
- MAKE_STD_ZVAL(obj);
- object_init(obj);
- disp = php_COM_export_object(obj TSRMLS_CC);
-#else
-
- disp = (IDispatch*) new ScriptDispatch;
-#endif
- trace("%08x: GetScriptDispatch(NULL --> %08x)\n", this, disp);
- }
-
- if (disp) {
- trace("--- Marshaling to stream\n");
- ret = CoMarshalInterThreadInterfaceInStream(IID_IDispatch, disp, &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(CoGetInterfaceAndReleaseStream(info->marshal, IID_IDispatch, (void**)&disp)))
- add_to_global_namespace(disp, info->dwFlags, name.ansi_string() TSRMLS_CC);
-
- }
- break;
- case PHPSE_SET_SITE:
- {
- LPSTREAM stream = (LPSTREAM)lParam;
-
- if (m_pass_eng) {
- m_pass_eng->Release();
- m_pass_eng = NULL;
- }
-
- if (stream)
- CoGetInterfaceAndReleaseStream(stream, 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
- code(info->pstrCode),
- formal_params(info->pstrFormalParams),
- procedure_name(info->pstrProcedureName),
- item_name(info->pstrItemName),
- delimiter(info->pstrDelimiter);
-
- trace("%08x: ParseProc:\n state=%s\ncode=%s\n params=%s\nproc=%s\nitem=%s\n delim=%s\n line=%d\n",
- this, scriptstate_to_string(m_scriptstate),
- code.safe_ansi_string(), 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->AddRef();
- disp->m_frag = frag;
- disp->m_procflags = info->dwFlags;
- disp->m_engine = this;
- frag->ptr = disp;
-
- *info->ppdisp = disp;
- /*
- ret = CoMarshalInterThreadInterfaceInStream(IID_IDispatch, disp, &info->disp);
- disp->Release();
- */
- } 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 {
-
- 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(&m_refcount);
-}
-
-STDMETHODIMP_(DWORD) TPHPScriptingEngine::Release(void)
-{
- DWORD ret = InterlockedDecrement(&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_IActiveScriptParse32, iid)) {
- *ppvObject = (IActiveScriptParse32*)this;
- } else if (IsEqualGUID(IID_IActiveScriptParseProcedure32, 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();
-
- LPSTREAM stream;
- if (SUCCEEDED(CoMarshalInterThreadInterfaceInStream(IID_IActiveScriptSite, m_pass, &stream)))
- SEND_THREAD_MESSAGE(this, PHPSE_SET_SITE, 0, (LPARAM)stream 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(CoMarshalInterThreadInterfaceInStream(IID_IDispatch, info.punk, &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)) {
- CoGetInterfaceAndReleaseStream(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;
- info.ppdisp = ppdisp;
-
- ret = SEND_THREAD_MESSAGE(this, PHPSE_PARSE_PROC, 0, (LPARAM)&info TSRMLS_CC);
-
- /*
- if (ret == S_OK) {
- ret = CoGetInterfaceAndReleaseStream(info.disp, 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(&m_refcount);
- }
-
- STDMETHODIMP_(DWORD) Release(void) {
- DWORD ret = InterlockedDecrement(&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 d33918f55a..0000000000
--- a/sapi/aolserver/aolserver.c
+++ /dev/null
@@ -1,624 +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: 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 align=\"center\">" 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;
-
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
-
- 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) == FAILURE
- || zend_startup_module(&php_aolserver_module) == 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;
- int buf_len;
-
- buf_len = 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 */
-
- NULL, /* php.ini path override */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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 f0d1fae255..0000000000
--- a/sapi/apache/config.m4
+++ /dev/null
@@ -1,237 +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`
-
- # Test that we're trying to configure with apache 1.x
- APACHE_VERSION=`$APXS_HTTPD -v | head -1 | cut -f3 -d' ' | cut -f2 -d'/' | cut -f1 -d'-' | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
- 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, 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, bundle, sapi_apache.c mod_php4.c php_apache.c, -I$APXS_INCLUDEDIR)
- ;;
- *)
- PHP_SELECT_SAPI(apache, 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/mod_php4.* sapi/apache/libphp4.module"
-
-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.],[
- 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, 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_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 ccb97493a7..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_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/mod_php4.c b/sapi/apache/mod_php4.c
deleted file mode 100644
index 0faa7b13f4..0000000000
--- a/sapi/apache/mod_php4.c
+++ /dev/null
@@ -1,883 +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: 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"
-
-#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);
-void php_save_umask(void);
-void php_restore_umask(void);
-int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC);
-char *sapi_apache_read_cookies(TSRMLS_D);
-int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC);
-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);
-int php_xbithack_handler(request_rec * r);
-void php_init_handler(server_rec *s, pool *p);
-/* }}} */
-
-#if MODULE_MAGIC_NUMBER >= 19970728
-static void php_child_exit_handler(server_rec *s, pool *p);
-#endif
-
-#if MODULE_MAGIC_NUMBER > 19961007
-#define CONST_PREFIX const
-#else
-#define CONST_PREFIX
-#endif
-CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
-CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
-CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
-CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
-CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
-CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
-
-/* ### these should be defined in mod_php4.h or somewhere else */
-#define USE_PATH 1
-#define IGNORE_URL 2
-
-module MODULE_VAR_EXPORT php4_module;
-
-int saved_umask;
-static unsigned char apache_php_initialized;
-
-typedef struct _php_per_dir_entry {
- char *key;
- char *value;
- uint key_length;
- uint value_length;
- int type;
-} php_per_dir_entry;
-
-/* some systems are missing these from their header files */
-
-/* {{{ php_save_umask
- */
-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
- */
-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);
-
- 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
- */
-char *sapi_apache_read_cookies(TSRMLS_D)
-{
- return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, "HTTP_COOKIE");
-}
-/* }}} */
-
-/* {{{ sapi_apache_header_handler
- */
-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) {
- 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
- */
-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) == FAILURE
- || zend_startup_module(&apache_module_entry) == 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);
- SG(server_context) = NULL; /* The server context (request) is invalid by the time run_cleanups() is called */
- if (AP(in_request)) {
- AP(in_request) = 0;
- php_request_shutdown(dummy);
- }
-}
-/* }}} */
-
-/* {{{ 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
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-/* }}} */
-
-/* {{{ php_restore_umask
- */
-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;
- 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_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 {
- /* We don't accept OPTIONS requests, but take everything else */
- if (r->method_number == M_OPTIONS) {
- r->allowed |= (1 << METHODS) - 1;
- return DECLINED;
- }
-
- /* Make sure file exists */
- if (filename == NULL && r->finfo.st_mode == 0) {
- return DECLINED;
- }
-
- 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(php_per_dir_entry *orig_per_dir_entry, php_per_dir_entry *new_per_dir_entry)
-{
- if (new_per_dir_entry->type==PHP_INI_SYSTEM
- && orig_per_dir_entry->type!=PHP_INI_SYSTEM) {
- return 1;
- } else {
- return 0;
- }
-}
-/* }}} */
-
-/* {{{ 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(per_dir_info, 5, NULL, (void (*)(void *)) destroy_per_dir_entry, 1);
- register_cleanup(p, (void *) per_dir_info, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) zend_hash_destroy);
-
- return per_dir_info;
-}
-/* }}} */
-
-/* {{{ 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), (zend_bool (*)(void *, void *)) should_overwrite_per_dir_entry);
- return addv;
-}
-/* }}} */
-
-/* {{{ php_apache_value_handler_ex
- */
-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
- */
-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
- */
-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
- */
-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
- */
-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
- */
-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)
- */
-int php_xbithack_handler(request_rec * r)
-{
- php_apache_info_struct *conf;
-
- conf = (php_apache_info_struct *) get_module_config(r->per_dir_config, &php4_module);
- if (!(r->finfo.st_mode & S_IXUSR)) {
- r->allowed |= (1 << METHODS) - 1;
- return DECLINED;
- }
- if (conf->xbithack == 0) {
- r->allowed |= (1 << METHODS) - 1;
- return DECLINED;
- }
- return send_parsed_php(r);
-}
-/* }}} */
-
-/* {{{ 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)
- */
-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 2570793e53..0000000000
--- a/sapi/apache/mod_php4.h
+++ /dev/null
@@ -1,54 +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: 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 a658d7dae9..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\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 - 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\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.dll" /pdbtype:sept /libpath:"..\..\..\php_build\apache\src\cored" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"
-
-!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\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 - 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 b7572922b5..0000000000
--- a/sapi/apache/php_apache.c
+++ /dev/null
@@ -1,474 +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: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Stig Sæther Bakken <ssb@fast.no> |
- | David Sklar <sklar@student.net> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include "php_apache_http.h"
-
-#ifdef PHP_WIN32
-#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")
-
-extern module *top_module;
-
-PHP_FUNCTION(virtual);
-PHP_FUNCTION(getallheaders);
-PHP_FUNCTION(apachelog);
-PHP_FUNCTION(apache_note);
-PHP_FUNCTION(apache_lookup_uri);
-PHP_FUNCTION(apache_child_terminate);
-PHP_FUNCTION(apache_setenv);
-
-PHP_MINFO_FUNCTION(apache);
-
-function_entry apache_functions[] = {
- PHP_FE(virtual, NULL)
- PHP_FE(getallheaders, NULL)
- PHP_FE(apache_note, NULL)
- PHP_FE(apache_lookup_uri, NULL)
- PHP_FE(apache_child_terminate, NULL)
- PHP_FE(apache_setenv, 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), 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 string 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)
-{
- pval **arg_name, **arg_val;
- char *note_val;
- int arg_count = ARG_COUNT(ht);
-
- 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();
-#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)
- 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 (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
-
- if (!(rr = sub_req_lookup_uri ((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error(E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
- RETURN_FALSE;
- }
-
- if (rr->status != 200) {
- php_error(E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
- RETURN_FALSE;
- }
-
- 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;
- }
-}
-/* }}} */
-
-/* {{{ proto array getallheaders(void)
- Fetch all HTTP request headers */
-PHP_FUNCTION(getallheaders)
-{
- array_header *env_arr;
- table_entry *tenv;
- int i;
-
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
- env_arr = table_elts(((request_rec *) SG(server_context))->headers_in);
- tenv = (table_entry *)env_arr->elts;
- for (i = 0; i < env_arr->nelts; ++i) {
- if (!tenv[i].key ||
- (PG(safe_mode) &&
- !strncasecmp(tenv[i].key, "authorization", 13))) {
- continue;
- }
- if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
- RETURN_FALSE;
- }
- }
-}
-/* }}} */
-
-/* {{{ proto 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 (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
-
- if(!(rr = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val);
- RETURN_FALSE;
- }
- object_init(return_value);
- add_property_long(return_value,"status", rr->status);
- if (rr->the_request) {
- add_property_string(return_value,"the_request", rr->the_request, 1);
- }
- if (rr->status_line) {
- add_property_string(return_value,"status_line", (char *)rr->status_line, 1);
- }
- if (rr->method) {
- add_property_string(return_value,"method", (char *)rr->method, 1);
- }
- if (rr->content_type) {
- add_property_string(return_value,"content_type", (char *)rr->content_type, 1);
- }
- if (rr->handler) {
- add_property_string(return_value,"handler", (char *)rr->handler, 1);
- }
- if (rr->uri) {
- add_property_string(return_value,"uri", rr->uri, 1);
- }
- if (rr->filename) {
- add_property_string(return_value,"filename", rr->filename, 1);
- }
- if (rr->path_info) {
- add_property_string(return_value,"path_info", rr->path_info, 1);
- }
- if (rr->args) {
- add_property_string(return_value,"args", rr->args, 1);
- }
- if (rr->boundary) {
- add_property_string(return_value,"boundary", rr->boundary, 1);
- }
- add_property_long(return_value,"no_cache", rr->no_cache);
- add_property_long(return_value,"no_local_copy", rr->no_local_copy);
- add_property_long(return_value,"allowed", rr->allowed);
- add_property_long(return_value,"sent_bodyct", rr->sent_bodyct);
- add_property_long(return_value,"bytes_sent", rr->bytes_sent);
- add_property_long(return_value,"byterange", rr->byterange);
- add_property_long(return_value,"clength", rr->clength);
-
-#if MODULE_MAGIC_NUMBER >= 19980324
- if (rr->unparsed_uri) {
- add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1);
- }
- if(rr->mtime) {
- add_property_long(return_value,"mtime", rr->mtime);
- }
-#endif
- if(rr->request_time) {
- add_property_long(return_value,"request_time", rr->request_time);
- }
-
- destroy_sub_req(rr);
-}
-/* }}} */
-
-
-#if 0
-This function is most likely a bad idea. Just playing with it for now.
-
-PHP_FUNCTION(apache_exec_uri)
-{
- pval **filename;
- request_rec *rr=NULL;
- TSRMLS_FETCH();
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
-
- if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val);
- RETURN_FALSE;
- }
- RETVAL_LONG(ap_run_sub_req(rr));
- ap_destroy_sub_req(rr);
-}
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * 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 6d41f418ab..0000000000
--- a/sapi/apache/php_apache_http.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#define NO_REGEX_EXTRA_H
-
-#ifdef WIN32
-#include <winsock2.h>
-#include <stddef.h>
-#endif
-
-#include "zend.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"
diff --git a/sapi/apache/sapi_apache.c b/sapi/apache/sapi_apache.c
deleted file mode 100644
index aa935b90db..0000000000
--- a/sapi/apache/sapi_apache.c
+++ /dev/null
@@ -1,75 +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: 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/README b/sapi/apache2filter/README
deleted file mode 100644
index 73498c1cc3..0000000000
--- a/sapi/apache2filter/README
+++ /dev/null
@@ -1,70 +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
-
- Get the latest Apache 2.0 sources from CVS and install it. This
- SAPI module is known to work with Apache 2.0.35.
-
- $ 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
-
- 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. Set the variable "ONE_PROCESS" to 1 and export it before
- starting Apache/a debugger.
-
- 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
- Syntax Highlighter (relies on files as well)
diff --git a/sapi/apache2filter/apache_config.c b/sapi/apache2filter/apache_config.c
deleted file mode 100644
index 90a544415f..0000000000
--- a/sapi/apache2filter/apache_config.c
+++ /dev/null
@@ -1,205 +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: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-#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;
- php_dir_entry *pe;
- size_t str_len;
-
- phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config)));
- e.value = apr_pstrdup(cmd->pool, value);
- e.value_len = strlen(value);
- e.status = status;
-
- str_len = strlen(name);
-
- if (zend_hash_find(&d->config, (char *) name, str_len + 1, (void **) &pe) == SUCCESS) {
- if (pe->status > status)
- return NULL;
- }
-
- 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_USER);
-}
-
-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")) {
- 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_USER);
-}
-
-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;
-}
-
-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 + 1,
- 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,
- "PHP Value Modifier (Admin)"),
- AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_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 76248f6f8c..0000000000
--- a/sapi/apache2filter/config.m4
+++ /dev/null
@@ -1,94 +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`
-
- 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
- APACHE_VERSION=`$APXS_HTTPD -v | head -1 | cut -f3 -d' ' | cut -f2 -d'/' | cut -f1 -d'-' | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
- 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 2000035; then
- AC_MSG_ERROR([Please note that Apache version >= 2.0.35 is required.])
- fi
-
- case $host_alias in
- *aix*)
- APXS_SBINDIR=`$APXS -q SBINDIR`
- EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-bI:$APXS_SBINDIR/httpd.exp"
- PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c)
- INSTALL_IT="$APXS -i -a -n php4 $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="$APXS -i -a -n php4 $SAPI_SHARED"
- ;;
- *)
- PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c)
- INSTALL_IT="$APXS -i -a -n php4 $SAPI_LIBTOOL"
- ;;
- esac
-
- PHP_ADD_INCLUDE($APXS_INCLUDEDIR)
- PHP_BUILD_THREAD_SAFE
- 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 e96fd404f1..0000000000
--- a/sapi/apache2filter/php_apache.h
+++ /dev/null
@@ -1,64 +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: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-#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;
- /* 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;
-
-int php_apache_register_module(void);
-void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf);
-void *create_php_config(apr_pool_t *p, char *dummy);
-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 605e6de390..0000000000
--- a/sapi/apache2filter/php_functions.c
+++ /dev/null
@@ -1,182 +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: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-#include "php.h"
-#include "SAPI.h"
-
-#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(INTERNAL_FUNCTION_PARAMETERS)
-{
- zval **p1;
- php_struct *ctx;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p1) == FAILURE)
- return NULL;
-
- convert_to_string_ex(p1);
-
- ctx = SG(server_context);
- return ap_sub_req_lookup_uri(Z_STRVAL_PP(p1), ctx->f->r, ctx->f->next);
-}
-
-/* {{{ proto bool virtual(string uri)
- Perform an apache sub-request */
-PHP_FUNCTION(virtual)
-{
- request_rec *rr;
-
- rr = php_apache_lookup_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-
- if (!rr)
- WRONG_PARAM_COUNT;
-
- if (rr->status == HTTP_OK) {
- ap_run_sub_req(rr);
- ap_destroy_sub_req(rr);
- RETURN_TRUE;
- }
- 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;
-
- rr = php_apache_lookup_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- if (!rr)
- WRONG_PARAM_COUNT;
-
- 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_AT_LEAST(20020506,0)
- 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;
- }
- ap_destroy_sub_req(rr);
- RETURN_FALSE;
-}
-
-/* {{{ proto array getallheaders(void)
- Fetch all HTTP request headers */
-PHP_FUNCTION(getallheaders)
-{
- php_struct *ctx;
- const apr_array_header_t *arr;
- char *key, *val;
-
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
-
- 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()
-}
-/* }}} */
-
-PHP_MINFO_FUNCTION(apache)
-{
-}
-
-static function_entry apache_functions[] = {
- PHP_FE(apache_lookup_uri, NULL)
- PHP_FE(virtual, NULL)
- PHP_FE(getallheaders, NULL)
- {NULL, NULL, NULL}
-};
-
-static 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
-};
-
-int php_apache_register_module(void)
-{
- return zend_startup_module(&php_apache_module);
-}
-
-/*
- * 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 4bd2a52146..0000000000
--- a/sapi/apache2filter/sapi_apache2.c
+++ /dev/null
@@ -1,570 +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: Sascha Schumann <sascha@schumann.cx> |
- | Parts based on Apache 1.3 SAPI module by |
- | Rasmus Lerdorf and Zeev Suraski |
- +----------------------------------------------------------------------+
- */
-
-#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"
-
-#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 "php_apache.h"
-
-/* 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);
-
- /* 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);
-
- 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) 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 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 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 sapi_module_struct apache2_sapi_module = {
- "apache2filter",
- "Apache 2.0 Filter",
-
- php_module_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- php_apache_sapi_ub_write, /* unbuffered write */
- php_apache_sapi_flush, /* flush */
- NULL, /* get uid */
- NULL, /* 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 */
-
- NULL, /* php_ini_path_override */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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;
- }
-
- APR_BRIGADE_FOREACH(b, bb) {
- 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");
- auth = apr_table_get(f->r->headers_in, "Authorization");
- php_handle_auth_data(auth TSRMLS_CC);
-
- 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).query_string) {
- 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);
- TSRMLS_FETCH();
-
- if (f->r->proxyreq) {
- 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);
- }
-
- APR_BRIGADE_FOREACH(b, bb) {
- 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);
- zfd.type = ZEND_HANDLE_FILENAME;
- zfd.filename = (char *) path;
- zfd.free_filename = 0;
- zfd.opened_path = NULL;
-
- php_execute_script(&zfd TSRMLS_CC);
- php_apache_request_dtor(f TSRMLS_CC);
-
- 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();
- tsrm_shutdown();
- 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)
-{
- /* 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;
- }
-
- tsrm_startup(1, 1, 0, NULL);
- 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_register_module();
- 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)
-{
- if (r->content_type &&
- strcmp(r->content_type, "application/x-httpd-php") == 0) {
- 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, AP_FTYPE_RESOURCE);
- ap_register_input_filter("PHP", php_input_filter, 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/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 f0f0284ed2..0000000000
--- a/sapi/caudium/caudium.c
+++ /dev/null
@@ -1,784 +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: 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");
-}
-
-/* this structure is static (as in "it does not change") */
-static sapi_module_struct caudium_sapi_module = {
- "caudium",
- "Caudium",
- php_module_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 */
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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);
- zend_startup_module(&php_caudium_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 734f5c5a78..0000000000
--- a/sapi/cgi/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-CGI
-Rasmus Lerdorf, Stig Bakken
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
deleted file mode 100644
index 7bb0b7dbba..0000000000
--- a/sapi/cgi/cgi_main.c
+++ /dev/null
@@ -1,1119 +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: 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> |
- +----------------------------------------------------------------------+
-*/
-
-
-#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>
-#else
-#include "build-defs.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"
-
-#ifdef PHP_FASTCGI
-#include "fcgi_config.h"
-#include "fcgiapp.h"
-/* don't want to include fcgios.h, causes conflicts */
-extern int OS_SetImpersonate(void);
-
-FCGX_Stream *in, *out, *err;
-FCGX_ParamArray envp;
-
-/* Our original environment from when the FastCGI first started */
-char **orig_env;
-
-/* The environment given by the FastCGI */
-char **cgi_env;
-
-/* The manufactured environment, from merging the base environ with
- * the parameters set by the per-connection environment
- */
-char **merge_env;
-
-/**
- * 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
-
-#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
-
-extern char *ap_php_optarg;
-extern int ap_php_optind;
-
-#define OPTSTRING "aCc:d:ef:g:hilmnqsw?vz:"
-
-static int _print_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
-{
- php_printf("%s\n", module->name);
- return 0;
-}
-
-static int _print_extension_info(zend_extension *module, void *arg TSRMLS_DC)
-{
- php_printf("%s\n", module->name);
- return 0;
-}
-
-#ifndef STDOUT_FILENO
-#define STDOUT_FILENO 1
-#endif
-
-static inline size_t sapi_cgibin_single_write(const char *str, uint str_length)
-{
-#ifdef PHP_WRITE_STDOUT
- long ret;
-#else
- size_t ret;
-#endif
-
-#ifdef PHP_FASTCGI
- if (!FCGX_IsCGI()) {
- return FCGX_PutStr( str, str_length, out );
- }
-#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);
- if (!ret) {
- php_handle_aborted_connection();
- }
- ptr += ret;
- remaining -= ret;
- }
-
- return str_length;
-}
-
-
-static void sapi_cgibin_flush(void *server_context)
-{
-#ifdef PHP_FASTCGI
- if (!FCGX_IsCGI()) {
- if( FCGX_FFlush( out ) == -1 ) {
- php_handle_aborted_connection();
- }
- } else
-#endif
- if (fflush(stdout)==EOF) {
- php_handle_aborted_connection();
- }
-}
-
-
-static void sapi_cgi_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 sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
- uint read_bytes=0, tmp_read_bytes;
-#ifdef 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) {
-#ifdef PHP_FASTCGI
- if (!FCGX_IsCGI()) {
- tmp_read_bytes = FCGX_GetStr( pos, count_bytes-read_bytes, 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_cgi_read_cookies(TSRMLS_D)
-{
- return getenv("HTTP_COOKIE");
-}
-
-
-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;
-}
-
-
-/* {{{ sapi_module_struct cgi_sapi_module
- */
-static sapi_module_struct cgi_sapi_module = {
- "cgi", /* name */
-#ifdef PHP_FASTCGI
- "CGI/FastCGI", /* pretty name */
-#else
- "CGI", /* pretty name */
-#endif
-
- php_module_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 */
- NULL, /* getenv */
-
- php_error, /* error handler */
-
- NULL, /* header handler */
- NULL, /* send headers handler */
- sapi_cgi_send_header, /* 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 */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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>] | {<file> [args...]}\n"
- " -q Quiet-mode. Suppress HTTP Header output.\n"
- " -s Display colour syntax highlighted source.\n"
- " -w Display source with stripped comments and whitespace.\n"
- " -f <file> Parse <file>. Implies `-q'\n"
- " -v Version number\n"
- " -C Do not chdir to the script's directory\n"
- " -c <path>|<file> Look for php.ini file in this directory\n"
- " -a Run interactively\n"
- " -d foo[=bar] Define INI entry foo with value 'bar'\n"
- " -e Generate extended information for debugger/profiler\n"
- " -z <file> Load Zend extension <file>.\n"
- " -l Syntax check only (lint)\n"
- " -m Show compiled in modules\n"
- " -i PHP information\n"
- " -h This help\n", prog);
-}
-/* }}} */
-
-/* {{{ init_request_info
- */
-static void init_request_info(TSRMLS_D)
-{
- char *content_length = getenv("CONTENT_LENGTH");
- char *content_type = getenv("CONTENT_TYPE");
- const char *auth;
-
-#if 0
-/* SG(request_info).path_translated is always set to NULL at the end of this function
- call so why the hell did this code exist in the first place? Am I missing something? */
- char *script_filename;
-
-
- script_filename = getenv("SCRIPT_FILENAME");
- /* Hack for annoying servers that do not set SCRIPT_FILENAME for us */
- if (!script_filename) {
- script_filename = SG(request_info).argv0;
- }
-#ifdef PHP_WIN32
- /* FIXME WHEN APACHE NT IS FIXED */
- /* a hack for apache nt because it does not appear to set argv[1] and sets
- script filename to php.exe thus makes us parse php.exe instead of file.php
- requires we get the info from path translated. This can be removed at
- such a time that apache nt is fixed */
- if (!script_filename) {
- script_filename = getenv("PATH_TRANSLATED");
- }
-#endif
-
- /* doc_root configuration variable is currently ignored,
- as it is with every other access method currently also. */
-
- /* We always need to emalloc() filename, since it gets placed into
- the include file hash table, and gets freed with that table.
- Notice that this means that we don't need to efree() it in
- php_destroy_request_info()! */
-#if DISCARD_PATH
- if (script_filename) {
- SG(request_info).path_translated = estrdup(script_filename);
- } else {
- SG(request_info).path_translated = NULL;
- }
-#endif
-
-#endif /* 0 */
-
- SG(request_info).request_method = getenv("REQUEST_METHOD");
- SG(request_info).query_string = getenv("QUERY_STRING");
- SG(request_info).request_uri = getenv("PATH_INFO");
- if (!SG(request_info).request_uri) {
- SG(request_info).request_uri = getenv("SCRIPT_NAME");
- }
- SG(request_info).path_translated = NULL; /* we have to update it later, when we have that information */
- SG(request_info).content_type = (content_type ? content_type : "" );
- SG(request_info).content_length = (content_length?atoi(content_length):0);
- SG(sapi_headers).http_response_code = 200;
-
- /* The CGI RFC allows servers to pass on unvalidated Authorization data */
- auth = getenv("HTTP_AUTHORIZATION");
- 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);
-}
-
-/* {{{ 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=ap_php_optind;
- char *orig_optarg=ap_php_optarg;
- char *argv0=NULL;
- 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
-
-#ifdef PHP_FASTCGI
- int env_size, cgi_env_size;
- int max_requests = 500;
- int requests = 0;
- int fastcgi = !FCGX_IsCGI();
-#ifdef PHP_WIN32
- int impersonate = 0;
-#endif
-
- if (fastcgi) {
- /* Calculate environment size */
- env_size = 0;
- while( environ[ env_size ] ) { env_size++; }
- /* Also include the final NULL pointer */
- env_size++;
-
- /* Allocate for our environment */
- orig_env = malloc( env_size * sizeof( char *));
- if( !orig_env ) {
- perror( "Can't malloc environment" );
- exit( 1 );
- }
- memcpy( orig_env, environ, env_size * sizeof( char *));
- }
-#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(&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
-
-
- /* 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 (argc > 1) {
- argv0 = strdup(argv[1]);
- } else {
- argv0 = NULL;
- }
- }
-
- if (!cgi
-#ifdef PHP_FASTCGI
- /* allow ini override for fastcgi */
-#endif
- ) {
- while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
- switch (c) {
- case 'c':
- cgi_sapi_module.php_ini_path_override = strdup(ap_php_optarg);
- break;
- }
-
- }
- ap_php_optind = orig_optind;
- ap_php_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)==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 */
-
-#ifdef PHP_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" );
- exit( 1 );
- }
- }
-
-#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" );
- exit( 1 );
- }
- }
-
- 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
-
- zend_first_try {
- if (!cgi
-#ifdef PHP_FASTCGI
- && !fastcgi
-#endif
- ) {
- while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
- switch (c) {
- 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;
- }
- }
- ap_php_optind = orig_optind;
- ap_php_optarg = orig_optarg;
- }
-
-#ifdef PHP_FASTCGI
- /* start of FAST CGI loop */
-
-#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( &in, &out, &err, &cgi_env ) >= 0) {
-
- if (fastcgi) {
- /* set up environment */
- cgi_env_size = 0;
- while( cgi_env[ cgi_env_size ] ) { cgi_env_size++; }
- merge_env = malloc( (env_size+cgi_env_size)*sizeof(char*) );
- if( !merge_env ) {
- perror( "Can't malloc environment" );
- exit( 1 );
- }
- memcpy( merge_env, orig_env, (env_size-1)*sizeof(char *) );
- memcpy( merge_env + env_size - 1,
- cgi_env, (cgi_env_size+1)*sizeof(char *) );
- environ = merge_env;
- }
-#endif
-
- init_request_info(TSRMLS_C);
- SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */
-
- SG(request_info).argv0 = argv0;
-
- zend_llist_init(&global_vars, sizeof(char *), NULL, 0);
-
- if (!cgi
-#ifdef PHP_FASTCGI
- && !fastcgi
-#endif
- ) { /* never execute the arguments if you are a CGI */
- if (SG(request_info).argv0) {
- free(SG(request_info).argv0);
- SG(request_info).argv0 = NULL;
- }
- 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 */
- SG(options) |= SAPI_OPTION_NO_CHDIR;
- break;
- case 'd': /* define ini entries on command line */
- define_command_line_ini_entry(ap_php_optarg);
- break;
-
- case 'e': /* enable extended info output */
- CG(extended_info) = 1;
- break;
-
- case 'f': /* parse file */
- script_file = estrdup(ap_php_optarg);
- no_headers = 1;
- break;
-
- case 'g': /* define global variables on command line */
- {
- char *arg = estrdup(ap_php_optarg);
-
- zend_llist_add_element(&global_vars, &arg);
- }
- break;
-
- case 'h': /* help & quit */
- 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;
-
- 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");
- zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) _print_module_info, NULL TSRMLS_CC);
- php_printf("\n[Zend Modules]\n");
- zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) _print_extension_info, NULL TSRMLS_CC);
- php_printf("\n");
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
-#if 0 /* not yet operational, see also below ... */
- case 'n': /* 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-2002 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(ap_php_optarg);
- break;
-
- default:
- break;
- }
- }
- } /* not cgi */
-
- CG(interactive) = interactive;
-
- if (!cgi
-#ifdef PHP_FASTCGI
- && !fastcgi
-#endif
- ) {
- if (!SG(request_info).query_string) {
- len = 0;
- if (script_file) {
- len += strlen(script_file) + 1;
- }
- for (i = ap_php_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 (ap_php_optind<argc) {
- strcat(s, "+");
- }
- }
- for (i = ap_php_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) {
- SG(request_info).path_translated = script_file;
- }
-
- 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;
- }
-#ifdef PHP_FASTCGI
- if (fastcgi) {
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = SG(request_info).path_translated;
- } else {
-#endif
- file_handle.filename = "-";
- file_handle.type = ZEND_HANDLE_FP;
- file_handle.handle.fp = stdin;
-#ifdef PHP_FASTCGI
- }
-#endif
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
-
- /* 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);
-
- if (!cgi
-#ifdef PHP_FASTCGI
- && !fastcgi
-#endif
- ) {
- if (!SG(request_info).path_translated && argc > ap_php_optind) {
- SG(request_info).path_translated = estrdup(argv[ap_php_optind]);
- }
- } else {
- /* If for some reason the CGI interface is not setting the
- PATH_TRANSLATED correctly, SG(request_info).path_translated is NULL.
- We still call php_fopen_primary_script, because if you set doc_root
- or user_dir configuration directives, PATH_INFO is used to construct
- the filename as a side effect of php_fopen_primary_script.
- */
- char *env_path_translated=NULL;
-#if DISCARD_PATH
- env_path_translated = getenv("SCRIPT_FILENAME");
-#else
- env_path_translated = getenv("PATH_TRANSLATED");
-#endif
- if(env_path_translated) {
-#ifdef __riscos__
- /* Convert path to unix format*/
- __riscosify_control|=__RISCOSIFY_DONT_CHECK_DIR;
- env_path_translated=__unixify(env_path_translated,0,NULL,1,0);
-#endif
- SG(request_info).path_translated = estrdup(env_path_translated);
- }
- }
- if (cgi || SG(request_info).path_translated) {
- retval = php_fopen_primary_script(&file_handle TSRMLS_CC);
- }
-
- if (cgi && (retval == FAILURE)) {
- if(!argv0 || !(file_handle.handle.fp = VCWD_FOPEN(argv0, "rb"))) {
- PUTS("No input file specified.\n");
- php_request_shutdown((void *) 0);
- php_module_shutdown(TSRMLS_C);
- return FAILURE;
- }
- file_handle.filename = argv0;
- file_handle.opened_path = expand_filepath(argv0, NULL TSRMLS_CC);
- }
-
- 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 */
- }
- CG(zend_lineno)++;
- } else {
- rewind(file_handle.handle.fp);
- }
- }
-
- switch (behavior) {
- case PHP_MODE_STANDARD:
- if (php_execute_script(&file_handle TSRMLS_CC)) {
- exit_status = EG(exit_status);
- } else {
- exit_status = 255;
- }
- 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
- }
-
- if (SG(request_info).path_translated) {
- persist_alloc(SG(request_info).path_translated);
- }
-
- php_request_shutdown((void *) 0);
-
- STR_FREE(SG(request_info).path_translated);
-
-#ifdef PHP_FASTCGI
- if (!fastcgi) break;
- /* only fastcgi will get here */
-
- /* TODO: We should free our environment here, but
- * some platforms are unhappy if they've altered our
- * existing environment and we then free() the new
- * environ pointer
- */
-
- requests++;
- if( max_requests && ( requests == max_requests )) {
- FCGX_Finish();
- 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);
-
-#ifdef ZTS
- tsrm_shutdown();
-#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/config.m4 b/sapi/cgi/config.m4
deleted file mode 100644
index d3aa978264..0000000000
--- a/sapi/cgi/config.m4
+++ /dev/null
@@ -1,99 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-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
-
- PHP_TEST_WRITE_STDOUT
-
- PHP_ARG_ENABLE(force-cgi-redirect,whether to force Apache CGI redirect,
-[ --enable-force-cgi-redirect
- Enable the security check for internal server
- redirects. You should use this if you are
- running the CGI version with Apache. ])
-
- if test "$PHP_FORCE_CGI_REDIRECT" = "yes"; then
- REDIRECT=1
- else
- REDIRECT=0
- fi
- AC_DEFINE_UNQUOTED(FORCE_CGI_REDIRECT,$REDIRECT,[ ])
-
- PHP_ARG_ENABLE(discard-path,whether to discard path_info + path_translated,
-[ --enable-discard-path If this is enabled, the PHP CGI binary
- can safely be placed outside of the
- web tree and people will not be able
- to circumvent .htaccess security. ])
-
- if test "$PHP_DISCARD_PATH" = "yes"; then
- DISCARD_PATH=1
- else
- DISCARD_PATH=0
- fi
- AC_DEFINE_UNQUOTED(DISCARD_PATH, $DISCARD_PATH, [ ])
-
- INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_PROGRAM \$(INSTALL_ROOT)\$(bindir)/php-cgi"
-fi
-
-AC_MSG_CHECKING(for fhttpd module support)
-AC_ARG_WITH(fhttpd,
-[ --with-fhttpd[=DIR] Build fhttpd module. DIR is the fhttpd sources
- directory, defaults to /usr/local/src/fhttpd.],
-[
- if test "$withval" = "yes"; then
- # fhttpd source directory
- withval=/usr/local/src/fhttpd
- fi
- if test "$withval" != "no"; then
-# For fhttpd 0.3.x
- if test -f $withval/servproc.h; then
- FHTTPD_INCLUDE=-I$withval/
- FHTTPD_LIB=$withval/servproc.o
- FHTTPD_TARGET=$withval/
- PHP_BUILD_STATIC
- PHP_SAPI=cgi
- AC_DEFINE(FHTTPD,1,[ ])
- AC_MSG_RESULT(yes - fhttpd 0.3.x)
- else
- AC_MSG_RESULT(no)
- AC_MSG_ERROR(Invalid fhttpd directory - unable to find servproc.h under $withval)
- fi
- else
- AC_MSG_RESULT(no)
- fi
-],[
- AC_MSG_RESULT(no)
-])
-INCLUDES="$INCLUDES $FHTTPD_INCLUDE"
-dnl## AC_SUBST(FHTTPD_INCLUDE)
-PHP_SUBST(FHTTPD_LIB)
-PHP_SUBST(FHTTPD_TARGET)
diff --git a/sapi/cgi/getopt.c b/sapi/cgi/getopt.c
deleted file mode 100644
index a26ca3c431..0000000000
--- a/sapi/cgi/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 "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_optopt;
-
-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;
- }
- }
- ap_php_optopt = argv[oint][optchr];
- 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/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/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 d35b3d140d..0000000000
--- a/sapi/cgi/libfcgi/fcgiapp.c
+++ /dev/null
@@ -1,2307 +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, BOOL 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.
- */
-}
-
-/*
- *======================================================================
- * Parameters
- *======================================================================
- */
-
-/*
- * 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;
-
-/*
- *----------------------------------------------------------------------
- *
- * 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;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * 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) {
- 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, BOOL 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);
-
- 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 81ff264d9f..0000000000
--- a/sapi/cgi/libfcgi/include/fcgi_config.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 394e2078f9..0000000000
--- a/sapi/cgi/libfcgi/include/fcgiapp.h
+++ /dev/null
@@ -1,626 +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;
-
-/*
- * 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;
- char **envp;
-
- /* Don't use anything below here */
-
- struct Params *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);
-
-/*
- *======================================================================
- * 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 4abc0dac04..0000000000
--- a/sapi/cgi/libfcgi/include/fcgios.h
+++ /dev/null
@@ -1,136 +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);
-DLLAPI int OS_SpawnChild(char *execPath, int listenFd, PROCESS_INFORMATION *pInfo, char *env);
-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/os_unix.c b/sapi/cgi/libfcgi/os_unix.c
deleted file mode 100644
index cefa193c48..0000000000
--- a/sapi/cgi/libfcgi/os_unix.c
+++ /dev/null
@@ -1,1265 +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.
- *
- * 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 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);
- exit(1);
- }
- if (hep->h_addr_list[1]) {
- fprintf(stderr, "Host %s has multiple addresses ---\n", host);
- fprintf(stderr, "you must choose one explicitly!!!\n");
- exit(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");
- exit(1001);
- }
- }
- } 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");
- exit(1000);
- }
- }
- if(bind(listenSock, (struct sockaddr *) &sa.unixVariant, servLen) < 0
- || listen(listenSock, backlog) < 0) {
- perror("bind/listen");
- exit(errno);
- }
-
- 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);
- exit(1000);
- }
- 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");
- exit(1000);
- }
- 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) {
- exit(errno);
- }
-
- 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");
- */
- exit(errno);
- }
- 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);
- }
-
- 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) {
- exit(errno);
- }
- val |= flags;
- if(fcntl(fd, F_SETFL, val) < 0) {
- exit(errno);
- }
-}
diff --git a/sapi/cgi/libfcgi/os_win32.c b/sapi/cgi/libfcgi/os_win32.c
deleted file mode 100644
index 2415e03bb1..0000000000
--- a/sapi/cgi/libfcgi/os_win32.c
+++ /dev/null
@@ -1,2076 +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;
-
- if (WaitForSingleObject(shutdownEvent, INFINITE) == WAIT_FAILED)
- {
- // Assuming it will happen again, all we can do is exit the thread
- return 1;
- }
- else
- {
- // "Simple reads and writes to properly-aligned 32-bit variables are atomic"
- 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 (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)) {
- DebugBreak();
- //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)) {
- DebugBreak();
- //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 (mutex == NULL)
- {
- return -2;
- }
-
- 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 = 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
- */
- 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)
- {
- if (WaitForSingleObject(acceptMutex, INFINITE) == 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 40da432b59..0000000000
--- a/sapi/cgi/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/cli/CREDITS b/sapi/cli/CREDITS
deleted file mode 100644
index 9e1fd3b3db..0000000000
--- a/sapi/cli/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-CLI
-Rasmus Lerdorf, Stig Bakken, Edin Kadribasic, Marcus Boerger
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 4b5086c17c..0000000000
--- a/sapi/cli/config.m4
+++ /dev/null
@@ -1,22 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for CLI build)
-
-AC_ARG_ENABLE(cli,
-[ --disable-cli Disable building CLI version of PHP.],
-[
- PHP_SAPI_CLI=$enableval
-],[
- PHP_SAPI_CLI=yes
-])
-
-if test "$PHP_SAPI_CLI" != "no"; then
- INSTALL_CLI="\$(INSTALL) -m 0755 sapi/cli/php \$(INSTALL_ROOT)\$(bindir)/php"
- PHP_SUBST(INSTALL_CLI)
-else
- PHP_DISABLE_CLI
-fi
-
-AC_MSG_RESULT($PHP_SAPI_CLI)
diff --git a/sapi/cli/getopt.c b/sapi/cli/getopt.c
deleted file mode 100644
index f5874d577e..0000000000
--- a/sapi/cli/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/cli/php_cli.c b/sapi/cli/php_cli.c
deleted file mode 100644
index 260fed2087..0000000000
--- a/sapi/cli/php_cli.c
+++ /dev/null
@@ -1,698 +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: 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_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>
-#else
-#include "build-defs.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
-
-extern char *ap_php_optarg;
-extern int ap_php_optind;
-
-#define OPTSTRING "aCc:d:ef:g:hilmnqr:sw?vz:"
-
-static int _print_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
-{
- php_printf("%s\n", module->name);
- return 0;
-}
-
-static int _print_extension_info(zend_extension *module, void *arg TSRMLS_DC)
-{
- php_printf("%s\n", module->name);
- return 0;
-}
-
-#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 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", SG(request_info).argv[0], 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);
-}
-
-/* {{{ sapi_module_struct cli_sapi_module
- */
-static sapi_module_struct cli_sapi_module = {
- "cli", /* name */
- "Command Line Interface", /* pretty name */
-
- php_module_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 */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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] [-- args...]\n"
- " -s Display colour syntax highlighted source.\n"
- " -w Display source with stripped comments and whitespace.\n"
- " -f <file> Parse <file>.\n"
- " -v Version number\n"
- " -c <path>|<file> Look for php.ini file in this directory\n"
- " -a Run interactively\n"
- " -d foo[=bar] Define INI entry foo with value 'bar'\n"
- " -e Generate extended information for debugger/profiler\n"
- " -z <file> Load Zend extension <file>.\n"
- " -l Syntax check only (lint)\n"
- " -m Show compiled in modules\n"
- " -i PHP information\n"
- " -r <code> Run PHP <code> without using script tags <?..?>\n"
- " -h This help\n"
- "\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);
-}
-
-
-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);
-}
-
-/* {{{ 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=ap_php_optind;
- char *orig_optarg=ap_php_optarg;
- char *arg_free=NULL, **arg_excp=&arg_free;
- char *script_file=NULL;
- zend_llist global_vars;
- int interactive=0;
- char *exec_direct=NULL;
- char *param_error=NULL;
-/* 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=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
- switch (c) {
- case 'c':
- cli_sapi_module.php_ini_path_override = strdup(ap_php_optarg);
- break;
- }
-
- }
- ap_php_optind = orig_optind;
- ap_php_optarg = orig_optarg;
-
- cli_sapi_module.executable_location = argv[0];
-
- /* startup after we get the above ini override se we get things right */
- if (php_module_startup(&cli_sapi_module)==FAILURE) {
- return FAILURE;
- }
-
-#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
-
- zend_first_try {
- while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
- switch (c) {
- 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;
- }
- }
- ap_php_optind = orig_optind;
- ap_php_optarg = orig_optarg;
-
- 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);
-
- 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 'e': /* enable extended info output */
- CG(extended_info) = 1;
- break;
-
- case 'f': /* parse file */
- if (behavior == PHP_MODE_CLI_DIRECT) {
- param_error = "Either execute direct code or use a file.\n";
- break;
- }
- script_file = ap_php_optarg;
- no_headers = 1;
- break;
-
- case 'g': /* define global variables on command line */
- {
- char *arg = estrdup(ap_php_optarg);
-
- zend_llist_add_element(&global_vars, &arg);
- }
- break;
-
- 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 '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 */
- 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");
- zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) _print_module_info, NULL TSRMLS_CC);
- php_printf("\n[Zend Modules]\n");
- zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) _print_extension_info, NULL TSRMLS_CC);
- php_printf("\n");
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
-#if 0 /* not yet operational, see also below ... */
- case 'n': /* generate indented source mode*/
- if (behavior == PHP_MODE_CLI_DIRECT) {
- 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_STANDARD) {
- param_error = "Either execute direct code or use a file.\n";
- break;
- }
- behavior=PHP_MODE_CLI_DIRECT;
- exec_direct=ap_php_optarg;
- break;
-
- case 's': /* generate highlighted HTML from source */
- if (behavior == PHP_MODE_CLI_DIRECT) {
- 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) {
- 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-2002 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':
- if (behavior == PHP_MODE_CLI_DIRECT) {
- param_error = "Source stripping only works for files.\n";
- break;
- }
- behavior=PHP_MODE_STRIP;
- 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 && !script_file && behavior!=PHP_MODE_CLI_DIRECT && strcmp(argv[ap_php_optind-1],"--")) {
- no_headers = 1;
- script_file=argv[ap_php_optind];
- ap_php_optind++;
- }
- /* before registering argv to modulule exchange the *new* argv[0] */
- /* we can achieve this without allocating more memory */
- SG(request_info).argc=argc-ap_php_optind+1;
- arg_excp = argv+ap_php_optind-1;
- arg_free = argv[ap_php_optind-1];
- if (script_file) {
- argv[ap_php_optind-1] = script_file;
- } else {
- argv[ap_php_optind-1] = "-"; /* should be stdin */
- }
- SG(request_info).argv=argv+ap_php_optind-1;
-
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- php_module_shutdown(TSRMLS_C);
- *arg_excp = arg_free;
- return FAILURE;
- }
- *arg_excp = arg_free; /* reconstuct argv */
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
- if (script_file) {
- if (!(file_handle.handle.fp = VCWD_FOPEN(script_file, "rb"))) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- PUTS("Could not open input file.\n");
- php_request_shutdown((void *) 0);
- php_module_shutdown(TSRMLS_C);
- return FAILURE;
- }
- php_register_variable("PHP_SELF", script_file, NULL TSRMLS_CC);
- 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 */
- }
- CG(zend_lineno)++;
- } else {
- rewind(file_handle.handle.fp);
- }
- } else {
- php_register_variable("PHP_SELF", "-", NULL TSRMLS_CC);
- file_handle.filename = "-";
- file_handle.handle.fp = stdin;
- }
- file_handle.type = ZEND_HANDLE_FP;
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
-
- /* 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 (php_execute_script(&file_handle TSRMLS_CC)) {
- exit_status = EG(exit_status);
- } else {
- exit_status = 255;
- }
- 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
- case PHP_MODE_CLI_DIRECT:
- if (zend_eval_string(exec_direct, NULL, "Command line code" TSRMLS_CC) == FAILURE) {
- exit_status=254;
- }
- }
-
- php_request_shutdown((void *) 0);
-
- if (cli_sapi_module.php_ini_path_override) {
- free(cli_sapi_module.php_ini_path_override);
- }
-
- } zend_catch {
- exit_status = 255;
- } zend_end_try();
-
- php_module_shutdown(TSRMLS_C);
-
-#ifdef ZTS
- tsrm_shutdown();
-#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/cli/php_getopt.h b/sapi/cli/php_getopt.h
deleted file mode 100644
index 40da432b59..0000000000
--- a/sapi/cli/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/fastcgi/CREDITS b/sapi/fastcgi/CREDITS
deleted file mode 100644
index eb9cece428..0000000000
--- a/sapi/fastcgi/CREDITS
+++ /dev/null
@@ -1,4 +0,0 @@
-fastcgi
-Ben Mansell
-Stephen Landamore
-Daniel Silverstone
diff --git a/sapi/fastcgi/README.Apache b/sapi/fastcgi/README.Apache
deleted file mode 100644
index c7a2172580..0000000000
--- a/sapi/fastcgi/README.Apache
+++ /dev/null
@@ -1,53 +0,0 @@
-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/1.3/mod_fastcgi.so
-
-Don't load mod_php, by the way. Make sure it is commented out!
-
- #LoadModule php4_module /usr/lib/apache/1.3/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 just 'php')
-
- ScriptAlias /fcgi-bin/ /space/fcgi-bin/
- <Location /fcgi-bin/>
- SetHandler fastcgi-script
- </Location>
-
-Next, 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-php .php
- Action application/x-httpd-php /fcgi-bin/php
-
-Now, if you restart Apache, php pages should now be delivered!
-
-
-Running PHP-FastCGI separately from the webserver
--------------------------------------------------
-
-(Read README.FastCGI for why you might want to do this).
-Easy! Add one more configuration line:
-
- FastCgiExternalServer /space/fcgi-bin/php -host localhost:8002
-
-Then, start the PHP off with the following command:
-
- /space/fcgi-bin/php 8002
-
-The number 8002 is the port that PHP will listen on for requests - change this
-to anything suitable. And be sure to firewall it out so that external
-connections are denied!
diff --git a/sapi/fastcgi/README.FastCGI b/sapi/fastcgi/README.FastCGI
deleted file mode 100644
index f0c4af718f..0000000000
--- a/sapi/fastcgi/README.FastCGI
+++ /dev/null
@@ -1,91 +0,0 @@
-FastCGI module
---------------
-
-This module requires the FastCGI development kit, available from
-http://www.fastcgi.com/
-
-Before building PHP, please enter the dev kit, and run:
-
-./configure
-make
-make export
-
-This will compile the library code required for the FastCGI module. All
-that is then required is to configure PHP with the '--with-fastcgi' option.
-After making the code, you will end up with a binary file called 'php'.
-Installation of this file will depend on the web server being used, please
-see their documentation for details.
-
-
-
-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 8002
-
-(you can also specify a bind address, e.g. ./php 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!
-
-
-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/fastcgi/config.m4 b/sapi/fastcgi/config.m4
deleted file mode 100644
index 1b0caac306..0000000000
--- a/sapi/fastcgi/config.m4
+++ /dev/null
@@ -1,28 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_MSG_CHECKING(for FastCGI support)
-AC_ARG_WITH(fastcgi,
-[ --with-fastcgi=SRCDIR Build PHP as FastCGI application],[
- if test "$withval" = "yes"; then
- FASTCGIPATH=/usr/local
- else
- FASTCGIPATH=$withval
- fi
- test -f "$FASTCGIPATH/lib/libfcgi.a" || AC_MSG_ERROR(Unable to find libfcgi.a in $FASTCGIPATH/lib)
- test -f "$FASTCGIPATH/include/fastcgi.h" || AC_MSG_ERROR(Unable to find fastcgi.h in $FASTCGIPATH/include)
-
- PHP_SELECT_SAPI(fastcgi, programm, fastcgi.c)
-
- PHP_ADD_INCLUDE($FASTCGIPATH/include)
- PHP_ADD_LIBRARY_WITH_PATH(fcgi, "$FASTCGIPATH/lib",)
-
- INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_PROGRAM \$(bindir)/$SAPI_FASTCGI"
- RESULT=yes
- PHP_SUBST(FASTCGI_LIBADD)
- PHP_SUBST(EXT_PROGRAM_LDADD)
-],[
- RESULT=no
-])
-AC_MSG_RESULT($RESULT)
diff --git a/sapi/fastcgi/fastcgi.c b/sapi/fastcgi/fastcgi.c
deleted file mode 100644
index ccf57eb308..0000000000
--- a/sapi/fastcgi/fastcgi.c
+++ /dev/null
@@ -1,621 +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: Ben Mansell <php@slimyhorror.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* Debugging */
-/* #define DEBUG_FASTCGI 1 */
-
-/* Two configurables for the FastCGI runner.
- *
- * PHP_FCGI_CHILDREN - if set, the FastCGI will pre-fork this many processes
- * which will accept requests.
- *
- * PHP_FCGI_MAX_REQUESTS - if set, the runner will kill itself after handling
- * the given number of requests. This is to curb any
- * memory leaks in PHP.
- */
-
-
-/* The following code is based mainly on the thttpd sapi and the original
- * CGI code, no doubt with many new and interesting bugs created... :)
- */
-
-#include "php.h"
-#include "SAPI.h"
-#include "php_main.h"
-#include "php_fastcgi.h"
-#include "php_variables.h"
-
-#include "fcgi_config.h"
-#include "fcgiapp.h"
-#include <stdio.h>
-#if HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef PHP_WIN32
-#include <io.h>
-#include <fcntl.h>
-#include "win32/php_registry.h"
-/* don't want to include fcgios.h, causes conflicts */
-extern int OS_SetImpersonate(void);
-#else
-#include <sys/wait.h>
-#endif
-#include <sys/stat.h>
-
-#if HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-
-#ifndef S_ISREG
-#define S_ISREG(mode) ((mode) & _S_IFREG)
-#endif
-
-FCGX_Stream *in, *out, *err;
-FCGX_ParamArray envp;
-char *path_info = NULL;
-#ifndef PHP_WIN32
-struct sigaction act, old_term, old_quit, old_int;
-#endif
-
-/* Our original environment from when the FastCGI first started */
-char **orig_env;
-
-/* The environment given by the FastCGI */
-char **cgi_env;
-
-/* The manufactured environment, from merging the base environ with
- * the parameters set by the per-connection environment
- */
-char **merge_env;
-
-/**
- * Number of child processes that will get created to service requests
- */
-static int children = 8;
-
-/**
- * Set to non-zero if we are the parent process
- */
-static int parent = 1;
-
-/**
- * Process group
- */
-static pid_t pgroup;
-
-
-static int sapi_fastcgi_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- uint sent = FCGX_PutStr( str, str_length, out );
- return sent;
-}
-
-
-static void sapi_fastcgi_flush( void *server_context )
-{
- if( FCGX_FFlush( out ) == -1 ) {
- php_handle_aborted_connection();
- }
-}
-
-
-static void sapi_fastcgi_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC)
-{
- if( sapi_header ) {
-#ifdef DEBUG_FASTCGI
- fprintf( stderr, "Header: %s\n", sapi_header->header );
-#endif
- FCGX_PutStr( sapi_header->header, sapi_header->header_len, out );
- }
- FCGX_PutStr( "\r\n", 2, out );
-}
-
-static int sapi_fastcgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
- size_t read_bytes = 0;
- int c;
- char *pos = buffer;
-
- while( count_bytes ) {
- c = FCGX_GetStr( pos, count_bytes, in );
- read_bytes += c;
- count_bytes -= c;
- pos += c;
- if( !c ) break;
- }
- return read_bytes;
-}
-
-static char *sapi_fastcgi_read_cookies(TSRMLS_D)
-{
- return getenv( "HTTP_COOKIE" );
-}
-
-
-static void sapi_fastcgi_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_fastcgi_log_message(char *message)
-{
-#ifdef DEBUG_FASTCGI
- fprintf( stderr, "Log Message: %s\n", message );
-#endif
- FCGX_FPrintF(err, "%s\n", message);
-}
-
-
-static sapi_module_struct fastcgi_sapi_module = {
- "fastcgi",
- "FastCGI",
-
- php_module_startup,
- php_module_shutdown_wrapper,
-
- NULL, /* activate */
- NULL, /* deactivate */
-
- sapi_fastcgi_ub_write,
- sapi_fastcgi_flush,
- NULL, /* get uid */
- NULL, /* getenv */
-
- php_error,
-
- NULL,
- NULL,
- sapi_fastcgi_send_header,
- sapi_fastcgi_read_post,
- sapi_fastcgi_read_cookies,
-
- sapi_fastcgi_register_variables,
- sapi_fastcgi_log_message,
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-static void fastcgi_module_main(TSRMLS_D)
-{
- zend_file_handle file_handle;
- int c, retval = 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;
-
- /* eat the bang line */
- if (SG(request_info).path_translated) {
- retval = php_fopen_primary_script(&file_handle TSRMLS_CC);
- }
-
- if (retval == SUCCESS) {
- /* #!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 */
- }
- CG(zend_lineno)++;
- } else {
- rewind(file_handle.handle.fp);
- }
- }
-
- if (php_request_startup(TSRMLS_C) == SUCCESS) {
- php_execute_script(&file_handle TSRMLS_CC);
- php_request_shutdown(NULL);
- }
-}
-
-
-static int init_request_info( TSRMLS_D )
-{
- char *content_length = getenv("CONTENT_LENGTH");
- char *content_type = getenv( "CONTENT_TYPE" );
- const char *auth;
- struct stat st;
- char *pi = getenv( "PATH_INFO" );
- char *pt = getenv( "PATH_TRANSLATED" );
- if (!pt) {
- pt = getenv("SCRIPT_FILENAME"); // apache mod_fastcgi sets this
- }
- path_info = strdup( pi );
-
- SG(request_info).request_method = getenv("REQUEST_METHOD");
- SG(request_info).query_string = getenv("QUERY_STRING");
- SG(request_info).request_uri = path_info;
- if (!SG(request_info).request_uri) {
- SG(request_info).request_uri = getenv("SCRIPT_NAME");
- }
- SG(request_info).content_type = ( content_type ? content_type : "" );
- SG(request_info).content_length = (content_length?atoi(content_length):0);
- SG(sapi_headers).http_response_code = 200;
-
- SG(request_info).path_translated = pt;
- if (!pt) return -1;
- /*
- * if the file doesn't exist, try to extract PATH_INFO out
- * of it by stat'ing back through the '/'
- */
- if ( stat( pt, &st ) == -1 ) {
- int len = strlen(pt);
- char *ptr;
- while( 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
- */
- int slen = len - strlen(pt);
- if ( pi ) {
- int pilen = strlen( pi );
- strcpy( pi, pi + pilen - slen );
- }
- break;
- }
- }
- /*
- * 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... is there a nice way to error?
- */
- } else {
- /* the first stat succeeded... */
- if ( pi ) *pi = 0;
- }
-
- /* The CGI RFC allows servers to pass on unvalidated Authorization data */
- auth = getenv("HTTP_AUTHORIZATION");
-#ifdef DEBUG_FASTCGI
- fprintf( stderr, "Authorization: %s\n", auth );
-#endif
- php_handle_auth_data(auth TSRMLS_CC);
-
- return 0;
-}
-
-
-void fastcgi_php_init(void)
-{
- TSRMLS_FETCH();
- sapi_startup(&fastcgi_sapi_module);
- fastcgi_sapi_module.startup(&fastcgi_sapi_module);
- SG(server_context) = (void *) 1;
-}
-
-void fastcgi_php_shutdown(void)
-{
- TSRMLS_FETCH();
- if (SG(server_context) != NULL) {
- fastcgi_sapi_module.shutdown(&fastcgi_sapi_module);
- sapi_shutdown();
- }
-}
-
-
-/**
- * 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 );
-}
-
-
-int main(int argc, char *argv[])
-{
- int exit_status = SUCCESS;
-#ifndef PHP_WIN32
- int c, i, len;
- zend_file_handle file_handle;
- char *s;
- int status;
-#else
- int impersonate = 0;
-#endif
- char *argv0=NULL;
- char *script_file=NULL;
- zend_llist global_vars;
- int max_requests = 500;
- int requests = 0;
- int fcgi_fd = 0;
- int env_size, cgi_env_size;
- FCGX_Request request;
-#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 DEBUG_FASTCGI
- fprintf( stderr, "Initialising now, pid %d!\n", getpid() );
-#endif
-
- if( FCGX_IsCGI() ) {
- /* Did a bind address or port get configured on the command line? */
- if( argc >= 2 ) {
- /* 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( argv[ 1 ] );
- if( port ) {
- char bindport[ 32 ];
- snprintf( bindport, 32, ":%s", argv[ 1 ] );
- fcgi_fd = FCGX_OpenSocket( bindport, 128 );
- } else {
- fcgi_fd = FCGX_OpenSocket( argv[ 1 ], 128 );
- }
- if( fcgi_fd < 0 ) {
- fprintf( stderr, "Couldn't create FastCGI listen socket\n" );
- exit( 1 );
- }
- } else {
- fprintf( stderr, "The FastCGI version of PHP cannot be "
- "run as a CGI application\n" );
- exit( 1 );
- }
- }
-
- /* Calculate environment size */
- env_size = 0;
- while( environ[ env_size ] ) { env_size++; }
- /* Also include the final NULL pointer */
- env_size++;
-
- /* Allocate for our environment */
- orig_env = malloc( env_size * sizeof( char *));
- if( !orig_env ) {
- perror( "Can't malloc environment" );
- exit( 1 );
- }
- memcpy( orig_env, environ, env_size * sizeof( char *));
-
-#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(&fastcgi_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_module_startup(&fastcgi_sapi_module)==FAILURE) {
- return FAILURE;
- }
-#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
-
- /* 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" );
- exit( 1 );
- }
- }
-
- /* Initialise FastCGI request structure */
- 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" );
- exit( 1 );
- }
- }
-
- 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 */
-
- /* Main FastCGI loop */
-#ifdef DEBUG_FASTCGI
- fprintf( stderr, "Going into accept loop\n" );
-#endif
-#ifdef PHP_WIN32
- /* attempt to set security impersonation for fastcgi
- will only happen on NT based OS, others will ignore it. */
- if (cfg_get_long("fastcgi.impersonate", &impersonate) == FAILURE) {
- impersonate = 0;
- }
- if (impersonate) OS_SetImpersonate();
-#endif
-
- while( FCGX_Accept_r( &request ) >= 0 ) {
-
-#ifdef DEBUG_FASTCGI
- fprintf( stderr, "Got accept\n" );
-#endif
-
- in = request.in;
- out = request.out;
- err = request.err;
- cgi_env = request.envp;
- cgi_env_size = 0;
- while( cgi_env[ cgi_env_size ] ) { cgi_env_size++; }
- merge_env = malloc( (env_size+cgi_env_size)*sizeof(char*) );
- if( !merge_env ) {
- perror( "Can't malloc environment" );
- exit( 1 );
- }
- memcpy( merge_env, orig_env, (env_size-1)*sizeof(char *) );
- memcpy( merge_env + env_size - 1,
- cgi_env, (cgi_env_size+1)*sizeof(char *) );
- environ = merge_env;
-
- if (init_request_info(TSRMLS_C)!=0) {
- /* we received some invalid environment */
- //char *b = "Can't init the request\n";
- //sapi_fastcgi_ub_write(b, strlen(b) TSRMLS_C);
- //FCGX_Finish();
- //break;
- }
- SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */
- SG(request_info).argv0 = argv0;
- zend_llist_init(&global_vars, sizeof(char *), NULL, 0);
-
- fastcgi_module_main(TSRMLS_C);
- if( path_info ) {
- free( path_info );
- path_info = NULL;
- }
-
- /* TODO: We should free our environment here, but
- * some platforms are unhappy if they've altered our
- * existing environment and we then free() the new
- * environ pointer
- */
-
- requests++;
- if( max_requests && ( requests == max_requests )) {
- FCGX_Finish();
- break;
- }
- }
-
-#ifdef ZTS
- tsrm_shutdown();
-#endif
-#ifdef DEBUG_FASTCGI
- fprintf( stderr, "Exiting...\n" );
-#endif
- return 0;
-}
diff --git a/sapi/fastcgi/fastcgi.dsp b/sapi/fastcgi/fastcgi.dsp
deleted file mode 100644
index 520396cf72..0000000000
--- a/sapi/fastcgi/fastcgi.dsp
+++ /dev/null
@@ -1,195 +0,0 @@
-# Microsoft Developer Studio Project File - Name="fastcgi" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=fastcgi - 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 "fastcgi.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 "fastcgi.mak" CFG="fastcgi - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "fastcgi - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "fastcgi - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE "fastcgi - Win32 Debug_TS" (based on "Win32 (x86) Console Application")
-!MESSAGE "fastcgi - Win32 Release_TS" (based on "Win32 (x86) Console Application")
-!MESSAGE "fastcgi - Win32 Release_TS_inline" (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)" == "fastcgi - 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 /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /Fr /FD /c
-# SUBTRACT CPP /YX
-# 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 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 php4nts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.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 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release/phpfcgi.exe" /libpath:"..\..\Release" /libpath:"fcgi\lib"
-
-!ELSEIF "$(CFG)" == "fastcgi - 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 /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "DEBUG" /D "_DEBUG" /D "_CONSOLE" /D "MSVC5" /D "PHP_WIN32" /D ZEND_DEBUG=1 /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /FR /FD /GZ /c
-# SUBTRACT CPP /YX
-# 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 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 libfcgi.lib winmm.lib wsock32.lib netapi32.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 php4nts_debug.lib /nologo /version:4.0 /subsystem:console /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"..\Debug\phpfcgi.exe" /pdbtype:sept /libpath:"..\..\Debug" /libpath:"fcgi\lib"
-
-!ELSEIF "$(CFG)" == "fastcgi - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "fastcgi___Win32_Debug_TS"
-# PROP BASE Intermediate_Dir "fastcgi___Win32_Debug_TS"
-# PROP BASE Ignore_Export_Lib 0
-# 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 "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "DEBUG" /D "_DEBUG" /D "_CONSOLE" /D "MSVC5" /D "PHP_WIN32" /D ZEND_DEBUG=1 /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /FR /FD /GZ /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "DEBUG" /D "_DEBUG" /D "_CONSOLE" /D "MSVC5" /D "PHP_WIN32" /D "ZTS" /D ZEND_DEBUG=1 /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /FR /FD /GZ /c
-# SUBTRACT CPP /YX
-# 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 libfcgi.lib winmm.lib wsock32.lib netapi32.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 php4nts_debug.lib /nologo /version:4.0 /subsystem:console /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"c:\php-fcgi\php-fcgi.exe" /pdbtype:sept /libpath:"..\..\Debug" /libpath:"fcgi\lib"
-# ADD LINK32 libfcgi.lib winmm.lib wsock32.lib netapi32.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 /subsystem:console /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"..\..\Debug_TS\phpfcgi.exe" /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"fcgi\lib"
-
-!ELSEIF "$(CFG)" == "fastcgi - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "fastcgi___Win32_Release_TS"
-# PROP BASE Intermediate_Dir "fastcgi___Win32_Release_TS"
-# PROP BASE Ignore_Export_Lib 0
-# 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 "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /Fr /FD /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "ZTS" /Fr /FD /c
-# SUBTRACT CPP /YX
-# 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 php4nts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.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 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release/php-fcgi.exe" /libpath:"..\..\Release" /libpath:"fcgi\lib"
-# ADD LINK32 php4ts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.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 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release_TS/phpfcgi.exe" /libpath:"..\..\Release_TS" /libpath:"fcgi\lib"
-
-!ELSEIF "$(CFG)" == "fastcgi - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "fastcgi___Win32_Release_TS_inline"
-# PROP BASE Intermediate_Dir "fastcgi___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 "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "ZTS" /Fr /FD /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D "ZEND_WIN32_FORCE_INLINE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "ZTS" /Fr /FD /c
-# SUBTRACT CPP /YX
-# 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 php4ts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.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 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release_TS/phpfcgi.exe" /libpath:"..\..\Release_TS" /libpath:"fcgi\lib"
-# ADD LINK32 php4ts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.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 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release_TS_inline/phpfcgi.exe" /libpath:"..\..\Release_TS_inline" /libpath:"fcgi\lib"
-
-!ENDIF
-
-# Begin Target
-
-# Name "fastcgi - Win32 Release"
-# Name "fastcgi - Win32 Debug"
-# Name "fastcgi - Win32 Debug_TS"
-# Name "fastcgi - Win32 Release_TS"
-# Name "fastcgi - 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=.\fastcgi.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php_fastcgi.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/fastcgi/php.sym b/sapi/fastcgi/php.sym
deleted file mode 100644
index e69de29bb2..0000000000
--- a/sapi/fastcgi/php.sym
+++ /dev/null
diff --git a/sapi/fastcgi/php_fastcgi.h b/sapi/fastcgi/php_fastcgi.h
deleted file mode 100644
index 60f93e21b9..0000000000
--- a/sapi/fastcgi/php_fastcgi.h
+++ /dev/null
@@ -1,28 +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: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-#ifndef PHP_FASTCGI_H
-#define PHP_FASTCGI_H
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-void fastcgi_php_shutdown(void);
-void fastcgi_php_init(void);
-
-#endif
diff --git a/sapi/fastcgi/windows.txt b/sapi/fastcgi/windows.txt
deleted file mode 100644
index fc12b0aaba..0000000000
--- a/sapi/fastcgi/windows.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-Windows support is currently experimental.
-
-Tested under IIS with cgi-fcgi.exe and Apache with mod_fastcgi.
-
-Compilation:
-Currently only supports Non-Thread safe compilation, however,
-that is realy all that is needed :)
-
-Get the devkit from www.fastcgi.com, build it.
-Create the directories
- php4/sapi/fastcgi/fcgi
- php4/sapi/fastcgi/fcgi/include
- php4/sapi/fastcgi/fcgi/lib
-Place headers and libs in the include and lib directories.
-Load the php.dsw, and compile.
-
-IIS configuration:
-
-Under the application configuration in the IIS configuration program, use:
-.php C:\php-fcgi\cgi-fcgi.exe -connect php c:\php-fcgi\php-fcgi.exe
-
-Apache Configuration:
-
-LoadModule fastcgi_module modules/mod_fastcgi.dll
-<IfModule mod_fastcgi.c>
-AddHandler fastcgi-script fphp php
-</IfModule>
-
-The scripts require the bang line as the first line
-of the script to work with mod_fastcgi,
-#!c:/php-fcgi/php-fcgi.exe
-
-TODO:
-make 'thread-safe' compilation, though it isn't necessary.
-
diff --git a/sapi/fhttpd/CREDITS b/sapi/fhttpd/CREDITS
deleted file mode 100644
index aaa5aac1fd..0000000000
--- a/sapi/fhttpd/CREDITS
+++ /dev/null
@@ -1,2 +0,0 @@
-fhttpd
-Alex Belits
diff --git a/sapi/fhttpd/fhttpd.c b/sapi/fhttpd/fhttpd.c
deleted file mode 100644
index fd81e67969..0000000000
--- a/sapi/fhttpd/fhttpd.c
+++ /dev/null
@@ -1,185 +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: Alex Belits <abelits@phobos.illtel.denver.co.us> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-#include "php.h"
-
-#include <stdlib.h>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <errno.h>
-#include <ctype.h>
-
-#if FHTTPD
-#include <servproc.h>
-#include <signal.h>
-
-struct http_server *server = NULL;
-struct request *req = NULL;
-struct httpresponse *response = NULL;
-int headermade = 0;
-int global_alarmflag = 0;
-int idle_timeout = IDLE_TIMEOUT;
-int exit_status = 0;
-char **currentheader = NULL;
-char *headerfirstline = NULL;
-int headerlines = 0;
-static int headerlinesallocated = 0;
-
-void alarmhandler(SIGACTARGS)
-{
- global_alarmflag = 1;
-}
-
-void setalarm(int t)
-{
- struct sigaction tmpsigaction;
- global_alarmflag = 0;
- if (t){
- bzero((char *) &tmpsigaction, sizeof(struct sigaction));
- tmpsigaction.sa_handler = alarmhandler;
- sigaddset(&tmpsigaction.sa_mask, SIGALRM);
- tmpsigaction.sa_flags = 0;
- sigaction(SIGALRM, &tmpsigaction, NULL);
- alarm(t);
- }
-}
-
-int checkinput(int h)
-{
- fd_set readfd;
- FD_ZERO(&readfd);
- FD_SET(h, &readfd);
- return select(h + 1, &readfd, NULL, NULL, NULL) > 0;
-}
-
-
-PHPAPI void php_fhttpd_free_header(void)
-{
- int i;
-
- if (headerfirstline) {
- free(headerfirstline);
- headerfirstline = NULL;
- }
- if (currentheader) {
- for (i = 0; i < headerlines; i++) {
- free(currentheader[i]);
- }
- free(currentheader);
- currentheader = NULL;
- }
- headerlines = 0;
- headerlinesallocated = 0;
- headermade = 0;
-}
-
-
-PHPAPI void php_fhttpd_puts_header(char *s)
-{
- char *p0, *p1, *p2, *p3, **p;
- int l;
-
- if (!s || !*s || *s == '\r' || *s == '\n')
- return;
- l = strlen(s);
- p2 = strchr(s, '\r');
- p3 = strchr(s, '\n');
- p0 = strchr(s, ':');
- p1 = strchr(s, ' ');
- if (p0 && (!p1 || p1 > p0)) {
- if (!headerlinesallocated) {
- currentheader = (char **) malloc(10 * sizeof(char *));
- if (currentheader)
- headerlinesallocated = 10;
- } else {
- if (headerlinesallocated <= headerlines) {
- p = (char **) realloc(currentheader, (headerlinesallocated + 10) * sizeof(char *));
- if (p) {
- currentheader = p;
- headerlinesallocated += 10;
- }
- }
- }
-
- if (headerlinesallocated > headerlines) {
- currentheader[headerlines] = malloc(l + 3);
- if (currentheader[headerlines]) {
- strcpy(currentheader[headerlines], s);
- if (!p3) {
- if (p2) {
- (currentheader[headerlines] + (p2 - s))[1] = '\n';
- (currentheader[headerlines] + (p2 - s))[2] = 0;
- } else {
- currentheader[headerlines][l] = '\r';
- currentheader[headerlines][l + 1] = '\n';
- currentheader[headerlines][l + 2] = 0;
- }
- }
- headerlines++;
- headermade = 1;
- }
- }
- } else {
- if (headerfirstline)
- free(headerfirstline);
- headerfirstline = malloc(l + 3);
- if (headerfirstline) {
- strcpy(headerfirstline, s);
- if (!p3) {
- if (p2) {
- (headerfirstline + (p2 - s))[1] = '\n';
- (headerfirstline + (p2 - s))[2] = 0;
- } else {
- headerfirstline[l] = '\r';
- headerfirstline[l + 1] = '\n';
- headerfirstline[l + 2] = 0;
- }
- }
- }
- headermade = 1;
- }
-}
-
-void fhttpd_flush(void)
-{
-}
-
-PHPAPI void php_fhttpd_puts(char *s)
-{
- putlinetoresponse(response, s);
-}
-
-PHPAPI void php_fhttpd_putc(char c)
-{
- writetoresponse(response, &c, 1);
-}
-
-PHPAPI int php_fhttpd_write(char *a, int n)
-{
- return writetoresponse(response, a, n);
-}
-#endif
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
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 55127da576..0000000000
--- a/sapi/isapi/php4isapi.c
+++ /dev/null
@@ -1,861 +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: Zeev Suraski <zeev@zend.com> |
- | Ben Mansell <ben@zeus.com> (Zeus Support) |
- +----------------------------------------------------------------------+
- */
-
-#ifdef PHP_WIN32
-# include <windows.h>
-# include <process.h>
-#else
-# define __try
-# define __except(val)
-# define __declspec(foo)
-#endif
-
-#include <httpext.h>
-#include <httpfilt.h>
-#include <httpext.h>
-#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"
-
-#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)==FAILURE
- || zend_startup_module(&php_isapi_module)==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 );
- }
-}
-#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);
-#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]);
- }
-
-#ifdef PHP_WIN32
- {
- HSE_URL_MAPEX_INFO humi;
- DWORD path_len = 2;
- char path[] = "/";
-
- if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, path, &path_len, (LPDWORD) &humi)) {
- /* Remove trailing \ */
- if (humi.lpszPath[path_len-2] == '\\') {
- humi.lpszPath[path_len-2] = 0;
- }
- php_register_variable("DOCUMENT_ROOT", humi.lpszPath, track_vars_array TSRMLS_CC);
- }
- }
-#endif
-}
-
-
-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 */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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 = 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;
-
-#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 = sapi_globals->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_request_startup(TSRMLS_C);
- php_execute_script(&file_handle TSRMLS_CC);
- if (SG(request_info).cookie_data) {
- efree(SG(request_info).cookie_data);
- }
-#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/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 b7af1be4da..0000000000
--- a/sapi/nsapi/config.m4
+++ /dev/null
@@ -1,38 +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)
- elif test -d $PHP_NSAPI/plugins/include ; then
- NSAPI_INCLUDE=$PHP_NSAPI/plugins/include
- AC_MSG_RESULT(iPlanet/4.x style)
- else
- AC_MSG_ERROR(Please check you have nsapi.h in either DIR/include or DIR/plugins/include)
- fi
- PHP_ADD_INCLUDE($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 d2c3b2db86..0000000000
--- a/sapi/nsapi/nsapi.c
+++ /dev/null
@@ -1,542 +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: Jayakumar Muthukumarasamy <jk@kasenna.com> |
- +----------------------------------------------------------------------+
-*/
-
-/*
- * 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)
-
-/*
- * 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" },
- { "HTTP_ACCEPT", "accept" },
- { "HTTP_ACCEPT_ENCODING", "accept-encoding" },
- { "HTTP_ACCEPT_LANGUAGE", "accept-language" },
- { "HTTP_ACCEPT_CHARSET", "accept-charset" },
- { "HTTP_AUTHORIZATION", "authorization" },
- { "HTTP_COOKIE", "cookie" },
- { "HTTP_IF_MODIFIED_SINCE", "if-modified-since" },
- { "HTTP_REFERER", "referer" },
- { "HTTP_USER_AGENT", "user-agent" },
- { "HTTP_USER_DEFINED", "user-defined" }
-};
-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" },
- { "SCRIPT_NAME", "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" },
- { "PATH_TRANSLATED", "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" }
-};
-static size_t nsapi_client_size = sizeof(nsapi_client)/sizeof(nsapi_client[0]);
-
-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) {
- 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);
- size_t i;
- char *value;
- char buf[128];
-
- 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 < 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 );
- }
- }
-
- value = session_dns(rc->sn);
- if (value) {
- php_register_variable("REMOTE_HOST", value, track_vars_array TSRMLS_CC );
- }
- sprintf(buf, "%d", conf_getglobals()->Vport);
- php_register_variable("SERVER_PORT", buf, track_vars_array TSRMLS_CC );
- php_register_variable("SERVER_NAME", util_hostname(), track_vars_array TSRMLS_CC );
- php_register_variable("SERVER_URL", http_uri2url("", ""), track_vars_array TSRMLS_CC );
- php_register_variable("HTTPS", (security_active ? "ON" : "OFF"), track_vars_array TSRMLS_CC );
-/* php_register_variable("SERVER_SOFTWARE", MAGNUS_VERSION_STRING, track_vars_array TSRMLS_CC ); */
-
- /*
- * Special PHP_SELF variable.
- */
- value = pblock_findval("uri", rc->rq->reqpb);
- if ( value != NULL ) {
- php_register_variable("PHP_SELF", value, 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_log_message", rc->sn, rc->rq,
- "%s", message);
-}
-
-
-static sapi_module_struct nsapi_sapi_module = {
- "nsapi", /* name */
- "NSAPI", /* pretty name */
-
- php_module_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 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 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 *path_translated = pblock_findval("path", 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);
-
- if ((path_translated == NULL) && (uri != NULL))
- path_translated = request_translate_uri(uri, NSG(sn));
-
-#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;
-}
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 268825c78f..0000000000
--- a/sapi/phttpd/php_phttpd.h
+++ /dev/null
@@ -1,24 +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: 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 7e7367d49d..0000000000
--- a/sapi/phttpd/phttpd.c
+++ /dev/null
@@ -1,312 +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: 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)
-{
-/*
- if(php_module_startup(sapi_module) == FAILURE
- || zend_startup_module(&php_aolserver_module) == FAILURE) {
-*/
- fprintf(stderr,"***php_phttpd_startup\n");
-
- if (php_module_startup(sapi_module)) {
- 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 */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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 3541a9cf19..0000000000
--- a/sapi/pi3web/config.m4
+++ /dev/null
@@ -1,27 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-PHP_ARG_WITH(pi3web,for Pi3Web Support,
-[ --with-pi3web=DIR Build PHP as a module for use with Pi3Web.])
-
-if test "$PHP_PI3WEB" != "no"; then
- if test "$PHP_PI3WEB" = "yes"; then
- PI3PATH=../.. # the default
- else
- PI3PATH=$PHP_PI3WEB
- 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/"
-fi
-
-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 2f49cdca72..0000000000
--- a/sapi/pi3web/pi3web_sapi.c
+++ /dev/null
@@ -1,482 +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. |
- +----------------------------------------------------------------------+
- | Pi3Web version 2.0 |
- +----------------------------------------------------------------------+
- | This file is committed by the Pi3 development group. |
- | (pi3web.sourceforge.net) |
- | |
- | Author: Holger Zimmermann (zimpel@users.sourceforge.net) |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "pi3web_sapi.h"
-#include "php.h"
-#include "php_main.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);
- }
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-
-static int php_pi3web_startup(sapi_module_struct *sapi_module)
-{
- if (php_module_startup(sapi_module)==FAILURE
- || zend_register_module(&php_pi3web_module)==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)
-{
- char *path_end = strrchr(lpCB->lpszFileName, PHP_DIR_SEPARATOR);
- if ( path_end ) *path_end = PHP_DIR_SEPARATOR;
-
- 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)
- && static_variable_buf[0]) {
- 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)
- && variable_buf[0]) {
- 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)
- && static_variable_buf[0]) {
- 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_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 */
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-DWORD PHP4_wrapper(LPCONTROL_BLOCK lpCB)
-{
- zend_file_handle file_handle;
- char *header_line;
- 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:
- header_line = (char *)estrdup("Content-Type: text/plain");
- sapi_add_header_ex(header_line, strlen(header_line), 1, 1 TSRMLS_CC);
- if ( open_file_for_scanning( &file_handle TSRMLS_CC ) == SUCCESS )
- {
- zend_indent();
- }
- else
- {
- iRet = PIAPI_ERROR;
- };
- efree(header_line);
- 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 400fdc6507..0000000000
--- a/sapi/roxen/roxen.c
+++ /dev/null
@@ -1,728 +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: 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) == FAILURE
- || zend_startup_module(&php_roxen_module) == 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_module_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 */
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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);
- 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 6570d92bde..0000000000
--- a/sapi/servlet/Makefile.frag
+++ /dev/null
@@ -1,19 +0,0 @@
-
-$(builddir)/java.c : $(srcdir)/../../ext/java/java.c
- @cp $(srcdir)/../../ext/java/java.c $(builddir)
-
-$(builddir)/phpsrvlt.jar : $(srcdir)/servlet.java $(srcdir)/../../ext/java/reflect.java
- $(mkinstalldirs) $(builddir)/net/php
- @echo library=php4 > $(builddir)/net/php/reflect.properties
- @echo library=php4 > $(builddir)/net/php/servlet.properties
- @cp $(builddir)/formatter.java $(builddir)/net/php
- @cp $(builddir)/servlet.java $(builddir)/net/php
- @cp $(srcdir)/../../ext/java/reflect.java $(builddir)/net/php
- cd $(builddir) && javac net/php/reflect.java
- @test ! -f $(builddir)/reflect.class || mv $(builddir)/reflect.class $(builddir)/net/php # bug in KJC javac
- javac -classpath .:$(SERVLET_CLASSPATH):$(CLASSPATH) $(builddir)/net/php/servlet.java
- @test ! -f $(builddir)/servlet.class || mv $(builddir)/servlet.class $(builddir)/net/php # bug in KJC javac
- javac -classpath .:$(SERVLET_CLASSPATH):$(CLASSPATH) $(builddir)/net/php/formatter.java
- @test ! -f $(builddir)/formatter.class || mv $(builddir)/formatter.class $(builddir)/net/php # bug in KJC javac
- cd $(builddir)/ && $(JAVA_JAR) phpsrvlt.jar net/php/*.class net/php/*.properties
- @rm -rf $(builddir)/net
diff --git a/sapi/servlet/README b/sapi/servlet/README
deleted file mode 100644
index 13c940fd77..0000000000
--- a/sapi/servlet/README
+++ /dev/null
@@ -1,122 +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
-
- 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 directory containing php4ts.dll and phpsrvlt.dll to
- PATH
-
- 2.) Tomcat 3
-
- * Add phpsrvlt.jar to CLASSPATH
-
- Tomcat 4
-
- * Copy phpsrvlt.jar into your $CATALINA_HOME/lib directory
-
- 3.) Tomcat 3
-
- * Merge or overwrite build/tomcat/examples/WEB-INF/web.xml
- with the configuration directives from the web.xml file
- that comes with the Java Servlet SAPI Module.
-
- Tomcat 4
-
- * Merge the configuration directives from web.xml file that
- comes with the Java Servlet SAPI Module into your
- Tomcat/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/conf/web.xml configuration file.
-
- 4.) Test your installation by creating a test.php file in your
- Tomcat/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.
-
---
- [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 46219bee00..0000000000
--- a/sapi/servlet/config.m4
+++ /dev/null
@@ -1,52 +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 \$(srcdir)/sapi/servlet/phpsrvlt.jar \$(libdir)"
- INSTALL_IT="$INSTALL_IT; \$(INSTALL) -m 0755 $SAPI_SHARED \$(libdir)"
- PHP_SAPI=servlet
- PHP_BUILD_THREAD_SAFE
- 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 727dd9fe94..0000000000
--- a/sapi/servlet/servlet.c
+++ /dev/null
@@ -1,404 +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) |
- +----------------------------------------------------------------------+
-*/
-
-#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>
-#else
-#include "build-defs.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;
-
-static zend_module_entry *additional_php_extensions[] = {
- &java_module_entry
-};
-
-#define EXTCOUNT (sizeof(additional_php_extensions)/sizeof(zend_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 sapi_module_struct servlet_sapi_module = {
- "java_servlet", /* name */
- "Java Servlet", /* pretty name */
-
- php_module_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 */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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)==FAILURE) {
- ThrowServletException(jenv,"module startup failure");
- return;
- }
-
- if (php_startup_extensions(additional_php_extensions, EXTCOUNT)==FAILURE) {
- ThrowServletException(jenv,"extension 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 5ce62fe8e1..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\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\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\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\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\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\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\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\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\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 03a3c7acad..0000000000
--- a/sapi/servlet/servlet.java
+++ /dev/null
@@ -1,219 +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 {
- 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 676dfa5ae1..0000000000
--- a/sapi/thttpd/README
+++ /dev/null
@@ -1,59 +0,0 @@
-README FOR THTTPD MODULE (by Sascha Schumann)
-($Date$)
-
- This is a SAPI module for PHP 4.0 supporting thttpd, the tiny,
- turbo, throttling HTTP server by Jef Poskanzer.
-
- The module contains a patch against version 2.21b of thttpd. The patch
- adds hooks to thttpd to call PHP, if a filename matches *.php. This
- patch will be applied when you install PHP.
-
- 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.
-
- NOTE: All requests will be serialized. That means, one long running
- script will block all other requests. Choose another web-server,
- if you want to execute arbitrary scripts.
-
-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.0.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 cb3764152b..0000000000
--- a/sapi/thttpd/config.m4
+++ /dev/null
@@ -1,27 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-AC_ARG_WITH(thttpd,
-[ --with-thttpd=SRCDIR Build PHP as thttpd module],[
- test -d $withval || AC_MSG_RESULT(thttpd directory does not exist ($withval))
- egrep thttpd.2.21b $withval/version.h >/dev/null || AC_MSG_RESULT([This version only supports thttpd-2.21b])
- 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 7bd4de3202..0000000000
--- a/sapi/thttpd/php_thttpd.h
+++ /dev/null
@@ -1,35 +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: 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);
-
-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 cd355c709d..0000000000
--- a/sapi/thttpd/thttpd.c
+++ /dev/null
@@ -1,651 +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: 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 "ext/standard/php_smart_str.h"
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-typedef struct {
- httpd_conn *hc;
- int read_post_data;
- void (*on_close)(int);
- long async_send;
-} 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
-
-PHP_INI_BEGIN()
- STD_PHP_INI_ENTRY("async_send", "0", PHP_INI_ALL, OnUpdateInt, async_send, php_thttpd_globals, thttpd_globals)
-PHP_INI_END()
-
-static int sapi_thttpd_ub_write(const char *str, uint str_length TSRMLS_DC)
-{
- int n;
- uint sent = 0;
-
- while (str_length > 0) {
- n = send(TG(hc)->conn_fd, str, str_length, 0);
-
- if (n == -1 && errno == EPIPE)
- php_handle_aborted_connection();
- if (n == -1 && errno == EAGAIN) {
- fd_set fdw;
-
- FD_ZERO(&fdw);
- FD_SET(TG(hc)->conn_fd, &fdw);
- n = select(TG(hc)->conn_fd + 1, NULL, &fdw, NULL, NULL);
- if (n <= 0)
- php_handle_aborted_connection();
-
- continue;
- }
- if (n <= 0)
- return n;
-
- 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 n, int len TSRMLS_DC)
-{
- /*
- * 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 (writev(TG(hc)->conn_fd, vec, n) == -1 && errno == EPIPE)
- php_handle_aborted_connection();
- TG(hc)->bytes_sent += len;
-
- return 0;
-}
-
-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.0 %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;
-
-#define DEF_CT "Content-Type: text/html\r\n"
- 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) {
- 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);
- }
-
- ADD_VEC("\r\n", 2);
-
- do_writev(vec, n, len TSRMLS_CC);
-
- return SAPI_HEADER_SENT_SUCCESSFULLY;
-}
-
-static int sapi_thttpd_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
- size_t read_bytes = 0, tmp;
- int c;
- int n;
-
- /* to understand this, read cgi_interpose_input() in libhttpd.c */
- c = TG(hc)->read_idx - TG(hc)->checked_idx;
- if (c > 0) {
- read_bytes = MIN(c, count_bytes);
- memcpy(buffer, TG(hc)->read_buf + TG(hc)->checked_idx, read_bytes);
- TG(hc)->checked_idx += read_bytes;
- count_bytes -= read_bytes;
- }
-
- count_bytes = MIN(count_bytes,
- SG(request_info).content_length - SG(read_post_bytes));
-
- while (read_bytes < count_bytes) {
- tmp = recv(TG(hc)->conn_fd, buffer + read_bytes,
- count_bytes - read_bytes, 0);
- if (tmp == 0 || (tmp == -1 && errno != EAGAIN))
- break;
- /* A simple "tmp > 0" produced broken code on Solaris/GCC */
- if (tmp != 0 && tmp != -1)
- read_bytes += tmp;
-
- if (tmp == -1 && errno == EAGAIN) {
- fd_set fdr;
-
- FD_ZERO(&fdr);
- FD_SET(TG(hc)->conn_fd, &fdr);
- n = select(TG(hc)->conn_fd + 1, &fdr, NULL, NULL, NULL);
- if (n <= 0)
- php_handle_aborted_connection();
-
- continue;
- }
- }
-
- TG(read_post_data) += read_bytes;
-
- /* Hack for user-agents which send a LR or CRLF after POST data */
- if (TG(read_post_data) >= TG(hc)->contentlength) {
- char tmpbuf[2];
-
- /* we are in non-blocking mode */
- recv(TG(hc)->conn_fd, tmpbuf, 2, 0);
- }
-
- 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;
-
- 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);
- }
-
- 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);
- 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)
-{
- REGISTER_INI_ENTRIES();
- 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_module_startup(sapi_module) == FAILURE
- || zend_startup_module(&php_thttpd_module) == FAILURE) {
- return FAILURE;
- }
- 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, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- STANDARD_SAPI_MODULE_PROPERTIES
-};
-
-static void thttpd_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 thttpd_request_ctor(TSRMLS_D)
-{
- smart_str s = {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;
- SG(request_info).content_type = TG(hc)->contenttype;
- SG(request_info).content_length = TG(hc)->contentlength;
-
- php_handle_auth_data(TG(hc)->authorization TSRMLS_CC);
-}
-
-static void thttpd_request_dtor(TSRMLS_D)
-{
- if (SG(request_info).query_string)
- free(SG(request_info).query_string);
- free(SG(request_info).request_uri);
- free(SG(request_info).path_translated);
-}
-
-#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 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 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 TSRMLS_DC)
-{
- TG(hc) = hc;
- hc->bytes_sent = 0;
-
- TG(read_post_data) = 0;
- if (hc->method == METHOD_POST)
- hc->should_linger = 1;
-
- thttpd_request_ctor(TSRMLS_C);
-
- thttpd_module_main(TSRMLS_C);
-
- thttpd_request_dtor(TSRMLS_C);
-
- return 0;
-}
-
-off_t thttpd_php_request(httpd_conn *hc)
-{
-#ifdef ZTS
- queue_request(hc);
-#else
- TSRMLS_FETCH();
- return thttpd_real_php_request(hc 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 fa6ae5ef6b..0000000000
--- a/sapi/thttpd/thttpd_patch
+++ /dev/null
@@ -1,240 +0,0 @@
-diff -ur thttpd-2.21b-orig/Makefile.in thttpd-2.21b/Makefile.in
---- thttpd-2.21b-orig/Makefile.in Thu Mar 29 20:36:21 2001
-+++ thttpd-2.21b/Makefile.in Mon Aug 13 23:50:27 2001
-@@ -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@
-
-@@ -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-orig/config.h thttpd-2.21b/config.h
---- thttpd-2.21b-orig/config.h Mon Apr 9 23:57:36 2001
-+++ thttpd-2.21b/config.h Mon Aug 13 23:51:00 2001
-@@ -316,7 +316,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-orig/fdwatch.c thttpd-2.21b/fdwatch.c
---- thttpd-2.21b-orig/fdwatch.c Fri Apr 13 07:36:08 2001
-+++ thttpd-2.21b/fdwatch.c Tue Aug 14 00:00:10 2001
-@@ -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-orig/libhttpd.c thttpd-2.21b/libhttpd.c
---- thttpd-2.21b-orig/libhttpd.c Tue Apr 24 00:42:40 2001
-+++ thttpd-2.21b/libhttpd.c Tue Aug 14 00:00:07 2001
-@@ -85,6 +85,8 @@
- #include "match.h"
- #include "tdate_parse.h"
-
-+#include "php_thttpd.h"
-+
- #ifndef STDIN_FILENO
- #define STDIN_FILENO 0
- #endif
-@@ -242,6 +244,8 @@
- 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->charset != (char*) 0 )
- free( (void*) hs->charset );
- if ( hs->url_pattern != (char*) 0 )
-@@ -249,6 +253,7 @@
- if ( hs->local_pattern != (char*) 0 )
- free( (void*) hs->local_pattern );
- free( (void*) hs );
-+ thttpd_php_shutdown();
- }
-
-
-@@ -312,6 +317,7 @@
- }
-
- hs->port = port;
-+ hs->php_pattern = strdup("**.php");
- if ( cgi_pattern == (char*) 0 )
- hs->cgi_pattern = (char*) 0;
- else
-@@ -385,6 +391,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 );
-@@ -2353,7 +2361,10 @@
- {
- 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;
-@@ -3026,11 +3037,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 );
- }
-
-
-@@ -3560,6 +3569,11 @@
- ( hc->sb.st_mode & S_IXOTH ) &&
- 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 );
-+ }
-
- /* 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
-Only in thttpd-2.21b: libhttpd.c~
-diff -ur thttpd-2.21b-orig/libhttpd.h thttpd-2.21b/libhttpd.h
---- thttpd-2.21b-orig/libhttpd.h Tue Apr 24 00:36:50 2001
-+++ thttpd-2.21b/libhttpd.h Mon Aug 13 23:50:27 2001
-@@ -69,6 +69,7 @@
- char* server_hostname;
- int port;
- char* cgi_pattern;
-+ char* php_pattern;
- char* charset;
- char* cwd;
- int listen4_fd, listen6_fd;
-diff -ur thttpd-2.21b-orig/thttpd.c thttpd-2.21b/thttpd.c
---- thttpd-2.21b-orig/thttpd.c Tue Apr 24 00:41:57 2001
-+++ thttpd-2.21b/thttpd.c Mon Aug 13 23:50:27 2001
-@@ -1333,7 +1333,7 @@
- clear_connection( c, tvP );
- return;
- }
-- hc->read_idx += sz;
-+ if (sz > 0) hc->read_idx += sz;
-
- /* Do we have a complete request yet? */
- switch ( httpd_got_request( hc ) )
-@@ -1387,6 +1387,12 @@
- clear_connection( c, tvP );
- return;
- }
-+ if (hc->file_address == (char *) 1) {
-+ tmr_cancel( c->idle_read_timer );
-+ c->idle_read_timer = (Timer*) 0;
-+ c->wouldblock_delay = 0;
-+ return;
-+ }
- if ( c->bytes_sent >= c->bytes_to_send )
- {
- /* There's nothing to send. */
-@@ -1500,7 +1506,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;
- }
-diff -ur thttpd-2.21b-plain/mime_encodings.txt thttpd-2.21b/mime_encodings.txt
---- thttpd-2.21b-plain/mime_encodings.txt Wed May 10 03:22:28 2000
-+++ thttpd-2.21b/mime_encodings.txt Mon Dec 10 15:10:25 2001
-@@ -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-plain/libhttpd.c thttpd-2.21b/libhttpd.c
---- thttpd-2.21b-plain/libhttpd.c Tue Apr 24 00:42:40 2001
-+++ thttpd-2.21b/libhttpd.c Mon Dec 10 14:32:26 2001
-@@ -3611,14 +3611,18 @@
- }
- else
- {
-+ char *extraheads = "";
- hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP );
- if ( hc->file_address == (char*) 0 )
- {
- httpd_send_err( hc, 500, err500title, "", err500form, hc->encodedurl );
- return -1;
- }
-+ if (strncmp(hc->decodedurl, "/nocache/", sizeof("/nocache/")-1) == 0)
-+ extraheads = "Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\nCache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r\nPragma: no-cache\r\n";
-+
- 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 --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 16a7be8133..0000000000
--- a/sapi/tux/php_tux.c
+++ /dev/null
@@ -1,444 +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: 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;
-
-
- sprintf(buf, "Server: %s", TUXAPI_version);
- sapi_add_header_ex(buf, strlen(buf), 1, 0 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 sapi_module_struct tux_sapi_module = {
- "tux",
- "tux",
-
- php_module_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 */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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 ad098dba00..0000000000
--- a/sapi/webjames/php_webjames.h
+++ /dev/null
@@ -1,28 +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: 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 1aba413dee..0000000000
--- a/sapi/webjames/webjames.c
+++ /dev/null
@@ -1,324 +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: 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 int sapi_webjames_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
-/*send the HTTP response line*/
-{
- char buf[256];
-
- if (WG(conn)->flags.outputheaders) {
- if (!SG(sapi_headers).http_status_line) {
- int code=SG(sapi_headers).http_response_code;
- snprintf(buf, 255, "HTTP/1.0 %d %s\r\n", code, code==200 ? "OK" : code==302 ? "Moved temporarily" : "Something");
- webjames_writestring(WG(conn), buf);
- }
- }
-
- return SAPI_HEADER_DO_SEND;
-}
-
-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) == FAILURE
- || zend_startup_module(&php_webjames_module) == 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 */
- sapi_webjames_send_headers, /* 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 */
-
- NULL, /* Block interruptions */
- NULL, /* Unblock interruptions */
-
- 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();
-}