summaryrefslogtreecommitdiff
path: root/sapi/pi3web
diff options
context:
space:
mode:
Diffstat (limited to 'sapi/pi3web')
-rw-r--r--sapi/pi3web/CREDITS2
-rw-r--r--sapi/pi3web/README50
-rw-r--r--sapi/pi3web/config.m427
-rw-r--r--sapi/pi3web/config.w3216
-rw-r--r--sapi/pi3web/php.sym0
-rw-r--r--sapi/pi3web/php5pi3web.dsp136
-rw-r--r--sapi/pi3web/pi3web_sapi.c439
-rw-r--r--sapi/pi3web/pi3web_sapi.h102
8 files changed, 772 insertions, 0 deletions
diff --git a/sapi/pi3web/CREDITS b/sapi/pi3web/CREDITS
new file mode 100644
index 0000000..c4541f8
--- /dev/null
+++ b/sapi/pi3web/CREDITS
@@ -0,0 +1,2 @@
+pi3web
+Holger Zimmermann
diff --git a/sapi/pi3web/README b/sapi/pi3web/README
new file mode 100644
index 0000000..e3e523e
--- /dev/null
+++ b/sapi/pi3web/README
@@ -0,0 +1,50 @@
+PHP5 Module
+==========
+This module requires PHP5 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 PHP5 source package from the
+PHP CVS tree into the Pi3Web source directory called 'PHP5' first. Then
+build PHP5 as Pi3Web module and after that build the Pi3Web PHP5 wrapper:
+
+1. Checkout PHP5
+================
+cvs -d :pserver:cvsread@cvs.php.net:/repository login
+The required password is phpfi
+
+cvs -z3 -d :pserver:cvsread@cvs.php.net:/repository co php5
+
+You must also checkout the TSRM and the ZEND module from the ZEND cvs tree
+into the PHP5 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 PHP5
+=============
+2.1 POSIX
+---------
+cd ./php5
+./buildconf
+./configure --with-pi3web
+make
+
+2.2 Win32
+---------
+other required downloads from the php website
+ - bison 1.25
+ - bindlib32
+ - number4.tar.gz
+nmake php5dllts.mak
+
+3. Build Pi3Web PHP5 wrapper
+============================
+Run make in the Pi3Web /Source/PHP5 directory.
+
+For further information refer to http://www.php.net/version4/
diff --git a/sapi/pi3web/config.m4 b/sapi/pi3web/config.m4
new file mode 100644
index 0000000..7859481
--- /dev/null
+++ b/sapi/pi3web/config.m4
@@ -0,0 +1,27 @@
+dnl
+dnl $Id$
+dnl
+
+PHP_ARG_WITH(pi3web, for Pi3Web support,
+[ --with-pi3web[=DIR] Build PHP as Pi3Web module], no, no)
+
+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/PHP5)
+ 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/config.w32 b/sapi/pi3web/config.w32
new file mode 100644
index 0000000..a5393e6
--- /dev/null
+++ b/sapi/pi3web/config.w32
@@ -0,0 +1,16 @@
+// vim:ft=javascript
+// $Id$
+
+ARG_WITH('pi3web', 'Pi3Web', 'no');
+
+if (PHP_PI3WEB != "no") {
+ if (CHECK_HEADER_ADD_INCLUDE('PiAPI.h', 'CFLAGS_PI3WEB', PHP_PHP_BUILD + "\\Pi3Web\\include;" + PHP_PI3WEB) &&
+ CHECK_LIB('piapi.lib', 'pi3web', PHP_PHP_BUILD + "\\Pi3Web\\lib;" + PHP_PI3WEB) &&
+ CHECK_LIB('pi2api.lib', 'pi3web', PHP_PHP_BUILD + "\\Pi3Web\\lib;" + PHP_PI3WEB) &&
+ CHECK_LIB('pi3api.lib', 'pi3web', PHP_PHP_BUILD + "\\Pi3Web\\lib;" + PHP_PI3WEB)) {
+ SAPI('pi3web', 'pi3web_sapi.c', 'php' + PHP_VERSION + 'pi3web.dll', '/D PHP5PI3WEB_EXPORTS');
+ AC_DEFINE('WITH_PI3WEB', 1);
+ } else {
+ WARNING('Pi3Web not enabled; headers/libraries not found');
+ }
+}
diff --git a/sapi/pi3web/php.sym b/sapi/pi3web/php.sym
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/sapi/pi3web/php.sym
diff --git a/sapi/pi3web/php5pi3web.dsp b/sapi/pi3web/php5pi3web.dsp
new file mode 100644
index 0000000..bb5a248
--- /dev/null
+++ b/sapi/pi3web/php5pi3web.dsp
@@ -0,0 +1,136 @@
+# Microsoft Developer Studio Project File - Name="php5pi3web" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=php5pi3web - 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 "php5pi3web.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 "php5pi3web.mak" CFG="php5pi3web - Win32 Debug_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "php5pi3web - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "php5pi3web - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "php5pi3web - 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)" == "php5pi3web - 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 "php5pi3web_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /I "..\..\..\..\PIAPI" /I "..\..\..\..\PI2API" /I "..\..\..\..\PI3API" /D "_DEBUG" /D ZEND_DEBUG=1 /D "_WINDOWS" /D "_USRDLL" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /D "PHP5PI3WEB_EXPORTS" /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 php5ts_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" /libpath:"..\..\..\..\PIAPI" /libpath:"..\..\..\..\PI2API" /libpath:"..\..\..\..\PI3API"
+
+!ELSEIF "$(CFG)" == "php5pi3web - 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 "php5pi3web_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /I "..\..\..\..\PIAPI" /I "..\..\..\..\PI2API" /I "..\..\..\..\PI3API" /D "NDEBUG" /D ZEND_DEBUG=0 /D "_WINDOWS" /D "_USRDLL" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /D "PHP5PI3WEB_EXPORTS" /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 php5ts.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" /libpath:"..\..\..\..\PIAPI" /libpath:"..\..\..\..\PI2API" /libpath:"..\..\..\..\PI3API"
+
+!ELSEIF "$(CFG)" == "php5pi3web - Win32 Release_TS_inline"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "php5pi3web___Win32_Release_TS_inline"
+# PROP BASE Intermediate_Dir "php5pi3web___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 "PHP5DLLTS_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" /I "..\..\..\..\PIAPI" /I "..\..\..\..\PI2API" /I "..\..\..\..\PI3API" /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" /D "PHP5PI3WEB_EXPORTS" /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\php5ts.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 php5ts.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" /libpath:"..\..\..\..\PIAPI" /libpath:"..\..\..\..\PI2API" /libpath:"..\..\..\..\PI3API"
+
+!ENDIF
+
+# Begin Target
+
+# Name "php5pi3web - Win32 Debug_TS"
+# Name "php5pi3web - Win32 Release_TS"
+# Name "php5pi3web - 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
new file mode 100644
index 0000000..64eb2a6
--- /dev/null
+++ b/sapi/pi3web/pi3web_sapi.c
@@ -0,0 +1,439 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Pi3Web version 2.0 |
+ +----------------------------------------------------------------------+
+ | This file is committed by the Pi3 development group. |
+ | (pi3web.sourceforge.net) |
+ | |
+ | Author: Holger Zimmermann (zimpel@users.sourceforge.net) |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+
+#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
+
+#include "php.h"
+#include "php_main.h"
+#include "php_variables.h"
+#include "SAPI.h"
+#include "php_globals.h"
+#include "ext/standard/info.h"
+#include "zend_highlight.h"
+#include "zend_indent.h"
+#include "zend_alloc.h"
+#include "ext/standard/basic_functions.h"
+#include "TSRM/TSRM.h"
+#include "PiAPI.h"
+#include "Pi3API.h"
+
+#include "pi3web_sapi.h"
+
+#define PI3WEB_SERVER_VAR_BUF_SIZE 1024
+
+int IWasLoaded=0;
+
+
+static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS)
+{
+ char variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE];
+ DWORD variable_len;
+ LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context);
+ PIDB *pDB = (PIDB *)lpCB->GetVariableNames(lpCB->ConnID);
+ PIDBIterator *pIter = PIDB_getIterator( pDB, PIDBTYPE_STRING, 0, 0 );
+
+ 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");
+
+ /* --- loop over all registered server variables --- */
+ for(; pIter && PIDBIterator_atValidElement( pIter ); PIDBIterator_next( pIter ) )
+ {
+ PCHAR pKey;
+ PIDBIterator_current( pIter, &pKey );
+ if ( !pKey ) { /* sanity */ continue; };
+
+ variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
+ if (lpCB->GetServerVariable(lpCB->ConnID, pKey, variable_buf, &variable_len)
+ && variable_buf[0]) {
+ php_info_print_table_row(2, pKey, variable_buf);
+ } else if (PIPlatform_getLastError() == PIAPI_EINVAL) {
+ char *tmp_variable_buf;
+
+ tmp_variable_buf = (char *) emalloc(variable_len);
+ if (lpCB->GetServerVariable(lpCB->ConnID, pKey, tmp_variable_buf, &variable_len)
+ && variable_buf[0]) {
+ php_info_print_table_row(2, pKey, tmp_variable_buf);
+ }
+ efree(tmp_variable_buf);
+ }
+ }
+
+ PUTS("</table>");
+}
+
+
+static zend_module_entry php_pi3web_module = {
+ STANDARD_MODULE_HEADER,
+ "PI3WEB",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ php_info_pi3web,
+ NULL,
+ STANDARD_MODULE_PROPERTIES
+};
+
+
+static int zend_pi3web_ub_write(const char *str, uint str_length TSRMLS_DC)
+{
+ DWORD num_bytes = str_length;
+ LPCONTROL_BLOCK cb;
+
+ cb = (LPCONTROL_BLOCK) SG(server_context);
+
+ if ( !IWasLoaded ) return 0;
+ cb->WriteClient(cb->ConnID, (char *) str, &num_bytes, 0 );
+
+ if (num_bytes != str_length)
+ php_handle_aborted_connection();
+ return num_bytes;
+}
+
+
+static int sapi_pi3web_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
+{
+ return SAPI_HEADER_ADD;
+}
+
+
+static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length TSRMLS_DC)
+{
+ *total_length += sapi_header->header_len+2;
+}
+
+
+static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr TSRMLS_DC)
+{
+ memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len);
+ *combined_headers_ptr += sapi_header->header_len;
+ **combined_headers_ptr = '\r';
+ (*combined_headers_ptr)++;
+ **combined_headers_ptr = '\n';
+ (*combined_headers_ptr)++;
+}
+
+
+static int sapi_pi3web_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
+{
+ uint total_length = 2; /* account for the trailing \r\n */
+ char *combined_headers, *combined_headers_ptr;
+ LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context);
+ sapi_header_struct default_content_type;
+
+ if ( !IWasLoaded ) return SAPI_HEADER_SENT_SUCCESSFULLY;
+
+
+ if (SG(sapi_headers).send_default_content_type) {
+ sapi_get_default_content_type_header(&default_content_type TSRMLS_CC);
+ accumulate_header_length(&default_content_type, (void *) &total_length TSRMLS_CC);
+ }
+ zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) accumulate_header_length, (void *) &total_length TSRMLS_CC);
+
+ /* Generate headers */
+ combined_headers = (char *) emalloc(total_length+1);
+ combined_headers_ptr = combined_headers;
+ if (SG(sapi_headers).send_default_content_type) {
+ concat_header(&default_content_type, (void *) &combined_headers_ptr TSRMLS_CC);
+ sapi_free_header(&default_content_type); /* we no longer need it */
+ }
+ zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) concat_header, (void *) &combined_headers_ptr TSRMLS_CC);
+ *combined_headers_ptr++ = '\r';
+ *combined_headers_ptr++ = '\n';
+ *combined_headers_ptr = 0;
+
+ lpCB->dwHttpStatusCode = SG(sapi_headers).http_response_code;
+ lpCB->SendHeaderFunction(lpCB->ConnID, &total_length, (LPDWORD) combined_headers);
+
+ efree(combined_headers);
+ if (SG(sapi_headers).http_status_line) {
+ efree(SG(sapi_headers).http_status_line);
+ SG(sapi_headers).http_status_line = 0;
+ }
+ return SAPI_HEADER_SENT_SUCCESSFULLY;
+}
+
+
+static int php_pi3web_startup(sapi_module_struct *sapi_module)
+{
+ if (php_module_startup(sapi_module, &php_pi3web_module, 1)==FAILURE) {
+ return FAILURE;
+ } else {
+ return SUCCESS;
+ }
+}
+
+
+static int sapi_pi3web_read_post(char *buffer, uint count_bytes TSRMLS_DC)
+{
+ LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context);
+ DWORD read_from_buf=0;
+ DWORD read_from_input=0;
+ DWORD total_read=0;
+
+ if ((DWORD)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;
+ }
+
+ /* removed after re-testing POST with Pi3Web 2.0.2 */
+ /* SG(read_post_bytes) += total_read; */
+ return total_read;
+}
+
+
+static char *sapi_pi3web_read_cookies(TSRMLS_D)
+{
+ LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context);
+ char variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE];
+ DWORD variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
+
+ if (lpCB->GetServerVariable(lpCB->ConnID, "HTTP_COOKIE", variable_buf, &variable_len)) {
+ return estrndup(variable_buf, variable_len);
+ } else if (PIPlatform_getLastError()==PIAPI_EINVAL) {
+ char *tmp_variable_buf = (char *) emalloc(variable_len+1);
+
+ if (lpCB->GetServerVariable(lpCB->ConnID, "HTTP_COOKIE", tmp_variable_buf, &variable_len)) {
+ tmp_variable_buf[variable_len] = 0;
+ return tmp_variable_buf;
+ } else {
+ efree(tmp_variable_buf);
+ }
+ }
+ return NULL;
+}
+
+static void init_request_info(LPCONTROL_BLOCK lpCB TSRMLS_DC)
+{
+ SG(server_context) = lpCB;
+ SG(request_info).request_method = lpCB->lpszMethod;
+ SG(request_info).query_string = lpCB->lpszQueryString;
+ SG(request_info).path_translated = lpCB->lpszPathTranslated;
+ SG(request_info).request_uri = lpCB->lpszUri;
+ SG(request_info).content_type = lpCB->lpszContentType;
+ SG(request_info).content_length = lpCB->cbTotalBytes;
+ SG(request_info).auth_user = (lpCB->lpszUser) ? (char *)estrdup((const char *)(lpCB->lpszUser)) : 0;
+ SG(request_info).auth_password = (lpCB->lpszPassword) ? (char *)estrdup((const char *)(lpCB->lpszPassword)) : 0;
+ SG(sapi_headers).http_response_code = 200;
+}
+
+static void sapi_pi3web_register_variables(zval *track_vars_array TSRMLS_DC)
+{
+ char static_variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE];
+ char *variable_buf;
+ DWORD variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
+ LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context);
+ PIDB *pDB = (PIDB *)lpCB->GetVariableNames(lpCB->ConnID);
+ PIDBIterator *pIter = PIDB_getIterator( pDB, PIDBTYPE_STRING, 0, 0 );
+
+ /* --- loop over all registered server variables --- */
+ for(; pIter && PIDBIterator_atValidElement( pIter ); PIDBIterator_next( pIter ) )
+ {
+ PCHAR pKey;
+ PIDBIterator_current( pIter, &pKey );
+ if ( !pKey ) { /* sanity */ continue; };
+
+ variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
+ if (lpCB->GetServerVariable(lpCB->ConnID, pKey, static_variable_buf, &variable_len)
+ && (variable_len > 1)) {
+ php_register_variable(pKey, 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, pKey, variable_buf, &variable_len)) {
+ php_register_variable(pKey, variable_buf, track_vars_array TSRMLS_CC);
+ }
+ efree(variable_buf);
+ }
+
+ }
+
+
+ /* PHP_SELF support */
+ variable_len = PI3WEB_SERVER_VAR_BUF_SIZE;
+ if (lpCB->GetServerVariable(lpCB->ConnID, "SCRIPT_NAME", static_variable_buf, &variable_len)
+ && (variable_len > 1)) {
+ php_register_variable("PHP_SELF", static_variable_buf, track_vars_array TSRMLS_CC);
+ }
+}
+
+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, /* Get request time */
+ NULL, /* Child terminate */
+
+ STANDARD_SAPI_MODULE_PROPERTIES
+};
+
+MODULE_API DWORD PHP5_wrapper(LPCONTROL_BLOCK lpCB)
+{
+ zend_file_handle file_handle = {0};
+ int iRet = PIAPI_COMPLETED;
+ TSRMLS_FETCH();
+
+ zend_first_try {
+ file_handle.filename = lpCB->lpszFileName;
+ file_handle.free_filename = 0;
+ file_handle.type = ZEND_HANDLE_FILENAME;
+ file_handle.opened_path = NULL;
+
+ init_request_info(lpCB TSRMLS_CC);
+ php_request_startup(TSRMLS_C);
+
+ switch ( lpCB->dwBehavior ) {
+ case PHP_MODE_STANDARD:
+ iRet = ( php_execute_script( &file_handle TSRMLS_CC ) ) ?
+ PIAPI_COMPLETED : PIAPI_ERROR;
+ break;
+ case PHP_MODE_HIGHLIGHT: {
+ zend_syntax_highlighter_ini syntax_highlighter_ini;
+ if ( open_file_for_scanning( &file_handle TSRMLS_CC ) == SUCCESS )
+ {
+ php_get_highlight_struct( &syntax_highlighter_ini );
+ zend_highlight( &syntax_highlighter_ini TSRMLS_CC );
+ }
+ else
+ {
+ iRet = PIAPI_ERROR;
+ };
+ };
+ break;
+ case PHP_MODE_INDENT: {
+ sapi_header_line ctr = {0};
+
+ ctr.line = "Content-Type: text/plain";
+ ctr.line_len = strlen(ctr.line);
+
+ sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
+ }
+ if ( open_file_for_scanning( &file_handle TSRMLS_CC ) == SUCCESS )
+ {
+ zend_indent();
+ }
+ else
+ {
+ iRet = PIAPI_ERROR;
+ };
+ break;
+ case PHP_MODE_LINT:
+ iRet = (php_lint_script(&file_handle TSRMLS_CC) == SUCCESS) ?
+ PIAPI_COMPLETED : PIAPI_ERROR;
+ break;
+ default:
+ iRet = PIAPI_ERROR;;
+ }
+
+ if (SG(request_info).cookie_data) {
+ efree(SG(request_info).cookie_data);
+ };
+
+ php_request_shutdown(NULL);
+ } zend_catch {
+ iRet = PIAPI_ERROR;
+ } zend_end_try();
+ return iRet;
+}
+
+MODULE_API BOOL PHP5_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;
+};
+
+MODULE_API BOOL PHP5_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
new file mode 100644
index 0000000..d229fec
--- /dev/null
+++ b/sapi/pi3web/pi3web_sapi.h
@@ -0,0 +1,102 @@
+#ifndef _PI3WEB_SAPI_H_
+#define _PI3WEB_SAPI_H_
+
+#ifdef PHP_WIN32
+# include <windows.h>
+# ifdef PHP5PI3WEB_EXPORTS
+# define MODULE_API __declspec(dllexport)
+# else
+# define MODULE_API __declspec(dllimport)
+# endif
+#else
+# if defined(__GNUC__) && __GNUC__ >= 4
+# define MODULE_API __attribute__ ((visibility("default")))
+# else
+# define MODULE_API
+# endif
+# define far
+
+ typedef int BOOL;
+ typedef void far *LPVOID;
+ typedef unsigned long DWORD;
+ typedef DWORD far *LPDWORD;
+ typedef char CHAR;
+ typedef CHAR *LPSTR;
+ typedef unsigned char BYTE;
+ typedef BYTE far *LPBYTE;
+#endif
+
+ typedef LPVOID HCONN;
+
+#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
+
+
+ LPVOID (* GetVariableNames) (HCONN hConn);
+
+ BOOL (* GetServerVariable) ( HCONN hConn,
+ LPSTR lpszVariableName,
+ LPVOID lpvBuffer,
+ LPDWORD lpdwSize );
+
+ BOOL (* WriteClient) ( HCONN hConn,
+ LPVOID lpvBuffer,
+ LPDWORD lpdwBytes,
+ DWORD dwReserved );
+
+ BOOL (* ReadClient) ( HCONN hConn,
+ LPVOID lpvBuffer,
+ LPDWORD lpdwSize );
+
+ BOOL (* SendHeaderFunction)( HCONN hConn,
+ LPDWORD lpdwSize,
+ LPDWORD lpdwDataType );
+
+} CONTROL_BLOCK, *LPCONTROL_BLOCK;
+
+MODULE_API DWORD PHP5_wrapper(LPCONTROL_BLOCK lpCB);
+MODULE_API BOOL PHP5_startup();
+MODULE_API BOOL PHP5_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_