diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /sapi/embed | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'sapi/embed')
-rw-r--r-- | sapi/embed/CREDITS | 2 | ||||
-rw-r--r-- | sapi/embed/EXPERIMENTAL | 5 | ||||
-rw-r--r-- | sapi/embed/config.m4 | 33 | ||||
-rw-r--r-- | sapi/embed/config.w32 | 9 | ||||
-rw-r--r-- | sapi/embed/php5embed.dsp | 100 | ||||
-rw-r--r-- | sapi/embed/php_embed.c | 241 | ||||
-rw-r--r-- | sapi/embed/php_embed.h | 73 |
7 files changed, 463 insertions, 0 deletions
diff --git a/sapi/embed/CREDITS b/sapi/embed/CREDITS new file mode 100644 index 0000000..a5227b4 --- /dev/null +++ b/sapi/embed/CREDITS @@ -0,0 +1,2 @@ +Embed +Edin Kadribasic diff --git a/sapi/embed/EXPERIMENTAL b/sapi/embed/EXPERIMENTAL new file mode 100644 index 0000000..293159a --- /dev/null +++ b/sapi/embed/EXPERIMENTAL @@ -0,0 +1,5 @@ +this module is experimental, +its functions may change their names +or move to extension all together +so do not rely to much on them +you have been warned! diff --git a/sapi/embed/config.m4 b/sapi/embed/config.m4 new file mode 100644 index 0000000..3a61b45 --- /dev/null +++ b/sapi/embed/config.m4 @@ -0,0 +1,33 @@ +dnl +dnl $Id$ +dnl + +PHP_ARG_ENABLE(embed,, +[ --enable-embed[=TYPE] EXPERIMENTAL: Enable building of embedded SAPI library + TYPE is either 'shared' or 'static'. [TYPE=shared]], no, no) + +AC_MSG_CHECKING([for embedded SAPI library support]) + +if test "$PHP_EMBED" != "no"; then + case "$PHP_EMBED" in + yes|shared) + PHP_EMBED_TYPE=shared + INSTALL_IT="\$(mkinstalldirs) \$(INSTALL_ROOT)\$(prefix)/lib; \$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)\$(prefix)/lib" + ;; + static) + PHP_EMBED_TYPE=static + INSTALL_IT="\$(mkinstalldirs) \$(INSTALL_ROOT)\$(prefix)/lib; \$(INSTALL) -m 0644 $SAPI_STATIC \$(INSTALL_ROOT)\$(prefix)/lib" + ;; + *) + PHP_EMBED_TYPE=no + ;; + esac + if test "$PHP_EMBED_TYPE" != "no"; then + PHP_SELECT_SAPI(embed, $PHP_EMBED_TYPE, php_embed.c) + PHP_INSTALL_HEADERS([sapi/embed/php_embed.h]) + fi + AC_MSG_RESULT([$PHP_EMBED_TYPE]) +else + AC_MSG_RESULT(no) +fi + diff --git a/sapi/embed/config.w32 b/sapi/embed/config.w32 new file mode 100644 index 0000000..f3cc60d --- /dev/null +++ b/sapi/embed/config.w32 @@ -0,0 +1,9 @@ +// vim:ft=javascript +// $Id$ + +ARG_ENABLE('embed', 'Embedded SAPI library', 'no'); + +if (PHP_EMBED != "no") { + SAPI('embed', 'php_embed.c', 'php' + PHP_VERSION + 'embed.lib'); + PHP_INSTALL_HEADERS("sapi/embed", "php_embed.h"); +} diff --git a/sapi/embed/php5embed.dsp b/sapi/embed/php5embed.dsp new file mode 100644 index 0000000..8564b11 --- /dev/null +++ b/sapi/embed/php5embed.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="php5embed" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=php5embed - 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 "php5embed.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 "php5embed.mak" CFG="php5embed - Win32 Debug_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "php5embed - Win32 Debug_TS" (based on "Win32 (x86) Static Library")
+!MESSAGE "php5embed - Win32 Release_TS" (based on "Win32 (x86) Static Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "php5embed - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug_TS"
+# PROP BASE Intermediate_Dir "Debug_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug_TS"
+# PROP Intermediate_Dir "Debug_TS"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D ZEND_DEBUG=1 /YX /FD /GZ /c
+# ADD BASE RSC /l 0x406 /d "_DEBUG"
+# ADD RSC /l 0x406 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo /out:"..\..\Debug_TS\php5embed.lib"
+
+!ELSEIF "$(CFG)" == "php5embed - Win32 Release_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release_TS"
+# PROP BASE Intermediate_Dir "Release_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TS"
+# PROP Intermediate_Dir "Release_TS"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D ZEND_DEBUG=0 /YX /FD /c
+# ADD BASE RSC /l 0x406 /d "NDEBUG"
+# ADD RSC /l 0x406 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo /out:"..\..\Release_TS\php5embed.lib"
+
+!ENDIF
+
+# Begin Target
+
+# Name "php5embed - Win32 Debug_TS"
+# Name "php5embed - Win32 Release_TS"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=php_embed.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=php_embed.h
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c new file mode 100644 index 0000000..414b4db --- /dev/null +++ b/sapi/embed/php_embed.c @@ -0,0 +1,241 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Edin Kadribasic <edink@php.net> | + +----------------------------------------------------------------------+ +*/ +/* $Id$ */ + +#include "php_embed.h" +#include "ext/standard/php_standard.h" + +#ifdef PHP_WIN32 +#include <io.h> +#include <fcntl.h> +#endif + +const char HARDCODED_INI[] = + "html_errors=0\n" + "register_argc_argv=1\n" + "implicit_flush=1\n" + "output_buffering=0\n" + "max_execution_time=0\n" + "max_input_time=-1\n\0"; + +static char* php_embed_read_cookies(TSRMLS_D) +{ + return NULL; +} + +static int php_embed_deactivate(TSRMLS_D) +{ + fflush(stdout); + return SUCCESS; +} + +static inline size_t php_embed_single_write(const char *str, uint str_length) +{ +#ifdef PHP_WRITE_STDOUT + long ret; + + ret = write(STDOUT_FILENO, str, str_length); + if (ret <= 0) return 0; + return ret; +#else + size_t ret; + + ret = fwrite(str, 1, MIN(str_length, 16384), stdout); + return ret; +#endif +} + + +static int php_embed_ub_write(const char *str, uint str_length TSRMLS_DC) +{ + const char *ptr = str; + uint remaining = str_length; + size_t ret; + + while (remaining > 0) { + ret = php_embed_single_write(ptr, remaining); + if (!ret) { + php_handle_aborted_connection(); + } + ptr += ret; + remaining -= ret; + } + + return str_length; +} + +static void php_embed_flush(void *server_context) +{ + if (fflush(stdout)==EOF) { + php_handle_aborted_connection(); + } +} + +static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) +{ +} + +static void php_embed_log_message(char *message TSRMLS_DC) +{ + fprintf (stderr, "%s\n", message); +} + +static void php_embed_register_variables(zval *track_vars_array TSRMLS_DC) +{ + php_import_environment_variables(track_vars_array TSRMLS_CC); +} + +static int php_embed_startup(sapi_module_struct *sapi_module) +{ + if (php_module_startup(sapi_module, NULL, 0)==FAILURE) { + return FAILURE; + } + return SUCCESS; +} + +extern EMBED_SAPI_API sapi_module_struct php_embed_module = { + "embed", /* name */ + "PHP Embedded Library", /* pretty name */ + + php_embed_startup, /* startup */ + php_module_shutdown_wrapper, /* shutdown */ + + NULL, /* activate */ + php_embed_deactivate, /* deactivate */ + + php_embed_ub_write, /* unbuffered write */ + php_embed_flush, /* flush */ + NULL, /* get uid */ + NULL, /* getenv */ + + php_error, /* error handler */ + + NULL, /* header handler */ + NULL, /* send headers handler */ + php_embed_send_header, /* send header handler */ + + NULL, /* read POST data */ + php_embed_read_cookies, /* read Cookies */ + + php_embed_register_variables, /* register server variables */ + php_embed_log_message, /* Log message */ + NULL, /* Get request time */ + NULL, /* Child terminate */ + + STANDARD_SAPI_MODULE_PROPERTIES +}; +/* }}} */ + +/* {{{ arginfo ext/standard/dl.c */ +ZEND_BEGIN_ARG_INFO(arginfo_dl, 0) + ZEND_ARG_INFO(0, extension_filename) +ZEND_END_ARG_INFO() +/* }}} */ + +static const zend_function_entry additional_functions[] = { + ZEND_FE(dl, arginfo_dl) + {NULL, NULL, NULL} +}; + +EMBED_SAPI_API int php_embed_init(int argc, char **argv PTSRMLS_DC) +{ + zend_llist global_vars; +#ifdef ZTS + void ***tsrm_ls = NULL; +#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); + tsrm_ls = ts_resource(0); + *ptsrm_ls = tsrm_ls; +#endif + + sapi_startup(&php_embed_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 + + php_embed_module.ini_entries = malloc(sizeof(HARDCODED_INI)); + memcpy(php_embed_module.ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI)); + + php_embed_module.additional_functions = additional_functions; + + if (argv) { + php_embed_module.executable_location = argv[0]; + } + + if (php_embed_module.startup(&php_embed_module)==FAILURE) { + return FAILURE; + } + + zend_llist_init(&global_vars, sizeof(char *), NULL, 0); + + /* Set some Embedded PHP defaults */ + SG(options) |= SAPI_OPTION_NO_CHDIR; + SG(request_info).argc=argc; + SG(request_info).argv=argv; + + if (php_request_startup(TSRMLS_C)==FAILURE) { + php_module_shutdown(TSRMLS_C); + return FAILURE; + } + + SG(headers_sent) = 1; + SG(request_info).no_headers = 1; + php_register_variable("PHP_SELF", "-", NULL TSRMLS_CC); + + return SUCCESS; +} + +EMBED_SAPI_API void php_embed_shutdown(TSRMLS_D) +{ + php_request_shutdown((void *) 0); + php_module_shutdown(TSRMLS_C); + sapi_shutdown(); +#ifdef ZTS + tsrm_shutdown(); +#endif + if (php_embed_module.ini_entries) { + free(php_embed_module.ini_entries); + php_embed_module.ini_entries = NULL; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/sapi/embed/php_embed.h b/sapi/embed/php_embed.h new file mode 100644 index 0000000..ad5f4bc --- /dev/null +++ b/sapi/embed/php_embed.h @@ -0,0 +1,73 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Edin Kadribasic <edink@php.net> | + +----------------------------------------------------------------------+ +*/ +/* $Id$ */ + +#ifndef _PHP_EMBED_H_ +#define _PHP_EMBED_H_ + +#include <main/php.h> +#include <main/SAPI.h> +#include <main/php_main.h> +#include <main/php_variables.h> +#include <main/php_ini.h> +#include <zend_ini.h> + +#ifdef ZTS +#define PTSRMLS_D void ****ptsrm_ls +#define PTSRMLS_DC , PTSRMLS_D +#define PTSRMLS_C &tsrm_ls +#define PTSRMLS_CC , PTSRMLS_C + +#define PHP_EMBED_START_BLOCK(x,y) { \ + void ***tsrm_ls; \ + php_embed_init(x, y PTSRMLS_CC); \ + zend_first_try { + +#else +#define PTSRMLS_D +#define PTSRMLS_DC +#define PTSRMLS_C +#define PTSRMLS_CC + +#define PHP_EMBED_START_BLOCK(x,y) { \ + php_embed_init(x, y); \ + zend_first_try { + +#endif + +#define PHP_EMBED_END_BLOCK() \ + } zend_catch { \ + /* int exit_status = EG(exit_status); */ \ + } zend_end_try(); \ + php_embed_shutdown(TSRMLS_C); \ +} + +#ifndef PHP_WIN32 + #define EMBED_SAPI_API SAPI_API +#else + #define EMBED_SAPI_API +#endif + +BEGIN_EXTERN_C() +EMBED_SAPI_API int php_embed_init(int argc, char **argv PTSRMLS_DC); +EMBED_SAPI_API void php_embed_shutdown(TSRMLS_D); +extern EMBED_SAPI_API sapi_module_struct php_embed_module; +END_EXTERN_C() + + +#endif /* _PHP_EMBED_H_ */ |