diff options
Diffstat (limited to 'sapi')
223 files changed, 14032 insertions, 9749 deletions
diff --git a/sapi/aolserver/README b/sapi/aolserver/README index 80c186ea5d..86af6a54b3 100644 --- a/sapi/aolserver/README +++ b/sapi/aolserver/README @@ -60,7 +60,7 @@ Then enable the PHP module: ns_section "ns/server/${servername}/modules" ... -ns_param php ${bindir}/libphp5.so +ns_param php ${bindir}/libphp7.so ============================================================================= diff --git a/sapi/aolserver/aolserver.c b/sapi/aolserver/aolserver.c index 9dac79b8df..4b6c5868b0 100644 --- a/sapi/aolserver/aolserver.c +++ b/sapi/aolserver/aolserver.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -86,7 +86,7 @@ static void php_ns_config(php_ns_context *ctx, char global); */ static int -php_ns_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) +php_ns_sapi_ub_write(const char *str, uint str_length) { int n; uint sent = 0; @@ -101,17 +101,17 @@ php_ns_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) sent += n; str_length -= n; } - + return sent; } /* - * php_ns_sapi_header_handler() sets a HTTP reply header to be + * 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) +php_ns_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers) { char *header_name, *header_content; char *p; @@ -135,7 +135,7 @@ php_ns_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct } sapi_free_header(sapi_header); - + return 0; } @@ -145,14 +145,14 @@ php_ns_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct */ static int -php_ns_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +php_ns_sapi_send_headers(sapi_headers_struct *sapi_headers) { 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; } @@ -162,15 +162,15 @@ php_ns_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) */ static int -php_ns_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) +php_ns_sapi_read_post(char *buf, uint count_bytes) { 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 { @@ -180,16 +180,16 @@ php_ns_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) 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) + +static char *php_ns_sapi_read_cookies(void) { int i; char *http_cookie = NULL; - + i = Ns_SetIFind(NSG(conn->headers), "cookie"); if(i != -1) { http_cookie = Ns_SetValue(NSG(conn->headers), i); @@ -203,7 +203,7 @@ 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()); @@ -215,7 +215,7 @@ static void php_info_aolserver(ZEND_MODULE_INFO_FUNC_ARGS) 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", + snprintf(buf, 511, "%d day(s), %02d:%02d:%02d", uptime / 86400, (uptime / 3600) % 24, (uptime / 60) % 60, @@ -268,12 +268,12 @@ PHP_FUNCTION(getallheaders) int i; array_init(return_value); - + for (i = 0; i < Ns_SetSize(NSG(conn->headers)); i++) { char *key = Ns_SetKey(NSG(conn->headers), i); char *value = Ns_SetValue(NSG(conn->headers), i); - - add_assoc_string(return_value, key, value, 1); + + add_assoc_string(return_value, key, value); } } @@ -295,13 +295,13 @@ php_ns_startup(sapi_module_struct *sapi_module) */ #define ADD_STRINGX(name, buf) \ - php_register_variable(name, buf, track_vars_array TSRMLS_CC) + php_register_variable(name, buf, track_vars_array) #define ADD_STRING(name) \ ADD_STRINGX(name, buf) static void -php_ns_sapi_register_variables(zval *track_vars_array TSRMLS_DC) +php_ns_sapi_register_variables(zval *track_vars_array) { int i; char buf[NS_BUF_SIZE + 1]; @@ -314,7 +314,7 @@ php_ns_sapi_register_variables(zval *track_vars_array TSRMLS_DC) char c; snprintf(buf, NS_BUF_SIZE, "HTTP_%s", key); - + for(p = buf + 5; (c = *p); p++) { c = toupper(c); if(c < 'A' || c > 'Z') { @@ -325,7 +325,7 @@ php_ns_sapi_register_variables(zval *track_vars_array TSRMLS_DC) 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); @@ -335,7 +335,7 @@ php_ns_sapi_register_variables(zval *track_vars_array TSRMLS_DC) 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))); @@ -402,7 +402,7 @@ static sapi_module_struct aolserver_sapi_module = { */ static int -php_ns_module_main(TSRMLS_D) +php_ns_module_main(void) { zend_file_handle file_handle; @@ -410,13 +410,13 @@ php_ns_module_main(TSRMLS_D) 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) { + if (php_request_startup() == FAILURE) { return NS_ERROR; } - - php_execute_script(&file_handle TSRMLS_CC); + + php_execute_script(&file_handle); php_request_shutdown(NULL); return NS_OK; @@ -427,23 +427,23 @@ php_ns_module_main(TSRMLS_D) * and fills it with data provided by the web server */ -static void -php_ns_request_ctor(TSRMLS_D) +static void +php_ns_request_ctor(void) { 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); @@ -454,7 +454,7 @@ php_ns_request_ctor(TSRMLS_D) else SG(request_info).proto_num = 1000; 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 : + SG(request_info).content_type = index == -1 ? NULL : Ns_SetValue(NSG(conn)->headers, index); SG(sapi_headers).http_response_code = 200; @@ -473,11 +473,11 @@ php_ns_request_ctor(TSRMLS_D) /* * php_ns_request_dtor() destroys all data associated with - * the per-request structure + * the per-request structure */ static void -php_ns_request_dtor(TSRMLS_D) +php_ns_request_dtor(void) { free(SG(request_info).path_translated); if (SG(request_info).query_string) @@ -494,17 +494,16 @@ 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); + php_ns_request_ctor(); + + status = php_ns_module_main(); + + php_ns_request_dtor(); return status; } @@ -515,7 +514,7 @@ php_ns_request_handler(void *context, Ns_Conn *conn) * It understands the "map" and "php_value" command. */ -static void +static void php_ns_config(php_ns_context *ctx, char global) { int i; @@ -535,10 +534,10 @@ php_ns_config(php_ns_context *ctx, char global) 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) + /* + * 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")) { @@ -549,25 +548,25 @@ php_ns_config(php_ns_context *ctx, char global) val = strchr(value, ' '); if (val) { char *new_key; - + new_key = estrndup(value, val - value); - - do { - val++; + + 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, + zend_alter_ini_entry(new_key, strlen(new_key) + 1, val, strlen(val) + 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); - + efree(new_key); } #endif } - + } } - + /* * php_ns_server_shutdown() performs the last steps before the * server exits. Shutdowns basic services and frees memory @@ -577,7 +576,7 @@ 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(); @@ -597,20 +596,20 @@ php_ns_server_shutdown(void *context) 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); diff --git a/sapi/aolserver/php5aolserver.dsp b/sapi/aolserver/php5aolserver.dsp deleted file mode 100644 index dd6ad71c53..0000000000 --- a/sapi/aolserver/php5aolserver.dsp +++ /dev/null @@ -1,135 +0,0 @@ -# Microsoft Developer Studio Project File - Name="php5aolserver" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php5aolserver - 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 "php5aolserver.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 "php5aolserver.mak" CFG="php5aolserver - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php5aolserver - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5aolserver - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5aolserver - 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)" == "php5aolserver - 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 "PHP5AOLSERVER_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 "PHP5AOLSERVER_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 php5ts.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/php5aolserver.so" /libpath:"..\..\..\php_build\nsapi30\lib\\" /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS"
-
-!ELSEIF "$(CFG)" == "php5aolserver - 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 "PHP5AOLSERVER_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 php5ts.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/php5aolserver.so" /libpath:"..\..\..\php_build\nsapi30\lib\\" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"
-
-!ELSEIF "$(CFG)" == "php5aolserver - 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 "PHP5AOLSERVER_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 "PHP5AOLSERVER_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 php5ts_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/php5aolserver.so" /pdbtype:sept /libpath:"..\..\..\php_build\nsapi30\lib\\" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php5aolserver - Win32 Release_TS"
-# Name "php5aolserver - Win32 Release_TS_inline"
-# Name "php5aolserver - 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/apMakefile.tmpl b/sapi/apache/apMakefile.tmpl index 5f77d9c9c9..c8b174775e 100644 --- a/sapi/apache/apMakefile.tmpl +++ b/sapi/apache/apMakefile.tmpl @@ -1,38 +1,38 @@ ## -## Apache 1.3 Makefile template for PHP 5.0 Module -## [src/modules/php5/Makefile.tmpl] +## Apache 1.3 Makefile template for PHP 7.0 Module +## [src/modules/php7/Makefile.tmpl] ## # the parametrized target -LIB=libphp5.$(LIBEXT) +LIB=libphp7.$(LIBEXT) # objects for building the static library -OBJS=mod_php5.o -OBJS_LIB=libmodphp5.a +OBJS=mod_php7.o +OBJS_LIB=libmodphp7.a # objects for building the shared object library -SHLIB_OBJS=mod_php5.so-o -SHLIB_OBJS_LIB=libmodphp5.a +SHLIB_OBJS=mod_php7.so-o +SHLIB_OBJS_LIB=libmodphp7.a # the general targets all: lib lib: $(LIB) # build the static library by merging the object files -libphp5.a: $(OBJS) $(OBJS_LIB) +libphp7.a: $(OBJS) $(OBJS_LIB) cp $(OBJS_LIB) $@ ar r $@ $(OBJS) $(RANLIB) $@ # ugly hack to support older Apache-1.3 betas that don't set $LIBEXT -libphp5.: $(OBJS) $(OBJS_LIB) +libphp7.: $(OBJS) $(OBJS_LIB) cp $(OBJS_LIB) $@ ar r $@ $(OBJS) $(RANLIB) $@ - cp libphp5. libphp5.a + cp libphp7. libphp7.a # build the shared object library by linking the object files -libphp5.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) +libphp7.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) rm -f $@ $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) $(LIBS) $(PHP_LIBS) @@ -69,9 +69,9 @@ depend: $(OBJS): Makefile # DO NOT REMOVE -mod_php5.o: mod_php5.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \ +mod_php7.o: mod_php7.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \ $(INCDIR)/buff.h \ $(INCDIR)/http_config.h \ $(INCDIR)/http_core.h $(INCDIR)/http_main.h \ $(INCDIR)/http_protocol.h $(INCDIR)/http_request.h \ - $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php5.h + $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php7.h diff --git a/sapi/apache/config.m4 b/sapi/apache/config.m4 index 7b0ee562eb..f5bfde4d68 100644 --- a/sapi/apache/config.m4 +++ b/sapi/apache/config.m4 @@ -78,7 +78,7 @@ if test "$PHP_APXS" != "no"; then *darwin*) MH_BUNDLE_FLAGS="-dynamic -twolevel_namespace -bundle -bundle_loader $APXS_HTTPD" PHP_SUBST(MH_BUNDLE_FLAGS) - SAPI_SHARED=libs/libphp5.so + SAPI_SHARED=libs/libphp7.so build_type=bundle ;; *) @@ -86,26 +86,26 @@ if test "$PHP_APXS" != "no"; then ;; esac - PHP_SELECT_SAPI(apache, $build_type, sapi_apache.c mod_php5.c php_apache.c, $APACHE_CPPFLAGS -I$APXS_INCLUDEDIR) + PHP_SELECT_SAPI(apache, $build_type, sapi_apache.c mod_php7.c php_apache.c, $APACHE_CPPFLAGS -I$APXS_INCLUDEDIR) # Test whether apxs support -S option $APXS -q -S CFLAGS="$APXS_CFLAGS" CFLAGS >/dev/null 2>&1 if test "$?" != "0"; then - APACHE_INSTALL="$APXS -i -a -n php5 $SAPI_SHARED" # Old apxs does not have -S option + APACHE_INSTALL="$APXS -i -a -n php7 $SAPI_SHARED" # Old apxs does not have -S option else APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR` if test -z `$APXS -q SYSCONFDIR`; then APACHE_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -i -n php5 $SAPI_SHARED" + -i -n php7 $SAPI_SHARED" else APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR` APACHE_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \ $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ -S SYSCONFDIR='$APXS_SYSCONFDIR' \ - -i -a -n php5 $SAPI_SHARED" + -i -a -n php7 $SAPI_SHARED" fi fi @@ -135,7 +135,7 @@ if test "$PHP_SAPI" != "apache" && test "$PHP_APACHE" != "no"; then PHP_APACHE=/usr/local/apache fi - APACHE_INSTALL_FILES="\$(srcdir)/sapi/apache/mod_php5.* sapi/apache/libphp5.module" + APACHE_INSTALL_FILES="\$(srcdir)/sapi/apache/mod_php7.* sapi/apache/libphp7.module" AC_DEFINE(HAVE_APACHE,1,[ ]) APACHE_MODULE=yes @@ -144,7 +144,7 @@ if test "$PHP_SAPI" != "apache" && test "$PHP_APACHE" != "no"; then if test -f $PHP_APACHE/src/httpd.h; then APACHE_INCLUDE=-I$PHP_APACHE/src APACHE_TARGET=$PHP_APACHE/src - PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) + PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php7.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]) @@ -159,13 +159,13 @@ if test "$PHP_SAPI" != "apache" && test "$PHP_APACHE" != "no"; then elif test -f $PHP_APACHE/src/main/httpd.h; then APACHE_HAS_REGEX=1 APACHE_INCLUDE="-I$PHP_APACHE/src/main -I$PHP_APACHE/src/os/unix -I$PHP_APACHE/src/ap" - APACHE_TARGET=$PHP_APACHE/src/modules/php5 + APACHE_TARGET=$PHP_APACHE/src/modules/php7 if test ! -d $APACHE_TARGET; then mkdir $APACHE_TARGET fi - PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) - APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.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/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5" + PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.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/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" AC_MSG_RESULT([yes - Apache 1.3.x]) STRONGHOLD= if test -f $PHP_APACHE/src/include/ap_config.h; then @@ -183,13 +183,13 @@ if test "$PHP_SAPI" != "apache" && test "$PHP_APACHE" != "no"; then elif test -f $PHP_APACHE/src/include/httpd.h; then APACHE_HAS_REGEX=1 APACHE_INCLUDE="-I$PHP_APACHE/src/include -I$PHP_APACHE/src/os/unix" - APACHE_TARGET=$PHP_APACHE/src/modules/php5 + APACHE_TARGET=$PHP_APACHE/src/modules/php7 if test ! -d $APACHE_TARGET; then mkdir $APACHE_TARGET fi - PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) - PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5" - APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.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_SELECT_SAPI(apache, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) + PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.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 $PHP_APACHE/src/include/ap_config.h; then @@ -207,9 +207,9 @@ if test "$PHP_SAPI" != "apache" && test "$PHP_APACHE" != "no"; then elif test -f $PHP_APACHE/apache/httpd.h; then APACHE_INCLUDE="-I$PHP_APACHE/apache -I$PHP_APACHE/ssl/include" APACHE_TARGET=$PHP_APACHE/apache - PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) - PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5" - APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET" + PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) + PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET" STRONGHOLD=-DSTRONGHOLD=1 AC_MSG_RESULT([yes - StrongHold]) if test -f $PHP_APACHE/apache/ap_config.h; then @@ -247,13 +247,13 @@ dnl Build as static module if test "$APACHE_MODULE" = "yes"; then PHP_TARGET_RDYNAMIC $php_shtool mkdir -p sapi/apache - PHP_OUTPUT(sapi/apache/libphp5.module) + PHP_OUTPUT(sapi/apache/libphp7.module) fi dnl General if test -n "$APACHE_INSTALL"; then if test "x$APXS" != "x" -a "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then - APXS_EXP=-bE:sapi/apache/mod_php5.exp + APXS_EXP=-bE:sapi/apache/mod_php7.exp fi PHP_APACHE_FD_CHECK diff --git a/sapi/apache/config.w32 b/sapi/apache/config.w32 index e876d7500e..e5b72f1bcf 100644 --- a/sapi/apache/config.w32 +++ b/sapi/apache/config.w32 @@ -15,9 +15,9 @@ if (PHP_APACHE != "no") { ";" + PHP_PHP_BUILD + "\\apache\\src\\corer")) { // We need to play tricks to get our readdir.h used by apache // headers - SAPI('apache', 'mod_php5.c sapi_apache.c php_apache.c', + SAPI('apache', 'mod_php7.c sapi_apache.c php_apache.c', 'php' + PHP_VERSION + 'apache.dll', - '/D APACHEPHP5_EXPORTS /D APACHE_READDIR_H /I win32'); + '/D APACHEPHP7_EXPORTS /D APACHE_READDIR_H /I win32'); } else { WARNING("Could not find apache libraries/headers"); } diff --git a/sapi/apache/libphp5.module.in b/sapi/apache/libphp7.module.in index 00d9c49f40..892df4d5cc 100644 --- a/sapi/apache/libphp5.module.in +++ b/sapi/apache/libphp7.module.in @@ -1,4 +1,4 @@ -Name: php5_module +Name: php7_module ConfigStart RULE_WANTHSREGEX=no RULE_HIDE=yes diff --git a/sapi/apache/libpre.c b/sapi/apache/libpre.c index 8695836c88..94385dbbd1 100644 --- a/sapi/apache/libpre.c +++ b/sapi/apache/libpre.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -25,7 +25,7 @@ * stops. By using these functions instead of defining a main() * and calling ExitThread(TSR_THREAD, 0), the load time of the * shared NLM is faster and memory size reduced. - * + * * You may also want to override these in your own Apache module * to do any cleanup other than the mechanism Apache modules provide. * ------------------------------------------------------------------ diff --git a/sapi/apache/mod_php5.exp b/sapi/apache/mod_php5.exp deleted file mode 100644 index 9ad0f0a0ad..0000000000 --- a/sapi/apache/mod_php5.exp +++ /dev/null @@ -1 +0,0 @@ -php5_module diff --git a/sapi/apache/mod_php5.c b/sapi/apache/mod_php7.c index 1fc4153f1e..27d6579da8 100644 --- a/sapi/apache/mod_php5.c +++ b/sapi/apache/mod_php7.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -30,13 +30,13 @@ /* {{{ Prototypes */ -int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC); +int apache_php_module_main(request_rec *r, int display_source_mode); static void php_save_umask(void); static void php_restore_umask(void); -static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC); -static char *sapi_apache_read_cookies(TSRMLS_D); -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC); -static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC); +static int sapi_apache_read_post(char *buffer, uint count_bytes); +static char *sapi_apache_read_cookies(void); +static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers); +static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers); 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); @@ -60,12 +60,12 @@ static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *con static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode); static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2); -/* ### these should be defined in mod_php5.h or somewhere else */ +/* ### these should be defined in mod_php7.h or somewhere else */ #define USE_PATH 1 #define IGNORE_URL 2 #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST POSSIBLE STATUS DESCRIPTION") -module MODULE_VAR_EXPORT php5_module; +module MODULE_VAR_EXPORT php7_module; int saved_umask; static unsigned char apache_php_initialized; @@ -92,10 +92,10 @@ static void php_save_umask(void) /* {{{ sapi_apache_ub_write */ -static int sapi_apache_ub_write(const char *str, uint str_length TSRMLS_DC) +static int sapi_apache_ub_write(const char *str, uint str_length) { int ret=0; - + if (SG(server_context)) { ret = rwrite(str, str_length, (request_rec *) SG(server_context)); } @@ -122,7 +122,7 @@ static void sapi_apache_flush(void *server_context) /* {{{ sapi_apache_read_post */ -static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static int sapi_apache_read_post(char *buffer, uint count_bytes) { int total_read_bytes=0, read_bytes; request_rec *r = (request_rec *) SG(server_context); @@ -137,7 +137,7 @@ static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC) if (!SG(read_post_bytes) && !ap_should_client_block(r)) { return total_read_bytes; } - + handler = signal(SIGPIPE, SIG_IGN); while (total_read_bytes<count_bytes) { hard_timeout("Read POST information", r); /* start timeout timer */ @@ -148,14 +148,14 @@ static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC) } total_read_bytes += read_bytes; } - signal(SIGPIPE, handler); + signal(SIGPIPE, handler); return total_read_bytes; } /* }}} */ /* {{{ sapi_apache_read_cookies */ -static char *sapi_apache_read_cookies(TSRMLS_D) +static char *sapi_apache_read_cookies(void) { return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, "HTTP_COOKIE"); } @@ -163,7 +163,7 @@ static char *sapi_apache_read_cookies(TSRMLS_D) /* {{{ sapi_apache_header_handler */ -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) { char *header_name, *header_content, *p; request_rec *r = (request_rec *) SG(server_context); @@ -218,7 +218,7 @@ static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_head /* {{{ sapi_apache_send_headers */ -static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers) { request_rec *r = SG(server_context); const char *sline = SG(sapi_headers).http_status_line; @@ -251,12 +251,12 @@ static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ sapi_apache_register_server_variables */ -static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_apache_register_server_variables(zval *track_vars_array) { 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; + zval *path_translated; HashTable *symbol_table; unsigned int new_val_len; @@ -270,25 +270,25 @@ static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_ val = ""; } val_len = strlen(val); - if (sapi_module.input_filter(PARSE_SERVER, elts[i].key, &val, val_len, &new_val_len TSRMLS_CC)) { - php_register_variable_safe(elts[i].key, val, new_val_len, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, elts[i].key, &val, val_len, &new_val_len)) { + php_register_variable_safe(elts[i].key, val, new_val_len, track_vars_array); } } /* If PATH_TRANSLATED doesn't exist, copy it from SCRIPT_FILENAME */ if (track_vars_array) { - symbol_table = track_vars_array->value.ht; + symbol_table = Z_ARRVAL_P(track_vars_array); } 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); + && !zend_hash_str_exists(symbol_table, "PATH_TRANSLATED", sizeof("PATH_TRANSLATED")-1) + && (path_translated = zend_hash_str_find(symbol_table, "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME")-1)) != NULL) { + php_register_variable("PATH_TRANSLATED", Z_STRVAL_P(path_translated), track_vars_array); } - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &((request_rec *) SG(server_context))->uri, strlen(((request_rec *) SG(server_context))->uri), &new_val_len TSRMLS_CC)) { - php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &((request_rec *) SG(server_context))->uri, strlen(((request_rec *) SG(server_context))->uri), &new_val_len)) { + php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array); } } /* }}} */ @@ -307,7 +307,7 @@ static int php_apache_startup(sapi_module_struct *sapi_module) /* {{{ php_apache_log_message */ -static void php_apache_log_message(char *message TSRMLS_DC) +static void php_apache_log_message(char *message) { if (SG(server_context)) { #if MODULE_MAGIC_NUMBER >= 19970831 @@ -325,26 +325,25 @@ static void php_apache_log_message(char *message TSRMLS_DC) */ static void php_apache_request_shutdown(void *dummy) { - TSRMLS_FETCH(); - php_output_set_status(PHP_OUTPUT_DISABLED TSRMLS_CC); + php_output_set_status(PHP_OUTPUT_DISABLED); if (AP(in_request)) { AP(in_request) = 0; php_request_shutdown(dummy); } - SG(server_context) = NULL; - /* - * The server context (request) is NOT invalid by the time - * run_cleanups() is called + SG(server_context) = NULL; + /* + * The server context (request) is NOT invalid by the time + * run_cleanups() is called */ } /* }}} */ /* {{{ php_apache_sapi_activate */ -static int php_apache_sapi_activate(TSRMLS_D) +static int php_apache_sapi_activate(void) { - request_rec *r = (request_rec *) SG(server_context); + request_rec *r = (request_rec *) SG(server_context); /* * For the Apache module version, this bit of code registers a cleanup @@ -352,7 +351,7 @@ static int php_apache_sapi_activate(TSRMLS_D) * 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. + * memory. */ block_alarms(); register_cleanup(r->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec); @@ -369,7 +368,7 @@ static int php_apache_sapi_activate(TSRMLS_D) /* {{{ php_apache_get_stat */ -static struct stat *php_apache_get_stat(TSRMLS_D) +static struct stat *php_apache_get_stat(void) { return &((request_rec *) SG(server_context))->finfo; } @@ -377,7 +376,7 @@ static struct stat *php_apache_get_stat(TSRMLS_D) /* {{{ php_apache_getenv */ -static char *php_apache_getenv(char *name, size_t name_len TSRMLS_DC) +static char *php_apache_getenv(char *name, size_t name_len) { if (SG(server_context) == NULL) { return NULL; @@ -389,14 +388,14 @@ static char *php_apache_getenv(char *name, size_t name_len TSRMLS_DC) /* {{{ sapi_apache_get_fd */ -static int sapi_apache_get_fd(int *nfd TSRMLS_DC) +static int sapi_apache_get_fd(int *nfd) { #if PHP_APACHE_HAVE_CLIENT_FD request_rec *r = SG(server_context); int fd; fd = r->connection->client->fd; - + if (fd >= 0) { if (nfd) *nfd = fd; return SUCCESS; @@ -408,19 +407,19 @@ static int sapi_apache_get_fd(int *nfd TSRMLS_DC) /* {{{ sapi_apache_force_http_10 */ -static int sapi_apache_force_http_10(TSRMLS_D) +static int sapi_apache_force_http_10(void) { request_rec *r = SG(server_context); - + r->proto_num = HTTP_VERSION(1,0); - + return SUCCESS; } /* }}} */ /* {{{ sapi_apache_get_target_uid */ -static int sapi_apache_get_target_uid(uid_t *obj TSRMLS_DC) +static int sapi_apache_get_target_uid(uid_t *obj) { *obj = ap_user_id; return SUCCESS; @@ -429,7 +428,7 @@ static int sapi_apache_get_target_uid(uid_t *obj TSRMLS_DC) /* {{{ sapi_apache_get_target_gid */ -static int sapi_apache_get_target_gid(gid_t *obj TSRMLS_DC) +static int sapi_apache_get_target_gid(gid_t *obj) { *obj = ap_group_id; return SUCCESS; @@ -438,7 +437,7 @@ static int sapi_apache_get_target_gid(gid_t *obj TSRMLS_DC) /* {{{ php_apache_get_request_time */ -static double php_apache_get_request_time(TSRMLS_D) +static double php_apache_get_request_time(void) { return (double) ((request_rec *)SG(server_context))->request_time; } @@ -446,7 +445,7 @@ static double php_apache_get_request_time(TSRMLS_D) /* {{{ sapi_apache_child_terminate */ -static void sapi_apache_child_terminate(TSRMLS_D) +static void sapi_apache_child_terminate(void) { #ifndef MULTITHREAD ap_child_terminate((request_rec *)SG(server_context)); @@ -459,7 +458,7 @@ static void sapi_apache_child_terminate(TSRMLS_D) static sapi_module_struct apache_sapi_module = { "apache", /* name */ "Apache", /* pretty name */ - + php_apache_startup, /* startup */ php_module_shutdown_wrapper, /* shutdown */ @@ -517,7 +516,7 @@ static void php_restore_umask(void) /* {{{ init_request_info */ -static void init_request_info(TSRMLS_D) +static void init_request_info(void) { request_rec *r = ((request_rec *) SG(server_context)); char *content_length = (char *) table_get(r->subprocess_env, "CONTENT_LENGTH"); @@ -564,24 +563,26 @@ static void init_request_info(TSRMLS_D) /* {{{ php_apache_alter_ini_entries */ -static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry TSRMLS_DC) +static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry) { - 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, per_dir_entry->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE); + zend_string *key = zend_string_init(per_dir_entry->key, per_dir_entry->key_length, 0); + zend_alter_ini_entry_chars(key, per_dir_entry->value, per_dir_entry->value_length, per_dir_entry->type, per_dir_entry->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE); + zend_string_release(key); return 0; } /* }}} */ /* {{{ php_apache_get_default_mimetype */ -static char *php_apache_get_default_mimetype(request_rec *r TSRMLS_DC) +static char *php_apache_get_default_mimetype(request_rec *r) { - + 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); + tmpmimetype = sapi_get_default_content_type(); mimetype = pstrdup(r->pool, tmpmimetype); efree(tmpmimetype); } else { @@ -597,7 +598,6 @@ 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; @@ -607,7 +607,7 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) fh.free_filename = 0; fh.type = ZEND_HANDLE_FILENAME; - zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &fh); + zend_execute_scripts(ZEND_INCLUDE, NULL, 1, &fh); return OK; } @@ -620,18 +620,18 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) return DECLINED; } - per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php5_module); + per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php7_module); if (per_dir_conf) { - zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC); + zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries); } - + /* 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->content_type = php_apache_get_default_mimetype(r); zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return DECLINED; } @@ -643,7 +643,7 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) #if MODULE_MAGIC_NUMBER > 19961007 if ((retval = setup_client_block(r, REQUEST_CHUNKED_DECHUNK))) { zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return retval; } @@ -653,7 +653,7 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) #if MODULE_MAGIC_NUMBER < 19970912 if ((retval = set_last_modified(r, r->finfo.st_mtime))) { zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return retval; } @@ -665,7 +665,7 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) } /* 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); + r->content_type = php_apache_get_default_mimetype(r); /* Init timeout */ hard_timeout("send", r); @@ -674,8 +674,8 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) add_common_vars(r); add_cgi_vars(r); - init_request_info(TSRMLS_C); - apache_php_module_main(r, display_source_mode TSRMLS_CC); + init_request_info(); + apache_php_module_main(r, display_source_mode); /* Done, restore umask, turn off timeout, close file and return */ php_restore_umask(); @@ -691,10 +691,9 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) static int send_parsed_php(request_rec * r) { int result = send_php(r, 0, NULL); - TSRMLS_FETCH(); - + ap_table_setn(r->notes, "mod_php_memory_usage", - ap_psprintf(r->pool, "%lu", zend_memory_peak_usage(1 TSRMLS_CC))); + ap_psprintf(r->pool, "%lu", zend_memory_peak_usage(1))); return result; } @@ -710,36 +709,44 @@ static int send_parsed_php_source(request_rec * r) /* {{{ destroy_per_dir_entry */ -static void destroy_per_dir_entry(php_per_dir_entry *per_dir_entry) +static void destroy_per_dir_entry(zval *zv) { + php_per_dir_entry *per_dir_entry = Z_PTR_P(zv); + free(per_dir_entry->key); free(per_dir_entry->value); + free(per_dir_entry); } /* }}} */ /* {{{ copy_per_dir_entry */ -static void copy_per_dir_entry(php_per_dir_entry *per_dir_entry) +static void copy_per_dir_entry(zval *zv) { - php_per_dir_entry tmp = *per_dir_entry; + php_per_dir_entry *old_per_dir_entry = Z_PTR_P(zv); + php_per_dir_entry *new_per_dir_entry = malloc(sizeof(php_per_dir_entry)); + + memcpy(new_per_dir_entry, old_per_dir_entry, sizeof(php_per_dir_entry)); + Z_PTR_P(zv) = new_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; + new_per_dir_entry->key = (char *) malloc(old_per_dir_entry->key_length+1); + memcpy(new_per_dir_entry->key, old_per_dir_entry->key, old_per_dir_entry->key_length); + new_per_dir_entry->key[new_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; + new_per_dir_entry->value = (char *) malloc(old_per_dir_entry->value_length+1); + memcpy(new_per_dir_entry->value, old_per_dir_entry->value, old_per_dir_entry->value_length); + new_per_dir_entry->value[new_per_dir_entry->value_length] = 0; } /* }}} */ /* {{{ should_overwrite_per_dir_entry */ -static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, php_per_dir_entry *new_per_dir_entry, zend_hash_key *hash_key, void *pData) +static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, zval *zv, zend_hash_key *hash_key, void *pData) { + php_per_dir_entry *new_per_dir_entry = Z_PTR_P(zv); php_per_dir_entry *orig_per_dir_entry; - if (zend_hash_find(target_ht, hash_key->arKey, hash_key->nKeyLength, (void **) &orig_per_dir_entry)==FAILURE) { + if ((orig_per_dir_entry = zend_hash_find_ptr(target_ht, hash_key->key)) == NULL) { return 1; /* does not exist in dest, copy from source */ } @@ -768,7 +775,7 @@ static void *php_create_dir(pool *p, char *dummy) HashTable *per_dir_info; per_dir_info = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init_ex(per_dir_info, 5, NULL, (void (*)(void *)) destroy_per_dir_entry, 1, 0); + zend_hash_init_ex(per_dir_info, 5, NULL, destroy_per_dir_entry, 1, 0); register_cleanup(p, (void *) per_dir_info, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) zend_hash_destroy); return per_dir_info; @@ -784,9 +791,9 @@ static void *php_merge_dir(pool *p, void *basev, void *addv) /* need a copy of addv to merge */ new = php_create_dir(p, "php_merge_dir"); - zend_hash_copy(new, (HashTable *) basev, (copy_ctor_func_t) copy_per_dir_entry, NULL, sizeof(php_per_dir_entry)); + zend_hash_copy(new, (HashTable *) basev, copy_per_dir_entry); - zend_hash_merge_ex(new, (HashTable *) addv, (copy_ctor_func_t) copy_per_dir_entry, sizeof(php_per_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL); + zend_hash_merge_ex(new, (HashTable *) addv, copy_per_dir_entry, should_overwrite_per_dir_entry, NULL); return new; } /* }}} */ @@ -823,7 +830,7 @@ static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable 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); + zend_hash_str_update_mem(conf, per_dir_entry.key, per_dir_entry.key_length, &per_dir_entry, sizeof(php_per_dir_entry)); return NULL; } /* }}} */ @@ -856,7 +863,7 @@ static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable * bool_val[0] = '0'; } bool_val[1] = 0; - + return php_apache_value_handler_ex(cmd, conf, arg1, bool_val, mode); } /* }}} */ @@ -894,18 +901,17 @@ static CONST_PREFIX char *php_apache_phpini_set(cmd_parms *cmd, HashTable *conf, static int php_xbithack_handler(request_rec * r) { HashTable *per_dir_conf; - TSRMLS_FETCH(); if (!(r->finfo.st_mode & S_IXUSR)) { return DECLINED; } - per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php5_module); + per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php7_module); if (per_dir_conf) { - zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC); + zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries); } if(!AP(xbithack)) { zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return DECLINED; } @@ -922,7 +928,7 @@ static void apache_php_module_shutdown_wrapper(void) #if MODULE_MAGIC_NUMBER >= 19970728 /* This function is only called on server exit if the apache API - * child_exit handler exists, so shutdown globally + * child_exit handler exists, so shutdown globally */ sapi_shutdown(); #endif @@ -963,8 +969,7 @@ static void php_init_handler(server_rec *s, pool *p) } #if MODULE_MAGIC_NUMBER >= 19980527 { - TSRMLS_FETCH(); - if (PG(expose_php)) { + if (PG(expose_php)) { ap_add_version_component("PHP/" PHP_VERSION); } } @@ -996,9 +1001,9 @@ command_rec php_commands[] = }; /* }}} */ -/* {{{ odule MODULE_VAR_EXPORT php5_module +/* {{{ odule MODULE_VAR_EXPORT php7_module */ -module MODULE_VAR_EXPORT php5_module = +module MODULE_VAR_EXPORT php7_module = { STANDARD_MODULE_STUFF, php_init_handler, /* initializer */ diff --git a/sapi/apache/mod_php7.exp b/sapi/apache/mod_php7.exp new file mode 100644 index 0000000000..1469b0314d --- /dev/null +++ b/sapi/apache/mod_php7.exp @@ -0,0 +1 @@ +php7_module diff --git a/sapi/apache/mod_php5.h b/sapi/apache/mod_php7.h index 73ba5592f7..81b6b30b42 100644 --- a/sapi/apache/mod_php5.h +++ b/sapi/apache/mod_php7.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -17,8 +17,8 @@ */ /* $Id$ */ -#ifndef MOD_PHP5_H -#define MOD_PHP5_H +#ifndef MOD_PHP7_H +#define MOD_PHP7_H #if !defined(WIN32) && !defined(WINNT) #ifndef MODULE_VAR_EXPORT @@ -50,7 +50,7 @@ extern php_apache_info_struct php_apache_info; # define MODULE_VAR_EXPORT PHPAPI #endif -#endif /* MOD_PHP5_H */ +#endif /* MOD_PHP7_H */ /* * Local variables: diff --git a/sapi/apache/php.sym b/sapi/apache/php.sym index 9ad0f0a0ad..1469b0314d 100644 --- a/sapi/apache/php.sym +++ b/sapi/apache/php.sym @@ -1 +1 @@ -php5_module +php7_module diff --git a/sapi/apache/php5apache.dsp b/sapi/apache/php5apache.dsp deleted file mode 100644 index fbdb7612b8..0000000000 --- a/sapi/apache/php5apache.dsp +++ /dev/null @@ -1,151 +0,0 @@ -# Microsoft Developer Studio Project File - Name="php5apache" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php5apache - Win32 Release_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "php5apache.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "php5apache.mak" CFG="php5apache - Win32 Release_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php5apache - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5apache - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5apache - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "php5apache - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS"
-# PROP BASE Intermediate_Dir "Release_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\includes" /I "..\..\main" /I "..\..\TSRM" /I "..\..\regex" /I "C:\Program Files\Apache Group\Apache\include" /D ZEND_DEBUG=0 /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php5ts.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x60000000" /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\release" /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS" /libpath:"C:\Program Files\Apache Group\Apache\libexec"
-
-!ELSEIF "$(CFG)" == "php5apache - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\includes" /I "..\..\main" /I "..\..\TSRM" /I "..\..\regex" /I "C:\Program Files\Apache Group\Apache\include" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php5ts_debug.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x60000000" /version:4.0 /dll /incremental:yes /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\php_build\release" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS" /libpath:"C:\Program Files\Apache Group\Apache\libexec"
-
-!ELSEIF "$(CFG)" == "php5apache - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS_inline"
-# PROP BASE Intermediate_Dir "Release_TS_inline"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Release_TS_inline"
-# PROP Intermediate_Dir "Release_TS_inline"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\includes" /I "..\..\main" /I "..\..\TSRM" /I "..\..\regex" /I "C:\Program Files\Apache Group\Apache\include" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php5ts.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\release" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline" /libpath:"C:\Program Files\Apache Group\Apache\libexec"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php5apache - Win32 Release_TS"
-# Name "php5apache - Win32 Debug_TS"
-# Name "php5apache - Win32 Release_TS_inline"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\mod_php5.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_apache.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\sapi_apache.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\mod_php5.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_apache_http.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
diff --git a/sapi/apache/php_apache.c b/sapi/apache/php_apache.c index 33c1504656..33d8a72b99 100644 --- a/sapi/apache/php_apache.c +++ b/sapi/apache/php_apache.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -120,7 +120,7 @@ PHP_INI_END() -static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRMLS_DC) +static void php_apache_globals_ctor(php_apache_info_struct *apache_globals) { apache_globals->in_request = 0; } @@ -131,7 +131,7 @@ static PHP_MINIT_FUNCTION(apache) #ifdef ZTS ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL); #else - php_apache_globals_ctor(&php_apache_info TSRMLS_CC); + php_apache_globals_ctor(&php_apache_info); #endif REGISTER_INI_ENTRIES(); return SUCCESS; @@ -298,11 +298,11 @@ PHP_FUNCTION(apache_child_terminate) ap_child_terminate( ((request_rec *)SG(server_context)) ); RETURN_TRUE; } else { /* tell them to get lost! */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is disabled"); + php_error_docref(NULL, E_WARNING, "This function is disabled"); RETURN_FALSE; } #else - php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is not supported in this build"); + php_error_docref(NULL, E_WARNING, "This function is not supported in this build"); RETURN_FALSE; #endif } @@ -316,7 +316,7 @@ PHP_FUNCTION(apache_note) int note_name_len, note_val_len; char *old_val; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { return; } @@ -327,7 +327,7 @@ PHP_FUNCTION(apache_note) } if (old_val) { - RETURN_STRING(old_val, 1); + RETURN_STRING(old_val); } RETURN_FALSE; @@ -350,29 +350,29 @@ PHP_FUNCTION(virtual) int filename_len; request_rec *rr = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { return; } if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) SG(server_context))))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); if (rr) destroy_sub_req (rr); RETURN_FALSE; } if (rr->status != 200) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename); + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); if (rr) destroy_sub_req (rr); RETURN_FALSE; } - php_output_end_all(TSRMLS_C); - php_header(TSRMLS_C); + php_output_end_all(); + php_header(); if (run_sub_req(rr)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", filename); + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - request execution failed", filename); if (rr) destroy_sub_req (rr); RETURN_FALSE; @@ -404,7 +404,7 @@ PHP_FUNCTION(apache_request_headers) if (!tenv[i].key) { continue; } - if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) { + if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val)==FAILURE) { RETURN_FALSE; } } @@ -424,7 +424,7 @@ PHP_FUNCTION(apache_response_headers) tenv = (table_entry *)env_arr->elts; for (i = 0; i < env_arr->nelts; ++i) { if (!tenv[i].key) continue; - if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) { + if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val)==FAILURE) { RETURN_FALSE; } } @@ -440,7 +440,7 @@ PHP_FUNCTION(apache_setenv) 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) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) { return; } @@ -462,12 +462,12 @@ PHP_FUNCTION(apache_lookup_uri) int filename_len; request_rec *rr=NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { return; } if (!(rr = sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed '%s'", filename); + php_error_docref(NULL, E_WARNING, "URI lookup failed '%s'", filename); RETURN_FALSE; } @@ -475,34 +475,34 @@ PHP_FUNCTION(apache_lookup_uri) add_property_long(return_value,"status", rr->status); if (rr->the_request) { - add_property_string(return_value,"the_request", rr->the_request, 1); + add_property_string(return_value,"the_request", rr->the_request); } if (rr->status_line) { - add_property_string(return_value,"status_line", (char *)rr->status_line, 1); + add_property_string(return_value,"status_line", (char *)rr->status_line); } if (rr->method) { - add_property_string(return_value,"method", (char *)rr->method, 1); + add_property_string(return_value,"method", (char *)rr->method); } if (rr->content_type) { - add_property_string(return_value,"content_type", (char *)rr->content_type, 1); + add_property_string(return_value,"content_type", (char *)rr->content_type); } if (rr->handler) { - add_property_string(return_value,"handler", (char *)rr->handler, 1); + add_property_string(return_value,"handler", (char *)rr->handler); } if (rr->uri) { - add_property_string(return_value,"uri", rr->uri, 1); + add_property_string(return_value,"uri", rr->uri); } if (rr->filename) { - add_property_string(return_value,"filename", rr->filename, 1); + add_property_string(return_value,"filename", rr->filename); } if (rr->path_info) { - add_property_string(return_value,"path_info", rr->path_info, 1); + add_property_string(return_value,"path_info", rr->path_info); } if (rr->args) { - add_property_string(return_value,"args", rr->args, 1); + add_property_string(return_value,"args", rr->args); } if (rr->boundary) { - add_property_string(return_value,"boundary", rr->boundary, 1); + add_property_string(return_value,"boundary", rr->boundary); } add_property_long(return_value,"no_cache", rr->no_cache); @@ -515,7 +515,7 @@ PHP_FUNCTION(apache_lookup_uri) #if MODULE_MAGIC_NUMBER >= 19980324 if (rr->unparsed_uri) { - add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1); + add_property_string(return_value,"unparsed_uri", rr->unparsed_uri); } if(rr->mtime) { add_property_long(return_value,"mtime", rr->mtime); @@ -540,12 +540,12 @@ PHP_FUNCTION(apache_exec_uri) int filename_len; request_rec *rr=NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { return; } if(!(rr = ap_sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed", filename); + php_error_docref(NULL, E_WARNING, "URI lookup failed", filename); RETURN_FALSE; } @@ -561,7 +561,7 @@ PHP_FUNCTION(apache_get_version) char *apv = (char *) ap_get_server_version(); if (apv && *apv) { - RETURN_STRING(apv, 1); + RETURN_STRING(apv); } RETURN_FALSE; @@ -580,9 +580,9 @@ PHP_FUNCTION(apache_get_modules) for (n = 0; ap_loaded_modules[n]; ++n) { char *s = (char *) ap_loaded_modules[n]->name; if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s), 1); + add_next_index_stringl(return_value, s, (p - s)); } else { - add_next_index_string(return_value, s, 1); + add_next_index_string(return_value, s); } } } diff --git a/sapi/apache/php_apache_http.h b/sapi/apache/php_apache_http.h index 3368a79b52..00bb9ca91a 100644 --- a/sapi/apache/php_apache_http.h +++ b/sapi/apache/php_apache_http.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -67,4 +67,4 @@ #include "php_ini.h" #include "ext/standard/php_standard.h" -#include "mod_php5.h" +#include "mod_php7.h" diff --git a/sapi/apache/sapi_apache.c b/sapi/apache/sapi_apache.c index 53a4472e13..302055ef25 100644 --- a/sapi/apache/sapi_apache.c +++ b/sapi/apache/sapi_apache.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -25,22 +25,22 @@ /* {{{ apache_php_module_main */ -int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC) +int apache_php_module_main(request_rec *r, int display_source_mode) { - int retval = OK; + int retval = OK; zend_file_handle file_handle; - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == 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) != SUCCESS) { + if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini) != SUCCESS) { retval = NOT_FOUND; } } else { @@ -50,15 +50,15 @@ int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC) file_handle.opened_path = NULL; file_handle.free_filename = 0; - (void) php_execute_script(&file_handle TSRMLS_CC); + (void) php_execute_script(&file_handle); } AP(in_request) = 0; - + zend_try { php_request_shutdown(NULL); } zend_end_try(); - + return retval; } /* }}} */ diff --git a/sapi/apache2filter/apache_config.c b/sapi/apache2filter/apache_config.c index 2b5a1186c8..ed27616d16 100644 --- a/sapi/apache2filter/apache_config.c +++ b/sapi/apache2filter/apache_config.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -60,11 +60,11 @@ static const char *real_value_hnd(cmd_parms *cmd, void *dummy, const char *name, php_dir_entry e; phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config))); - + if (!strncasecmp(value, "none", sizeof("none"))) { value = ""; } - + e.value = apr_pstrdup(cmd->pool, value); e.value_len = strlen(value); e.status = status; @@ -132,12 +132,12 @@ void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf) phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n)); 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_get_current_key(&d->config, &str, &str_len, + &num_index) == 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(&n->config, str, str_len, (void **) &pe) == SUCCESS) { + if ((pe = zend_hash_find(&n->config, str, str_len) != NULL) != NULL) { if (pe->status >= data->status) continue; } zend_hash_update(&n->config, str, str_len, data, sizeof(*data), NULL); @@ -151,8 +151,8 @@ char *get_php_config(void *conf, char *name, size_t name_len) { php_conf_rec *d = conf; php_dir_entry *pe; - - if (zend_hash_find(&d->config, name, name_len, (void **) &pe) == SUCCESS) { + + if ((pe = zend_hash_find(&d->config, name, name_len)) != NULL) { return pe->value; } @@ -165,16 +165,15 @@ void apply_config(void *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_get_current_key(&d->config, &str, &str_len, NULL) == HASH_KEY_IS_STRING; zend_hash_move_forward(&d->config)) { zend_hash_get_current_data(&d->config, (void **) &data); phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value)); if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) { phpapdebug((stderr, "..FAILED\n")); - } + } } } @@ -192,7 +191,7 @@ static apr_status_t destroy_php_config(void *data) { php_conf_rec *d = data; - phpapdebug((stderr, "Destroying config %p\n", data)); + phpapdebug((stderr, "Destroying config %p\n", data)); zend_hash_destroy(&d->config); return APR_SUCCESS; diff --git a/sapi/apache2filter/config.m4 b/sapi/apache2filter/config.m4 index b6524fd874..11cc051015 100644 --- a/sapi/apache2filter/config.m4 +++ b/sapi/apache2filter/config.m4 @@ -71,14 +71,14 @@ if test "$PHP_APXS2FILTER" != "no"; then if test -z `$APXS -q SYSCONFDIR`; then INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -i -n php5" + -i -n php7" else APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR` INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \ $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ -S SYSCONFDIR='$APXS_SYSCONFDIR' \ - -i -a -n php5" + -i -a -n php7" fi case $host_alias in @@ -101,7 +101,7 @@ if test "$PHP_APXS2FILTER" != "no"; then 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, $APACHE_CFLAGS) - SAPI_SHARED=libs/libphp5.so + SAPI_SHARED=libs/libphp7.so INSTALL_IT="$INSTALL_IT $SAPI_SHARED" ;; *beos*) diff --git a/sapi/apache2filter/php.sym b/sapi/apache2filter/php.sym index 9ad0f0a0ad..1469b0314d 100644 --- a/sapi/apache2filter/php.sym +++ b/sapi/apache2filter/php.sym @@ -1 +1 @@ -php5_module +php7_module diff --git a/sapi/apache2filter/php_apache.h b/sapi/apache2filter/php_apache.h index 724a9c55e6..72d4896820 100644 --- a/sapi/apache2filter/php_apache.h +++ b/sapi/apache2filter/php_apache.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -26,7 +26,7 @@ #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 php5_module; +extern module AP_MODULE_DECLARE_DATA php7_module; /* A way to specify the location of the php.ini dir in an apache directive */ extern char *apache2_php_ini_path_override; @@ -36,7 +36,7 @@ typedef struct php_struct { int state; request_rec *r; ap_filter_t *f; /* downstream output filters after the PHP filter. */ - /* stat structure of the current file */ + /* stat structure of the current file */ struct stat finfo; /* Set-aside request body bucket brigade */ apr_bucket_brigade *post_data; @@ -54,8 +54,8 @@ char *get_php_config(void *conf, char *name, size_t name_len); void apply_config(void *); extern const command_rec php_dir_cmds[]; -static size_t php_apache_read_stream(void *, char *, size_t TSRMLS_DC); -static size_t php_apache_fsizer_stream(void * TSRMLS_DC); +static size_t php_apache_read_stream(void *, char *, size_t); +static size_t php_apache_fsizer_stream(void *); #define APR_ARRAY_FOREACH_OPEN(arr, key, val) \ { \ diff --git a/sapi/apache2filter/php_functions.c b/sapi/apache2filter/php_functions.c index 5976918caa..061fc7b26c 100644 --- a/sapi/apache2filter/php_functions.c +++ b/sapi/apache2filter/php_functions.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -22,7 +22,7 @@ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h" -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" #include "ext/standard/info.h" #include "SAPI.h" @@ -43,14 +43,14 @@ #include "php_apache.h" -static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC) +static request_rec *php_apache_lookup_uri(char *filename) { php_struct *ctx; - + if (!filename) { return NULL; } - + ctx = SG(server_context); return ap_sub_req_lookup_uri(filename, ctx->f->r, ctx->f->next); } @@ -63,26 +63,26 @@ PHP_FUNCTION(virtual) int filename_len; request_rec *rr; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { return; } - if (!(rr = php_apache_lookup_uri(filename TSRMLS_CC))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); + if (!(rr = php_apache_lookup_uri(filename))) { + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); RETURN_FALSE; } - + if (rr->status == HTTP_OK) { if (ap_run_sub_req(rr)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", filename); + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - request execution failed", filename); ap_destroy_sub_req(rr); RETURN_FALSE; } ap_destroy_sub_req(rr); RETURN_TRUE; } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename); + + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); ap_destroy_sub_req(rr); RETURN_FALSE; } @@ -93,7 +93,7 @@ PHP_FUNCTION(virtual) #define ADD_TIME(name) \ add_property_long(return_value, #name, apr_time_sec(rr->name)); #define ADD_STRING(name) \ - if (rr->name) add_property_string(return_value, #name, (char *) rr->name, 1) + if (rr->name) add_property_string(return_value, #name, (char *) rr->name) PHP_FUNCTION(apache_lookup_uri) { @@ -101,15 +101,15 @@ PHP_FUNCTION(apache_lookup_uri) char *filename; int filename_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { return; } - if (!(rr = php_apache_lookup_uri(filename TSRMLS_CC))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); + if (!(rr = php_apache_lookup_uri(filename))) { + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); RETURN_FALSE; } - + if (rr->status == HTTP_OK) { object_init(return_value); @@ -142,8 +142,8 @@ PHP_FUNCTION(apache_lookup_uri) ap_destroy_sub_req(rr); return; } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename); + + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); ap_destroy_sub_req(rr); RETURN_FALSE; } @@ -157,13 +157,13 @@ PHP_FUNCTION(apache_request_headers) char *key, *val; array_init(return_value); - + ctx = SG(server_context); arr = apr_table_elts(ctx->f->r->headers_in); APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) val = ""; - add_assoc_string(return_value, key, val, 1); + add_assoc_string(return_value, key, val); APR_ARRAY_FOREACH_CLOSE() } /* }}} */ @@ -177,13 +177,13 @@ PHP_FUNCTION(apache_response_headers) char *key, *val; array_init(return_value); - + ctx = SG(server_context); arr = apr_table_elts(ctx->f->r->headers_out); APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) val = ""; - add_assoc_string(return_value, key, val, 1); + add_assoc_string(return_value, key, val); APR_ARRAY_FOREACH_CLOSE() } /* }}} */ @@ -197,7 +197,7 @@ PHP_FUNCTION(apache_note) int note_name_len, note_val_len; char *old_note_val=NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { return; } @@ -228,7 +228,7 @@ PHP_FUNCTION(apache_setenv) zend_bool walk_to_top = 0; int arg_count = ZEND_NUM_ARGS(); - if (zend_parse_parameters(arg_count TSRMLS_CC, "ss|b", &variable, &variable_len, &string_val, &string_val_len, &walk_to_top) == FAILURE) { + if (zend_parse_parameters(arg_count, "ss|b", &variable, &variable_len, &string_val, &string_val_len, &walk_to_top) == FAILURE) { return; } @@ -257,7 +257,7 @@ PHP_FUNCTION(apache_getenv) int arg_count = ZEND_NUM_ARGS(); char *env_val=NULL; - if (zend_parse_parameters(arg_count TSRMLS_CC, "s|b", &variable, &variable_len, &walk_to_top) == FAILURE) { + if (zend_parse_parameters(arg_count, "s|b", &variable, &variable_len, &walk_to_top) == FAILURE) { return; } @@ -307,15 +307,15 @@ PHP_FUNCTION(apache_get_modules) { int n; char *p; - + array_init(return_value); - + for (n = 0; ap_loaded_modules[n]; ++n) { char *s = (char *) ap_loaded_modules[n]->name; if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s), 1); + add_next_index_stringl(return_value, s, (p - s)); } else { - add_next_index_string(return_value, s, 1); + add_next_index_string(return_value, s); } } } @@ -327,7 +327,7 @@ PHP_MINFO_FUNCTION(apache) smart_str tmp1 = {0}; int n; char *p; - + for (n = 0; ap_loaded_modules[n]; ++n) { char *s = (char *) ap_loaded_modules[n]->name; if ((p = strchr(s, '.'))) { @@ -340,7 +340,7 @@ PHP_MINFO_FUNCTION(apache) if ((tmp1.len - 1) >= 0) { tmp1.c[tmp1.len - 1] = '\0'; } - + php_info_print_table_start(); if (apv && *apv) { php_info_print_table_row(2, "Apache Version", apv); diff --git a/sapi/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c index 13b6e6798b..3b639db61a 100644 --- a/sapi/apache2filter/sapi_apache2.c +++ b/sapi/apache2filter/sapi_apache2.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -30,7 +30,7 @@ #include "php_variables.h" #include "SAPI.h" -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" #ifndef NETWARE #include "ext/standard/php_standard.h" #else @@ -49,7 +49,7 @@ #include "http_log.h" #include "http_main.h" #include "util_script.h" -#include "http_core.h" +#include "http_core.h" #include "ap_mpm.h" #include "php_apache.h" @@ -64,7 +64,7 @@ char *apache2_php_ini_path_override = NULL; static int -php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) +php_apache_sapi_ub_write(const char *str, uint str_length) { apr_bucket *b; apr_bucket_brigade *bb; @@ -74,9 +74,9 @@ php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) 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); @@ -86,12 +86,12 @@ php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) if (ap_pass_brigade(f->next, bb) != APR_SUCCESS || ctx->r->connection->aborted) { 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_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) +php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) { php_struct *ctx; char *val, *ptr; @@ -118,7 +118,7 @@ php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_e ptr = val; *val = '\0'; - + do { val++; } while (*val == ' '); @@ -131,7 +131,7 @@ php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_e apr_table_set(ctx->r->headers_out, sapi_header->header, val); else apr_table_add(ctx->r->headers_out, sapi_header->header, val); - + *ptr = ':'; return SAPI_HEADER_ADD; @@ -141,7 +141,7 @@ php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_e } static int -php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers) { php_struct *ctx = SG(server_context); @@ -151,7 +151,7 @@ php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) } static int -php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) +php_apache_sapi_read_post(char *buf, uint count_bytes) { apr_size_t len; php_struct *ctx = SG(server_context); @@ -177,7 +177,7 @@ php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) return len; } static struct stat* -php_apache_sapi_get_stat(TSRMLS_D) +php_apache_sapi_get_stat(void) { php_struct *ctx = SG(server_context); @@ -202,7 +202,7 @@ php_apache_sapi_get_stat(TSRMLS_D) } static char * -php_apache_sapi_read_cookies(TSRMLS_D) +php_apache_sapi_read_cookies(void) { php_struct *ctx = SG(server_context); const char *http_cookie; @@ -214,36 +214,36 @@ php_apache_sapi_read_cookies(TSRMLS_D) } static char * -php_apache_sapi_getenv(char *name, size_t name_len TSRMLS_DC) +php_apache_sapi_getenv(char *name, size_t name_len) { php_struct *ctx = SG(server_context); const char *env_var; - + env_var = apr_table_get(ctx->r->subprocess_env, name); return (char *) env_var; } static void -php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC) +php_apache_sapi_register_variables(zval *track_vars_array) { php_struct *ctx = SG(server_context); const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env); char *key, *val; unsigned int new_val_len; - + APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) { val = ""; } - if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), &new_val_len TSRMLS_CC)) { - php_register_variable_safe(key, val, new_val_len, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), &new_val_len)) { + php_register_variable_safe(key, val, new_val_len, track_vars_array); } APR_ARRAY_FOREACH_CLOSE() - - php_register_variable("PHP_SELF", ctx->r->uri, track_vars_array TSRMLS_CC); - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), &new_val_len TSRMLS_CC)) { - php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array TSRMLS_CC); + + php_register_variable("PHP_SELF", ctx->r->uri, track_vars_array); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), &new_val_len)) { + php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array); } } @@ -255,7 +255,6 @@ php_apache_sapi_flush(void *server_context) apr_bucket_alloc_t *ba; apr_bucket *b; ap_filter_t *f; /* output filters */ - TSRMLS_FETCH(); ctx = server_context; @@ -264,7 +263,7 @@ php_apache_sapi_flush(void *server_context) if (!server_context) return; - sapi_send_headers(TSRMLS_C); + sapi_send_headers(); ctx->r->status = SG(sapi_headers).http_response_code; SG(headers_sent) = 1; @@ -275,7 +274,7 @@ php_apache_sapi_flush(void *server_context) * 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); @@ -285,12 +284,12 @@ php_apache_sapi_flush(void *server_context) } } -static void php_apache_sapi_log_message(char *msg TSRMLS_DC) +static void php_apache_sapi_log_message(char *msg) { php_struct *ctx; ctx = SG(server_context); - + if (ctx == NULL) { /* we haven't initialized our ctx yet, oh well */ ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, 0, NULL, "%s", msg); } @@ -302,16 +301,16 @@ static void php_apache_sapi_log_message(char *msg TSRMLS_DC) static int php_apache_disable_caching(ap_filter_t *f) { - /* Identify PHP scripts as non-cacheable, thus preventing + /* Identify PHP scripts as non-cacheable, thus preventing * Apache from sending a 304 status when the browser sends * If-Modified-Since header. */ f->r->no_local_copy = 1; - + return OK; } -static double php_apache_sapi_get_request_time(TSRMLS_D) +static double php_apache_sapi_get_request_time(void) { php_struct *ctx = SG(server_context); return ((double) apr_time_as_msec(ctx->r->request_time)) / 1000.0; @@ -359,12 +358,11 @@ static sapi_module_struct apache2_sapi_module = { STANDARD_SAPI_MODULE_PROPERTIES }; -static int php_input_filter(ap_filter_t *f, apr_bucket_brigade *bb, +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; apr_status_t rv; - TSRMLS_FETCH(); if (f->r->proxyreq) { return ap_get_brigade(f->next, bb, mode, block, readbytes); @@ -393,7 +391,7 @@ static int php_input_filter(ap_filter_t *f, apr_bucket_brigade *bb, return APR_SUCCESS; } -static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx TSRMLS_DC) +static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx) { char *content_type; char *content_length; @@ -403,28 +401,28 @@ static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx TSRMLS_DC) SG(sapi_headers).http_response_code = !f->r->status ? HTTP_OK : f->r->status; 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) +#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).proto_num = f->r->proto_num; SG(request_info).request_uri = safe_strdup(f->r->uri); SG(request_info).path_translated = safe_strdup(f->r->filename); f->r->no_local_copy = 1; - content_type = sapi_get_default_content_type(TSRMLS_C); + content_type = sapi_get_default_content_type(); f->r->content_type = apr_pstrdup(f->r->pool, content_type); efree(content_type); content_length = (char *) apr_table_get(f->r->headers_in, "Content-Length"); SG(request_info).content_length = (content_length ? atol(content_length) : 0); - + 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"); auth = apr_table_get(f->r->headers_in, "Authorization"); - php_handle_auth_data(auth TSRMLS_CC); + php_handle_auth_data(auth); if (SG(request_info).auth_user == NULL && f->r->user) { SG(request_info).auth_user = estrdup(f->r->user); @@ -432,13 +430,13 @@ static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx TSRMLS_DC) ctx->r->user = apr_pstrdup(ctx->r->pool, SG(request_info).auth_user); - php_request_startup(TSRMLS_C); + php_request_startup(); } -static void php_apache_request_dtor(ap_filter_t *f TSRMLS_DC) +static void php_apache_request_dtor(ap_filter_t *f) { php_apr_bucket_brigade *pbb = (php_apr_bucket_brigade *)f->ctx; - + php_request_shutdown(NULL); if (SG(request_info).query_string) { @@ -450,35 +448,34 @@ static void php_apache_request_dtor(ap_filter_t *f TSRMLS_DC) if (SG(request_info).path_translated) { free(SG(request_info).path_translated); } - + apr_brigade_destroy(pbb->bb); } static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) { php_struct *ctx; - void *conf = ap_get_module_config(f->r->per_dir_config, &php5_module); + void *conf = ap_get_module_config(f->r->per_dir_config, &php7_module); char *p = get_php_config(conf, "engine", sizeof("engine")); zend_file_handle zfd; php_apr_bucket_brigade *pbb; apr_bucket *b; - TSRMLS_FETCH(); - + if (f->r->proxyreq) { zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return ap_pass_brigade(f->next, bb); } - + /* handle situations where user turns the engine off */ if (*p == '0') { zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return ap_pass_brigade(f->next, bb); - } - + } + if(f->ctx) { pbb = (php_apr_bucket_brigade *)f->ctx; } else { @@ -489,17 +486,17 @@ static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) if(ap_save_brigade(NULL, &pbb->bb, &bb, f->r->pool) != APR_SUCCESS) { /* Bad */ } - + apr_brigade_cleanup(bb); - + /* Check to see if the last bucket in this brigade, it not * we have to wait until then. */ if(!APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(pbb->bb))) { return 0; - } - + } + /* Setup the CGI variables if this is the main request.. */ - if (f->r->main == NULL || + if (f->r->main == NULL || /* .. or if the sub-request envinronment differs from the main-request. */ f->r->subprocess_env != f->r->main->subprocess_env ) { @@ -507,58 +504,58 @@ static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) 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, 0, f->r, "php failed to get server context"); zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return HTTP_INTERNAL_SERVER_ERROR; } - + ctx->f = f->next; /* save whatever filters are after us in the chain. */ if (ctx->request_processed) { zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return ap_pass_brigade(f->next, bb); } apply_config(conf); - php_apache_request_ctor(f, ctx TSRMLS_CC); - + php_apache_request_ctor(f, ctx); + /* It'd be nice if we could highlight based of a zend_file_handle here.... * ...but we can't. */ - + zfd.type = ZEND_HANDLE_STREAM; - + zfd.handle.stream.handle = pbb; zfd.handle.stream.reader = php_apache_read_stream; zfd.handle.stream.closer = NULL; zfd.handle.stream.fsizer = php_apache_fsizer_stream; zfd.handle.stream.isatty = 0; - + zfd.filename = f->r->filename; zfd.opened_path = NULL; zfd.free_filename = 0; - - php_execute_script(&zfd TSRMLS_CC); + + php_execute_script(&zfd); apr_table_set(ctx->r->notes, "mod_php_memory_usage", - apr_psprintf(ctx->r->pool, "%lu", (unsigned long) zend_memory_peak_usage(1 TSRMLS_CC))); - - php_apache_request_dtor(f TSRMLS_CC); - + apr_psprintf(ctx->r->pool, "%lu", (unsigned long) zend_memory_peak_usage(1))); + + php_apache_request_dtor(f); + if (!f->r->main) { ctx->request_processed = 1; } - + b = apr_bucket_eos_create(f->c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(pbb->bb, b); - + /* Pass whatever is left on the brigade. */ return ap_pass_brigade(f->next, pbb->bb); } @@ -576,7 +573,6 @@ php_apache_server_shutdown(void *tmp) static void php_apache_add_version(apr_pool_t *p) { - TSRMLS_FETCH(); if (PG(expose_php)) { ap_add_version_component(p, "PHP/" PHP_VERSION); } @@ -663,10 +659,10 @@ static void php_insert_filter(request_rec *r) int content_type_len = strlen("application/x-httpd-php"); if (r->content_type && !strncmp(r->content_type, "application/x-httpd-php", content_type_len-1)) { - if (r->content_type[content_type_len] == '\0' || !strncmp(r->content_type+content_type_len, "-source", sizeof("-source"))) { + if (r->content_type[content_type_len] == '\0' || !strncmp(r->content_type+content_type_len, "-source", sizeof("-source"))) { php_add_filter(r, r->output_filters); php_add_filter(r, r->input_filters); - } + } } } @@ -680,7 +676,6 @@ static apr_status_t php_server_context_cleanup(void *data_) 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)); @@ -709,27 +704,27 @@ static void php_register_hook(apr_pool_t *p) ap_register_input_filter("PHP", php_input_filter, php_apache_disable_caching, AP_FTYPE_RESOURCE); } -static size_t php_apache_read_stream(void *handle, char *buf, size_t wantlen TSRMLS_DC) +static size_t php_apache_read_stream(void *handle, char *buf, size_t wantlen) { php_apr_bucket_brigade *pbb = (php_apr_bucket_brigade *)handle; apr_bucket_brigade *rbb; apr_size_t readlen; apr_bucket *b = NULL; - + rbb = pbb->bb; - + if((apr_brigade_partition(pbb->bb, wantlen, &b) == APR_SUCCESS) && b){ pbb->bb = apr_brigade_split(rbb, b); - } + } readlen = wantlen; apr_brigade_flatten(rbb, buf, &readlen); apr_brigade_cleanup(rbb); - + return readlen; } -static size_t php_apache_fsizer_stream(void *handle TSRMLS_DC) +static size_t php_apache_fsizer_stream(void *handle) { php_apr_bucket_brigade *pbb = (php_apr_bucket_brigade *)handle; apr_off_t actual = 0; @@ -741,7 +736,7 @@ static size_t php_apache_fsizer_stream(void *handle TSRMLS_DC) return 0; } -AP_MODULE_DECLARE_DATA module php5_module = { +AP_MODULE_DECLARE_DATA module php7_module = { STANDARD20_MODULE_STUFF, create_php_config, /* create per-directory config structure */ merge_php_config, /* merge per-directory config structures */ diff --git a/sapi/apache2handler/apache_config.c b/sapi/apache2handler/apache_config.c index a7dbbeb810..de7546b5cd 100644 --- a/sapi/apache2handler/apache_config.c +++ b/sapi/apache2handler/apache_config.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -60,17 +60,17 @@ static const char *real_value_hnd(cmd_parms *cmd, void *dummy, const char *name, php_dir_entry e; phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config))); - + if (!strncasecmp(value, "none", sizeof("none"))) { value = ""; } - + e.value = apr_pstrdup(cmd->pool, value); e.value_len = strlen(value); e.status = status; e.htaccess = ((cmd->override & (RSRC_CONF|ACCESS_CONF)) == 0); - zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e, sizeof(e), NULL); + zend_hash_str_update_mem(&d->config, (char *) name, strlen(name), &e, sizeof(e)); return NULL; } @@ -117,11 +117,12 @@ static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig, const ch return NULL; } -static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, php_dir_entry *new_per_dir_entry, zend_hash_key *hash_key, void *pData) +static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, zval *zv, zend_hash_key *hash_key, void *pData) { + php_dir_entry *new_per_dir_entry = Z_PTR_P(zv); php_dir_entry *orig_per_dir_entry; - if (zend_hash_find(target_ht, hash_key->arKey, hash_key->nKeyLength, (void **) &orig_per_dir_entry)==FAILURE) { + if ((orig_per_dir_entry = zend_hash_find_ptr(target_ht, hash_key->key)) == NULL) { return 1; /* does not exist in dest, copy from source */ } @@ -148,14 +149,16 @@ void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf) n = create_php_config(p, "merge_php_config"); /* copy old config */ - zend_hash_copy(&n->config, &d->config, NULL, NULL, sizeof(php_dir_entry)); + zend_hash_copy(&n->config, &d->config, NULL); +//??? zend_hash_copy(&n->config, &d->config, NULL, NULL, sizeof(php_dir_entry)); /* merge new config */ phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n)); - zend_hash_merge_ex(&n->config, &e->config, NULL, sizeof(php_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL); + zend_hash_merge_ex(&n->config, &e->config, NULL, should_overwrite_per_dir_entry, NULL); +//??? zend_hash_merge_ex(&n->config, &e->config, NULL, sizeof(php_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL); #if STAS_0 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_get_current_key(&d->config, &str, &str_len, + &num_index) == HASH_KEY_IS_STRING; zend_hash_move_forward(&d->config)) { pe = NULL; zend_hash_get_current_data(&d->config, (void **) &data); @@ -173,8 +176,8 @@ char *get_php_config(void *conf, char *name, size_t name_len) { php_conf_rec *d = conf; php_dir_entry *pe; - - if (zend_hash_find(&d->config, name, name_len, (void **) &pe) == SUCCESS) { + + if ((pe = zend_hash_str_find_ptr(&d->config, name, name_len)) != NULL) { return pe->value; } @@ -184,21 +187,15 @@ char *get_php_config(void *conf, char *name, size_t name_len) void apply_config(void *dummy) { php_conf_rec *d = dummy; - char *str; - uint str_len; + zend_string *str; 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)) { - if (zend_hash_get_current_data(&d->config, (void **) &data) == SUCCESS) { - phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value)); - if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) { - phpapdebug((stderr, "..FAILED\n")); - } + + ZEND_HASH_FOREACH_STR_KEY_PTR(&d->config, str, data) { + phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value)); + if (zend_alter_ini_entry_chars(str, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) { + phpapdebug((stderr, "..FAILED\n")); } - } + } ZEND_HASH_FOREACH_END(); } const command_rec php_dir_cmds[] = @@ -215,7 +212,7 @@ static apr_status_t destroy_php_config(void *data) { php_conf_rec *d = data; - phpapdebug((stderr, "Destroying config %p\n", data)); + phpapdebug((stderr, "Destroying config %p\n", data)); zend_hash_destroy(&d->config); return APR_SUCCESS; diff --git a/sapi/apache2handler/config.m4 b/sapi/apache2handler/config.m4 index 02f8a0b3ad..2e64b215e5 100644 --- a/sapi/apache2handler/config.m4 +++ b/sapi/apache2handler/config.m4 @@ -56,7 +56,7 @@ if test "$PHP_APXS2" != "no"; then esac done - APACHE_CFLAGS="$APACHE_CPPFLAGS -I$APXS_INCLUDEDIR $APR_CFLAGS $APU_CFLAGS" + APACHE_CFLAGS="$APACHE_CPPFLAGS -I$APXS_INCLUDEDIR $APR_CFLAGS $APU_CFLAGS -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1" # Test that we're trying to configure with apache 2.x PHP_AP_EXTRACT_VERSION($APXS_HTTPD) @@ -70,20 +70,20 @@ if test "$PHP_APXS2" != "no"; then if test -z `$APXS -q SYSCONFDIR`; then INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -i -n php5" + -i -n php7" else APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR` INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \ $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ -S SYSCONFDIR='$APXS_SYSCONFDIR' \ - -i -a -n php5" + -i -a -n php7" fi case $host_alias in *aix*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-brtl -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp" - PHP_SELECT_SAPI(apache2handler, shared, mod_php5.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) + PHP_SELECT_SAPI(apache2handler, shared, mod_php7.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL" ;; *darwin*) @@ -99,19 +99,19 @@ if test "$PHP_APXS2" != "no"; then fi MH_BUNDLE_FLAGS="-bundle -bundle_loader $APXS_HTTPD $MH_BUNDLE_FLAGS" PHP_SUBST(MH_BUNDLE_FLAGS) - PHP_SELECT_SAPI(apache2handler, bundle, mod_php5.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) - SAPI_SHARED=libs/libphp5.so + PHP_SELECT_SAPI(apache2handler, bundle, mod_php7.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) + SAPI_SHARED=libs/libphp7.so INSTALL_IT="$INSTALL_IT $SAPI_SHARED" ;; *beos*) if test -f _APP_; then `rm _APP_`; fi `ln -s $APXS_BINDIR/httpd _APP_` EXTRA_LIBS="$EXTRA_LIBS _APP_" - PHP_SELECT_SAPI(apache2handler, shared, mod_php5.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) + PHP_SELECT_SAPI(apache2handler, shared, mod_php7.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL" ;; *) - PHP_SELECT_SAPI(apache2handler, shared, mod_php5.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) + PHP_SELECT_SAPI(apache2handler, shared, mod_php7.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL" ;; esac diff --git a/sapi/apache2handler/config.w32 b/sapi/apache2handler/config.w32 index a7547514d8..8ea1305d4f 100644 --- a/sapi/apache2handler/config.w32 +++ b/sapi/apache2handler/config.w32 @@ -11,9 +11,9 @@ if (PHP_APACHE2HANDLER != "no") { CHECK_LIB("libapr.lib", "apache2handler", PHP_PHP_BUILD + "\\lib\\apache2") && CHECK_LIB("libaprutil.lib", "apache2handler", PHP_PHP_BUILD + "\\lib\\apache2") ) { - SAPI('apache2handler', 'mod_php5.c sapi_apache2.c apache_config.c php_functions.c', + SAPI('apache2handler', 'mod_php7.c sapi_apache2.c apache_config.c php_functions.c', 'php' + PHP_VERSION + 'apache2.dll', - '/D PHP_APACHE2_EXPORTS /I win32'); + '/D PHP_APACHE2_EXPORTS /I win32 /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); } else { WARNING("Could not find apache2 libraries/headers"); } @@ -29,9 +29,9 @@ if (PHP_APACHE2_2HANDLER != "no") { CHECK_LIB("libapr-1.lib", "apache2_2handler", PHP_PHP_BUILD + "\\lib\\apache2_2") && CHECK_LIB("libaprutil-1.lib", "apache2_2handler", PHP_PHP_BUILD + "\\lib\\apache2_2") ) { - SAPI('apache2_2handler', 'mod_php5.c sapi_apache2.c apache_config.c php_functions.c', + SAPI('apache2_2handler', 'mod_php7.c sapi_apache2.c apache_config.c php_functions.c', 'php' + PHP_VERSION + 'apache2_2.dll', - '/D PHP_APACHE2_EXPORTS /I win32', + '/D PHP_APACHE2_EXPORTS /I win32 /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1', 'sapi\\apache2_2handler'); } else { WARNING("Could not find apache2.2 libraries/headers"); @@ -47,9 +47,9 @@ if (PHP_APACHE2_4HANDLER != "no") { CHECK_LIB("libapr-1.lib", "apache2_4handler", PHP_PHP_BUILD + "\\lib\\apache2_4") && CHECK_LIB("libaprutil-1.lib", "apache2_4handler", PHP_PHP_BUILD + "\\lib\\apache2_4") ) { - SAPI('apache2_4handler', 'mod_php5.c sapi_apache2.c apache_config.c php_functions.c', + SAPI('apache2_4handler', 'mod_php7.c sapi_apache2.c apache_config.c php_functions.c', 'php' + PHP_VERSION + 'apache2_4.dll', - '/D PHP_APACHE2_EXPORTS /I win32', + '/D PHP_APACHE2_EXPORTS /I win32 /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1', 'sapi\\apache2handler'); } else { WARNING("Could not find apache 2.4 libraries/headers"); diff --git a/sapi/apache2handler/mod_php5.c b/sapi/apache2handler/mod_php7.c index b6d6c51b9f..cf6fdaae12 100644 --- a/sapi/apache2handler/mod_php5.c +++ b/sapi/apache2handler/mod_php7.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -25,7 +25,7 @@ #include "php.h" #include "php_apache.h" -AP_MODULE_DECLARE_DATA module php5_module = { +AP_MODULE_DECLARE_DATA module php7_module = { STANDARD20_MODULE_STUFF, create_php_config, /* create per-directory config structure */ merge_php_config, /* merge per-directory config structures */ diff --git a/sapi/apache2handler/php.sym b/sapi/apache2handler/php.sym index 9ad0f0a0ad..1469b0314d 100644 --- a/sapi/apache2handler/php.sym +++ b/sapi/apache2handler/php.sym @@ -1 +1 @@ -php5_module +php7_module diff --git a/sapi/apache2handler/php5apache2.dsp b/sapi/apache2handler/php5apache2.dsp deleted file mode 100644 index 40cd58cb92..0000000000 --- a/sapi/apache2handler/php5apache2.dsp +++ /dev/null @@ -1,146 +0,0 @@ -# Microsoft Developer Studio Project File - Name="php5apache2" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php5apache2 - 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 "php5apache2.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 "php5apache2.mak" CFG="php5apache2 - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php5apache2 - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5apache2 - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5apache2 - 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)" == "php5apache2 - 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 "PHP_APACHE2_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" /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 php5ts.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)" == "php5apache2 - 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 "PHP_APACHE2_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" /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 php5ts.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/php5apache2.dll" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"
-
-!ELSEIF "$(CFG)" == "php5apache2 - 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 "PHP_APACHE2_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" /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 php5ts_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 "php5apache2 - Win32 Release_TS"
-# Name "php5apache2 - Win32 Release_TS_inline"
-# Name "php5apache2 - 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=.\mod_php5.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_functions.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\sapi_apache2.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php_apache.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/sapi/apache2handler/php_apache.h b/sapi/apache2handler/php_apache.h index d0673e1498..9ef1c7fdc9 100644 --- a/sapi/apache2handler/php_apache.h +++ b/sapi/apache2handler/php_apache.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -25,8 +25,11 @@ #include "http_config.h" #include "http_core.h" +#include "php.h" +#include "main/php_streams.h" + /* Declare this so we can get to it from outside the sapi_apache2.c file */ -extern module AP_MODULE_DECLARE_DATA php5_module; +extern module AP_MODULE_DECLARE_DATA php7_module; /* A way to specify the location of the php.ini dir in an apache directive */ extern char *apache2_php_ini_path_override; @@ -40,7 +43,7 @@ typedef struct php_struct { #if defined(NETWARE) && defined(CLIB_STAT_PATCH) struct stat_libc finfo; #else - struct stat finfo; + zend_stat_t finfo; #endif /* Whether or not we've processed PHP in the output filters yet. */ int request_processed; @@ -67,16 +70,17 @@ void php_ap2_register_hook(apr_pool_t *p); #define APR_ARRAY_FOREACH_CLOSE() }} typedef struct { - long engine; - long xbithack; - long last_modified; + zend_bool engine; + zend_bool xbithack; + zend_bool last_modified; } php_apache2_info_struct; extern zend_module_entry apache2_module_entry; #ifdef ZTS extern int php_apache2_info_id; -#define AP2(v) TSRMG(php_apache2_info_id, php_apache2_info_struct *, v) +#define AP2(v) ZEND_TSRMG(php_apache2_info_id, php_apache2_info_struct *, v) +ZEND_TSRMLS_CACHE_EXTERN; #else extern php_apache2_info_struct php_apache2_info; #define AP2(v) (php_apache2_info.v) diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c index 71002c7aaa..3c4cbd9f7b 100644 --- a/sapi/apache2handler/php_functions.c +++ b/sapi/apache2handler/php_functions.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -21,7 +21,7 @@ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h" -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" #include "ext/standard/info.h" #include "ext/standard/head.h" #include "php_ini.h" @@ -56,10 +56,10 @@ php_apache2_info_struct php_apache2_info; #define SECTION(name) PUTS("<h2>" name "</h2>\n") -static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC) +static request_rec *php_apache_lookup_uri(char *filename) { php_struct *ctx = SG(server_context); - + if (!filename || !ctx || !ctx->r) { return NULL; } @@ -72,34 +72,34 @@ static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC) PHP_FUNCTION(virtual) { char *filename; - int filename_len; + size_t filename_len; request_rec *rr; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { return; } - if (!(rr = php_apache_lookup_uri(filename TSRMLS_CC))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); + if (!(rr = php_apache_lookup_uri(filename))) { + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); RETURN_FALSE; } if (rr->status != HTTP_OK) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename); + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); ap_destroy_sub_req(rr); RETURN_FALSE; } /* Flush everything. */ - php_output_end_all(TSRMLS_C); - php_header(TSRMLS_C); + php_output_end_all(); + php_header(); /* Ensure that the ap_r* layer for the main request is flushed, to * work around http://issues.apache.org/bugzilla/show_bug.cgi?id=17629 */ ap_rflush(rr->main); if (ap_run_sub_req(rr)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", filename); + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - request execution failed", filename); ap_destroy_sub_req(rr); RETURN_FALSE; } @@ -113,23 +113,23 @@ PHP_FUNCTION(virtual) #define ADD_TIME(name) \ add_property_long(return_value, #name, apr_time_sec(rr->name)); #define ADD_STRING(name) \ - if (rr->name) add_property_string(return_value, #name, (char *) rr->name, 1) + if (rr->name) add_property_string(return_value, #name, (char *) rr->name) PHP_FUNCTION(apache_lookup_uri) { request_rec *rr; char *filename; - int filename_len; + size_t filename_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { return; } - if (!(rr = php_apache_lookup_uri(filename TSRMLS_CC))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); + if (!(rr = php_apache_lookup_uri(filename))) { + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); RETURN_FALSE; } - + if (rr->status == HTTP_OK) { object_init(return_value); @@ -162,8 +162,8 @@ PHP_FUNCTION(apache_lookup_uri) ap_destroy_sub_req(rr); return; } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename); + + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); ap_destroy_sub_req(rr); RETURN_FALSE; } @@ -181,13 +181,13 @@ PHP_FUNCTION(apache_request_headers) } array_init(return_value); - + ctx = SG(server_context); arr = apr_table_elts(ctx->r->headers_in); APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) val = ""; - add_assoc_string(return_value, key, val, 1); + add_assoc_string(return_value, key, val); APR_ARRAY_FOREACH_CLOSE() } /* }}} */ @@ -205,13 +205,13 @@ PHP_FUNCTION(apache_response_headers) } array_init(return_value); - + ctx = SG(server_context); arr = apr_table_elts(ctx->r->headers_out); APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) val = ""; - add_assoc_string(return_value, key, val, 1); + add_assoc_string(return_value, key, val); APR_ARRAY_FOREACH_CLOSE() } /* }}} */ @@ -222,10 +222,10 @@ PHP_FUNCTION(apache_note) { php_struct *ctx; char *note_name, *note_val = NULL; - int note_name_len, note_val_len; + size_t note_name_len, note_val_len; char *old_note_val=NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { return; } @@ -238,7 +238,7 @@ PHP_FUNCTION(apache_note) } if (old_note_val) { - RETURN_STRING(old_note_val, 1); + RETURN_STRING(old_note_val); } RETURN_FALSE; @@ -254,12 +254,12 @@ PHP_FUNCTION(apache_setenv) { php_struct *ctx; char *variable=NULL, *string_val=NULL; - int variable_len, string_val_len; + size_t variable_len, string_val_len; zend_bool walk_to_top = 0; int arg_count = ZEND_NUM_ARGS(); request_rec *r; - if (zend_parse_parameters(arg_count TSRMLS_CC, "ss|b", &variable, &variable_len, &string_val, &string_val_len, &walk_to_top) == FAILURE) { + if (zend_parse_parameters(arg_count, "ss|b", &variable, &variable_len, &string_val, &string_val_len, &walk_to_top) == FAILURE) { return; } @@ -288,14 +288,14 @@ PHP_FUNCTION(apache_setenv) PHP_FUNCTION(apache_getenv) { php_struct *ctx; - char *variable=NULL; - int variable_len; + char *variable; + size_t variable_len; zend_bool walk_to_top = 0; int arg_count = ZEND_NUM_ARGS(); char *env_val=NULL; request_rec *r; - if (zend_parse_parameters(arg_count TSRMLS_CC, "s|b", &variable, &variable_len, &walk_to_top) == FAILURE) { + if (zend_parse_parameters(arg_count, "s|b", &variable, &variable_len, &walk_to_top) == FAILURE) { return; } @@ -313,7 +313,7 @@ PHP_FUNCTION(apache_getenv) env_val = (char*) apr_table_get(r->subprocess_env, variable); if (env_val != NULL) { - RETURN_STRING(env_val, 1); + RETURN_STRING(env_val); } RETURN_FALSE; @@ -336,7 +336,7 @@ PHP_FUNCTION(apache_get_version) char *apv = php_apache_get_version(); if (apv && *apv) { - RETURN_STRING(apv, 1); + RETURN_STRING(apv); } else { RETURN_FALSE; } @@ -349,15 +349,15 @@ PHP_FUNCTION(apache_get_modules) { int n; char *p; - + array_init(return_value); - + for (n = 0; ap_loaded_modules[n]; ++n) { char *s = (char *) ap_loaded_modules[n]->name; if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s), 1); + add_next_index_stringl(return_value, s, (p - s)); } else { - add_next_index_string(return_value, s, 1); + add_next_index_string(return_value, s); } } } @@ -378,7 +378,7 @@ PHP_MINFO_FUNCTION(apache) AP_DECLARE_DATA extern unixd_config_rec unixd_config; #endif #endif - + for (n = 0; ap_loaded_modules[n]; ++n) { char *s = (char *) ap_loaded_modules[n]->name; if ((p = strchr(s, '.'))) { @@ -388,24 +388,28 @@ PHP_MINFO_FUNCTION(apache) } smart_str_appendc(&tmp1, ' '); } - if ((tmp1.len - 1) >= 0) { - tmp1.c[tmp1.len - 1] = '\0'; + if (tmp1.s) { + if (tmp1.s->len > 0) { + tmp1.s->val[tmp1.s->len - 1] = '\0'; + } else { + tmp1.s->val[0] = '\0'; + } } - + php_info_print_table_start(); if (apv && *apv) { php_info_print_table_row(2, "Apache Version", apv); } snprintf(tmp, sizeof(tmp), "%d", MODULE_MAGIC_NUMBER); php_info_print_table_row(2, "Apache API Version", tmp); - + if (serv->server_admin && *(serv->server_admin)) { php_info_print_table_row(2, "Server Administrator", serv->server_admin); } - + snprintf(tmp, sizeof(tmp), "%s:%u", serv->server_hostname, serv->port); php_info_print_table_row(2, "Hostname:Port", tmp); - + #if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE) #if MODULE_MAGIC_NUMBER_MAJOR >= 20081201 snprintf(tmp, sizeof(tmp), "%s(%d)/%d", ap_unixd_config.user_name, ap_unixd_config.user_id, ap_unixd_config.group_id); @@ -420,25 +424,25 @@ PHP_MINFO_FUNCTION(apache) php_info_print_table_row(2, "Max Requests", tmp); apr_snprintf(tmp, sizeof tmp, - "Connection: %" APR_TIME_T_FMT " - Keep-Alive: %" APR_TIME_T_FMT, + "Connection: %" APR_TIME_T_FMT " - Keep-Alive: %" APR_TIME_T_FMT, apr_time_sec(serv->timeout), apr_time_sec(serv->keep_alive_timeout)); php_info_print_table_row(2, "Timeouts", tmp); - + php_info_print_table_row(2, "Virtual Server", (serv->is_virtual ? "Yes" : "No")); php_info_print_table_row(2, "Server Root", ap_server_root); - php_info_print_table_row(2, "Loaded Modules", tmp1.c); + php_info_print_table_row(2, "Loaded Modules", tmp1.s->val); smart_str_free(&tmp1); php_info_print_table_end(); - + DISPLAY_INI_ENTRIES(); { const apr_array_header_t *arr = apr_table_elts(((php_struct *) SG(server_context))->r->subprocess_env); char *key, *val; - + SECTION("Apache Environment"); - php_info_print_table_start(); + php_info_print_table_start(); php_info_print_table_header(2, "Variable", "Value"); APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) { @@ -446,14 +450,14 @@ PHP_MINFO_FUNCTION(apache) } php_info_print_table_row(2, key, val); APR_ARRAY_FOREACH_CLOSE() - - php_info_print_table_end(); - + + 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", ((php_struct *) SG(server_context))->r->the_request); - + arr = apr_table_elts(((php_struct *) SG(server_context))->r->headers_in); APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) { @@ -470,7 +474,7 @@ PHP_MINFO_FUNCTION(apache) } php_info_print_table_row(2, key, val); APR_ARRAY_FOREACH_CLOSE() - + php_info_print_table_end(); } } @@ -515,7 +519,7 @@ ZEND_END_ARG_INFO() static const zend_function_entry apache_functions[] = { PHP_FE(apache_lookup_uri, arginfo_apache2handler_lookup_uri) - PHP_FE(virtual, arginfo_apache2handler_virtual) + PHP_FE(virtual, arginfo_apache2handler_virtual) PHP_FE(apache_request_headers, arginfo_apache2handler_getallheaders) PHP_FE(apache_response_headers, arginfo_apache2handler_response_headers) PHP_FE(apache_setenv, arginfo_apache2handler_setenv) @@ -528,9 +532,9 @@ static const zend_function_entry apache_functions[] = { }; PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateLong, xbithack, php_apache2_info_struct, php_apache2_info) - STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateLong, engine, php_apache2_info_struct, php_apache2_info) - STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateLong, last_modified, php_apache2_info_struct, php_apache2_info) + STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateBool, xbithack, php_apache2_info_struct, php_apache2_info) + STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateBool, engine, php_apache2_info_struct, php_apache2_info) + STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateBool, last_modified, php_apache2_info_struct, php_apache2_info) PHP_INI_END() static PHP_MINIT_FUNCTION(apache) @@ -555,7 +559,7 @@ zend_module_entry php_apache_module = { PHP_MINIT(apache), PHP_MSHUTDOWN(apache), NULL, - NULL, + NULL, PHP_MINFO(apache), NULL, STANDARD_MODULE_PROPERTIES diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 088ff77769..f5fc78695b 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -30,7 +30,7 @@ #include <fcntl.h> -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" #ifndef NETWARE #include "ext/standard/php_standard.h" #else @@ -67,13 +67,16 @@ #define PHP_MAGIC_TYPE "application/x-httpd-php" #define PHP_SOURCE_MAGIC_TYPE "application/x-httpd-php-source" -#define PHP_SCRIPT "php5-script" +#define PHP_SCRIPT "php7-script" /* A way to specify the location of the php.ini dir in an apache directive */ char *apache2_php_ini_path_override = NULL; +#if defined(PHP_WIN32) && defined(ZTS) +ZEND_TSRMLS_CACHE_DEFINE; +#endif -static int -php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t +php_apache_sapi_ub_write(const char *str, size_t str_length) { request_rec *r; php_struct *ctx; @@ -89,7 +92,7 @@ php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) } static int -php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) +php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) { php_struct *ctx; char *val, *ptr; @@ -151,7 +154,7 @@ php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_e } static int -php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers) { php_struct *ctx = SG(server_context); const char *sline = SG(sapi_headers).http_status_line; @@ -171,7 +174,7 @@ php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* call ap_set_content_type only once, else each time we call it, configured output filters for that content type will be added */ if (!ctx->content_type) { - ctx->content_type = sapi_get_default_content_type(TSRMLS_C); + ctx->content_type = sapi_get_default_content_type(); } ap_set_content_type(ctx->r, apr_pstrdup(ctx->r->pool, ctx->content_type)); efree(ctx->content_type); @@ -180,8 +183,8 @@ php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) return SAPI_HEADER_SENT_SUCCESSFULLY; } -static int -php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) +static apr_size_t +php_apache_sapi_read_post(char *buf, size_t count_bytes) { apr_size_t len, tlen=0; php_struct *ctx = SG(server_context); @@ -212,8 +215,8 @@ php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) return tlen; } -static struct stat* -php_apache_sapi_get_stat(TSRMLS_D) +static zend_stat_t* +php_apache_sapi_get_stat(void) { php_struct *ctx = SG(server_context); @@ -238,7 +241,7 @@ php_apache_sapi_get_stat(TSRMLS_D) } static char * -php_apache_sapi_read_cookies(TSRMLS_D) +php_apache_sapi_read_cookies(void) { php_struct *ctx = SG(server_context); const char *http_cookie; @@ -250,7 +253,7 @@ php_apache_sapi_read_cookies(TSRMLS_D) } static char * -php_apache_sapi_getenv(char *name, size_t name_len TSRMLS_DC) +php_apache_sapi_getenv(char *name, size_t name_len) { php_struct *ctx = SG(server_context); const char *env_var; @@ -265,24 +268,24 @@ php_apache_sapi_getenv(char *name, size_t name_len TSRMLS_DC) } static void -php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC) +php_apache_sapi_register_variables(zval *track_vars_array) { php_struct *ctx = SG(server_context); const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env); char *key, *val; - int new_val_len; + size_t new_val_len; APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) { val = ""; } - if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), (unsigned int *)&new_val_len TSRMLS_CC)) { - php_register_variable_safe(key, val, new_val_len, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), &new_val_len)) { + php_register_variable_safe(key, val, new_val_len, track_vars_array); } APR_ARRAY_FOREACH_CLOSE() - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), (unsigned int *)&new_val_len TSRMLS_CC)) { - php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), &new_val_len)) { + php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array); } } @@ -291,7 +294,6 @@ php_apache_sapi_flush(void *server_context) { php_struct *ctx; request_rec *r; - TSRMLS_FETCH(); ctx = server_context; @@ -303,7 +305,7 @@ php_apache_sapi_flush(void *server_context) r = ctx->r; - sapi_send_headers(TSRMLS_C); + sapi_send_headers(); r->status = SG(sapi_headers).http_response_code; SG(headers_sent) = 1; @@ -313,7 +315,7 @@ php_apache_sapi_flush(void *server_context) } } -static void php_apache_sapi_log_message(char *msg TSRMLS_DC) +static void php_apache_sapi_log_message(char *msg) { php_struct *ctx; @@ -326,16 +328,16 @@ static void php_apache_sapi_log_message(char *msg TSRMLS_DC) } } -static void php_apache_sapi_log_message_ex(char *msg, request_rec *r TSRMLS_DC) +static void php_apache_sapi_log_message_ex(char *msg, request_rec *r) { if (r) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, msg, r->filename); } else { - php_apache_sapi_log_message(msg TSRMLS_CC); + php_apache_sapi_log_message(msg); } } -static double php_apache_sapi_get_request_time(TSRMLS_D) +static double php_apache_sapi_get_request_time(void) { php_struct *ctx = SG(server_context); return ((double) apr_time_as_msec(ctx->r->request_time)) / 1000.0; @@ -404,7 +406,6 @@ static apr_status_t php_apache_child_shutdown(void *tmp) static void php_apache_add_version(apr_pool_t *p) { - TSRMLS_FETCH(); if (PG(expose_php)) { ap_add_version_component(p, "PHP/" PHP_VERSION); } @@ -452,6 +453,8 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp } #ifdef ZTS tsrm_startup(1, 1, 0, NULL); + (void)ts_resource(0); + ZEND_TSRMLS_CACHE_UPDATE; #endif sapi_startup(&apache2_sapi_module); apache2_sapi_module.startup(&apache2_sapi_module); @@ -468,7 +471,7 @@ static apr_status_t php_server_context_cleanup(void *data_) return APR_SUCCESS; } -static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC) +static int php_apache_request_ctor(request_rec *r, php_struct *ctx) { char *content_length; const char *auth; @@ -483,7 +486,11 @@ static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC) r->no_local_copy = 1; content_length = (char *) apr_table_get(r->headers_in, "Content-Length"); - SG(request_info).content_length = (content_length ? atol(content_length) : 0); + if (content_length) { + ZEND_ATOL(SG(request_info).content_length, content_length); + } else { + SG(request_info).content_length = 0; + } apr_table_unset(r->headers_out, "Content-Length"); apr_table_unset(r->headers_out, "Last-Modified"); @@ -491,7 +498,7 @@ static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC) apr_table_unset(r->headers_out, "ETag"); auth = apr_table_get(r->headers_in, "Authorization"); - php_handle_auth_data(auth TSRMLS_CC); + php_handle_auth_data(auth); if (SG(request_info).auth_user == NULL && r->user) { SG(request_info).auth_user = estrdup(r->user); @@ -499,32 +506,28 @@ static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC) ctx->r->user = apr_pstrdup(ctx->r->pool, SG(request_info).auth_user); - return php_request_startup(TSRMLS_C); + return php_request_startup(); } -static void php_apache_request_dtor(request_rec *r TSRMLS_DC) +static void php_apache_request_dtor(request_rec *r) { php_request_shutdown(NULL); } -static void php_apache_ini_dtor(request_rec *r, request_rec *p TSRMLS_DC) +static void php_apache_ini_dtor(request_rec *r, request_rec *p) { if (strcmp(r->protocol, "INCLUDED")) { - zend_try { zend_ini_deactivate(TSRMLS_C); } zend_end_try(); + zend_try { zend_ini_deactivate(); } zend_end_try(); } else { typedef struct { HashTable config; } php_conf_rec; - char *str; - uint str_len; - php_conf_rec *c = ap_get_module_config(r->per_dir_config, &php5_module); - - for (zend_hash_internal_pointer_reset(&c->config); - zend_hash_get_current_key_ex(&c->config, &str, &str_len, NULL, 0, NULL) == HASH_KEY_IS_STRING; - zend_hash_move_forward(&c->config) - ) { - zend_restore_ini_entry(str, str_len, ZEND_INI_STAGE_SHUTDOWN); - } + zend_string *str; + php_conf_rec *c = ap_get_module_config(r->per_dir_config, &php7_module); + + ZEND_HASH_FOREACH_STR_KEY(&c->config, str) { + zend_restore_ini_entry(str, ZEND_INI_STAGE_SHUTDOWN); + } ZEND_HASH_FOREACH_END(); } if (p) { ((php_struct *)SG(server_context))->r = p; @@ -541,11 +544,15 @@ static int php_handler(request_rec *r) apr_bucket *bucket; apr_status_t rv; request_rec * volatile parent_req = NULL; - TSRMLS_FETCH(); +#ifdef ZTS + /* initial resource fetch */ + void ***tsrm_ls = ts_resource(0); + ZEND_TSRMLS_CACHE_UPDATE; +#endif -#define PHPAP_INI_OFF php_apache_ini_dtor(r, parent_req TSRMLS_CC); +#define PHPAP_INI_OFF php_apache_ini_dtor(r, parent_req); - conf = ap_get_module_config(r->per_dir_config, &php5_module); + conf = ap_get_module_config(r->per_dir_config, &php7_module); /* apply_config() needs r in some cases, so allocate server_context early */ ctx = SG(server_context); @@ -588,12 +595,12 @@ normal: } if (r->finfo.filetype == 0) { - php_apache_sapi_log_message_ex("script '%s' not found or unable to stat", r TSRMLS_CC); + php_apache_sapi_log_message_ex("script '%s' not found or unable to stat", r); PHPAP_INI_OFF; return HTTP_NOT_FOUND; } if (r->finfo.filetype == APR_DIR) { - php_apache_sapi_log_message_ex("attempt to invoke directory '%s' as script", r TSRMLS_CC); + php_apache_sapi_log_message_ex("attempt to invoke directory '%s' as script", r); PHPAP_INI_OFF; return HTTP_FORBIDDEN; } @@ -615,7 +622,7 @@ zend_first_try { ctx = SG(server_context); ctx->brigade = brigade; - if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) { + if (php_apache_request_ctor(r, ctx)!=SUCCESS) { zend_bailout(); } } else { @@ -626,7 +633,7 @@ zend_first_try { strcmp(parent_req->handler, PHP_MAGIC_TYPE) && strcmp(parent_req->handler, PHP_SOURCE_MAGIC_TYPE) && strcmp(parent_req->handler, PHP_SCRIPT)) { - if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) { + if (php_apache_request_ctor(r, ctx)!=SUCCESS) { zend_bailout(); } } @@ -654,7 +661,7 @@ zend_first_try { if (strncmp(r->handler, PHP_SOURCE_MAGIC_TYPE, sizeof(PHP_SOURCE_MAGIC_TYPE) - 1) == 0) { zend_syntax_highlighter_ini syntax_highlighter_ini; php_get_highlight_struct(&syntax_highlighter_ini); - highlight_file((char *)r->filename, &syntax_highlighter_ini TSRMLS_CC); + highlight_file((char *)r->filename, &syntax_highlighter_ini); } else { zend_file_handle zfd; @@ -664,19 +671,19 @@ zend_first_try { zfd.opened_path = NULL; if (!parent_req) { - php_execute_script(&zfd TSRMLS_CC); + php_execute_script(&zfd); } else { - zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &zfd); + zend_execute_scripts(ZEND_INCLUDE, NULL, 1, &zfd); } apr_table_set(r->notes, "mod_php_memory_usage", - apr_psprintf(ctx->r->pool, "%" APR_SIZE_T_FMT, zend_memory_peak_usage(1 TSRMLS_CC))); + apr_psprintf(ctx->r->pool, "%" APR_SIZE_T_FMT, zend_memory_peak_usage(1))); } } zend_end_try(); if (!parent_req) { - php_apache_request_dtor(r TSRMLS_CC); + php_apache_request_dtor(r); ctx->request_processed = 1; bucket = apr_bucket_eos_create(r->connection->bucket_alloc); APR_BRIGADE_INSERT_TAIL(brigade, bucket); diff --git a/sapi/apache_hooks/apMakefile.tmpl b/sapi/apache_hooks/apMakefile.tmpl index 4054e8e119..1e5e465f65 100644 --- a/sapi/apache_hooks/apMakefile.tmpl +++ b/sapi/apache_hooks/apMakefile.tmpl @@ -1,38 +1,38 @@ ## ## Apache 1.3 Makefile template for PHP 4.0 Module -## [src/modules/php5/Makefile.tmpl] +## [src/modules/php7/Makefile.tmpl] ## # the parametrized target -LIB=libphp5.$(LIBEXT) +LIB=libphp7.$(LIBEXT) # objects for building the static library -OBJS=mod_php5.o -OBJS_LIB=libmodphp5.a +OBJS=mod_php7.o +OBJS_LIB=libmodphp7.a # objects for building the shared object library -SHLIB_OBJS=mod_php5.so-o -SHLIB_OBJS_LIB=libmodphp5.a +SHLIB_OBJS=mod_php7.so-o +SHLIB_OBJS_LIB=libmodphp7.a # the general targets all: lib lib: $(LIB) # build the static library by merging the object files -libphp5.a: $(OBJS) $(OBJS_LIB) +libphp7.a: $(OBJS) $(OBJS_LIB) cp $(OBJS_LIB) $@ ar r $@ $(OBJS) $(RANLIB) $@ # ugly hack to support older Apache-1.3 betas that don't set $LIBEXT -libphp5.: $(OBJS) $(OBJS_LIB) +libphp7.: $(OBJS) $(OBJS_LIB) cp $(OBJS_LIB) $@ ar r $@ $(OBJS) $(RANLIB) $@ - cp libphp5. libphp5.a + cp libphp7. libphp7.a # build the shared object library by linking the object files -libphp5.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) +libphp7.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) rm -f $@ $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) $(LIBS) $(PHP_LIBS) @@ -69,9 +69,9 @@ depend: $(OBJS): Makefile # DO NOT REMOVE -mod_php5.o: mod_php5.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \ +mod_php7.o: mod_php7.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \ $(INCDIR)/buff.h \ $(INCDIR)/http_config.h \ $(INCDIR)/http_core.h $(INCDIR)/http_main.h \ $(INCDIR)/http_protocol.h $(INCDIR)/http_request.h \ - $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php5.h + $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php7.h diff --git a/sapi/apache_hooks/config.m4 b/sapi/apache_hooks/config.m4 index e2c71b4274..a1ee213492 100644 --- a/sapi/apache_hooks/config.m4 +++ b/sapi/apache_hooks/config.m4 @@ -79,7 +79,7 @@ if test "$PHP_APACHE_HOOKS" != "no"; then *darwin*) MH_BUNDLE_FLAGS="-dynamic -twolevel_namespace -bundle -bundle_loader $APXS_HTTPD" PHP_SUBST(MH_BUNDLE_FLAGS) - SAPI_SHARED=libs/libphp5.so + SAPI_SHARED=libs/libphp7.so build_type=bundle ;; *) @@ -87,26 +87,26 @@ if test "$PHP_APACHE_HOOKS" != "no"; then ;; esac - PHP_SELECT_SAPI(apache_hooks, $build_type, sapi_apache.c mod_php5.c php_apache.c, $APACHE_CPPFLAGS -I$APXS_INCLUDEDIR) + PHP_SELECT_SAPI(apache_hooks, $build_type, sapi_apache.c mod_php7.c php_apache.c, $APACHE_CPPFLAGS -I$APXS_INCLUDEDIR) # Test whether apxs support -S option $APXS -q -S CFLAGS="$APXS_CFLAGS" CFLAGS >/dev/null 2>&1 if test "$?" != "0"; then - APACHE_HOOKS_INSTALL="$APXS -i -a -n php5 $SAPI_SHARED" # Old apxs does not have -S option + APACHE_HOOKS_INSTALL="$APXS -i -a -n php7 $SAPI_SHARED" # Old apxs does not have -S option else APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR` if test -z `$APXS -q SYSCONFDIR`; then APACHE_HOOKS_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -i -n php5 $SAPI_SHARED" + -i -n php7 $SAPI_SHARED" else APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR` APACHE_HOOKS_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \ $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ -S SYSCONFDIR='$APXS_SYSCONFDIR' \ - -i -a -n php5 $SAPI_SHARED" + -i -a -n php7 $SAPI_SHARED" fi fi @@ -137,7 +137,7 @@ if test "$PHP_SAPI" != "apache" && test "$PHP_SAPI" != "apache_hooks" && test "$ PHP_APACHE_HOOKS_STATIC=/usr/local/apache fi - APACHE_HOOKS_INSTALL_FILES="\$(srcdir)/sapi/apache_hooks/mod_php5.* sapi/apache_hooks/libphp5.module" + APACHE_HOOKS_INSTALL_FILES="\$(srcdir)/sapi/apache_hooks/mod_php7.* sapi/apache_hooks/libphp7.module" AC_DEFINE(HAVE_APACHE,1,[ ]) APACHE_HOOKS_MODULE=yes @@ -146,7 +146,7 @@ if test "$PHP_SAPI" != "apache" && test "$PHP_SAPI" != "apache_hooks" && test "$ if test -f $PHP_APACHE_HOOKS_STATIC/src/httpd.h; then APACHE_INCLUDE=-I$PHP_APACHE_HOOKS_STATIC/src APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) + PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET" PHP_LIBS="-L. -lphp3" AC_MSG_RESULT([yes - Apache 1.2.x]) @@ -161,13 +161,13 @@ if test "$PHP_SAPI" != "apache" && test "$PHP_SAPI" != "apache_hooks" && test "$ elif test -f $PHP_APACHE_HOOKS_STATIC/src/main/httpd.h; then APACHE_HAS_REGEX=1 APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/src/main -I$PHP_APACHE_HOOKS_STATIC/src/os/unix -I$PHP_APACHE_HOOKS_STATIC/src/ap" - APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src/modules/php5 + APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src/modules/php7 if test ! -d $APACHE_TARGET; then mkdir $APACHE_TARGET fi - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_hooks/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache_hooks/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" - PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5" + PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) + APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_hooks/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache_hooks/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" + PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" AC_MSG_RESULT([yes - Apache 1.3.x]) STRONGHOLD= if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config.h; then @@ -185,13 +185,13 @@ if test "$PHP_SAPI" != "apache" && test "$PHP_SAPI" != "apache_hooks" && test "$ elif test -f $PHP_APACHE_HOOKS_STATIC/src/include/httpd.h; then APACHE_HAS_REGEX=1 APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/src/include -I$PHP_APACHE_HOOKS_STATIC/src/os/unix" - APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src/modules/php5 + APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src/modules/php7 if test ! -d $APACHE_TARGET; then mkdir $APACHE_TARGET fi - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) - PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5" - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_hooks/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache_hooks/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" + PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) + PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" + APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_hooks/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache_hooks/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" AC_MSG_RESULT([yes - Apache 1.3.x]) STRONGHOLD= if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config.h; then @@ -209,9 +209,9 @@ if test "$PHP_SAPI" != "apache" && test "$PHP_SAPI" != "apache_hooks" && test "$ elif test -f $PHP_APACHE_HOOKS_STATIC/apache/httpd.h; then APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/apache -I$PHP_APACHE_HOOKS_STATIC/ssl/include" APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/apache - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) - PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5" - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET" + PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) + PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" + APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET" STRONGHOLD=-DSTRONGHOLD=1 AC_MSG_RESULT([yes - StrongHold]) if test -f $PHP_APACHE_HOOKS_STATIC/apache/ap_config.h; then @@ -249,13 +249,13 @@ dnl Build as static module if test "$APACHE_HOOKS_MODULE" = "yes"; then PHP_TARGET_RDYNAMIC $php_shtool mkdir -p sapi/apache_hooks - PHP_OUTPUT(sapi/apache_hooks/libphp5.module) + PHP_OUTPUT(sapi/apache_hooks/libphp7.module) fi dnl General if test -n "$APACHE_HOOKS_INSTALL"; then if test "x$APXS" != "x" -a "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then - APXS_EXP=-bE:sapi/apache_hooks/mod_php5.exp + APXS_EXP=-bE:sapi/apache_hooks/mod_php7.exp fi PHP_APACHE_FD_CHECK diff --git a/sapi/apache_hooks/config.w32 b/sapi/apache_hooks/config.w32 index 85dc624d60..1c9129e615 100644 --- a/sapi/apache_hooks/config.w32 +++ b/sapi/apache_hooks/config.w32 @@ -12,9 +12,9 @@ if (PHP_APACHE_HOOKS != "no") { ";" + PHP_PHP_BUILD + "\\apache\\src\\corer")) { // We need to play tricks to get our readdir.h used by apache // headers - SAPI('apache_hooks', 'mod_php5.c sapi_apache.c php_apache.c', + SAPI('apache_hooks', 'mod_php7.c sapi_apache.c php_apache.c', 'php' + PHP_VERSION + 'apache_hooks.dll', - '/D APACHEPHP5_EXPORTS /D APACHE_READDIR_H /I win32'); + '/D APACHEPHP7_EXPORTS /D APACHE_READDIR_H /I win32'); } else { WARNING("Could not find apache libraries/headers"); } diff --git a/sapi/apache_hooks/libphp5.module.in b/sapi/apache_hooks/libphp7.module.in index 8488181897..5bea79ef95 100644 --- a/sapi/apache_hooks/libphp5.module.in +++ b/sapi/apache_hooks/libphp7.module.in @@ -1,4 +1,4 @@ -Name: php5_module +Name: php7_module ConfigStart RULE_WANTHSREGEX=no RULE_HIDE=yes diff --git a/sapi/apache_hooks/mod_php5.exp b/sapi/apache_hooks/mod_php5.exp deleted file mode 100644 index 9ad0f0a0ad..0000000000 --- a/sapi/apache_hooks/mod_php5.exp +++ /dev/null @@ -1 +0,0 @@ -php5_module diff --git a/sapi/apache_hooks/mod_php5.c b/sapi/apache_hooks/mod_php7.c index eb3317c4db..6eb15f3ef8 100644 --- a/sapi/apache_hooks/mod_php5.c +++ b/sapi/apache_hooks/mod_php7.c @@ -29,13 +29,13 @@ /* {{{ Prototypes */ -int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC); +int apache_php_module_main(request_rec *r, int display_source_mode); static void php_save_umask(void); static void php_restore_umask(void); -static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC); -static char *sapi_apache_read_cookies(TSRMLS_D); -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC); -static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC); +static int sapi_apache_read_post(char *buffer, uint count_bytes); +static char *sapi_apache_read_cookies(void); +static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers); +static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers); 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); @@ -84,11 +84,11 @@ static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, php_per_dir_co static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode); static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2); -/* ### these should be defined in mod_php5.h or somewhere else */ +/* ### these should be defined in mod_php7.h or somewhere else */ #define USE_PATH 1 #define IGNORE_URL 2 -module MODULE_VAR_EXPORT php5_module; +module MODULE_VAR_EXPORT php7_module; int saved_umask; /* static int setup_env = 0; */ @@ -108,7 +108,7 @@ typedef struct _php_per_dir_entry { */ /* This code is ripped part and parcel from zend_stack.[ch]. Assuming that the - patch supporting zend_stack_init_ex is applied, all but the bottom two + patch supporting zend_stack_init_ex is applied, all but the bottom two module-specific iterators will be removed */ @@ -152,18 +152,18 @@ int sapi_stack_destroy(sapi_stack *stack) int sapi_stack_apply_with_argument_all(sapi_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg) { - int i, retval; + int i, retval; - switch (type) { + switch (type) { case ZEND_STACK_APPLY_TOPDOWN: for (i=stack->top-1; i>=0; i--) { - retval = apply_function(stack->elements[i], arg); + retval = apply_function(stack->elements[i], arg); } break; case ZEND_STACK_APPLY_BOTTOMUP: - for (i=0; i<stack->top; i++) { + for (i=0; i<stack->top; i++) { retval = apply_function(stack->elements[i], arg); - } + } break; } return retval; @@ -224,7 +224,7 @@ void php_handler_stack_destroy(sapi_stack *stack) free(ph); } } -/* }}} */ +/* }}} */ /* {{{ php_save_umask */ @@ -237,10 +237,10 @@ static void php_save_umask(void) /* {{{ sapi_apache_ub_write */ -static int sapi_apache_ub_write(const char *str, uint str_length TSRMLS_DC) +static int sapi_apache_ub_write(const char *str, uint str_length) { int ret=0; - + if (SG(server_context)) { ret = rwrite(str, str_length, (request_rec *) SG(server_context)); } @@ -267,7 +267,7 @@ static void sapi_apache_flush(void *server_context) /* {{{ sapi_apache_read_post */ -static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static int sapi_apache_read_post(char *buffer, uint count_bytes) { uint total_read_bytes=0, read_bytes; request_rec *r = (request_rec *) SG(server_context); @@ -282,7 +282,7 @@ static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC) if (!SG(read_post_bytes) && !ap_should_client_block(r)) { return total_read_bytes; } - + handler = signal(SIGPIPE, SIG_IGN); while (total_read_bytes<count_bytes) { hard_timeout("Read POST information", r); /* start timeout timer */ @@ -293,14 +293,14 @@ static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC) } total_read_bytes += read_bytes; } - signal(SIGPIPE, handler); + signal(SIGPIPE, handler); return total_read_bytes; } /* }}} */ /* {{{ sapi_apache_read_cookies */ -static char *sapi_apache_read_cookies(TSRMLS_D) +static char *sapi_apache_read_cookies(void) { return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, "HTTP_COOKIE"); } @@ -308,7 +308,7 @@ static char *sapi_apache_read_cookies(TSRMLS_D) /* {{{ sapi_apache_header_handler */ -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) { char *header_name, *header_content, *p; request_rec *r = (request_rec *) SG(server_context); @@ -361,7 +361,7 @@ static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_head /* {{{ sapi_apache_send_headers */ -static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers) { if(SG(server_context) == NULL) { /* server_context is not here anymore */ return SAPI_HEADER_SEND_FAILED; @@ -369,7 +369,7 @@ static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) ((request_rec *) SG(server_context))->status = SG(sapi_headers).http_response_code; /* check that we haven't sent headers already, we use our own - * headers_sent since we may send headers at anytime + * headers_sent since we may send headers at anytime */ if(!AP(headers_sent)) { send_http_header((request_rec *) SG(server_context)); @@ -381,7 +381,7 @@ static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ sapi_apache_register_server_variables */ -static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_apache_register_server_variables(zval *track_vars_array) { register int i; array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env); @@ -397,7 +397,7 @@ static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_ } else { val = ""; } - php_register_variable(elts[i].key, val, track_vars_array TSRMLS_CC); + php_register_variable(elts[i].key, val, track_vars_array ); } /* If PATH_TRANSLATED doesn't exist, copy it from SCRIPT_FILENAME */ @@ -409,10 +409,10 @@ static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_ 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("PATH_TRANSLATED", Z_STRVAL_PP(path_translated), track_vars_array); } - php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array TSRMLS_CC); + php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array); } /* }}} */ @@ -430,7 +430,7 @@ static int php_apache_startup(sapi_module_struct *sapi_module) /* {{{ php_apache_log_message */ -static void php_apache_log_message(char *message TSRMLS_DC) +static void php_apache_log_message(char *message) { if (SG(server_context)) { #if MODULE_MAGIC_NUMBER >= 19970831 @@ -449,9 +449,8 @@ static void php_apache_log_message(char *message TSRMLS_DC) */ static void php_apache_request_shutdown(void *dummy) { - TSRMLS_FETCH(); AP(current_hook) = AP_CLEANUP; - php_output_set_status(PHP_OUTPUT_DISABLED TSRMLS_CC); + php_output_set_status(PHP_OUTPUT_DISABLED); SG(server_context) = NULL; /* The server context (request) is invalid by the time run_cleanups() is called */ if(SG(sapi_started)) { php_request_shutdown(dummy); @@ -468,9 +467,9 @@ static void php_apache_request_shutdown(void *dummy) /* {{{ php_apache_sapi_activate */ -static int php_apache_sapi_activate(TSRMLS_D) +static int php_apache_sapi_activate(void) { - request_rec *r = (request_rec *) SG(server_context); + request_rec *r = (request_rec *) SG(server_context); /* * For the Apache module version, this bit of code registers a cleanup @@ -478,7 +477,7 @@ static int php_apache_sapi_activate(TSRMLS_D) * 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. + * memory. */ block_alarms(); register_cleanup(r->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec); @@ -495,7 +494,7 @@ static int php_apache_sapi_activate(TSRMLS_D) /* {{{ php_apache_get_stat */ -static struct stat *php_apache_get_stat(TSRMLS_D) +static struct stat *php_apache_get_stat(void) { return &((request_rec *) SG(server_context))->finfo; } @@ -503,7 +502,7 @@ static struct stat *php_apache_get_stat(TSRMLS_D) /* {{{ php_apache_getenv */ -static char *php_apache_getenv(char *name, size_t name_len TSRMLS_DC) +static char *php_apache_getenv(char *name, size_t name_len) { return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, name); } @@ -514,7 +513,7 @@ static char *php_apache_getenv(char *name, size_t name_len TSRMLS_DC) static sapi_module_struct apache_sapi_module = { "apache", /* name */ "Apache", /* pretty name */ - + php_apache_startup, /* startup */ php_module_shutdown_wrapper, /* shutdown */ @@ -555,7 +554,7 @@ static sapi_module_struct apache_sapi_module = { NULL, /* exe location */ 0, /* ini ignore */ NULL - + }; /* }}} */ @@ -569,7 +568,7 @@ static void php_restore_umask(void) /* {{{ init_request_info */ -static void init_request_info(TSRMLS_D) +static void init_request_info(void) { request_rec *r = ((request_rec *) SG(server_context)); char *content_length = (char *) table_get(r->subprocess_env, "CONTENT_LENGTH"); @@ -614,7 +613,7 @@ static void init_request_info(TSRMLS_D) /* {{{ php_apache_alter_ini_entries */ -static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry TSRMLS_DC) +static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry) { 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; @@ -623,15 +622,15 @@ static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry TSRMLS_ /* {{{ php_apache_get_default_mimetype */ -static char *php_apache_get_default_mimetype(request_rec *r TSRMLS_DC) +static char *php_apache_get_default_mimetype(request_rec *r) { - + 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); + tmpmimetype = sapi_get_default_content_type(); mimetype = pstrdup(r->pool, tmpmimetype); efree(tmpmimetype); } else { @@ -647,7 +646,6 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) { int retval; php_per_dir_config *per_dir_conf; - TSRMLS_FETCH(); if (AP(in_request)) { zend_file_handle fh; @@ -656,7 +654,7 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) fh.free_filename = 0; fh.type = ZEND_HANDLE_FILENAME; - zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &fh); + zend_execute_scripts(ZEND_INCLUDE, NULL, 1, &fh); return OK; } @@ -667,19 +665,19 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) return DECLINED; } - per_dir_conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); + per_dir_conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); if (per_dir_conf) { - zend_hash_apply((HashTable *) per_dir_conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC); + zend_hash_apply((HashTable *) per_dir_conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries); } /* 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->content_type = php_apache_get_default_mimetype(r); r->allowed |= (1 << METHODS) - 1; zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return DECLINED; } @@ -691,7 +689,7 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) #if MODULE_MAGIC_NUMBER > 19961007 if ((retval = setup_client_block(r, REQUEST_CHUNKED_ERROR))) { zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return retval; } @@ -701,7 +699,7 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) #if MODULE_MAGIC_NUMBER < 19970912 if ((retval = set_last_modified(r, r->finfo.st_mtime))) { zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return retval; } @@ -713,22 +711,22 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) } /* 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); + r->content_type = php_apache_get_default_mimetype(r); /* Init timeout */ hard_timeout("send", r); SG(server_context) = r; - + php_save_umask(); if(!AP(setup_env)) { AP(setup_env) = 1; add_common_vars(r); add_cgi_vars(r); } - init_request_info(TSRMLS_C); - apache_php_module_main(r, display_source_mode TSRMLS_CC); - + init_request_info(); + apache_php_module_main(r, display_source_mode); + /* Done, restore umask, turn off timeout, close file and return */ php_restore_umask(); kill_timeout(r); @@ -743,10 +741,9 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) static int send_parsed_php(request_rec * r) { int result = send_php(r, 0, NULL); - TSRMLS_FETCH(); - + ap_table_setn(r->notes, "mod_php_memory_usage", - ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC))); + ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1))); return result; } @@ -816,7 +813,7 @@ static void php_destroy_per_server_info(php_per_server_config *conf) /* {{{ php_destroy_per_dir_info */ -static void php_destroy_per_dir_info(php_per_dir_config *conf) +static void php_destroy_per_dir_info(php_per_dir_config *conf) { zend_hash_destroy(conf->ini_settings); php_handler_stack_destroy(&conf->response_handlers); @@ -838,12 +835,12 @@ static void *php_create_server(pool *p, char *dummy) php_per_server_config *conf; conf = (php_per_server_config *) malloc(sizeof(php_per_server_config)); register_cleanup(p, (void *) conf, (void (*)(void *)) php_destroy_per_server_info, (void (*)(void *)) php_destroy_per_server_info); - + sapi_stack_init_ex(&conf->requires, 1); sapi_stack_init_ex(&conf->uri_handlers, 1); return conf; } - + /* }}} */ @@ -864,7 +861,7 @@ static void *php_create_dir(pool *p, char *dummy) sapi_stack_init_ex(&conf->logger_handlers, 1); sapi_stack_init_ex(&conf->post_read_handlers, 1); register_cleanup(p, (void *) conf, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) php_destroy_per_dir_info); - + return conf; } @@ -934,7 +931,7 @@ static CONST_PREFIX char *php_set_server_handler(server_rec *s, char *arg1, long handler->type = handler_type; handler->stage = handler_stage; handler->name = strdup(arg1); - conf = get_module_config(s->module_config, &php5_module); + conf = get_module_config(s->module_config, &php7_module); switch(handler_stage) { case AP_URI_TRANS: sapi_stack_push(&conf->uri_handlers, handler); @@ -986,7 +983,7 @@ static CONST_PREFIX char *php_set_dir_handler(php_per_dir_config *conf, char *ar return NULL; } -/* {{{ php_set_uri_handler +/* {{{ php_set_uri_handler */ static CONST_PREFIX char *php_set_uri_handler(cmd_parms *cmd, void *dummy, char *arg1) { @@ -1013,7 +1010,7 @@ static CONST_PREFIX char *php_set_header_handler_code(cmd_parms *cmd, php_per_di } /* }}} */ -/* {{{ php_set_auth_handler +/* {{{ php_set_auth_handler */ static CONST_PREFIX char *php_set_auth_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) { @@ -1075,7 +1072,7 @@ static CONST_PREFIX char *php_set_logger_handler_code(cmd_parms *cmd, php_per_di return php_set_dir_handler(conf, arg1, AP_LOGGING, AP_HANDLER_TYPE_METHOD); } -/* }}} */ +/* }}} */ /* {{{ php_set_post_read_handler */ @@ -1111,7 +1108,7 @@ static CONST_PREFIX char *php_set_response_handler_code(cmd_parms *cmd, php_per_ return php_set_dir_handler(conf, arg1, AP_RESPONSE, AP_HANDLER_TYPE_METHOD); } /* }}} */ - + /* {{{ php_apache_value_handler */ static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2) @@ -1140,7 +1137,7 @@ static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable * bool_val[0] = '0'; } bool_val[1] = 0; - + return php_apache_value_handler_ex(cmd, conf, arg1, bool_val, mode); } /* }}} */ @@ -1178,20 +1175,19 @@ static CONST_PREFIX char *php_apache_phpini_set(cmd_parms *cmd, HashTable *conf, static int php_xbithack_handler(request_rec * r) { php_per_dir_config *conf; - TSRMLS_FETCH(); if (!(r->finfo.st_mode & S_IXUSR)) { r->allowed |= (1 << METHODS) - 1; return DECLINED; } - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); + conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); if (conf) { - zend_hash_apply((HashTable *) conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC); + zend_hash_apply((HashTable *) conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries); } if(!AP(xbithack)) { r->allowed |= (1 << METHODS) - 1; zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); return DECLINED; } @@ -1208,7 +1204,7 @@ static void apache_php_module_shutdown_wrapper(void) #if MODULE_MAGIC_NUMBER >= 19970728 /* This function is only called on server exit if the apache API - * child_exit handler exists, so shutdown globally + * child_exit handler exists, so shutdown globally */ sapi_shutdown(); #endif @@ -1249,8 +1245,7 @@ static void php_init_handler(server_rec *s, pool *p) } #if MODULE_MAGIC_NUMBER >= 19980527 { - TSRMLS_FETCH(); - if (PG(expose_php)) { + if (PG(expose_php)) { ap_add_version_component("PHP/" PHP_VERSION); } } @@ -1263,12 +1258,11 @@ static int php_run_hook(php_handler *handler, request_rec *r) zval *ret = NULL; php_per_dir_config *conf; - TSRMLS_FETCH(); if(!AP(apache_config_loaded)) { - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); + conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); if (conf) - zend_hash_apply((HashTable *)conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC); + zend_hash_apply((HashTable *)conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries); AP(apache_config_loaded) = 1; } if (!handler->name) { @@ -1281,8 +1275,8 @@ static int php_run_hook(php_handler *handler, request_rec *r) add_cgi_vars(r); } SG(server_context) = r; - init_request_info(TSRMLS_C); - apache_php_module_hook(r, handler, &ret TSRMLS_CC); + init_request_info(); + apache_php_module_hook(r, handler, &ret); php_restore_umask(); kill_timeout(r); if (ret) { @@ -1291,25 +1285,23 @@ static int php_run_hook(php_handler *handler, request_rec *r) } return HTTP_INTERNAL_SERVER_ERROR; } - + static int php_uri_translation(request_rec *r) -{ +{ php_per_server_config *conf; - TSRMLS_FETCH(); AP(current_hook) = AP_URI_TRANS; - conf = (php_per_server_config *) get_module_config(r->server->module_config, &php5_module); - return sapi_stack_apply_with_argument_stop_if_equals(&conf->uri_handlers, - ZEND_STACK_APPLY_BOTTOMUP, + conf = (php_per_server_config *) get_module_config(r->server->module_config, &php7_module); + return sapi_stack_apply_with_argument_stop_if_equals(&conf->uri_handlers, + ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r, OK); } static int php_header_hook(request_rec *r) { php_per_dir_config *conf; - TSRMLS_FETCH(); AP(current_hook) = AP_HEADER_PARSE; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); + conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); return sapi_stack_apply_with_argument_stop_if_http_error(&conf->headers_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r); @@ -1318,11 +1310,10 @@ static int php_header_hook(request_rec *r) static int php_auth_hook(request_rec *r) { php_per_dir_config *conf; - TSRMLS_FETCH(); AP(current_hook) = AP_AUTHENTICATION; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); - return sapi_stack_apply_with_argument_stop_if_equals(&conf->auth_handlers, - ZEND_STACK_APPLY_BOTTOMUP, + conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); + return sapi_stack_apply_with_argument_stop_if_equals(&conf->auth_handlers, + ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r, OK); } @@ -1330,9 +1321,8 @@ static int php_access_hook(request_rec *r) { php_per_dir_config *conf; int status = DECLINED; - TSRMLS_FETCH(); AP(current_hook) = AP_ACCESS_CONTROL; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); + conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); status = sapi_stack_apply_with_argument_stop_if_http_error(&conf->access_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r); @@ -1343,9 +1333,8 @@ static int php_access_hook(request_rec *r) static int php_type_hook(request_rec *r) { php_per_dir_config *conf; - TSRMLS_FETCH(); AP(current_hook) = AP_TYPE_CHECKING; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); + conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); return sapi_stack_apply_with_argument_stop_if_equals(&conf->type_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, @@ -1355,9 +1344,8 @@ static int php_type_hook(request_rec *r) static int php_fixup_hook(request_rec *r) { php_per_dir_config *conf; - TSRMLS_FETCH(); AP(current_hook) = AP_FIXUP; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); + conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); return sapi_stack_apply_with_argument_stop_if_http_error(&conf->fixup_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, @@ -1367,26 +1355,24 @@ static int php_fixup_hook(request_rec *r) static int php_logger_hook(request_rec *r) { php_per_dir_config *conf; - TSRMLS_FETCH(); AP(current_hook) = AP_LOGGING; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); + conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); return sapi_stack_apply_with_argument_stop_if_http_error(&conf->logger_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r); } - + static int php_post_read_hook(request_rec *r) { php_per_dir_config *conf; php_per_server_config *svr; - TSRMLS_FETCH(); AP(current_hook) = AP_POST_READ; - svr = get_module_config(r->server->module_config, &php5_module); + svr = get_module_config(r->server->module_config, &php7_module); if(ap_is_initial_req(r)) { sapi_stack_apply_with_argument_all(&svr->requires, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r); } - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); + conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); return sapi_stack_apply_with_argument_stop_if_http_error(&conf->post_read_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r); @@ -1395,9 +1381,8 @@ static int php_post_read_hook(request_rec *r) static int php_response_handler(request_rec *r) { php_per_dir_config *conf; - TSRMLS_FETCH(); AP(current_hook) = AP_RESPONSE; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module); + conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); return sapi_stack_apply_with_argument_all(&conf->response_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r); } @@ -1449,9 +1434,9 @@ command_rec php_commands[] = }; /* }}} */ -/* {{{ module MODULE_VAR_EXPORT php5_module +/* {{{ module MODULE_VAR_EXPORT php7_module */ -module MODULE_VAR_EXPORT php5_module = +module MODULE_VAR_EXPORT php7_module = { STANDARD_MODULE_STUFF, php_init_handler, /* initializer */ diff --git a/sapi/apache_hooks/mod_php7.exp b/sapi/apache_hooks/mod_php7.exp new file mode 100644 index 0000000000..1469b0314d --- /dev/null +++ b/sapi/apache_hooks/mod_php7.exp @@ -0,0 +1 @@ +php7_module diff --git a/sapi/apache_hooks/mod_php5.h b/sapi/apache_hooks/mod_php7.h index 5eacb9cb8f..34fc20bd31 100644 --- a/sapi/apache_hooks/mod_php5.h +++ b/sapi/apache_hooks/mod_php7.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -17,8 +17,8 @@ */ /* $Id$ */ -#ifndef MOD_PHP5_H -#define MOD_PHP5_H +#ifndef MOD_PHP7_H +#define MOD_PHP7_H #if !defined(WIN32) && !defined(WINNT) #ifndef MODULE_VAR_EXPORT @@ -78,7 +78,7 @@ extern php_apache_info_struct php_apache_info; # define MODULE_VAR_EXPORT PHPAPI #endif -#endif /* MOD_PHP5_H */ +#endif /* MOD_PHP7_H */ /* * Local variables: diff --git a/sapi/apache_hooks/php.sym b/sapi/apache_hooks/php.sym index 9ad0f0a0ad..1469b0314d 100644 --- a/sapi/apache_hooks/php.sym +++ b/sapi/apache_hooks/php.sym @@ -1 +1 @@ -php5_module +php7_module diff --git a/sapi/apache_hooks/php5apache_hooks.dsp b/sapi/apache_hooks/php5apache_hooks.dsp deleted file mode 100755 index cc60f4b3b1..0000000000 --- a/sapi/apache_hooks/php5apache_hooks.dsp +++ /dev/null @@ -1,151 +0,0 @@ -# Microsoft Developer Studio Project File - Name="php5apache_hooks" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php5apache_hooks - Win32 Release_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "php5apache_hooks.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "php5apache_hooks.mak" CFG="php5apache_hooks - Win32 Release_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php5apache_hooks - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5apache_hooks - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5apache_hooks - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "php5apache_hooks - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS"
-# PROP BASE Intermediate_Dir "Release_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\..\regex" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\apache\src\include" /I "..\..\main" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php5ts.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x60000000" /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\apache\src\corer" /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS"
-
-!ELSEIF "$(CFG)" == "php5apache_hooks - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\..\regex" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\apache\src\include" /I "..\..\main" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php5ts_debug.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x60000000" /version:4.0 /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php5apache_hooks.dll" /pdbtype:sept /libpath:"..\..\..\php_build\apache\src\cored" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"
-
-!ELSEIF "$(CFG)" == "php5apache_hooks - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS_inline"
-# PROP BASE Intermediate_Dir "Release_TS_inline"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\Release_TS_inline"
-# PROP Intermediate_Dir "Release_TS_inline"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\..\regex" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\apache\src\include" /I "..\..\main" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php5ts.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"\apache\src\corer" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php5apache_hooks - Win32 Release_TS"
-# Name "php5apache_hooks - Win32 Debug_TS"
-# Name "php5apache_hooks - Win32 Release_TS_inline"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\mod_php5.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_apache.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\sapi_apache.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\mod_php5.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_apache_http.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
diff --git a/sapi/apache_hooks/php_apache.c b/sapi/apache_hooks/php_apache.c index b66b8f6221..55581b9bb8 100644 --- a/sapi/apache_hooks/php_apache.c +++ b/sapi/apache_hooks/php_apache.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -105,7 +105,7 @@ PHP_INI_BEGIN() PHP_INI_END() /* }}} */ -static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRMLS_DC) +static void php_apache_globals_ctor(php_apache_info_struct *apache_globals) { apache_globals->in_request = 0; } @@ -113,20 +113,20 @@ static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRML #define APREQ_GET_THIS(ZVAL) if (NULL == (ZVAL = getThis())) { \ php_error(E_WARNING, "%s(): underlying ApacheRequest object missing", \ - get_active_function_name(TSRMLS_C)); \ + get_active_function_name()); \ RETURN_FALSE; \ } #define APREQ_GET_REQUEST(ZVAL, R) APREQ_GET_THIS(ZVAL); \ - R = get_apache_request(ZVAL TSRMLS_CC) + R = get_apache_request(ZVAL) -static void php_apache_request_free(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_apache_request_free(zend_rsrc_list_entry *rsrc) { zval *z = (zval *)rsrc->ptr; /* fprintf(stderr, "%s() %p\n", __FUNCTION__, z); */ zval_ptr_dtor(&z); } -static request_rec *get_apache_request(zval *z TSRMLS_DC) +static request_rec *get_apache_request(zval *z) { request_rec *r; zval **addr; @@ -137,18 +137,18 @@ static request_rec *get_apache_request(zval *z TSRMLS_DC) } if (Z_TYPE_P(z) != IS_OBJECT) { - php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name(TSRMLS_C)); + php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name()); return NULL; } if (zend_hash_index_find(Z_OBJPROP_P(z), 0, (void **)&addr) == FAILURE) { - php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name(TSRMLS_C)); + php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name()); return NULL; } r = (request_rec *)Z_LVAL_PP(addr); if (!r) { - php_error(E_WARNING, "%s(): request_rec invalid", get_active_function_name(TSRMLS_C)); + php_error(E_WARNING, "%s(): request_rec invalid", get_active_function_name()); return NULL; } @@ -162,8 +162,6 @@ zval *php_apache_request_new(request_rec *r) { zval *req; zval *addr; - - TSRMLS_FETCH(); MAKE_STD_ZVAL(addr); Z_TYPE_P(addr) = IS_LONG; @@ -212,7 +210,7 @@ static void apache_request_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) int new_value_len; char **target; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &new_value, &new_value_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &new_value, &new_value_len) == FAILURE) { return; } @@ -262,7 +260,7 @@ static void apache_request_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) long old_value, new_value; long *target; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &new_value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &new_value) == FAILURE) { return; } @@ -506,7 +504,7 @@ PHP_FUNCTION(apache_request_content_length) long zlen; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &zlen) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &zlen) == FAILURE) { return; } @@ -586,7 +584,7 @@ static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS) zend_bool replace = 0; HashPosition pos; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zb", &first, &second, &replace) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|zb", &first, &second, &replace) == FAILURE) { RETURN_FALSE; } @@ -596,7 +594,7 @@ static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS) case 3: zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(first), &pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(first), (void **)&entry, &pos) == SUCCESS) { - switch(zend_hash_get_current_key_ex(Z_ARRVAL_P(first), &string_key, &string_key_len, &num_key, 0, &pos)) { + switch(zend_hash_get_current_key_ex(Z_ARRVAL_P(first), &string_key, &string_key_len, &num_key, &pos)) { case HASH_KEY_IS_STRING: if (zend_hash_find(Z_ARRVAL_P(first), string_key, string_key_len, (void **)&value) == FAILURE) { zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos); @@ -616,7 +614,7 @@ static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS) break; case HASH_KEY_IS_LONG: default: - php_error(E_WARNING, "%s(): Can only add STRING keys to headers!", get_active_function_name(TSRMLS_C)); + php_error(E_WARNING, "%s(): Can only add STRING keys to headers!", get_active_function_name()); break; } @@ -717,7 +715,7 @@ PHP_FUNCTION(apache_request_remote_host) request_rec *r; char *res; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &type) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &type) == FAILURE) { return; } @@ -745,7 +743,7 @@ PHP_FUNCTION(apache_request_update_mtime) request_rec *r; long mtime = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mtime) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mtime) == FAILURE) { return; } @@ -933,7 +931,7 @@ PHP_FUNCTION(apache_request_basic_auth_pw) const char *pw; long status; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zpw) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zpw) == FAILURE) { return; } @@ -965,7 +963,7 @@ PHP_FUNCTION(apache_request_send_http_header) char *type = NULL; int typelen; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &type, &typelen) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() , "|s", &type, &typelen) == FAILURE) { return; } @@ -1036,7 +1034,7 @@ PHP_FUNCTION(apache_request_send_error_response) request_rec *r; long rec = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &rec) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &rec) == FAILURE) { return; } @@ -1051,7 +1049,7 @@ PHP_FUNCTION(apache_request_set_content_length) zval *id; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &length) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &length) == FAILURE) { return; } @@ -1094,7 +1092,7 @@ PHP_FUNCTION(apache_request_rputs) zval *id; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buffer, &buffer_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &buffer, &buffer_len) == FAILURE) { return; } @@ -1138,7 +1136,7 @@ PHP_FUNCTION(apache_request_log_error) long facility = APLOG_ERR; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &z_errstr, &z_errstr_len, &facility) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &z_errstr, &z_errstr_len, &facility) == FAILURE) { return; } @@ -1160,7 +1158,7 @@ PHP_FUNCTION(apache_request_sub_req_lookup_uri) int file_len; request_rec *r, *sub_r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &file_len) == FAILURE) { return; } @@ -1185,7 +1183,7 @@ PHP_FUNCTION(apache_request_sub_req_lookup_file) int file_len; request_rec *r, *sub_r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &file_len) == FAILURE) { return; } @@ -1211,7 +1209,7 @@ PHP_FUNCTION(apache_request_sub_req_method_uri) int file_len, method_len; request_rec *r, *sub_r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &method, &method_len, &file, &file_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &method, &method_len, &file, &file_len) == FAILURE) { return; } @@ -1257,7 +1255,7 @@ PHP_FUNCTION(apache_request_internal_redirect) int new_uri_len; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &new_uri, &new_uri_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &new_uri, &new_uri_len) == FAILURE) { return; } @@ -1273,7 +1271,7 @@ PHP_FUNCTION(apache_request_send_header_field) zval *id; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &fieldname, &fieldname_len, &fieldval, &fieldval_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &fieldname, &fieldname_len, &fieldval, &fieldval_len) == FAILURE) { return; } @@ -1396,14 +1394,14 @@ static PHP_MINIT_FUNCTION(apache) #ifdef ZTS ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL); #else - php_apache_globals_ctor(&php_apache_info TSRMLS_CC); + php_apache_globals_ctor(&php_apache_info); #endif REGISTER_INI_ENTRIES(); le_apachereq = zend_register_list_destructors_ex(php_apache_request_free, NULL, "ApacheRequest", module_number); INIT_OVERLOADED_CLASS_ENTRY(ce, "ApacheRequest", php_apache_request_class_functions, NULL, NULL, NULL); - apacherequest_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); + apacherequest_class_entry = zend_register_internal_class_ex(&ce, NULL); REGISTER_LONG_CONSTANT("OK", OK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DECLINED", DECLINED, CONST_CS | CONST_PERSISTENT); @@ -1553,7 +1551,7 @@ PHP_FUNCTION(apache_note) int arg_name_len, arg_val_len; char *note_val; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &arg_name, &arg_name_len, &arg_val, &arg_val_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &arg_name, &arg_name_len, &arg_val, &arg_val_len) == FAILURE) { return; } @@ -1716,7 +1714,7 @@ PHP_FUNCTION(virtual) int filename_len; request_rec *rr = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { return; } @@ -1734,8 +1732,8 @@ PHP_FUNCTION(virtual) RETURN_FALSE; } - php_output_end_all(TSRMLS_C); - php_header(TSRMLS_C); + php_output_end_all(); + php_header(); if (run_sub_req(rr)) { php_error(E_WARNING, "Unable to include '%s' - request execution failed", filename); @@ -1766,7 +1764,7 @@ static void apache_table_to_zval(table *t, zval *return_value) if (!tenv[i].key) { continue; } - if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) { + if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val)==FAILURE) { RETURN_FALSE; } } @@ -1813,7 +1811,7 @@ PHP_FUNCTION(apache_setenv) 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) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) { RETURN_FALSE; } @@ -1837,7 +1835,7 @@ PHP_FUNCTION(apache_lookup_uri) int filename_len; request_rec *rr=NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { return; } @@ -1850,34 +1848,34 @@ PHP_FUNCTION(apache_lookup_uri) add_property_long(return_value,"status", rr->status); if (rr->the_request) { - add_property_string(return_value,"the_request", rr->the_request, 1); + add_property_string(return_value,"the_request", rr->the_request); } if (rr->status_line) { - add_property_string(return_value,"status_line", (char *)rr->status_line, 1); + add_property_string(return_value,"status_line", (char *)rr->status_line); } if (rr->method) { - add_property_string(return_value,"method", (char *)rr->method, 1); + add_property_string(return_value,"method", (char *)rr->method); } if (rr->content_type) { - add_property_string(return_value,"content_type", (char *)rr->content_type, 1); + add_property_string(return_value,"content_type", (char *)rr->content_type); } if (rr->handler) { - add_property_string(return_value,"handler", (char *)rr->handler, 1); + add_property_string(return_value,"handler", (char *)rr->handler); } if (rr->uri) { - add_property_string(return_value,"uri", rr->uri, 1); + add_property_string(return_value,"uri", rr->uri); } if (rr->filename) { - add_property_string(return_value,"filename", rr->filename, 1); + add_property_string(return_value,"filename", rr->filename); } if (rr->path_info) { - add_property_string(return_value,"path_info", rr->path_info, 1); + add_property_string(return_value,"path_info", rr->path_info); } if (rr->args) { - add_property_string(return_value,"args", rr->args, 1); + add_property_string(return_value,"args", rr->args); } if (rr->boundary) { - add_property_string(return_value,"boundary", rr->boundary, 1); + add_property_string(return_value,"boundary", rr->boundary); } add_property_long(return_value,"no_cache", rr->no_cache); add_property_long(return_value,"no_local_copy", rr->no_local_copy); @@ -1889,7 +1887,7 @@ PHP_FUNCTION(apache_lookup_uri) #if MODULE_MAGIC_NUMBER >= 19980324 if (rr->unparsed_uri) { - add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1); + add_property_string(return_value,"unparsed_uri", rr->unparsed_uri); } if(rr->mtime) { add_property_long(return_value,"mtime", rr->mtime); @@ -1954,9 +1952,9 @@ PHP_FUNCTION(apache_get_modules) for (n = 0; ap_loaded_modules[n]; ++n) { char *s = (char *) ap_loaded_modules[n]->name; if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s), 1); + add_next_index_stringl(return_value, s, (p - s)); } else { - add_next_index_string(return_value, s, 1); + add_next_index_string(return_value, s); } } } diff --git a/sapi/apache_hooks/php_apache_http.h b/sapi/apache_hooks/php_apache_http.h index 23cf7fea69..5684de9179 100644 --- a/sapi/apache_hooks/php_apache_http.h +++ b/sapi/apache_hooks/php_apache_http.h @@ -28,17 +28,17 @@ #include "http_main.h" #include "http_protocol.h" #include "http_request.h" -#include "http_log.h" +#include "http_log.h" #include "util_script.h" #include "php_variables.h" -#include "php_main.h" +#include "php_main.h" #include "php_ini.h" #include "ext/standard/php_standard.h" -#include "mod_php5.h" +#include "mod_php7.h" zval *php_apache_request_new(request_rec *r); -int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret TSRMLS_DC); +int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret); diff --git a/sapi/apache_hooks/sapi_apache.c b/sapi/apache_hooks/sapi_apache.c index c9d9853e36..dd5a6b60ea 100644 --- a/sapi/apache_hooks/sapi_apache.c +++ b/sapi/apache_hooks/sapi_apache.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -25,21 +25,21 @@ /* {{{ apache_php_module_main */ -int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC) +int apache_php_module_main(request_rec *r, int display_source_mode) { zend_file_handle file_handle; - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == 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)){ + if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini)){ return OK; } else { return NOT_FOUND; @@ -50,17 +50,17 @@ int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC) 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); + (void) php_execute_script(&file_handle); } AP(in_request) = 0; - + return (OK); } /* }}} */ /* {{{ apache_php_module_hook */ -int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret TSRMLS_DC) +int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret) { zend_file_handle file_handle; zval *req; @@ -70,24 +70,24 @@ int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret TSRM signal(SIGCHLD, sigchld_handler); #endif if(AP(current_hook) == AP_RESPONSE) { - if (php_request_startup_for_hook(TSRMLS_C) == FAILURE) + if (php_request_startup_for_hook() == FAILURE) return FAILURE; } else { - if (php_request_startup_for_hook(TSRMLS_C) == FAILURE) + if (php_request_startup_for_hook() == FAILURE) return FAILURE; } req = php_apache_request_new(r); - php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); + php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER]); switch(handler->type) { case AP_HANDLER_TYPE_FILE: - php_register_variable("PHP_SELF_HOOK", handler->name, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); + php_register_variable("PHP_SELF_HOOK", handler->name, PG(http_globals)[TRACK_VARS_SERVER]); memset(&file_handle, 0, sizeof(file_handle)); file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = handler->name; - (void) php_execute_simple_script(&file_handle, ret TSRMLS_CC); + (void) php_execute_simple_script(&file_handle, ret); break; case AP_HANDLER_TYPE_METHOD: if( (tmp = strstr(handler->name, "::")) != NULL && *(tmp+2) != '\0' ) { @@ -99,7 +99,7 @@ int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret TSRM ALLOC_ZVAL(method); ZVAL_STRING(method, tmp +2, 1); *tmp = ':'; - call_user_function_ex(EG(function_table), &class, method, ret, 0, NULL, 0, NULL TSRMLS_CC); + call_user_function_ex(EG(function_table), &class, method, ret, 0, NULL, 0, NULL); zval_dtor(class); zval_dtor(method); } diff --git a/sapi/caudium/caudium.c b/sapi/caudium/caudium.c index c0ffae41b1..9a00b1620a 100644 --- a/sapi/caudium/caudium.c +++ b/sapi/caudium/caudium.c @@ -1,6 +1,6 @@ -/* +/* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -25,12 +25,12 @@ #include "php_ini.h" #include "php_globals.h" #include "SAPI.h" -#include "php_main.h" +#include "php_main.h" #include "ext/standard/info.h" #include "php_version.h" -/* Pike Include Files +/* 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. @@ -38,7 +38,7 @@ */ #define NO_PIKE_SHORTHAND -/* Ok, we are now using Pike level threads to handle PHP5 since +/* Ok, we are now using Pike level threads to handle PHP7 since * the nice th_farm threads aren't working on Linux with glibc 2.2 * (why this is I don't know). */ @@ -79,7 +79,7 @@ #endif #ifndef PIKE_THREADS -#error The PHP5 module requires that your Pike has thread support. +#error The PHP7 module requires that your Pike has thread support. #endif #undef HIDE_GLOBAL_VARIABLES @@ -103,7 +103,7 @@ typedef struct void pike_module_init(void); void pike_module_exit(void); -static void free_struct(TSRMLS_D); +static void free_struct(void); void f_php_caudium_request_handler(INT32 args); /* Defines to get to the data supplied when the script is started. */ @@ -114,7 +114,7 @@ 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 +/* File descriptor integer. Used to write directly to the FD without * passing Pike */ #define MY_FD (THIS->my_fd) @@ -161,7 +161,7 @@ static unsigned char caudium_php_initialized; /* 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; @@ -204,12 +204,12 @@ INLINE static int lookup_integer_header(char *headername, int default_value) /* * 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 + * 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) { +php_caudium_low_ub_write(const char *str, uint str_length) { int sent_bytes = 0; struct pike_string *to_write = NULL; GET_THIS(); @@ -235,11 +235,11 @@ php_caudium_low_ub_write(const char *str, uint str_length TSRMLS_DC) { /* * 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. + * disabled. */ static int -php_caudium_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) +php_caudium_sapi_ub_write(const char *str, uint str_length) { GET_THIS(); int sent_bytes = 0, fd = MY_FD; @@ -259,7 +259,7 @@ php_caudium_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) zend_bailout(); THIS->written += sent_bytes; return sent_bytes; - case EINTR: + case EINTR: case EWOULDBLOCK: continue; } @@ -269,7 +269,7 @@ php_caudium_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) } THIS->written += sent_bytes; } else { - THREAD_SAFE_RUN(sent_bytes = php_caudium_low_ub_write(str, str_length TSRMLS_CC), + THREAD_SAFE_RUN(sent_bytes = php_caudium_low_ub_write(str, str_length), "write"); } return sent_bytes; @@ -295,7 +295,7 @@ php_caudium_set_header(char *header_name, char *value, char *p) s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind); if(!s_headermap || s_headermap->type != PIKE_T_MAPPING) { - struct svalue mappie; + struct svalue mappie; mappie.type = PIKE_T_MAPPING; headermap = allocate_mapping(1); mappie.u.mapping = headermap; @@ -306,7 +306,7 @@ php_caudium_set_header(char *header_name, char *value, char *p) headermap = s_headermap->u.mapping; soldval = low_mapping_string_lookup(headermap, hind); vallen = strlen(value); - if(soldval != NULL && + if(soldval != NULL && soldval->type == PIKE_T_STRING && soldval->u.string->size_shift == 0) { /* Existing, valid header. Prepend.*/ @@ -315,7 +315,7 @@ php_caudium_set_header(char *header_name, char *value, char *p) STR0(hval)[soldval->u.string->len] = '\0'; MEMCPY(hval->str+soldval->u.string->len+1, value, vallen); hval = end_shared_string(hval); - } else { + } else { hval = make_shared_string(value); } } @@ -330,17 +330,17 @@ php_caudium_set_header(char *header_name, char *value, char *p) } /* - * php_caudium_sapi_header_handler() sets a HTTP reply header to be + * 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) + sapi_headers_struct *sapi_headers) { char *header_name, *header_content, *p; header_name = sapi_header->header; header_content = p = strchr(header_name, ':'); - + if(p) { do { header_content++; @@ -357,7 +357,7 @@ php_caudium_sapi_header_handler(sapi_header_struct *sapi_header, */ INLINE static int -php_caudium_low_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +php_caudium_low_send_headers(sapi_headers_struct *sapi_headers) { struct pike_string *ind; struct svalue *s_headermap; @@ -367,10 +367,10 @@ php_caudium_low_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) zend_bailout(); return SAPI_HEADER_SEND_FAILED; } - ind = make_shared_string(" _headers"); + 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); @@ -378,15 +378,15 @@ php_caudium_low_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) 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) +php_caudium_sapi_send_headers(sapi_headers_struct *sapi_headers) { int res = 0; - THREAD_SAFE_RUN(res = php_caudium_low_send_headers(sapi_headers TSRMLS_CC), "send headers"); + THREAD_SAFE_RUN(res = php_caudium_low_send_headers(sapi_headers), "send headers"); return res; } @@ -399,8 +399,7 @@ 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; @@ -420,20 +419,20 @@ INLINE static int php_caudium_low_read_post(char *buf, uint count_bytes) } static int -php_caudium_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) +php_caudium_sapi_read_post(char *buf, uint count_bytes) { 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) +php_caudium_sapi_read_cookies(void) { char *cookies; cookies = lookup_string_header("HTTP_COOKIE", NULL); @@ -454,7 +453,7 @@ static void php_info_caudium(ZEND_MODULE_INFO_FUNC_ARGS) 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", + snprintf(buf, 511, "%d day(s), %02d:%02d:%02d", uptime / 86400, (uptime / 3600) % 24, (uptime / 60) % 60, @@ -478,7 +477,7 @@ static zend_module_entry php_caudium_module = { }; -INLINE static void low_sapi_caudium_register_variables(zval *track_vars_array TSRMLS_DC) +INLINE static void low_sapi_caudium_register_variables(zval *track_vars_array) { int i; struct keypair *k; @@ -488,16 +487,16 @@ INLINE static void low_sapi_caudium_register_variables(zval *track_vars_array TS struct svalue *val; GET_THIS(); php_register_variable("PHP_SELF", SG(request_info).request_uri, - track_vars_array TSRMLS_CC); + track_vars_array); php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", - track_vars_array TSRMLS_CC); + track_vars_array); php_register_variable("REQUEST_METHOD", (char *) SG(request_info).request_method, - track_vars_array TSRMLS_CC); + track_vars_array); php_register_variable("REQUEST_URI", SG(request_info).request_uri, - track_vars_array TSRMLS_CC); + track_vars_array); php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, - track_vars_array TSRMLS_CC); + track_vars_array); sind = make_shared_string("env"); headers = low_mapping_string_lookup(REQUEST_DATA, sind); @@ -509,15 +508,15 @@ INLINE static void low_sapi_caudium_register_variables(zval *track_vars_array TS 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 ); + track_vars_array ); } } } } -static void sapi_caudium_register_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_caudium_register_variables(zval *track_vars_array) { - THREAD_SAFE_RUN(low_sapi_caudium_register_variables(track_vars_array TSRMLS_CC), "register_variables"); + THREAD_SAFE_RUN(low_sapi_caudium_register_variables(track_vars_array), "register_variables"); } @@ -569,8 +568,7 @@ static void php_caudium_module_main(php_caudium_request *ureq) struct thread_state *state; extern struct program *thread_id_prog; #endif - TSRMLS_FETCH(); - GET_THIS(); + GET_THIS(); THIS->filename = ureq->filename; THIS->done_cb = ureq->done_cb; THIS->my_fd_obj = ureq->my_fd_obj; @@ -604,7 +602,7 @@ static void php_caudium_module_main(php_caudium_request *ureq) state->status=THREAD_RUNNING; #endif state->swapped = 0; -#endif +#endif SG(request_info).query_string = lookup_string_header("QUERY_STRING", 0); SG(server_context) = (void *)1; /* avoid server_context == NULL */ @@ -626,8 +624,8 @@ static void php_caudium_module_main(php_caudium_request *ureq) SG(request_info).headers_only = 0; } - /* Let PHP5 handle the deconding of the AUTH */ - php_handle_auth_data(lookup_string_header("HTTP_AUTHORIZATION", NULL), TSRMLS_C); + /* Let PHP7 handle the deconding of the AUTH */ + php_handle_auth_data(lookup_string_header("HTTP_AUTHORIZATION", NULL), ); /* 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. @@ -645,22 +643,22 @@ static void php_caudium_module_main(php_caudium_request *ureq) file_handle.free_filename = 0; THIS->written = 0; - res = php_request_startup(TSRMLS_C); + res = php_request_startup(); if(res == FAILURE) { THREAD_SAFE_RUN({ apply_svalue(&THIS->done_cb, 0); pop_stack(); - free_struct(TSRMLS_C); + free_struct(); }, "Negative run response"); } else { - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); php_request_shutdown(NULL); THREAD_SAFE_RUN({ push_int(THIS->written); apply_svalue(&THIS->done_cb, 1); pop_stack(); - free_struct(TSRMLS_C); + free_struct(); }, "positive run response"); } @@ -708,7 +706,7 @@ void f_php_caudium_request_handler(INT32 args) get_all_args("PHP5.Interpreter->run", args, "%S%m%O%*", &script, &request_data, &my_fd_obj, &done_callback); - if(done_callback->type != PIKE_T_FUNCTION) + if(done_callback->type != PIKE_T_FUNCTION) Pike_error("PHP5.Interpreter->run: Bad argument 4, expected function.\n"); add_ref(request_data); add_ref(my_fd_obj); @@ -738,7 +736,7 @@ void f_php_caudium_request_handler(INT32 args) pop_n_elems(args); } -static void free_struct(TSRMLS_D) +static void free_struct(void) { GET_THIS(); if(THIS->request_data) free_mapping(THIS->request_data); diff --git a/sapi/caudium/config.m4 b/sapi/caudium/config.m4 index 5ce55f3f01..13a6b2943e 100644 --- a/sapi/caudium/config.m4 +++ b/sapi/caudium/config.m4 @@ -79,12 +79,12 @@ if test "$PHP_CAUDIUM" != "no"; then AC_MSG_RESULT(not found) fi else - AC_MSG_ERROR([Caudium PHP5 requires Pike 7.0 or newer]) + AC_MSG_ERROR([Caudium PHP7 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 $PHP_CAUDIUM/lib/$PIKE_VERSION/PHP5.so" + INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PHP_CAUDIUM/lib/$PIKE_VERSION/PHP7.so" RESULT=" *** Pike binary used: $PIKE *** Pike include dir(s) used: $PIKE_INCLUDE_DIR *** Pike version: $PIKE_VERSION" diff --git a/sapi/cgi/CHANGES b/sapi/cgi/CHANGES index de029474e5..b7cf41cf5e 100755 --- a/sapi/cgi/CHANGES +++ b/sapi/cgi/CHANGES @@ -31,4 +31,3 @@ In PHP5.3 all additional configure options (except --enable-cgi) are removed: Now it is disabled by default, but can be enabled with ini directive "cgi.discard_path=1". - diff --git a/sapi/cgi/README.FastCGI b/sapi/cgi/README.FastCGI index 3dda295d84..f0f11e102d 100644 --- a/sapi/cgi/README.FastCGI +++ b/sapi/cgi/README.FastCGI @@ -69,7 +69,7 @@ a line in your config like: Don't load mod_php, by the way. Make sure it is commented out! - #LoadModule php5_module /usr/lib/apache/2.0/libphp5.so + #LoadModule php7_module /usr/lib/apache/2.0/libphp7.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 diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index de1be31c41..a0bba17f06 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -69,6 +69,7 @@ #include "php_globals.h" #include "php_main.h" #include "fopen_wrappers.h" +#include "http_status_codes.h" #include "ext/standard/php_standard.h" #include "ext/standard/url.h" @@ -97,7 +98,7 @@ int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS; struct sigaction act, old_term, old_quit, old_int; #endif -static void (*php_php_import_environment_variables)(zval *array_ptr TSRMLS_DC); +static void (*php_php_import_environment_variables)(zval *array_ptr); #ifndef PHP_WIN32 /* these globals used for forking children on unix systems */ @@ -159,6 +160,8 @@ static const opt_struct OPTIONS[] = { }; typedef struct _php_cgi_globals_struct { + HashTable user_config_cache; + char *redirect_status_env; zend_bool rfc2616_headers; zend_bool nph; zend_bool check_shebang_line; @@ -166,11 +169,9 @@ typedef struct _php_cgi_globals_struct { zend_bool force_redirect; zend_bool discard_path; zend_bool fcgi_logging; - char *redirect_status_env; #ifdef PHP_WIN32 zend_bool impersonate; #endif - HashTable user_config_cache; } php_cgi_globals_struct; /* {{{ user_config_cache @@ -187,16 +188,21 @@ typedef struct _user_config_cache_entry { HashTable *user_config; } user_config_cache_entry; -static void user_config_cache_entry_dtor(user_config_cache_entry *entry) +static void user_config_cache_entry_dtor(zval *el) { + user_config_cache_entry *entry = (user_config_cache_entry *)Z_PTR_P(el); zend_hash_destroy(entry->user_config); free(entry->user_config); + free(entry); } /* }}} */ #ifdef ZTS static int php_cgi_globals_id; -#define CGIG(v) TSRMG(php_cgi_globals_id, php_cgi_globals_struct *, v) +#define CGIG(v) ZEND_TSRMG(php_cgi_globals_id, php_cgi_globals_struct *, v) +#if defined(PHP_WIN32) +ZEND_TSRMLS_CACHE_DEFINE; +#endif #else static php_cgi_globals_struct php_cgi_globals; #define CGIG(v) (php_cgi_globals.v) @@ -215,53 +221,53 @@ static php_cgi_globals_struct php_cgi_globals; #define TRANSLATE_SLASHES(path) #endif -static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC) +static int print_module_info(zval *element) { + zend_module_entry *module = Z_PTR_P(element); php_printf("%s\n", module->name); - return 0; + return ZEND_HASH_APPLY_KEEP; } -static int module_name_cmp(const void *a, const void *b TSRMLS_DC) +static int module_name_cmp(const void *a, const void *b) { - Bucket *f = *((Bucket **) a); - Bucket *s = *((Bucket **) b); + Bucket *f = (Bucket *) a; + Bucket *s = (Bucket *) b; - return strcasecmp( ((zend_module_entry *)f->pData)->name, - ((zend_module_entry *)s->pData)->name); + return strcasecmp( ((zend_module_entry *)Z_PTR(f->val))->name, + ((zend_module_entry *)Z_PTR(s->val))->name); } -static void print_modules(TSRMLS_D) +static void print_modules(void) { HashTable sorted_registry; - zend_module_entry tmp; - zend_hash_init(&sorted_registry, 50, NULL, NULL, 1); - zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry)); - zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC); - zend_hash_apply_with_argument(&sorted_registry, (apply_func_arg_t) print_module_info, NULL TSRMLS_CC); + zend_hash_init(&sorted_registry, 64, NULL, NULL, 1); + zend_hash_copy(&sorted_registry, &module_registry, NULL); + zend_hash_sort(&sorted_registry, module_name_cmp, 0); + zend_hash_apply(&sorted_registry, print_module_info); zend_hash_destroy(&sorted_registry); } -static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC) +static int print_extension_info(zend_extension *ext, void *arg) { php_printf("%s\n", ext->name); return 0; } -static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s TSRMLS_DC) +static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s) { return strcmp( ((zend_extension *)(*f)->data)->name, ((zend_extension *)(*s)->data)->name); } -static void print_extensions(TSRMLS_D) +static void print_extensions(void) { zend_llist sorted_exts; zend_llist_copy(&sorted_exts, &zend_extensions); sorted_exts.dtor = NULL; - zend_llist_sort(&sorted_exts, extension_name_cmp TSRMLS_CC); - zend_llist_apply_with_argument(&sorted_exts, (llist_apply_with_arg_func_t) print_extension_info, NULL TSRMLS_CC); + zend_llist_sort(&sorted_exts, extension_name_cmp); + zend_llist_apply_with_argument(&sorted_exts, (llist_apply_with_arg_func_t) print_extension_info, NULL); zend_llist_destroy(&sorted_exts); } @@ -269,10 +275,10 @@ static void print_extensions(TSRMLS_D) #define STDOUT_FILENO 1 #endif -static inline size_t sapi_cgi_single_write(const char *str, uint str_length TSRMLS_DC) +static inline size_t sapi_cgi_single_write(const char *str, size_t str_length) { #ifdef PHP_WRITE_STDOUT - long ret; + int ret; ret = write(STDOUT_FILENO, str, str_length); if (ret <= 0) return 0; @@ -285,14 +291,14 @@ static inline size_t sapi_cgi_single_write(const char *str, uint str_length TSRM #endif } -static int sapi_cgi_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t sapi_cgi_ub_write(const char *str, size_t str_length) { const char *ptr = str; - uint remaining = str_length; + size_t remaining = str_length; size_t ret; while (remaining > 0) { - ret = sapi_cgi_single_write(ptr, remaining TSRMLS_CC); + ret = sapi_cgi_single_write(ptr, remaining); if (!ret) { php_handle_aborted_connection(); return str_length - remaining; @@ -304,14 +310,15 @@ static int sapi_cgi_ub_write(const char *str, uint str_length TSRMLS_DC) return str_length; } -static int sapi_fcgi_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t sapi_fcgi_ub_write(const char *str, size_t str_length) { const char *ptr = str; - uint remaining = str_length; + size_t remaining = str_length; fcgi_request *request = (fcgi_request*) SG(server_context); while (remaining > 0) { - long ret = fcgi_write(request, FCGI_STDOUT, ptr, remaining); + int to_write = remaining > INT_MAX ? INT_MAX : (int)remaining; + int ret = fcgi_write(request, FCGI_STDOUT, ptr, to_write); if (ret <= 0) { php_handle_aborted_connection(); @@ -347,57 +354,7 @@ static void sapi_fcgi_flush(void *server_context) #define SAPI_CGI_MAX_HEADER_LENGTH 1024 -typedef struct _http_error { - int code; - const char* msg; -} http_error; - -static const http_error http_error_codes[] = { - {100, "Continue"}, - {101, "Switching Protocols"}, - {200, "OK"}, - {201, "Created"}, - {202, "Accepted"}, - {203, "Non-Authoritative Information"}, - {204, "No Content"}, - {205, "Reset Content"}, - {206, "Partial Content"}, - {300, "Multiple Choices"}, - {301, "Moved Permanently"}, - {302, "Moved Temporarily"}, - {303, "See Other"}, - {304, "Not Modified"}, - {305, "Use Proxy"}, - {400, "Bad Request"}, - {401, "Unauthorized"}, - {402, "Payment Required"}, - {403, "Forbidden"}, - {404, "Not Found"}, - {405, "Method Not Allowed"}, - {406, "Not Acceptable"}, - {407, "Proxy Authentication Required"}, - {408, "Request Time-out"}, - {409, "Conflict"}, - {410, "Gone"}, - {411, "Length Required"}, - {412, "Precondition Failed"}, - {413, "Request Entity Too Large"}, - {414, "Request-URI Too Large"}, - {415, "Unsupported Media Type"}, - {428, "Precondition Required"}, - {429, "Too Many Requests"}, - {431, "Request Header Fields Too Large"}, - {500, "Internal Server Error"}, - {501, "Not Implemented"}, - {502, "Bad Gateway"}, - {503, "Service Unavailable"}, - {504, "Gateway Time-out"}, - {505, "HTTP Version not supported"}, - {511, "Network Authentication Required"}, - {0, NULL} -}; - -static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers) { char buf[SAPI_CGI_MAX_HEADER_LENGTH]; sapi_header_struct *h; @@ -447,7 +404,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos); } if (!has_status) { - http_error *err = (http_error*)http_error_codes; + http_response_status_code_pair *err = (http_response_status_code_pair*)http_status_map; while (err->code != 0) { if (err->code == SG(sapi_headers).http_response_code) { @@ -455,8 +412,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) } err++; } - if (err->msg) { - len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg); + if (err->str) { + len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->str); } else { len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code); } @@ -474,7 +431,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) while (h) { /* prevent CRLFCRLF */ if (h->header_len) { - if (h->header_len > sizeof("Status:")-1 && + if (h->header_len > sizeof("Status:")-1 && strncasecmp(h->header, "Status:", sizeof("Status:")-1) == 0 ) { if (!ignore_status) { @@ -503,14 +460,26 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) # define STDIN_FILENO 0 #endif -static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static size_t sapi_cgi_read_post(char *buffer, size_t count_bytes) { - uint read_bytes = 0; + size_t read_bytes = 0; int tmp_read_bytes; + size_t remaining_bytes; - count_bytes = MIN(count_bytes, SG(request_info).content_length - SG(read_post_bytes)); + assert(SG(request_info).content_length >= SG(read_post_bytes)); + + remaining_bytes = (size_t)(SG(request_info).content_length - SG(read_post_bytes)); + + count_bytes = MIN(count_bytes, remaining_bytes); while (read_bytes < count_bytes) { +#ifdef PHP_WIN32 + size_t diff = count_bytes - read_bytes; + unsigned int to_read = (diff > UINT_MAX) ? UINT_MAX : (unsigned int)diff; + + tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, to_read); +#else tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, count_bytes - read_bytes); +#endif if (tmp_read_bytes <= 0) { break; } @@ -519,9 +488,9 @@ static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) return read_bytes; } -static int sapi_fcgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static size_t sapi_fcgi_read_post(char *buffer, size_t count_bytes) { - uint read_bytes = 0; + size_t read_bytes = 0; int tmp_read_bytes; fcgi_request *request = (fcgi_request*) SG(server_context); size_t remaining = SG(request_info).content_length - SG(read_post_bytes); @@ -530,7 +499,10 @@ static int sapi_fcgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) count_bytes = remaining; } while (read_bytes < count_bytes) { - tmp_read_bytes = fcgi_read(request, buffer + read_bytes, count_bytes - read_bytes); + size_t diff = count_bytes - read_bytes; + int to_read = (diff > INT_MAX) ? INT_MAX : (int)diff; + + tmp_read_bytes = fcgi_read(request, buffer + read_bytes, to_read); if (tmp_read_bytes <= 0) { break; } @@ -539,19 +511,19 @@ static int sapi_fcgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) return read_bytes; } -static char *sapi_cgi_getenv(char *name, size_t name_len TSRMLS_DC) +static char *sapi_cgi_getenv(char *name, size_t name_len) { return getenv(name); } -static char *sapi_fcgi_getenv(char *name, size_t name_len TSRMLS_DC) +static char *sapi_fcgi_getenv(char *name, size_t name_len) { /* when php is started by mod_fastcgi, no regular environment * is provided to PHP. It is always sent to PHP at the start * of a request. So we have to do our own lookup to get env * vars. This could probably be faster somehow. */ fcgi_request *request = (fcgi_request*) SG(server_context); - char *ret = fcgi_getenv(request, name, name_len); + char *ret = fcgi_getenv(request, name, (int)name_len); if (ret) return ret; /* if cgi, or fastcgi and not found in fcgi env @@ -559,10 +531,10 @@ static char *sapi_fcgi_getenv(char *name, size_t name_len TSRMLS_DC) return getenv(name); } -static char *_sapi_cgi_putenv(char *name, int name_len, char *value) +static char *_sapi_cgi_putenv(char *name, size_t name_len, char *value) { #if !HAVE_SETENV || !HAVE_UNSETENV - int len; + size_t len; char *buf; #endif @@ -604,71 +576,65 @@ static char *_sapi_cgi_putenv(char *name, int name_len, char *value) return getenv(name); } -static char *sapi_cgi_read_cookies(TSRMLS_D) +static char *sapi_cgi_read_cookies(void) { return getenv("HTTP_COOKIE"); } -static char *sapi_fcgi_read_cookies(TSRMLS_D) +static char *sapi_fcgi_read_cookies(void) { fcgi_request *request = (fcgi_request*) SG(server_context); return FCGI_GETENV(request, "HTTP_COOKIE"); } -static void cgi_php_load_env_var(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg TSRMLS_DC) +static void cgi_php_load_env_var(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg) { - zval *array_ptr = (zval*)arg; - int filter_arg = (array_ptr == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER; - unsigned int new_val_len; + zval *array_ptr = (zval*)arg; + int filter_arg = (Z_ARR_P(array_ptr) == Z_ARR(PG(http_globals)[TRACK_VARS_ENV]))?PARSE_ENV:PARSE_SERVER; + size_t new_val_len; - if (sapi_module.input_filter(filter_arg, var, &val, strlen(val), &new_val_len TSRMLS_CC)) { - php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC); + if (sapi_module.input_filter(filter_arg, var, &val, strlen(val), &new_val_len)) { + php_register_variable_safe(var, val, new_val_len, array_ptr); } } -static void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC) +static void cgi_php_import_environment_variables(zval *array_ptr) { - if (PG(http_globals)[TRACK_VARS_ENV] && - array_ptr != PG(http_globals)[TRACK_VARS_ENV] && - Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY && - zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0 + if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY && + Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV]) && + zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_ENV])) > 0 ) { zval_dtor(array_ptr); - *array_ptr = *PG(http_globals)[TRACK_VARS_ENV]; - INIT_PZVAL(array_ptr); - zval_copy_ctor(array_ptr); + ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_ENV]); return; - } else if (PG(http_globals)[TRACK_VARS_SERVER] && - array_ptr != PG(http_globals)[TRACK_VARS_SERVER] && - Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY && - zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0 + } else if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY && + Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_SERVER]) && + zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])) > 0 ) { zval_dtor(array_ptr); - *array_ptr = *PG(http_globals)[TRACK_VARS_SERVER]; - INIT_PZVAL(array_ptr); - zval_copy_ctor(array_ptr); + ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_SERVER]); return; } /* call php's original import as a catch-all */ - php_php_import_environment_variables(array_ptr TSRMLS_CC); + php_php_import_environment_variables(array_ptr); if (fcgi_is_fastcgi()) { fcgi_request *request = (fcgi_request*) SG(server_context); - fcgi_loadenv(request, cgi_php_load_env_var, array_ptr TSRMLS_CC); + fcgi_loadenv(request, cgi_php_load_env_var, array_ptr); } } -static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_cgi_register_variables(zval *track_vars_array) { - unsigned int php_self_len; + size_t php_self_len; char *php_self; /* In CGI mode, we consider the environment to be a part of the server * variables */ - php_import_environment_variables(track_vars_array TSRMLS_CC); + php_import_environment_variables(track_vars_array); if (CGIG(fix_pathinfo)) { char *script_name = SG(request_info).request_uri; @@ -685,10 +651,10 @@ static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) } if (path_info) { - unsigned int path_info_len = strlen(path_info); + size_t path_info_len = strlen(path_info); if (script_name) { - unsigned int script_name_len = strlen(script_name); + size_t script_name_len = strlen(script_name); php_self_len = script_name_len + path_info_len; php_self = do_alloca(php_self_len + 1, use_heap); @@ -711,8 +677,8 @@ static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) } /* Build the special-case PHP_SELF variable for the CGI version */ - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len TSRMLS_CC)) { - php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len)) { + php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array); } if (free_php_self) { free_alloca(php_self, use_heap); @@ -720,25 +686,25 @@ static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) } else { php_self = SG(request_info).request_uri ? SG(request_info).request_uri : ""; php_self_len = strlen(php_self); - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len TSRMLS_CC)) { - php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len)) { + php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array); } } } -static void sapi_cgi_log_message(char *message TSRMLS_DC) +static void sapi_cgi_log_message(char *message) { if (fcgi_is_fastcgi() && CGIG(fcgi_logging)) { fcgi_request *request; request = (fcgi_request*) SG(server_context); if (request) { - int ret, len = strlen(message); + int ret, len = (int)strlen(message); char *buf = malloc(len+2); memcpy(buf, message, len); memcpy(buf + len, "\n", sizeof("\n")); - ret = fcgi_write(request, FCGI_STDERR, buf, len + 1); + ret = fcgi_write(request, FCGI_STDERR, buf, (int)(len + 1)); free(buf); if (ret < 0) { php_handle_aborted_connection(); @@ -754,34 +720,33 @@ static void sapi_cgi_log_message(char *message TSRMLS_DC) /* {{{ php_cgi_ini_activate_user_config */ -static void php_cgi_ini_activate_user_config(char *path, int path_len, const char *doc_root, int doc_root_len, int start TSRMLS_DC) +static void php_cgi_ini_activate_user_config(char *path, size_t path_len, const char *doc_root, size_t doc_root_len, int start) { char *ptr; user_config_cache_entry *new_entry, *entry; - time_t request_time = sapi_get_request_time(TSRMLS_C); + time_t request_time = (time_t)sapi_get_request_time(); /* Find cached config entry: If not found, create one */ - if (zend_hash_find(&CGIG(user_config_cache), path, path_len + 1, (void **) &entry) == FAILURE) { + if ((entry = zend_hash_str_find_ptr(&CGIG(user_config_cache), path, path_len)) == NULL) { new_entry = pemalloc(sizeof(user_config_cache_entry), 1); new_entry->expires = 0; new_entry->user_config = (HashTable *) pemalloc(sizeof(HashTable), 1); - zend_hash_init(new_entry->user_config, 0, NULL, (dtor_func_t) config_zval_dtor, 1); - zend_hash_update(&CGIG(user_config_cache), path, path_len + 1, new_entry, sizeof(user_config_cache_entry), (void **) &entry); - free(new_entry); + zend_hash_init(new_entry->user_config, 8, NULL, (dtor_func_t) config_zval_dtor, 1); + entry = zend_hash_str_update_ptr(&CGIG(user_config_cache), path, path_len, new_entry); } /* Check whether cache entry has expired and rescan if it is */ if (request_time > entry->expires) { char *real_path = NULL; - int real_path_len; + size_t real_path_len; char *s1, *s2; - int s_len; + size_t s_len; /* Clear the expired config */ zend_hash_clean(entry->user_config); if (!IS_ABSOLUTE_PATH(path, path_len)) { - real_path = tsrm_realpath(path, NULL TSRMLS_CC); + real_path = tsrm_realpath(path, NULL); if (real_path == NULL) { return; } @@ -801,23 +766,23 @@ static void php_cgi_ini_activate_user_config(char *path, int path_len, const cha } /* we have to test if path is part of DOCUMENT_ROOT. - if it is inside the docroot, we scan the tree up to the docroot + if it is inside the docroot, we scan the tree up to the docroot to find more user.ini, if not we only scan the current path. */ #ifdef PHP_WIN32 if (strnicmp(s1, s2, s_len) == 0) { -#else +#else if (strncmp(s1, s2, s_len) == 0) { #endif ptr = s2 + start; /* start is the point where doc_root ends! */ while ((ptr = strchr(ptr, DEFAULT_SLASH)) != NULL) { *ptr = 0; - php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config TSRMLS_CC); + php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config); *ptr = '/'; ptr++; } } else { - php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config TSRMLS_CC); + php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config); } if (real_path) { @@ -827,14 +792,14 @@ static void php_cgi_ini_activate_user_config(char *path, int path_len, const cha } /* Activate ini entries with values from the user config hash */ - php_ini_activate_config(entry->user_config, PHP_INI_PERDIR, PHP_INI_STAGE_HTACCESS TSRMLS_CC); + php_ini_activate_config(entry->user_config, PHP_INI_PERDIR, PHP_INI_STAGE_HTACCESS); } /* }}} */ -static int sapi_cgi_activate(TSRMLS_D) +static int sapi_cgi_activate(void) { char *path, *doc_root, *server_name; - uint path_len, doc_root_len, server_name_len; + size_t path_len, doc_root_len, server_name_len; /* PATH_TRANSLATED should be defined at this stage but better safe than sorry :) */ if (!SG(request_info).path_translated) { @@ -855,7 +820,7 @@ static int sapi_cgi_activate(TSRMLS_D) server_name_len = strlen(server_name); server_name = estrndup(server_name, server_name_len); zend_str_tolower(server_name, server_name_len); - php_ini_activate_per_host_config(server_name, server_name_len + 1 TSRMLS_CC); + php_ini_activate_per_host_config(server_name, server_name_len); efree(server_name); } } @@ -879,7 +844,7 @@ static int sapi_cgi_activate(TSRMLS_D) path[path_len] = 0; /* Activate per-dir-system-configuration defined in php.ini and stored into configuration_hash during startup */ - php_ini_activate_per_dir_config(path, path_len TSRMLS_CC); /* Note: for global settings sake we check from root to path */ + php_ini_activate_per_dir_config(path, path_len); /* Note: for global settings sake we check from root to path */ /* Load and activate user ini files in path starting from DOCUMENT_ROOT */ if (PG(user_ini_filename) && *PG(user_ini_filename)) { @@ -901,8 +866,8 @@ static int sapi_cgi_activate(TSRMLS_D) doc_root = estrndup(doc_root, doc_root_len); zend_str_tolower(doc_root, doc_root_len); #endif - php_cgi_ini_activate_user_config(path, path_len, doc_root, doc_root_len, doc_root_len - 1 TSRMLS_CC); - + php_cgi_ini_activate_user_config(path, path_len, doc_root, doc_root_len, (doc_root_len > 0 && (doc_root_len - 1))); + #ifdef PHP_WIN32 efree(doc_root); #endif @@ -915,7 +880,7 @@ static int sapi_cgi_activate(TSRMLS_D) return SUCCESS; } -static int sapi_cgi_deactivate(TSRMLS_D) +static int sapi_cgi_deactivate(void) { /* flush only when SAPI was started. The reasons are: 1. SAPI Deactivate is called from two places: module init and request shutdown @@ -1052,7 +1017,7 @@ static int is_valid_path(const char *path) p++; if (UNEXPECTED(!*p) || UNEXPECTED(IS_SLASH(*p))) { return 0; - } + } } } } @@ -1138,7 +1103,7 @@ static int is_valid_path(const char *path) Comments in the code below refer to using the above URL in a request */ -static void init_request_info(fcgi_request *request TSRMLS_DC) +static void init_request_info(fcgi_request *request) { char *env_script_filename = CGI_GETENV("SCRIPT_FILENAME"); char *env_path_translated = CGI_GETENV("PATH_TRANSLATED"); @@ -1192,7 +1157,7 @@ static void init_request_info(fcgi_request *request TSRMLS_DC) #endif if (CGIG(fix_pathinfo)) { - struct stat st; + zend_stat_t st; char *real_path = NULL; char *env_redirect_url = CGI_GETENV("REDIRECT_URL"); char *env_document_root = CGI_GETENV("DOCUMENT_ROOT"); @@ -1200,7 +1165,7 @@ static void init_request_info(fcgi_request *request TSRMLS_DC) char *orig_path_info = env_path_info; char *orig_script_name = env_script_name; char *orig_script_filename = env_script_filename; - int script_path_translated_len; + size_t script_path_translated_len; if (!env_document_root && PG(doc_root)) { env_document_root = CGI_PUTENV("DOCUMENT_ROOT", PG(doc_root)); @@ -1238,15 +1203,15 @@ static void init_request_info(fcgi_request *request TSRMLS_DC) #ifdef PHP_WIN32 script_path_translated[script_path_translated_len-1] == '\\' || #endif - (real_path = tsrm_realpath(script_path_translated, NULL TSRMLS_CC)) == NULL) + (real_path = tsrm_realpath(script_path_translated, NULL)) == NULL) ) { char *pt = estrndup(script_path_translated, script_path_translated_len); - int len = script_path_translated_len; + size_t len = script_path_translated_len; char *ptr; while ((ptr = strrchr(pt, '/')) || (ptr = strrchr(pt, '\\'))) { *ptr = 0; - if (stat(pt, &st) == 0 && S_ISREG(st.st_mode)) { + if (zend_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; @@ -1262,8 +1227,8 @@ static void init_request_info(fcgi_request *request TSRMLS_DC) * we have to play the game of hide and seek to figure * out what SCRIPT_NAME should be */ - int slen = len - strlen(pt); - int pilen = env_path_info ? strlen(env_path_info) : 0; + size_t slen = len - strlen(pt); + size_t pilen = env_path_info ? strlen(env_path_info) : 0; char *path_info = env_path_info ? env_path_info + pilen - slen : NULL; if (orig_path_info != path_info) { @@ -1299,8 +1264,8 @@ static void init_request_info(fcgi_request *request TSRMLS_DC) * SCRIPT_FILENAME minus SCRIPT_NAME */ if (env_document_root) { - int l = strlen(env_document_root); - int path_translated_len = 0; + size_t l = strlen(env_document_root); + size_t path_translated_len = 0; char *path_translated = NULL; if (l && env_document_root[l - 1] == '/') { @@ -1329,8 +1294,8 @@ static void init_request_info(fcgi_request *request TSRMLS_DC) strstr(pt, env_script_name) ) { /* PATH_TRANSLATED = PATH_TRANSLATED - SCRIPT_NAME + PATH_INFO */ - int ptlen = strlen(pt) - strlen(env_script_name); - int path_translated_len = ptlen + (env_path_info ? strlen(env_path_info) : 0); + size_t ptlen = strlen(pt) - strlen(env_script_name); + size_t path_translated_len = ptlen + (env_path_info ? strlen(env_path_info) : 0); char *path_translated = NULL; path_translated = (char *) emalloc(path_translated_len + 1); @@ -1428,7 +1393,7 @@ static void init_request_info(fcgi_request *request TSRMLS_DC) /* The CGI RFC allows servers to pass on unvalidated Authorization data */ auth = CGI_GETENV("HTTP_AUTHORIZATION"); - php_handle_auth_data(auth TSRMLS_CC); + php_handle_auth_data(auth); } } /* }}} */ @@ -1472,8 +1437,11 @@ PHP_INI_END() /* {{{ php_cgi_globals_ctor */ -static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals TSRMLS_DC) +static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals) { +#ifdef ZTS + ZEND_TSRMLS_CACHE_UPDATE; +#endif php_cgi_globals->rfc2616_headers = 0; php_cgi_globals->nph = 0; php_cgi_globals->check_shebang_line = 1; @@ -1485,7 +1453,7 @@ static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals TSRMLS_ #ifdef PHP_WIN32 php_cgi_globals->impersonate = 0; #endif - zend_hash_init(&php_cgi_globals->user_config_cache, 0, NULL, (dtor_func_t) user_config_cache_entry_dtor, 1); + zend_hash_init(&php_cgi_globals->user_config_cache, 8, NULL, user_config_cache_entry_dtor, 1); } /* }}} */ @@ -1496,7 +1464,7 @@ static PHP_MINIT_FUNCTION(cgi) #ifdef ZTS ts_allocate_id(&php_cgi_globals_id, sizeof(php_cgi_globals_struct), (ts_allocate_ctor) php_cgi_globals_ctor, NULL); #else - php_cgi_globals_ctor(&php_cgi_globals TSRMLS_CC); + php_cgi_globals_ctor(&php_cgi_globals); #endif REGISTER_INI_ENTRIES(); return SUCCESS; @@ -1533,7 +1501,7 @@ PHP_FUNCTION(apache_child_terminate) /* {{{ */ } /* }}} */ -static void add_request_header(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg TSRMLS_DC) /* {{{ */ +static void add_request_header(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg) /* {{{ */ { zval *return_value = (zval*)arg; char *str = NULL; @@ -1574,7 +1542,7 @@ static void add_request_header(char *var, unsigned int var_len, char *val, unsig } else { return; } - add_assoc_stringl_ex(return_value, var, var_len+1, val, val_len, 1); + add_assoc_stringl_ex(return_value, var, var_len+1, val, val_len); if (str) { free_alloca(var, use_heap); } @@ -1590,12 +1558,12 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ if (fcgi_is_fastcgi()) { fcgi_request *request = (fcgi_request*) SG(server_context); - fcgi_loadenv(request, add_request_header, return_value TSRMLS_CC); + fcgi_loadenv(request, add_request_header, return_value); } else { char buf[128]; char **env, *p, *q, *var, *val, *t = buf; size_t alloc_size = sizeof(buf); - unsigned long var_len; + zend_ulong var_len; for (env = environ; env != NULL && *env != NULL; env++) { val = strchr(*env, '='); @@ -1655,7 +1623,7 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ continue; } val++; - add_assoc_string_ex(return_value, var, var_len+1, val, 1); + add_assoc_string_ex(return_value, var, var_len, val); } if (t != buf && t != NULL) { efree(t); @@ -1664,10 +1632,10 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ } /* }}} */ -static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS_DC) /* {{{ */ +static void add_response_header(sapi_header_struct *h, zval *return_value) /* {{{ */ { char *s, *p; - int len = 0; + size_t len = 0; ALLOCA_FLAG(use_heap) if (h->header_len > 0) { @@ -1676,9 +1644,9 @@ static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS len = p - h->header; } if (len > 0) { - while (len > 0 && (h->header[len-1] == ' ' || h->header[len-1] == '\t')) { + do { len--; - } + } while (len != 0 && (h->header[len-1] == ' ' || h->header[len-1] == '\t')); if (len) { s = do_alloca(len + 1, use_heap); memcpy(s, h->header, len); @@ -1686,7 +1654,7 @@ static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS do { p++; } while (*p == ' ' || *p == '\t'); - add_assoc_stringl_ex(return_value, s, len+1, p, h->header_len - (p - h->header), 1); + add_assoc_stringl_ex(return_value, s, len, p, h->header_len - (p - h->header)); free_alloca(s, use_heap); } } @@ -1704,7 +1672,7 @@ PHP_FUNCTION(apache_response_headers) /* {{{ */ RETURN_FALSE; } array_init(return_value); - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t)add_response_header, return_value TSRMLS_CC); + zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t)add_response_header, return_value); } /* }}} */ @@ -1738,7 +1706,8 @@ int main(int argc, char *argv[]) { int free_query_string = 0; int exit_status = SUCCESS; - int cgi = 0, c, i, len; + int cgi = 0, c, i; + size_t len; zend_file_handle file_handle; char *s; @@ -1748,7 +1717,7 @@ int main(int argc, char *argv[]) int orig_optind = php_optind; char *orig_optarg = php_optarg; char *script_file = NULL; - int ini_entries_len = 0; + size_t ini_entries_len = 0; /* end of temporary locals */ #ifdef ZTS @@ -1761,6 +1730,7 @@ int main(int argc, char *argv[]) char *bindpath = NULL; int fcgi_fd = 0; fcgi_request *request = NULL; + int warmup_repeats = 0; int repeats = 1; int benchmark = 0; #if HAVE_GETTIMEOFDAY @@ -1799,6 +1769,7 @@ int main(int argc, char *argv[]) #ifdef ZTS tsrm_startup(1, 1, 0, NULL); tsrm_ls = ts_resource(0); + ZEND_TSRMLS_CACHE_UPDATE; #endif sapi_startup(&cgi_sapi_module); @@ -1851,7 +1822,7 @@ int main(int argc, char *argv[]) break; case 'd': { /* define ini entries on command line */ - int len = strlen(php_optarg); + size_t len = strlen(php_optarg); char *val; if ((val = strchr(php_optarg, '='))) { @@ -2104,7 +2075,15 @@ consult the installation file that came with this distribution, or visit \n\ switch (c) { case 'T': benchmark = 1; - repeats = atoi(php_optarg); + { + char *comma = strchr(php_optarg, ','); + if (comma) { + warmup_repeats = atoi(php_optarg); + repeats = atoi(comma + 1); + } else { + repeats = atoi(php_optarg); + } + } #ifdef HAVE_GETTIMEOFDAY gettimeofday(&start, NULL); #else @@ -2120,7 +2099,7 @@ consult the installation file that came with this distribution, or visit \n\ no_headers = 1; SG(headers_sent) = 1; php_cgi_usage(argv[0]); - php_output_end_all(TSRMLS_C); + php_output_end_all(); exit_status = 0; goto out; } @@ -2139,8 +2118,7 @@ consult the installation file that came with this distribution, or visit \n\ #endif while (!fastcgi || fcgi_accept_request(request) >= 0) { SG(server_context) = fastcgi ? (void *) request : (void *) 1; - init_request_info(request TSRMLS_CC); - CG(interactive) = 0; + init_request_info(request); if (!cgi && !fastcgi) { while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { @@ -2148,7 +2126,6 @@ consult the installation file that came with this distribution, or visit \n\ case 'a': /* interactive mode */ printf("Interactive mode enabled\n\n"); - CG(interactive) = 1; break; case 'C': /* don't chdir to the script directory */ @@ -2171,16 +2148,16 @@ consult the installation file that came with this distribution, or visit \n\ if (script_file) { efree(script_file); } - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { SG(server_context) = NULL; - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); return FAILURE; } if (no_headers) { SG(headers_sent) = 1; SG(request_info).no_headers = 1; } - php_print_info(0xFFFFFFFF TSRMLS_CC); + php_print_info(0xFFFFFFFF); php_request_shutdown((void *) 0); fcgi_shutdown(); exit_status = 0; @@ -2197,11 +2174,11 @@ consult the installation file that came with this distribution, or visit \n\ } SG(headers_sent) = 1; php_printf("[PHP Modules]\n"); - print_modules(TSRMLS_C); + print_modules(); php_printf("\n[Zend Modules]\n"); - print_extensions(TSRMLS_C); + print_extensions(); php_printf("\n"); - php_output_end_all(TSRMLS_C); + php_output_end_all(); fcgi_shutdown(); exit_status = 0; goto out; @@ -2221,9 +2198,9 @@ consult the installation file that came with this distribution, or visit \n\ efree(script_file); } no_headers = 1; - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { SG(server_context) = NULL; - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); return FAILURE; } if (no_headers) { @@ -2255,7 +2232,7 @@ consult the installation file that came with this distribution, or visit \n\ if (script_file) { /* override path_translated if -f on command line */ - STR_FREE(SG(request_info).path_translated); + if (SG(request_info).path_translated) efree(SG(request_info).path_translated); SG(request_info).path_translated = script_file; /* before registering argv to module exchange the *new* argv[0] */ /* we can achieve this without allocating more memory */ @@ -2264,7 +2241,7 @@ consult the installation file that came with this distribution, or visit \n\ SG(request_info).argv[0] = script_file; } else if (argc > php_optind) { /* file is on command line, but not in -f opt */ - STR_FREE(SG(request_info).path_translated); + if (SG(request_info).path_translated) efree(SG(request_info).path_translated); SG(request_info).path_translated = estrdup(argv[php_optind]); /* arguments after the file are considered script args */ SG(request_info).argc = argc - php_optind; @@ -2286,7 +2263,7 @@ consult the installation file that came with this distribution, or visit \n\ * test.php v1=test "v2=hello world!" */ if (!SG(request_info).query_string && argc > php_optind) { - int slen = strlen(PG(arg_separator).input); + size_t slen = strlen(PG(arg_separator).input); len = 0; for (i = php_optind; i < argc; i++) { if (i < (argc - 1)) { @@ -2330,12 +2307,12 @@ consult the installation file that came with this distribution, or visit \n\ /* request startup only after we've done all we can to * get path_translated */ - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { if (fastcgi) { fcgi_finish_request(request, 1); } SG(server_context) = NULL; - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); return FAILURE; } if (no_headers) { @@ -2349,7 +2326,7 @@ consult the installation file that came with this distribution, or visit \n\ 2. we are running as cgi or fastcgi */ if (cgi || fastcgi || SG(request_info).path_translated) { - if (php_fopen_primary_script(&file_handle TSRMLS_CC) == FAILURE) { + if (php_fopen_primary_script(&file_handle) == FAILURE) { zend_try { if (errno == EACCES) { SG(sapi_headers).http_response_code = 403; @@ -2367,7 +2344,7 @@ consult the installation file that came with this distribution, or visit \n\ goto fastcgi_request_done; } - STR_FREE(SG(request_info).path_translated); + if (SG(request_info).path_translated) efree(SG(request_info).path_translated); if (free_query_string && SG(request_info).query_string) { free(SG(request_info).query_string); @@ -2376,7 +2353,7 @@ consult the installation file that came with this distribution, or visit \n\ php_request_shutdown((void *) 0); SG(server_context) = NULL; - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); sapi_shutdown(); #ifdef ZTS tsrm_shutdown(); @@ -2408,8 +2385,8 @@ consult the installation file that came with this distribution, or visit \n\ /* handle situations where line is terminated by \r\n */ if (c == '\r') { if (fgetc(file_handle.handle.fp) != '\n') { - long pos = ftell(file_handle.handle.fp); - fseek(file_handle.handle.fp, pos - 1, SEEK_SET); + zend_long pos = zend_ftell(file_handle.handle.fp); + zend_fseek(file_handle.handle.fp, pos - 1, SEEK_SET); } } CG(start_lineno) = 2; @@ -2426,7 +2403,7 @@ consult the installation file that came with this distribution, or visit \n\ /* handle situations where line is terminated by \r\n */ if (c == '\r') { if (php_stream_getc((php_stream*)file_handle.handle.stream.handle) != '\n') { - long pos = php_stream_tell((php_stream*)file_handle.handle.stream.handle); + zend_off_t pos = php_stream_tell((php_stream*)file_handle.handle.stream.handle); php_stream_seek((php_stream*)file_handle.handle.stream.handle, pos - 1, SEEK_SET); } } @@ -2437,7 +2414,7 @@ consult the installation file that came with this distribution, or visit \n\ break; case ZEND_HANDLE_MAPPED: if (file_handle.handle.stream.mmap.buf[0] == '#') { - int i = 1; + size_t i = 1; c = file_handle.handle.stream.mmap.buf[i++]; while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) { @@ -2462,11 +2439,11 @@ consult the installation file that came with this distribution, or visit \n\ switch (behavior) { case PHP_MODE_STANDARD: - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); break; case PHP_MODE_LINT: PG(during_request_startup) = 0; - exit_status = php_lint_script(&file_handle TSRMLS_CC); + exit_status = php_lint_script(&file_handle); if (exit_status == SUCCESS) { zend_printf("No syntax errors detected in %s\n", file_handle.filename); } else { @@ -2474,9 +2451,9 @@ consult the installation file that came with this distribution, or visit \n\ } break; case PHP_MODE_STRIP: - if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) { - zend_strip(TSRMLS_C); - zend_file_handle_dtor(&file_handle TSRMLS_CC); + if (open_file_for_scanning(&file_handle) == SUCCESS) { + zend_strip(); + zend_file_handle_dtor(&file_handle); php_output_teardown(); } return SUCCESS; @@ -2485,13 +2462,13 @@ consult the installation file that came with this distribution, or visit \n\ { zend_syntax_highlighter_ini syntax_highlighter_ini; - if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) { + if (open_file_for_scanning(&file_handle) == SUCCESS) { php_get_highlight_struct(&syntax_highlighter_ini); - zend_highlight(&syntax_highlighter_ini TSRMLS_CC); + zend_highlight(&syntax_highlighter_ini); if (fastcgi) { goto fastcgi_request_done; } - zend_file_handle_dtor(&file_handle TSRMLS_CC); + zend_file_handle_dtor(&file_handle); php_output_teardown(); } return SUCCESS; @@ -2500,9 +2477,9 @@ consult the installation file that came with this distribution, or visit \n\ #if 0 /* Zeev might want to do something with this one day */ case PHP_MODE_INDENT: - open_file_for_scanning(&file_handle TSRMLS_CC); + open_file_for_scanning(&file_handle); zend_indent(); - zend_file_handle_dtor(&file_handle TSRMLS_CC); + zend_file_handle_dtor(&file_handle); php_output_teardown(); return SUCCESS; break; @@ -2511,7 +2488,7 @@ consult the installation file that came with this distribution, or visit \n\ fastcgi_request_done: { - STR_FREE(SG(request_info).path_translated); + if (SG(request_info).path_translated) efree(SG(request_info).path_translated); php_request_shutdown((void *) 0); @@ -2527,12 +2504,24 @@ fastcgi_request_done: if (!fastcgi) { if (benchmark) { - repeats--; - if (repeats > 0) { - script_file = NULL; - php_optind = orig_optind; - php_optarg = orig_optarg; + if (warmup_repeats) { + warmup_repeats--; + if (!warmup_repeats) { +#ifdef HAVE_GETTIMEOFDAY + gettimeofday(&start, NULL); +#else + time(&start); +#endif + } continue; + } else { + repeats--; + if (repeats > 0) { + script_file = NULL; + php_optind = orig_optind; + php_optarg = orig_optarg; + continue; + } } } break; @@ -2595,7 +2584,7 @@ parent_out: #endif SG(server_context) = NULL; - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); sapi_shutdown(); #ifdef ZTS diff --git a/sapi/cgi/config.w32 b/sapi/cgi/config.w32 index 8d1d431da4..daf4f05687 100644 --- a/sapi/cgi/config.w32 +++ b/sapi/cgi/config.w32 @@ -4,7 +4,7 @@ ARG_ENABLE('cgi', 'Build CGI version of PHP', 'yes'); if (PHP_CGI == "yes") { - ADD_FLAG("LDFLAGS_CGI", "/stack:8388608"); - SAPI('cgi', 'cgi_main.c fastcgi.c', 'php-cgi.exe'); + ADD_FLAG("LDFLAGS_CGI", "/stack:67108864"); + SAPI('cgi', 'cgi_main.c fastcgi.c', 'php-cgi.exe', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); ADD_FLAG('LIBS_CGI', 'ws2_32.lib kernel32.lib advapi32.lib'); } diff --git a/sapi/cgi/config9.m4 b/sapi/cgi/config9.m4 index 49e61c83c3..a005f8e0ad 100644 --- a/sapi/cgi/config9.m4 +++ b/sapi/cgi/config9.m4 @@ -50,7 +50,7 @@ if test "$PHP_CGI" != "no"; then esac dnl Select SAPI - PHP_SELECT_SAPI(cgi, program, cgi_main.c fastcgi.c,, '$(SAPI_CGI_PATH)') + PHP_SELECT_SAPI(cgi, program, cgi_main.c fastcgi.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1, '$(SAPI_CGI_PATH)') case $host_alias in *aix*) diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c index b79fbfac4b..7d6fd649ea 100644 --- a/sapi/cgi/fastcgi.c +++ b/sapi/cgi/fastcgi.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -19,6 +19,7 @@ /* $Id$ */ #include "php.h" +#include "php_network.h" #include "fastcgi.h" #include <string.h> @@ -76,8 +77,6 @@ # include <netdb.h> # include <signal.h> -# define closesocket(s) close(s) - # if defined(HAVE_SYS_POLL_H) && defined(HAVE_POLL) # include <sys/poll.h> # endif @@ -248,7 +247,7 @@ static inline char* fcgi_hash_strndup(fcgi_hash *h, char *str, unsigned int str_ p->next = h->data; h->data = p; } - ret = h->data->pos; + ret = h->data->pos; memcpy(ret, str, str_len); ret[str_len] = 0; h->data->pos += str_len + 1; @@ -328,13 +327,13 @@ static char *fcgi_hash_get(fcgi_hash *h, unsigned int hash_value, char *var, uns return NULL; } -static void fcgi_hash_apply(fcgi_hash *h, fcgi_apply_func func, void *arg TSRMLS_DC) +static void fcgi_hash_apply(fcgi_hash *h, fcgi_apply_func func, void *arg) { fcgi_hash_bucket *p = h->list; while (p) { if (EXPECTED(p->val != NULL)) { - func(p->var, p->var_len, p->val, p->val_len, arg TSRMLS_CC); + func(p->var, p->var_len, p->val, p->val_len, arg); } p = p->list_next; } @@ -415,7 +414,7 @@ int fcgi_init(void) sa_t sa; socklen_t len = sizeof(sa); #endif - zend_hash_init(&fcgi_mgmt_vars, 0, NULL, fcgi_free_mgmt_var_cb, 1); + zend_hash_init(&fcgi_mgmt_vars, 8, NULL, fcgi_free_mgmt_var_cb, 1); fcgi_set_mgmt_var("FCGI_MPXS_CONNS", sizeof("FCGI_MPXS_CONNS")-1, "0", sizeof("0")-1); is_initialized = 1; @@ -440,7 +439,11 @@ int fcgi_init(void) str = getenv("_FCGI_SHUTDOWN_EVENT_"); if (str != NULL) { - HANDLE shutdown_event = (HANDLE) atoi(str); + zend_long ev; + HANDLE shutdown_event; + + ZEND_ATOL(ev, str); + shutdown_event = (HANDLE) ev; if (!CreateThread(NULL, 0, fcgi_shutdown_thread, shutdown_event, 0, NULL)) { return -1; @@ -448,7 +451,9 @@ int fcgi_init(void) } str = getenv("_FCGI_MUTEX_"); if (str != NULL) { - fcgi_accept_mutex = (HANDLE) atoi(str); + zend_long mt; + ZEND_ATOL(mt, str); + fcgi_accept_mutex = (HANDLE) mt; } return is_fastcgi = 1; } else { @@ -650,7 +655,7 @@ int fcgi_listen(const char *path, int backlog) if (namedPipe == INVALID_HANDLE_VALUE) { return -1; } - listen_socket = _open_osfhandle((long)namedPipe, 0); + listen_socket = _open_osfhandle((intptr_t)namedPipe, 0); if (!is_initialized) { fcgi_init(); } @@ -731,7 +736,7 @@ int fcgi_listen(const char *path, int backlog) #ifdef _WIN32 if (tcp) { - listen_socket = _open_osfhandle((long)listen_socket, 0); + listen_socket = _open_osfhandle((intptr_t)listen_socket, 0); } #else fcgi_setup_signals(); @@ -777,12 +782,21 @@ static inline ssize_t safe_write(fcgi_request *req, const void *buf, size_t coun size_t n = 0; do { +#ifdef _WIN32 + size_t tmp; +#endif errno = 0; #ifdef _WIN32 + tmp = count - n; + if (!req->tcp) { - ret = write(req->fd, ((char*)buf)+n, count-n); + unsigned int out_len = tmp > UINT_MAX ? UINT_MAX : (unsigned int)tmp; + + ret = write(req->fd, ((char*)buf)+n, out_len); } else { - ret = send(req->fd, ((char*)buf)+n, count-n, 0); + int out_len = tmp > INT_MAX ? INT_MAX : (int)tmp; + + ret = send(req->fd, ((char*)buf)+n, out_len, 0); if (ret <= 0) { errno = WSAGetLastError(); } @@ -805,12 +819,21 @@ static inline ssize_t safe_read(fcgi_request *req, const void *buf, size_t count size_t n = 0; do { +#ifdef _WIN32 + size_t tmp; +#endif errno = 0; #ifdef _WIN32 + tmp = count - n; + if (!req->tcp) { - ret = read(req->fd, ((char*)buf)+n, count-n); + unsigned int in_len = tmp > UINT_MAX ? UINT_MAX : (unsigned int)tmp; + + ret = read(req->fd, ((char*)buf)+n, in_len); } else { - ret = recv(req->fd, ((char*)buf)+n, count-n, 0); + int in_len = tmp > INT_MAX ? INT_MAX : (int)tmp; + + ret = recv(req->fd, ((char*)buf)+n, in_len, 0); if (ret <= 0) { errno = WSAGetLastError(); } @@ -981,7 +1004,7 @@ static int fcgi_read_request(fcgi_request *req) } } else if (hdr.type == FCGI_GET_VALUES) { unsigned char *p = buf + sizeof(fcgi_header); - zval ** value; + zval *value; unsigned int zlen; fcgi_hash_bucket *q; @@ -997,11 +1020,11 @@ static int fcgi_read_request(fcgi_request *req) q = req->env.list; while (q != NULL) { - if (zend_hash_find(&fcgi_mgmt_vars, q->var, q->var_len, (void**) &value) != SUCCESS) { + if ((value = zend_hash_str_find(&fcgi_mgmt_vars, q->var, q->var_len)) == NULL) { q = q->list_next; continue; } - zlen = Z_STRLEN_PP(value); + zlen = (unsigned int)Z_STRLEN_P(value); if ((p + 4 + 4 + q->var_len + zlen) >= (buf + sizeof(buf))) { break; } @@ -1023,11 +1046,11 @@ static int fcgi_read_request(fcgi_request *req) } memcpy(p, q->var, q->var_len); p += q->var_len; - memcpy(p, Z_STRVAL_PP(value), zlen); + memcpy(p, Z_STRVAL_P(value), zlen); p += zlen; q = q->list_next; } - len = p - buf - sizeof(fcgi_header); + len = (int)(p - buf - sizeof(fcgi_header)); len += fcgi_make_header((fcgi_header*)buf, FCGI_GET_VALUES_RESULT, 0, len); if (safe_write(req, buf, sizeof(fcgi_header)+len) != (int)sizeof(fcgi_header)+len) { req->keep = 0; @@ -1065,9 +1088,9 @@ int fcgi_read(fcgi_request *req, char *str, int len) } if (req->in_len >= rest) { - ret = safe_read(req, str, rest); + ret = (int)safe_read(req, str, rest); } else { - ret = safe_read(req, str, req->in_len); + ret = (int)safe_read(req, str, req->in_len); } if (ret < 0) { req->keep = 0; @@ -1302,7 +1325,7 @@ static inline fcgi_header* open_packet(fcgi_request *req, fcgi_request_type type static inline void close_packet(fcgi_request *req) { if (req->out_hdr) { - int len = req->out_pos - ((unsigned char*)req->out_hdr + sizeof(fcgi_header)); + int len = (int)(req->out_pos - ((unsigned char*)req->out_hdr + sizeof(fcgi_header))); req->out_pos += fcgi_make_header(req->out_hdr, (fcgi_request_type)req->out_hdr->type, req->id, len); req->out_hdr = NULL; @@ -1315,7 +1338,7 @@ int fcgi_flush(fcgi_request *req, int close) close_packet(req); - len = req->out_pos - req->out_buf; + len = (int)(req->out_pos - req->out_buf); if (close) { fcgi_end_request_rec *rec = (fcgi_end_request_rec*)(req->out_pos); @@ -1381,7 +1404,7 @@ int fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, int l } #else /* Optimized version */ - limit = sizeof(req->out_buf) - (req->out_pos - req->out_buf); + limit = (int)(sizeof(req->out_buf) - (req->out_pos - req->out_buf)); if (!req->out_hdr) { limit -= sizeof(fcgi_header); if (limit < 0) limit = 0; @@ -1488,7 +1511,7 @@ char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val) fcgi_hash_del(&req->env, FCGI_HASH_FUNC(var, var_len), var, var_len); return NULL; } else { - return fcgi_hash_set(&req->env, FCGI_HASH_FUNC(var, var_len), var, var_len, val, strlen(val)); + return fcgi_hash_set(&req->env, FCGI_HASH_FUNC(var, var_len), var, var_len, val, (unsigned int)strlen(val)); } } @@ -1498,13 +1521,13 @@ char* fcgi_quick_putenv(fcgi_request *req, char* var, int var_len, unsigned int fcgi_hash_del(&req->env, hash_value, var, var_len); return NULL; } else { - return fcgi_hash_set(&req->env, hash_value, var, var_len, val, strlen(val)); + return fcgi_hash_set(&req->env, hash_value, var, var_len, val, (unsigned int)strlen(val)); } } -void fcgi_loadenv(fcgi_request *req, fcgi_apply_func func, zval *array TSRMLS_DC) +void fcgi_loadenv(fcgi_request *req, fcgi_apply_func func, zval *array) { - fcgi_hash_apply(&req->env, func, array TSRMLS_CC); + fcgi_hash_apply(&req->env, func, array); } #ifdef _WIN32 @@ -1521,19 +1544,14 @@ void fcgi_impersonate(void) void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len) { - zval * zvalue; - zvalue = pemalloc(sizeof(*zvalue), 1); - Z_TYPE_P(zvalue) = IS_STRING; - Z_STRVAL_P(zvalue) = pestrndup(value, value_len, 1); - Z_STRLEN_P(zvalue) = value_len; - zend_hash_add(&fcgi_mgmt_vars, name, name_len, &zvalue, sizeof(zvalue), NULL); + zval zvalue; + ZVAL_NEW_STR(&zvalue, zend_string_init(value, value_len, 1)); + zend_hash_str_add(&fcgi_mgmt_vars, name, name_len, &zvalue); } -void fcgi_free_mgmt_var_cb(void * ptr) +void fcgi_free_mgmt_var_cb(zval *zv) { - zval ** var = (zval **)ptr; - pefree(Z_STRVAL_PP(var), 1); - pefree(*var, 1); + pefree(Z_STR_P(zv), 1); } /* diff --git a/sapi/cgi/fastcgi.h b/sapi/cgi/fastcgi.h index bc3bca977e..fa98730220 100644 --- a/sapi/cgi/fastcgi.h +++ b/sapi/cgi/fastcgi.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -108,7 +108,7 @@ typedef struct _fcgi_end_request_rec { /* FastCGI client API */ -typedef void (*fcgi_apply_func)(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg TSRMLS_DC); +typedef void (*fcgi_apply_func)(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg); typedef struct _fcgi_request fcgi_request; @@ -127,7 +127,7 @@ char* fcgi_getenv(fcgi_request *req, const char* var, int var_len); char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val); char* fcgi_quick_getenv(fcgi_request *req, const char* var, int var_len, unsigned int hash_value); char* fcgi_quick_putenv(fcgi_request *req, char* var, int var_len, unsigned int hash_value, char* val); -void fcgi_loadenv(fcgi_request *req, fcgi_apply_func load_func, zval *array TSRMLS_DC); +void fcgi_loadenv(fcgi_request *req, fcgi_apply_func load_func, zval *array); int fcgi_read(fcgi_request *req, char *str, int len); @@ -139,7 +139,7 @@ void fcgi_impersonate(void); #endif void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len); -void fcgi_free_mgmt_var_cb(void * ptr); +void fcgi_free_mgmt_var_cb(zval *zv); /* * Local variables: diff --git a/sapi/cli/cli.h b/sapi/cli/cli.h index f0bad23d0b..c571eeb5c5 100644 --- a/sapi/cli/cli.h +++ b/sapi/cli/cli.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -30,12 +30,12 @@ #endif -extern PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS_DC); +extern PHP_CLI_API size_t sapi_cli_single_write(const char *str, size_t str_length); typedef struct { - size_t (*cli_shell_write)(const char *str, uint str_length TSRMLS_DC); - int (*cli_shell_ub_write)(const char *str, uint str_length TSRMLS_DC); - int (*cli_shell_run)(TSRMLS_D); + size_t (*cli_shell_write)(const char *str, size_t str_length); + size_t (*cli_shell_ub_write)(const char *str, size_t str_length); + int (*cli_shell_run)(void); } cli_shell_callbacks_t; extern PHP_CLI_API cli_shell_callbacks_t *php_cli_get_shell_callbacks(); diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4 index 9a1b98da46..c5819cd8b4 100644 --- a/sapi/cli/config.m4 +++ b/sapi/cli/config.m4 @@ -31,7 +31,7 @@ if test "$PHP_CLI" != "no"; then SAPI_CLI_PATH=sapi/cli/php dnl Select SAPI - PHP_SELECT_SAPI(cli, program, php_cli.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c,, '$(SAPI_CLI_PATH)') + PHP_SELECT_SAPI(cli, program, php_cli.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1, '$(SAPI_CLI_PATH)') case $host_alias in *aix*) @@ -45,7 +45,7 @@ if test "$PHP_CLI" != "no"; then BUILD_CLI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_BINARY_OBJS:.lo=.o) \$(PHP_CLI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)" ;; *netware*) - BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_BINARY_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -Lnetware -lphp5lib -o \$(SAPI_CLI_PATH)" + BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_BINARY_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -Lnetware -lphp7lib -o \$(SAPI_CLI_PATH)" ;; *) BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)" diff --git a/sapi/cli/config.w32 b/sapi/cli/config.w32 index adcbb2b496..664394c8a6 100644 --- a/sapi/cli/config.w32 +++ b/sapi/cli/config.w32 @@ -6,16 +6,16 @@ ARG_ENABLE('crt-debug', 'Enable CRT memory dumps for debugging sent to STDERR', ARG_ENABLE('cli-win32', 'Build console-less CLI version of PHP', 'no'); if (PHP_CLI == "yes") { - SAPI('cli', 'php_cli.c php_http_parser.c php_cli_server.c php_cli_process_title.c ps_title.c', 'php.exe'); + SAPI('cli', 'php_cli.c php_http_parser.c php_cli_server.c php_cli_process_title.c ps_title.c', 'php.exe', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); ADD_FLAG("LIBS_CLI", "ws2_32.lib"); if (PHP_CRT_DEBUG == "yes") { ADD_FLAG("CFLAGS_CLI", "/D PHP_WIN32_DEBUG_HEAP"); } - ADD_FLAG("LDFLAGS_CLI", "/stack:8388608"); + ADD_FLAG("LDFLAGS_CLI", "/stack:67108864"); } if (PHP_CLI_WIN32 == "yes") { - SAPI('cli_win32', 'cli_win32.c php_cli_process_title.c ps_title.c', 'php-win.exe'); - ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:8388608"); + SAPI('cli_win32', 'cli_win32.c php_cli_process_title.c ps_title.c', 'php-win.exe', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); + ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:67108864"); } diff --git a/sapi/cli/generate_mime_type_map.php b/sapi/cli/generate_mime_type_map.php new file mode 100644 index 0000000000..9e088814a0 --- /dev/null +++ b/sapi/cli/generate_mime_type_map.php @@ -0,0 +1,76 @@ +#!/usr/bin/env php +<?php + +// Check if we are being given a mime.types file or if we should use the +// default URL. +$source = count($_SERVER['argv']) > 1 ? $_SERVER['argv'][1] : 'https://raw.githubusercontent.com/apache/httpd/trunk/docs/conf/mime.types'; + +// See if we can actually load it. +$types = @file($source); +if ($types === false) { + fprintf(STDERR, "Error: unable to read $source\n"); + exit(1); +} + +// Remove comments and flip into an extensions array. +$extensions = []; +array_walk($types, function ($line) use (&$extensions) { + $line = trim($line); + if ($line && $line[0] != '#') { + $fields = preg_split('/\s+/', $line); + if (count($fields) > 1) { + $mime = array_shift($fields); + foreach ($fields as $extension) { + $extensions[$extension] = $mime; + } + } + } +}); + +?> +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 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: Moriyoshi Koizumi <moriyoshi@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* This is a generated file. Rather than modifying it, please run + * "php generate_mime_type_map.php > mime_type_map.h" to regenerate the file. */ + +#ifndef PHP_CLI_SERVER_MIME_TYPE_MAP_H +#define PHP_CLI_SERVER_MIME_TYPE_MAP_H + +typedef struct php_cli_server_ext_mime_type_pair { + const char *ext; + const char *mime_type; +} php_cli_server_ext_mime_type_pair; + +static php_cli_server_ext_mime_type_pair mime_type_map[] = { +<?php foreach ($extensions as $extension => $mime): ?> + { "<?= addcslashes($extension, "\0..\37!@\@\177..\377") ?>", "<?= addcslashes($mime, "\0..\37!@\@\177..\377") ?>" }, +<?php endforeach ?> + { NULL, NULL } +}; + +#endif /* PHP_CLI_SERVER_MIME_TYPE_MAP_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/sapi/cli/mime_type_map.h b/sapi/cli/mime_type_map.h new file mode 100644 index 0000000000..e82fc3fd7f --- /dev/null +++ b/sapi/cli/mime_type_map.h @@ -0,0 +1,1024 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 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: Moriyoshi Koizumi <moriyoshi@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* This is a generated file. Rather than modifying it, please run + * "php generate_mime_type_map.php > mime_type_map.h" to regenerate the file. */ + +#ifndef PHP_CLI_SERVER_MIME_TYPE_MAP_H +#define PHP_CLI_SERVER_MIME_TYPE_MAP_H + +typedef struct php_cli_server_ext_mime_type_pair { + const char *ext; + const char *mime_type; +} php_cli_server_ext_mime_type_pair; + +static php_cli_server_ext_mime_type_pair mime_type_map[] = { + { "ez", "application/andrew-inset" }, + { "aw", "application/applixware" }, + { "atom", "application/atom+xml" }, + { "atomcat", "application/atomcat+xml" }, + { "atomsvc", "application/atomsvc+xml" }, + { "ccxml", "application/ccxml+xml" }, + { "cdmia", "application/cdmi-capability" }, + { "cdmic", "application/cdmi-container" }, + { "cdmid", "application/cdmi-domain" }, + { "cdmio", "application/cdmi-object" }, + { "cdmiq", "application/cdmi-queue" }, + { "cu", "application/cu-seeme" }, + { "davmount", "application/davmount+xml" }, + { "dbk", "application/docbook+xml" }, + { "dssc", "application/dssc+der" }, + { "xdssc", "application/dssc+xml" }, + { "ecma", "application/ecmascript" }, + { "emma", "application/emma+xml" }, + { "epub", "application/epub+zip" }, + { "exi", "application/exi" }, + { "pfr", "application/font-tdpfr" }, + { "gml", "application/gml+xml" }, + { "gpx", "application/gpx+xml" }, + { "gxf", "application/gxf" }, + { "stk", "application/hyperstudio" }, + { "ink", "application/inkml+xml" }, + { "inkml", "application/inkml+xml" }, + { "ipfix", "application/ipfix" }, + { "jar", "application/java-archive" }, + { "ser", "application/java-serialized-object" }, + { "class", "application/java-vm" }, + { "js", "application/javascript" }, + { "json", "application/json" }, + { "jsonml", "application/jsonml+json" }, + { "lostxml", "application/lost+xml" }, + { "hqx", "application/mac-binhex40" }, + { "cpt", "application/mac-compactpro" }, + { "mads", "application/mads+xml" }, + { "mrc", "application/marc" }, + { "mrcx", "application/marcxml+xml" }, + { "ma", "application/mathematica" }, + { "nb", "application/mathematica" }, + { "mb", "application/mathematica" }, + { "mathml", "application/mathml+xml" }, + { "mbox", "application/mbox" }, + { "mscml", "application/mediaservercontrol+xml" }, + { "metalink", "application/metalink+xml" }, + { "meta4", "application/metalink4+xml" }, + { "mets", "application/mets+xml" }, + { "mods", "application/mods+xml" }, + { "m21", "application/mp21" }, + { "mp21", "application/mp21" }, + { "mp4s", "application/mp4" }, + { "doc", "application/msword" }, + { "dot", "application/msword" }, + { "mxf", "application/mxf" }, + { "bin", "application/octet-stream" }, + { "dms", "application/octet-stream" }, + { "lrf", "application/octet-stream" }, + { "mar", "application/octet-stream" }, + { "so", "application/octet-stream" }, + { "dist", "application/octet-stream" }, + { "distz", "application/octet-stream" }, + { "pkg", "application/octet-stream" }, + { "bpk", "application/octet-stream" }, + { "dump", "application/octet-stream" }, + { "elc", "application/octet-stream" }, + { "deploy", "application/octet-stream" }, + { "oda", "application/oda" }, + { "opf", "application/oebps-package+xml" }, + { "ogx", "application/ogg" }, + { "omdoc", "application/omdoc+xml" }, + { "onetoc", "application/onenote" }, + { "onetoc2", "application/onenote" }, + { "onetmp", "application/onenote" }, + { "onepkg", "application/onenote" }, + { "oxps", "application/oxps" }, + { "xer", "application/patch-ops-error+xml" }, + { "pdf", "application/pdf" }, + { "pgp", "application/pgp-encrypted" }, + { "asc", "application/pgp-signature" }, + { "sig", "application/pgp-signature" }, + { "prf", "application/pics-rules" }, + { "p10", "application/pkcs10" }, + { "p7m", "application/pkcs7-mime" }, + { "p7c", "application/pkcs7-mime" }, + { "p7s", "application/pkcs7-signature" }, + { "p8", "application/pkcs8" }, + { "ac", "application/pkix-attr-cert" }, + { "cer", "application/pkix-cert" }, + { "crl", "application/pkix-crl" }, + { "pkipath", "application/pkix-pkipath" }, + { "pki", "application/pkixcmp" }, + { "pls", "application/pls+xml" }, + { "ai", "application/postscript" }, + { "eps", "application/postscript" }, + { "ps", "application/postscript" }, + { "cww", "application/prs.cww" }, + { "pskcxml", "application/pskc+xml" }, + { "rdf", "application/rdf+xml" }, + { "rif", "application/reginfo+xml" }, + { "rnc", "application/relax-ng-compact-syntax" }, + { "rl", "application/resource-lists+xml" }, + { "rld", "application/resource-lists-diff+xml" }, + { "rs", "application/rls-services+xml" }, + { "gbr", "application/rpki-ghostbusters" }, + { "mft", "application/rpki-manifest" }, + { "roa", "application/rpki-roa" }, + { "rsd", "application/rsd+xml" }, + { "rss", "application/rss+xml" }, + { "rtf", "application/rtf" }, + { "sbml", "application/sbml+xml" }, + { "scq", "application/scvp-cv-request" }, + { "scs", "application/scvp-cv-response" }, + { "spq", "application/scvp-vp-request" }, + { "spp", "application/scvp-vp-response" }, + { "sdp", "application/sdp" }, + { "setpay", "application/set-payment-initiation" }, + { "setreg", "application/set-registration-initiation" }, + { "shf", "application/shf+xml" }, + { "smi", "application/smil+xml" }, + { "smil", "application/smil+xml" }, + { "rq", "application/sparql-query" }, + { "srx", "application/sparql-results+xml" }, + { "gram", "application/srgs" }, + { "grxml", "application/srgs+xml" }, + { "sru", "application/sru+xml" }, + { "ssdl", "application/ssdl+xml" }, + { "ssml", "application/ssml+xml" }, + { "tei", "application/tei+xml" }, + { "teicorpus", "application/tei+xml" }, + { "tfi", "application/thraud+xml" }, + { "tsd", "application/timestamped-data" }, + { "plb", "application/vnd.3gpp.pic-bw-large" }, + { "psb", "application/vnd.3gpp.pic-bw-small" }, + { "pvb", "application/vnd.3gpp.pic-bw-var" }, + { "tcap", "application/vnd.3gpp2.tcap" }, + { "pwn", "application/vnd.3m.post-it-notes" }, + { "aso", "application/vnd.accpac.simply.aso" }, + { "imp", "application/vnd.accpac.simply.imp" }, + { "acu", "application/vnd.acucobol" }, + { "atc", "application/vnd.acucorp" }, + { "acutc", "application/vnd.acucorp" }, + { "air", "application/vnd.adobe.air-application-installer-package+zip" }, + { "fcdt", "application/vnd.adobe.formscentral.fcdt" }, + { "fxp", "application/vnd.adobe.fxp" }, + { "fxpl", "application/vnd.adobe.fxp" }, + { "xdp", "application/vnd.adobe.xdp+xml" }, + { "xfdf", "application/vnd.adobe.xfdf" }, + { "ahead", "application/vnd.ahead.space" }, + { "azf", "application/vnd.airzip.filesecure.azf" }, + { "azs", "application/vnd.airzip.filesecure.azs" }, + { "azw", "application/vnd.amazon.ebook" }, + { "acc", "application/vnd.americandynamics.acc" }, + { "ami", "application/vnd.amiga.ami" }, + { "apk", "application/vnd.android.package-archive" }, + { "cii", "application/vnd.anser-web-certificate-issue-initiation" }, + { "fti", "application/vnd.anser-web-funds-transfer-initiation" }, + { "atx", "application/vnd.antix.game-component" }, + { "mpkg", "application/vnd.apple.installer+xml" }, + { "m3u8", "application/vnd.apple.mpegurl" }, + { "swi", "application/vnd.aristanetworks.swi" }, + { "iota", "application/vnd.astraea-software.iota" }, + { "aep", "application/vnd.audiograph" }, + { "mpm", "application/vnd.blueice.multipass" }, + { "bmi", "application/vnd.bmi" }, + { "rep", "application/vnd.businessobjects" }, + { "cdxml", "application/vnd.chemdraw+xml" }, + { "mmd", "application/vnd.chipnuts.karaoke-mmd" }, + { "cdy", "application/vnd.cinderella" }, + { "cla", "application/vnd.claymore" }, + { "rp9", "application/vnd.cloanto.rp9" }, + { "c4g", "application/vnd.clonk.c4group" }, + { "c4d", "application/vnd.clonk.c4group" }, + { "c4f", "application/vnd.clonk.c4group" }, + { "c4p", "application/vnd.clonk.c4group" }, + { "c4u", "application/vnd.clonk.c4group" }, + { "c11amc", "application/vnd.cluetrust.cartomobile-config" }, + { "c11amz", "application/vnd.cluetrust.cartomobile-config-pkg" }, + { "csp", "application/vnd.commonspace" }, + { "cdbcmsg", "application/vnd.contact.cmsg" }, + { "cmc", "application/vnd.cosmocaller" }, + { "clkx", "application/vnd.crick.clicker" }, + { "clkk", "application/vnd.crick.clicker.keyboard" }, + { "clkp", "application/vnd.crick.clicker.palette" }, + { "clkt", "application/vnd.crick.clicker.template" }, + { "clkw", "application/vnd.crick.clicker.wordbank" }, + { "wbs", "application/vnd.criticaltools.wbs+xml" }, + { "pml", "application/vnd.ctc-posml" }, + { "ppd", "application/vnd.cups-ppd" }, + { "car", "application/vnd.curl.car" }, + { "pcurl", "application/vnd.curl.pcurl" }, + { "dart", "application/vnd.dart" }, + { "rdz", "application/vnd.data-vision.rdz" }, + { "uvf", "application/vnd.dece.data" }, + { "uvvf", "application/vnd.dece.data" }, + { "uvd", "application/vnd.dece.data" }, + { "uvvd", "application/vnd.dece.data" }, + { "uvt", "application/vnd.dece.ttml+xml" }, + { "uvvt", "application/vnd.dece.ttml+xml" }, + { "uvx", "application/vnd.dece.unspecified" }, + { "uvvx", "application/vnd.dece.unspecified" }, + { "uvz", "application/vnd.dece.zip" }, + { "uvvz", "application/vnd.dece.zip" }, + { "fe_launch", "application/vnd.denovo.fcselayout-link" }, + { "dna", "application/vnd.dna" }, + { "mlp", "application/vnd.dolby.mlp" }, + { "dpg", "application/vnd.dpgraph" }, + { "dfac", "application/vnd.dreamfactory" }, + { "kpxx", "application/vnd.ds-keypoint" }, + { "ait", "application/vnd.dvb.ait" }, + { "svc", "application/vnd.dvb.service" }, + { "geo", "application/vnd.dynageo" }, + { "mag", "application/vnd.ecowin.chart" }, + { "nml", "application/vnd.enliven" }, + { "esf", "application/vnd.epson.esf" }, + { "msf", "application/vnd.epson.msf" }, + { "qam", "application/vnd.epson.quickanime" }, + { "slt", "application/vnd.epson.salt" }, + { "ssf", "application/vnd.epson.ssf" }, + { "es3", "application/vnd.eszigno3+xml" }, + { "et3", "application/vnd.eszigno3+xml" }, + { "ez2", "application/vnd.ezpix-album" }, + { "ez3", "application/vnd.ezpix-package" }, + { "fdf", "application/vnd.fdf" }, + { "mseed", "application/vnd.fdsn.mseed" }, + { "seed", "application/vnd.fdsn.seed" }, + { "dataless", "application/vnd.fdsn.seed" }, + { "gph", "application/vnd.flographit" }, + { "ftc", "application/vnd.fluxtime.clip" }, + { "fm", "application/vnd.framemaker" }, + { "frame", "application/vnd.framemaker" }, + { "maker", "application/vnd.framemaker" }, + { "book", "application/vnd.framemaker" }, + { "fnc", "application/vnd.frogans.fnc" }, + { "ltf", "application/vnd.frogans.ltf" }, + { "fsc", "application/vnd.fsc.weblaunch" }, + { "oas", "application/vnd.fujitsu.oasys" }, + { "oa2", "application/vnd.fujitsu.oasys2" }, + { "oa3", "application/vnd.fujitsu.oasys3" }, + { "fg5", "application/vnd.fujitsu.oasysgp" }, + { "bh2", "application/vnd.fujitsu.oasysprs" }, + { "ddd", "application/vnd.fujixerox.ddd" }, + { "xdw", "application/vnd.fujixerox.docuworks" }, + { "xbd", "application/vnd.fujixerox.docuworks.binder" }, + { "fzs", "application/vnd.fuzzysheet" }, + { "txd", "application/vnd.genomatix.tuxedo" }, + { "ggb", "application/vnd.geogebra.file" }, + { "ggt", "application/vnd.geogebra.tool" }, + { "gex", "application/vnd.geometry-explorer" }, + { "gre", "application/vnd.geometry-explorer" }, + { "gxt", "application/vnd.geonext" }, + { "g2w", "application/vnd.geoplan" }, + { "g3w", "application/vnd.geospace" }, + { "gmx", "application/vnd.gmx" }, + { "kml", "application/vnd.google-earth.kml+xml" }, + { "kmz", "application/vnd.google-earth.kmz" }, + { "gqf", "application/vnd.grafeq" }, + { "gqs", "application/vnd.grafeq" }, + { "gac", "application/vnd.groove-account" }, + { "ghf", "application/vnd.groove-help" }, + { "gim", "application/vnd.groove-identity-message" }, + { "grv", "application/vnd.groove-injector" }, + { "gtm", "application/vnd.groove-tool-message" }, + { "tpl", "application/vnd.groove-tool-template" }, + { "vcg", "application/vnd.groove-vcard" }, + { "hal", "application/vnd.hal+xml" }, + { "zmm", "application/vnd.handheld-entertainment+xml" }, + { "hbci", "application/vnd.hbci" }, + { "les", "application/vnd.hhe.lesson-player" }, + { "hpgl", "application/vnd.hp-hpgl" }, + { "hpid", "application/vnd.hp-hpid" }, + { "hps", "application/vnd.hp-hps" }, + { "jlt", "application/vnd.hp-jlyt" }, + { "pcl", "application/vnd.hp-pcl" }, + { "pclxl", "application/vnd.hp-pclxl" }, + { "sfd-hdstx", "application/vnd.hydrostatix.sof-data" }, + { "mpy", "application/vnd.ibm.minipay" }, + { "afp", "application/vnd.ibm.modcap" }, + { "listafp", "application/vnd.ibm.modcap" }, + { "list3820", "application/vnd.ibm.modcap" }, + { "irm", "application/vnd.ibm.rights-management" }, + { "sc", "application/vnd.ibm.secure-container" }, + { "icc", "application/vnd.iccprofile" }, + { "icm", "application/vnd.iccprofile" }, + { "igl", "application/vnd.igloader" }, + { "ivp", "application/vnd.immervision-ivp" }, + { "ivu", "application/vnd.immervision-ivu" }, + { "igm", "application/vnd.insors.igm" }, + { "xpw", "application/vnd.intercon.formnet" }, + { "xpx", "application/vnd.intercon.formnet" }, + { "i2g", "application/vnd.intergeo" }, + { "qbo", "application/vnd.intu.qbo" }, + { "qfx", "application/vnd.intu.qfx" }, + { "rcprofile", "application/vnd.ipunplugged.rcprofile" }, + { "irp", "application/vnd.irepository.package+xml" }, + { "xpr", "application/vnd.is-xpr" }, + { "fcs", "application/vnd.isac.fcs" }, + { "jam", "application/vnd.jam" }, + { "rms", "application/vnd.jcp.javame.midlet-rms" }, + { "jisp", "application/vnd.jisp" }, + { "joda", "application/vnd.joost.joda-archive" }, + { "ktz", "application/vnd.kahootz" }, + { "ktr", "application/vnd.kahootz" }, + { "karbon", "application/vnd.kde.karbon" }, + { "chrt", "application/vnd.kde.kchart" }, + { "kfo", "application/vnd.kde.kformula" }, + { "flw", "application/vnd.kde.kivio" }, + { "kon", "application/vnd.kde.kontour" }, + { "kpr", "application/vnd.kde.kpresenter" }, + { "kpt", "application/vnd.kde.kpresenter" }, + { "ksp", "application/vnd.kde.kspread" }, + { "kwd", "application/vnd.kde.kword" }, + { "kwt", "application/vnd.kde.kword" }, + { "htke", "application/vnd.kenameaapp" }, + { "kia", "application/vnd.kidspiration" }, + { "kne", "application/vnd.kinar" }, + { "knp", "application/vnd.kinar" }, + { "skp", "application/vnd.koan" }, + { "skd", "application/vnd.koan" }, + { "skt", "application/vnd.koan" }, + { "skm", "application/vnd.koan" }, + { "sse", "application/vnd.kodak-descriptor" }, + { "lasxml", "application/vnd.las.las+xml" }, + { "lbd", "application/vnd.llamagraphics.life-balance.desktop" }, + { "lbe", "application/vnd.llamagraphics.life-balance.exchange+xml" }, + { "123", "application/vnd.lotus-1-2-3" }, + { "apr", "application/vnd.lotus-approach" }, + { "pre", "application/vnd.lotus-freelance" }, + { "nsf", "application/vnd.lotus-notes" }, + { "org", "application/vnd.lotus-organizer" }, + { "scm", "application/vnd.lotus-screencam" }, + { "lwp", "application/vnd.lotus-wordpro" }, + { "portpkg", "application/vnd.macports.portpkg" }, + { "mcd", "application/vnd.mcd" }, + { "mc1", "application/vnd.medcalcdata" }, + { "cdkey", "application/vnd.mediastation.cdkey" }, + { "mwf", "application/vnd.mfer" }, + { "mfm", "application/vnd.mfmp" }, + { "flo", "application/vnd.micrografx.flo" }, + { "igx", "application/vnd.micrografx.igx" }, + { "mif", "application/vnd.mif" }, + { "daf", "application/vnd.mobius.daf" }, + { "dis", "application/vnd.mobius.dis" }, + { "mbk", "application/vnd.mobius.mbk" }, + { "mqy", "application/vnd.mobius.mqy" }, + { "msl", "application/vnd.mobius.msl" }, + { "plc", "application/vnd.mobius.plc" }, + { "txf", "application/vnd.mobius.txf" }, + { "mpn", "application/vnd.mophun.application" }, + { "mpc", "application/vnd.mophun.certificate" }, + { "xul", "application/vnd.mozilla.xul+xml" }, + { "cil", "application/vnd.ms-artgalry" }, + { "cab", "application/vnd.ms-cab-compressed" }, + { "xls", "application/vnd.ms-excel" }, + { "xlm", "application/vnd.ms-excel" }, + { "xla", "application/vnd.ms-excel" }, + { "xlc", "application/vnd.ms-excel" }, + { "xlt", "application/vnd.ms-excel" }, + { "xlw", "application/vnd.ms-excel" }, + { "xlam", "application/vnd.ms-excel.addin.macroenabled.12" }, + { "xlsb", "application/vnd.ms-excel.sheet.binary.macroenabled.12" }, + { "xlsm", "application/vnd.ms-excel.sheet.macroenabled.12" }, + { "xltm", "application/vnd.ms-excel.template.macroenabled.12" }, + { "eot", "application/vnd.ms-fontobject" }, + { "chm", "application/vnd.ms-htmlhelp" }, + { "ims", "application/vnd.ms-ims" }, + { "lrm", "application/vnd.ms-lrm" }, + { "thmx", "application/vnd.ms-officetheme" }, + { "cat", "application/vnd.ms-pki.seccat" }, + { "stl", "application/vnd.ms-pki.stl" }, + { "ppt", "application/vnd.ms-powerpoint" }, + { "pps", "application/vnd.ms-powerpoint" }, + { "pot", "application/vnd.ms-powerpoint" }, + { "ppam", "application/vnd.ms-powerpoint.addin.macroenabled.12" }, + { "pptm", "application/vnd.ms-powerpoint.presentation.macroenabled.12" }, + { "sldm", "application/vnd.ms-powerpoint.slide.macroenabled.12" }, + { "ppsm", "application/vnd.ms-powerpoint.slideshow.macroenabled.12" }, + { "potm", "application/vnd.ms-powerpoint.template.macroenabled.12" }, + { "mpp", "application/vnd.ms-project" }, + { "mpt", "application/vnd.ms-project" }, + { "docm", "application/vnd.ms-word.document.macroenabled.12" }, + { "dotm", "application/vnd.ms-word.template.macroenabled.12" }, + { "wps", "application/vnd.ms-works" }, + { "wks", "application/vnd.ms-works" }, + { "wcm", "application/vnd.ms-works" }, + { "wdb", "application/vnd.ms-works" }, + { "wpl", "application/vnd.ms-wpl" }, + { "xps", "application/vnd.ms-xpsdocument" }, + { "mseq", "application/vnd.mseq" }, + { "mus", "application/vnd.musician" }, + { "msty", "application/vnd.muvee.style" }, + { "taglet", "application/vnd.mynfc" }, + { "nlu", "application/vnd.neurolanguage.nlu" }, + { "ntf", "application/vnd.nitf" }, + { "nitf", "application/vnd.nitf" }, + { "nnd", "application/vnd.noblenet-directory" }, + { "nns", "application/vnd.noblenet-sealer" }, + { "nnw", "application/vnd.noblenet-web" }, + { "ngdat", "application/vnd.nokia.n-gage.data" }, + { "n-gage", "application/vnd.nokia.n-gage.symbian.install" }, + { "rpst", "application/vnd.nokia.radio-preset" }, + { "rpss", "application/vnd.nokia.radio-presets" }, + { "edm", "application/vnd.novadigm.edm" }, + { "edx", "application/vnd.novadigm.edx" }, + { "ext", "application/vnd.novadigm.ext" }, + { "odc", "application/vnd.oasis.opendocument.chart" }, + { "otc", "application/vnd.oasis.opendocument.chart-template" }, + { "odb", "application/vnd.oasis.opendocument.database" }, + { "odf", "application/vnd.oasis.opendocument.formula" }, + { "odft", "application/vnd.oasis.opendocument.formula-template" }, + { "odg", "application/vnd.oasis.opendocument.graphics" }, + { "otg", "application/vnd.oasis.opendocument.graphics-template" }, + { "odi", "application/vnd.oasis.opendocument.image" }, + { "oti", "application/vnd.oasis.opendocument.image-template" }, + { "odp", "application/vnd.oasis.opendocument.presentation" }, + { "otp", "application/vnd.oasis.opendocument.presentation-template" }, + { "ods", "application/vnd.oasis.opendocument.spreadsheet" }, + { "ots", "application/vnd.oasis.opendocument.spreadsheet-template" }, + { "odt", "application/vnd.oasis.opendocument.text" }, + { "odm", "application/vnd.oasis.opendocument.text-master" }, + { "ott", "application/vnd.oasis.opendocument.text-template" }, + { "oth", "application/vnd.oasis.opendocument.text-web" }, + { "xo", "application/vnd.olpc-sugar" }, + { "dd2", "application/vnd.oma.dd2+xml" }, + { "oxt", "application/vnd.openofficeorg.extension" }, + { "pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation" }, + { "sldx", "application/vnd.openxmlformats-officedocument.presentationml.slide" }, + { "ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow" }, + { "potx", "application/vnd.openxmlformats-officedocument.presentationml.template" }, + { "xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }, + { "xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template" }, + { "docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }, + { "dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template" }, + { "mgp", "application/vnd.osgeo.mapguide.package" }, + { "dp", "application/vnd.osgi.dp" }, + { "esa", "application/vnd.osgi.subsystem" }, + { "pdb", "application/vnd.palm" }, + { "pqa", "application/vnd.palm" }, + { "oprc", "application/vnd.palm" }, + { "paw", "application/vnd.pawaafile" }, + { "str", "application/vnd.pg.format" }, + { "ei6", "application/vnd.pg.osasli" }, + { "efif", "application/vnd.picsel" }, + { "wg", "application/vnd.pmi.widget" }, + { "plf", "application/vnd.pocketlearn" }, + { "pbd", "application/vnd.powerbuilder6" }, + { "box", "application/vnd.previewsystems.box" }, + { "mgz", "application/vnd.proteus.magazine" }, + { "qps", "application/vnd.publishare-delta-tree" }, + { "ptid", "application/vnd.pvi.ptid1" }, + { "qxd", "application/vnd.quark.quarkxpress" }, + { "qxt", "application/vnd.quark.quarkxpress" }, + { "qwd", "application/vnd.quark.quarkxpress" }, + { "qwt", "application/vnd.quark.quarkxpress" }, + { "qxl", "application/vnd.quark.quarkxpress" }, + { "qxb", "application/vnd.quark.quarkxpress" }, + { "bed", "application/vnd.realvnc.bed" }, + { "mxl", "application/vnd.recordare.musicxml" }, + { "musicxml", "application/vnd.recordare.musicxml+xml" }, + { "cryptonote", "application/vnd.rig.cryptonote" }, + { "cod", "application/vnd.rim.cod" }, + { "rm", "application/vnd.rn-realmedia" }, + { "rmvb", "application/vnd.rn-realmedia-vbr" }, + { "link66", "application/vnd.route66.link66+xml" }, + { "st", "application/vnd.sailingtracker.track" }, + { "see", "application/vnd.seemail" }, + { "sema", "application/vnd.sema" }, + { "semd", "application/vnd.semd" }, + { "semf", "application/vnd.semf" }, + { "ifm", "application/vnd.shana.informed.formdata" }, + { "itp", "application/vnd.shana.informed.formtemplate" }, + { "iif", "application/vnd.shana.informed.interchange" }, + { "ipk", "application/vnd.shana.informed.package" }, + { "twd", "application/vnd.simtech-mindmapper" }, + { "twds", "application/vnd.simtech-mindmapper" }, + { "mmf", "application/vnd.smaf" }, + { "teacher", "application/vnd.smart.teacher" }, + { "sdkm", "application/vnd.solent.sdkm+xml" }, + { "sdkd", "application/vnd.solent.sdkm+xml" }, + { "dxp", "application/vnd.spotfire.dxp" }, + { "sfs", "application/vnd.spotfire.sfs" }, + { "sdc", "application/vnd.stardivision.calc" }, + { "sda", "application/vnd.stardivision.draw" }, + { "sdd", "application/vnd.stardivision.impress" }, + { "smf", "application/vnd.stardivision.math" }, + { "sdw", "application/vnd.stardivision.writer" }, + { "vor", "application/vnd.stardivision.writer" }, + { "sgl", "application/vnd.stardivision.writer-global" }, + { "smzip", "application/vnd.stepmania.package" }, + { "sm", "application/vnd.stepmania.stepchart" }, + { "sxc", "application/vnd.sun.xml.calc" }, + { "stc", "application/vnd.sun.xml.calc.template" }, + { "sxd", "application/vnd.sun.xml.draw" }, + { "std", "application/vnd.sun.xml.draw.template" }, + { "sxi", "application/vnd.sun.xml.impress" }, + { "sti", "application/vnd.sun.xml.impress.template" }, + { "sxm", "application/vnd.sun.xml.math" }, + { "sxw", "application/vnd.sun.xml.writer" }, + { "sxg", "application/vnd.sun.xml.writer.global" }, + { "stw", "application/vnd.sun.xml.writer.template" }, + { "sus", "application/vnd.sus-calendar" }, + { "susp", "application/vnd.sus-calendar" }, + { "svd", "application/vnd.svd" }, + { "sis", "application/vnd.symbian.install" }, + { "sisx", "application/vnd.symbian.install" }, + { "xsm", "application/vnd.syncml+xml" }, + { "bdm", "application/vnd.syncml.dm+wbxml" }, + { "xdm", "application/vnd.syncml.dm+xml" }, + { "tao", "application/vnd.tao.intent-module-archive" }, + { "pcap", "application/vnd.tcpdump.pcap" }, + { "cap", "application/vnd.tcpdump.pcap" }, + { "dmp", "application/vnd.tcpdump.pcap" }, + { "tmo", "application/vnd.tmobile-livetv" }, + { "tpt", "application/vnd.trid.tpt" }, + { "mxs", "application/vnd.triscape.mxs" }, + { "tra", "application/vnd.trueapp" }, + { "ufd", "application/vnd.ufdl" }, + { "ufdl", "application/vnd.ufdl" }, + { "utz", "application/vnd.uiq.theme" }, + { "umj", "application/vnd.umajin" }, + { "unityweb", "application/vnd.unity" }, + { "uoml", "application/vnd.uoml+xml" }, + { "vcx", "application/vnd.vcx" }, + { "vsd", "application/vnd.visio" }, + { "vst", "application/vnd.visio" }, + { "vss", "application/vnd.visio" }, + { "vsw", "application/vnd.visio" }, + { "vis", "application/vnd.visionary" }, + { "vsf", "application/vnd.vsf" }, + { "wbxml", "application/vnd.wap.wbxml" }, + { "wmlc", "application/vnd.wap.wmlc" }, + { "wmlsc", "application/vnd.wap.wmlscriptc" }, + { "wtb", "application/vnd.webturbo" }, + { "nbp", "application/vnd.wolfram.player" }, + { "wpd", "application/vnd.wordperfect" }, + { "wqd", "application/vnd.wqd" }, + { "stf", "application/vnd.wt.stf" }, + { "xar", "application/vnd.xara" }, + { "xfdl", "application/vnd.xfdl" }, + { "hvd", "application/vnd.yamaha.hv-dic" }, + { "hvs", "application/vnd.yamaha.hv-script" }, + { "hvp", "application/vnd.yamaha.hv-voice" }, + { "osf", "application/vnd.yamaha.openscoreformat" }, + { "osfpvg", "application/vnd.yamaha.openscoreformat.osfpvg+xml" }, + { "saf", "application/vnd.yamaha.smaf-audio" }, + { "spf", "application/vnd.yamaha.smaf-phrase" }, + { "cmp", "application/vnd.yellowriver-custom-menu" }, + { "zir", "application/vnd.zul" }, + { "zirz", "application/vnd.zul" }, + { "zaz", "application/vnd.zzazz.deck+xml" }, + { "vxml", "application/voicexml+xml" }, + { "wgt", "application/widget" }, + { "hlp", "application/winhlp" }, + { "wsdl", "application/wsdl+xml" }, + { "wspolicy", "application/wspolicy+xml" }, + { "7z", "application/x-7z-compressed" }, + { "abw", "application/x-abiword" }, + { "ace", "application/x-ace-compressed" }, + { "dmg", "application/x-apple-diskimage" }, + { "aab", "application/x-authorware-bin" }, + { "x32", "application/x-authorware-bin" }, + { "u32", "application/x-authorware-bin" }, + { "vox", "application/x-authorware-bin" }, + { "aam", "application/x-authorware-map" }, + { "aas", "application/x-authorware-seg" }, + { "bcpio", "application/x-bcpio" }, + { "torrent", "application/x-bittorrent" }, + { "blb", "application/x-blorb" }, + { "blorb", "application/x-blorb" }, + { "bz", "application/x-bzip" }, + { "bz2", "application/x-bzip2" }, + { "boz", "application/x-bzip2" }, + { "cbr", "application/x-cbr" }, + { "cba", "application/x-cbr" }, + { "cbt", "application/x-cbr" }, + { "cbz", "application/x-cbr" }, + { "cb7", "application/x-cbr" }, + { "vcd", "application/x-cdlink" }, + { "cfs", "application/x-cfs-compressed" }, + { "chat", "application/x-chat" }, + { "pgn", "application/x-chess-pgn" }, + { "nsc", "application/x-conference" }, + { "cpio", "application/x-cpio" }, + { "csh", "application/x-csh" }, + { "deb", "application/x-debian-package" }, + { "udeb", "application/x-debian-package" }, + { "dgc", "application/x-dgc-compressed" }, + { "dir", "application/x-director" }, + { "dcr", "application/x-director" }, + { "dxr", "application/x-director" }, + { "cst", "application/x-director" }, + { "cct", "application/x-director" }, + { "cxt", "application/x-director" }, + { "w3d", "application/x-director" }, + { "fgd", "application/x-director" }, + { "swa", "application/x-director" }, + { "wad", "application/x-doom" }, + { "ncx", "application/x-dtbncx+xml" }, + { "dtb", "application/x-dtbook+xml" }, + { "res", "application/x-dtbresource+xml" }, + { "dvi", "application/x-dvi" }, + { "evy", "application/x-envoy" }, + { "eva", "application/x-eva" }, + { "bdf", "application/x-font-bdf" }, + { "gsf", "application/x-font-ghostscript" }, + { "psf", "application/x-font-linux-psf" }, + { "otf", "application/x-font-otf" }, + { "pcf", "application/x-font-pcf" }, + { "snf", "application/x-font-snf" }, + { "ttf", "application/x-font-ttf" }, + { "ttc", "application/x-font-ttf" }, + { "pfa", "application/x-font-type1" }, + { "pfb", "application/x-font-type1" }, + { "pfm", "application/x-font-type1" }, + { "afm", "application/x-font-type1" }, + { "woff", "application/font-woff" }, + { "arc", "application/x-freearc" }, + { "spl", "application/x-futuresplash" }, + { "gca", "application/x-gca-compressed" }, + { "ulx", "application/x-glulx" }, + { "gnumeric", "application/x-gnumeric" }, + { "gramps", "application/x-gramps-xml" }, + { "gtar", "application/x-gtar" }, + { "hdf", "application/x-hdf" }, + { "install", "application/x-install-instructions" }, + { "iso", "application/x-iso9660-image" }, + { "jnlp", "application/x-java-jnlp-file" }, + { "latex", "application/x-latex" }, + { "lzh", "application/x-lzh-compressed" }, + { "lha", "application/x-lzh-compressed" }, + { "mie", "application/x-mie" }, + { "prc", "application/x-mobipocket-ebook" }, + { "mobi", "application/x-mobipocket-ebook" }, + { "application", "application/x-ms-application" }, + { "lnk", "application/x-ms-shortcut" }, + { "wmd", "application/x-ms-wmd" }, + { "wmz", "application/x-msmetafile" }, + { "xbap", "application/x-ms-xbap" }, + { "mdb", "application/x-msaccess" }, + { "obd", "application/x-msbinder" }, + { "crd", "application/x-mscardfile" }, + { "clp", "application/x-msclip" }, + { "exe", "application/x-msdownload" }, + { "dll", "application/x-msdownload" }, + { "com", "application/x-msdownload" }, + { "bat", "application/x-msdownload" }, + { "msi", "application/x-msdownload" }, + { "mvb", "application/x-msmediaview" }, + { "m13", "application/x-msmediaview" }, + { "m14", "application/x-msmediaview" }, + { "wmf", "application/x-msmetafile" }, + { "emf", "application/x-msmetafile" }, + { "emz", "application/x-msmetafile" }, + { "mny", "application/x-msmoney" }, + { "pub", "application/x-mspublisher" }, + { "scd", "application/x-msschedule" }, + { "trm", "application/x-msterminal" }, + { "wri", "application/x-mswrite" }, + { "nc", "application/x-netcdf" }, + { "cdf", "application/x-netcdf" }, + { "nzb", "application/x-nzb" }, + { "p12", "application/x-pkcs12" }, + { "pfx", "application/x-pkcs12" }, + { "p7b", "application/x-pkcs7-certificates" }, + { "spc", "application/x-pkcs7-certificates" }, + { "p7r", "application/x-pkcs7-certreqresp" }, + { "rar", "application/x-rar-compressed" }, + { "ris", "application/x-research-info-systems" }, + { "sh", "application/x-sh" }, + { "shar", "application/x-shar" }, + { "swf", "application/x-shockwave-flash" }, + { "xap", "application/x-silverlight-app" }, + { "sql", "application/x-sql" }, + { "sit", "application/x-stuffit" }, + { "sitx", "application/x-stuffitx" }, + { "srt", "application/x-subrip" }, + { "sv4cpio", "application/x-sv4cpio" }, + { "sv4crc", "application/x-sv4crc" }, + { "t3", "application/x-t3vm-image" }, + { "gam", "application/x-tads" }, + { "tar", "application/x-tar" }, + { "tcl", "application/x-tcl" }, + { "tex", "application/x-tex" }, + { "tfm", "application/x-tex-tfm" }, + { "texinfo", "application/x-texinfo" }, + { "texi", "application/x-texinfo" }, + { "obj", "application/x-tgif" }, + { "ustar", "application/x-ustar" }, + { "src", "application/x-wais-source" }, + { "der", "application/x-x509-ca-cert" }, + { "crt", "application/x-x509-ca-cert" }, + { "fig", "application/x-xfig" }, + { "xlf", "application/x-xliff+xml" }, + { "xpi", "application/x-xpinstall" }, + { "xz", "application/x-xz" }, + { "z1", "application/x-zmachine" }, + { "z2", "application/x-zmachine" }, + { "z3", "application/x-zmachine" }, + { "z4", "application/x-zmachine" }, + { "z5", "application/x-zmachine" }, + { "z6", "application/x-zmachine" }, + { "z7", "application/x-zmachine" }, + { "z8", "application/x-zmachine" }, + { "xaml", "application/xaml+xml" }, + { "xdf", "application/xcap-diff+xml" }, + { "xenc", "application/xenc+xml" }, + { "xhtml", "application/xhtml+xml" }, + { "xht", "application/xhtml+xml" }, + { "xml", "application/xml" }, + { "xsl", "application/xml" }, + { "dtd", "application/xml-dtd" }, + { "xop", "application/xop+xml" }, + { "xpl", "application/xproc+xml" }, + { "xslt", "application/xslt+xml" }, + { "xspf", "application/xspf+xml" }, + { "mxml", "application/xv+xml" }, + { "xhvml", "application/xv+xml" }, + { "xvml", "application/xv+xml" }, + { "xvm", "application/xv+xml" }, + { "yang", "application/yang" }, + { "yin", "application/yin+xml" }, + { "zip", "application/zip" }, + { "adp", "audio/adpcm" }, + { "au", "audio/basic" }, + { "snd", "audio/basic" }, + { "mid", "audio/midi" }, + { "midi", "audio/midi" }, + { "kar", "audio/midi" }, + { "rmi", "audio/midi" }, + { "mp4a", "audio/mp4" }, + { "mpga", "audio/mpeg" }, + { "mp2", "audio/mpeg" }, + { "mp2a", "audio/mpeg" }, + { "mp3", "audio/mpeg" }, + { "m2a", "audio/mpeg" }, + { "m3a", "audio/mpeg" }, + { "oga", "audio/ogg" }, + { "ogg", "audio/ogg" }, + { "spx", "audio/ogg" }, + { "s3m", "audio/s3m" }, + { "sil", "audio/silk" }, + { "uva", "audio/vnd.dece.audio" }, + { "uvva", "audio/vnd.dece.audio" }, + { "eol", "audio/vnd.digital-winds" }, + { "dra", "audio/vnd.dra" }, + { "dts", "audio/vnd.dts" }, + { "dtshd", "audio/vnd.dts.hd" }, + { "lvp", "audio/vnd.lucent.voice" }, + { "pya", "audio/vnd.ms-playready.media.pya" }, + { "ecelp4800", "audio/vnd.nuera.ecelp4800" }, + { "ecelp7470", "audio/vnd.nuera.ecelp7470" }, + { "ecelp9600", "audio/vnd.nuera.ecelp9600" }, + { "rip", "audio/vnd.rip" }, + { "weba", "audio/webm" }, + { "aac", "audio/x-aac" }, + { "aif", "audio/x-aiff" }, + { "aiff", "audio/x-aiff" }, + { "aifc", "audio/x-aiff" }, + { "caf", "audio/x-caf" }, + { "flac", "audio/x-flac" }, + { "mka", "audio/x-matroska" }, + { "m3u", "audio/x-mpegurl" }, + { "wax", "audio/x-ms-wax" }, + { "wma", "audio/x-ms-wma" }, + { "ram", "audio/x-pn-realaudio" }, + { "ra", "audio/x-pn-realaudio" }, + { "rmp", "audio/x-pn-realaudio-plugin" }, + { "wav", "audio/x-wav" }, + { "xm", "audio/xm" }, + { "cdx", "chemical/x-cdx" }, + { "cif", "chemical/x-cif" }, + { "cmdf", "chemical/x-cmdf" }, + { "cml", "chemical/x-cml" }, + { "csml", "chemical/x-csml" }, + { "xyz", "chemical/x-xyz" }, + { "bmp", "image/bmp" }, + { "cgm", "image/cgm" }, + { "g3", "image/g3fax" }, + { "gif", "image/gif" }, + { "ief", "image/ief" }, + { "jpeg", "image/jpeg" }, + { "jpg", "image/jpeg" }, + { "jpe", "image/jpeg" }, + { "ktx", "image/ktx" }, + { "png", "image/png" }, + { "btif", "image/prs.btif" }, + { "sgi", "image/sgi" }, + { "svg", "image/svg+xml" }, + { "svgz", "image/svg+xml" }, + { "tiff", "image/tiff" }, + { "tif", "image/tiff" }, + { "psd", "image/vnd.adobe.photoshop" }, + { "uvi", "image/vnd.dece.graphic" }, + { "uvvi", "image/vnd.dece.graphic" }, + { "uvg", "image/vnd.dece.graphic" }, + { "uvvg", "image/vnd.dece.graphic" }, + { "sub", "text/vnd.dvb.subtitle" }, + { "djvu", "image/vnd.djvu" }, + { "djv", "image/vnd.djvu" }, + { "dwg", "image/vnd.dwg" }, + { "dxf", "image/vnd.dxf" }, + { "fbs", "image/vnd.fastbidsheet" }, + { "fpx", "image/vnd.fpx" }, + { "fst", "image/vnd.fst" }, + { "mmr", "image/vnd.fujixerox.edmics-mmr" }, + { "rlc", "image/vnd.fujixerox.edmics-rlc" }, + { "mdi", "image/vnd.ms-modi" }, + { "wdp", "image/vnd.ms-photo" }, + { "npx", "image/vnd.net-fpx" }, + { "wbmp", "image/vnd.wap.wbmp" }, + { "xif", "image/vnd.xiff" }, + { "webp", "image/webp" }, + { "3ds", "image/x-3ds" }, + { "ras", "image/x-cmu-raster" }, + { "cmx", "image/x-cmx" }, + { "fh", "image/x-freehand" }, + { "fhc", "image/x-freehand" }, + { "fh4", "image/x-freehand" }, + { "fh5", "image/x-freehand" }, + { "fh7", "image/x-freehand" }, + { "ico", "image/x-icon" }, + { "sid", "image/x-mrsid-image" }, + { "pcx", "image/x-pcx" }, + { "pic", "image/x-pict" }, + { "pct", "image/x-pict" }, + { "pnm", "image/x-portable-anymap" }, + { "pbm", "image/x-portable-bitmap" }, + { "pgm", "image/x-portable-graymap" }, + { "ppm", "image/x-portable-pixmap" }, + { "rgb", "image/x-rgb" }, + { "tga", "image/x-tga" }, + { "xbm", "image/x-xbitmap" }, + { "xpm", "image/x-xpixmap" }, + { "xwd", "image/x-xwindowdump" }, + { "eml", "message/rfc822" }, + { "mime", "message/rfc822" }, + { "igs", "model/iges" }, + { "iges", "model/iges" }, + { "msh", "model/mesh" }, + { "mesh", "model/mesh" }, + { "silo", "model/mesh" }, + { "dae", "model/vnd.collada+xml" }, + { "dwf", "model/vnd.dwf" }, + { "gdl", "model/vnd.gdl" }, + { "gtw", "model/vnd.gtw" }, + { "mts", "model/vnd.mts" }, + { "vtu", "model/vnd.vtu" }, + { "wrl", "model/vrml" }, + { "vrml", "model/vrml" }, + { "x3db", "model/x3d+binary" }, + { "x3dbz", "model/x3d+binary" }, + { "x3dv", "model/x3d+vrml" }, + { "x3dvz", "model/x3d+vrml" }, + { "x3d", "model/x3d+xml" }, + { "x3dz", "model/x3d+xml" }, + { "appcache", "text/cache-manifest" }, + { "ics", "text/calendar" }, + { "ifb", "text/calendar" }, + { "css", "text/css" }, + { "csv", "text/csv" }, + { "html", "text/html" }, + { "htm", "text/html" }, + { "n3", "text/n3" }, + { "txt", "text/plain" }, + { "text", "text/plain" }, + { "conf", "text/plain" }, + { "def", "text/plain" }, + { "list", "text/plain" }, + { "log", "text/plain" }, + { "in", "text/plain" }, + { "dsc", "text/prs.lines.tag" }, + { "rtx", "text/richtext" }, + { "sgml", "text/sgml" }, + { "sgm", "text/sgml" }, + { "tsv", "text/tab-separated-values" }, + { "t", "text/troff" }, + { "tr", "text/troff" }, + { "roff", "text/troff" }, + { "man", "text/troff" }, + { "me", "text/troff" }, + { "ms", "text/troff" }, + { "ttl", "text/turtle" }, + { "uri", "text/uri-list" }, + { "uris", "text/uri-list" }, + { "urls", "text/uri-list" }, + { "vcard", "text/vcard" }, + { "curl", "text/vnd.curl" }, + { "dcurl", "text/vnd.curl.dcurl" }, + { "scurl", "text/vnd.curl.scurl" }, + { "mcurl", "text/vnd.curl.mcurl" }, + { "fly", "text/vnd.fly" }, + { "flx", "text/vnd.fmi.flexstor" }, + { "gv", "text/vnd.graphviz" }, + { "3dml", "text/vnd.in3d.3dml" }, + { "spot", "text/vnd.in3d.spot" }, + { "jad", "text/vnd.sun.j2me.app-descriptor" }, + { "wml", "text/vnd.wap.wml" }, + { "wmls", "text/vnd.wap.wmlscript" }, + { "s", "text/x-asm" }, + { "asm", "text/x-asm" }, + { "c", "text/x-c" }, + { "cc", "text/x-c" }, + { "cxx", "text/x-c" }, + { "cpp", "text/x-c" }, + { "h", "text/x-c" }, + { "hh", "text/x-c" }, + { "dic", "text/x-c" }, + { "f", "text/x-fortran" }, + { "for", "text/x-fortran" }, + { "f77", "text/x-fortran" }, + { "f90", "text/x-fortran" }, + { "java", "text/x-java-source" }, + { "opml", "text/x-opml" }, + { "p", "text/x-pascal" }, + { "pas", "text/x-pascal" }, + { "nfo", "text/x-nfo" }, + { "etx", "text/x-setext" }, + { "sfv", "text/x-sfv" }, + { "uu", "text/x-uuencode" }, + { "vcs", "text/x-vcalendar" }, + { "vcf", "text/x-vcard" }, + { "3gp", "video/3gpp" }, + { "3g2", "video/3gpp2" }, + { "h261", "video/h261" }, + { "h263", "video/h263" }, + { "h264", "video/h264" }, + { "jpgv", "video/jpeg" }, + { "jpm", "video/jpm" }, + { "jpgm", "video/jpm" }, + { "mj2", "video/mj2" }, + { "mjp2", "video/mj2" }, + { "mp4", "video/mp4" }, + { "mp4v", "video/mp4" }, + { "mpg4", "video/mp4" }, + { "mpeg", "video/mpeg" }, + { "mpg", "video/mpeg" }, + { "mpe", "video/mpeg" }, + { "m1v", "video/mpeg" }, + { "m2v", "video/mpeg" }, + { "ogv", "video/ogg" }, + { "qt", "video/quicktime" }, + { "mov", "video/quicktime" }, + { "uvh", "video/vnd.dece.hd" }, + { "uvvh", "video/vnd.dece.hd" }, + { "uvm", "video/vnd.dece.mobile" }, + { "uvvm", "video/vnd.dece.mobile" }, + { "uvp", "video/vnd.dece.pd" }, + { "uvvp", "video/vnd.dece.pd" }, + { "uvs", "video/vnd.dece.sd" }, + { "uvvs", "video/vnd.dece.sd" }, + { "uvv", "video/vnd.dece.video" }, + { "uvvv", "video/vnd.dece.video" }, + { "dvb", "video/vnd.dvb.file" }, + { "fvt", "video/vnd.fvt" }, + { "mxu", "video/vnd.mpegurl" }, + { "m4u", "video/vnd.mpegurl" }, + { "pyv", "video/vnd.ms-playready.media.pyv" }, + { "uvu", "video/vnd.uvvu.mp4" }, + { "uvvu", "video/vnd.uvvu.mp4" }, + { "viv", "video/vnd.vivo" }, + { "webm", "video/webm" }, + { "f4v", "video/x-f4v" }, + { "fli", "video/x-fli" }, + { "flv", "video/x-flv" }, + { "m4v", "video/x-m4v" }, + { "mkv", "video/x-matroska" }, + { "mk3d", "video/x-matroska" }, + { "mks", "video/x-matroska" }, + { "mng", "video/x-mng" }, + { "asf", "video/x-ms-asf" }, + { "asx", "video/x-ms-asf" }, + { "vob", "video/x-ms-vob" }, + { "wm", "video/x-ms-wm" }, + { "wmv", "video/x-ms-wmv" }, + { "wmx", "video/x-ms-wmx" }, + { "wvx", "video/x-ms-wvx" }, + { "avi", "video/x-msvideo" }, + { "movie", "video/x-sgi-movie" }, + { "smv", "video/x-smv" }, + { "ice", "x-conference/x-cooltalk" }, + { NULL, NULL } +}; + +#endif /* PHP_CLI_SERVER_MIME_TYPE_MAP_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index db5ddb2567..ca0ea57fa7 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -99,6 +99,10 @@ PHPAPI extern char *php_ini_opened_path; PHPAPI extern char *php_ini_scanned_path; PHPAPI extern char *php_ini_scanned_files; +#if defined(PHP_WIN32) && defined(ZTS) +ZEND_TSRMLS_CACHE_DEFINE; +#endif + #ifndef O_BINARY #define O_BINARY 0 #endif @@ -173,58 +177,58 @@ const opt_struct OPTIONS[] = { {'-', 0, NULL} /* end of args */ }; -static int print_module_info(zend_module_entry *module TSRMLS_DC) /* {{{ */ +static int print_module_info(zval *element) /* {{{ */ { + zend_module_entry *module = (zend_module_entry*)Z_PTR_P(element); php_printf("%s\n", module->name); return ZEND_HASH_APPLY_KEEP; } /* }}} */ -static int module_name_cmp(const void *a, const void *b TSRMLS_DC) /* {{{ */ +static int module_name_cmp(const void *a, const void *b) /* {{{ */ { - Bucket *f = *((Bucket **) a); - Bucket *s = *((Bucket **) b); + Bucket *f = (Bucket *) a; + Bucket *s = (Bucket *) b; - return strcasecmp(((zend_module_entry *)f->pData)->name, - ((zend_module_entry *)s->pData)->name); + return strcasecmp(((zend_module_entry *)Z_PTR(f->val))->name, + ((zend_module_entry *)Z_PTR(s->val))->name); } /* }}} */ -static void print_modules(TSRMLS_D) /* {{{ */ +static void print_modules(void) /* {{{ */ { HashTable sorted_registry; - zend_module_entry tmp; - zend_hash_init(&sorted_registry, 50, NULL, NULL, 1); - zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry)); - zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC); - zend_hash_apply(&sorted_registry, (apply_func_t) print_module_info TSRMLS_CC); + zend_hash_init(&sorted_registry, 50, NULL, NULL, 0); + zend_hash_copy(&sorted_registry, &module_registry, NULL); + zend_hash_sort(&sorted_registry, module_name_cmp, 0); + zend_hash_apply(&sorted_registry, print_module_info); zend_hash_destroy(&sorted_registry); } /* }}} */ -static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC) /* {{{ */ +static int print_extension_info(zend_extension *ext, void *arg) /* {{{ */ { php_printf("%s\n", ext->name); return ZEND_HASH_APPLY_KEEP; } /* }}} */ -static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s TSRMLS_DC) /* {{{ */ +static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s) /* {{{ */ { return strcmp(((zend_extension *)(*f)->data)->name, ((zend_extension *)(*s)->data)->name); } /* }}} */ -static void print_extensions(TSRMLS_D) /* {{{ */ +static void print_extensions(void) /* {{{ */ { zend_llist sorted_exts; zend_llist_copy(&sorted_exts, &zend_extensions); sorted_exts.dtor = NULL; - zend_llist_sort(&sorted_exts, extension_name_cmp TSRMLS_CC); - zend_llist_apply(&sorted_exts, (llist_apply_func_t) print_extension_info TSRMLS_CC); + zend_llist_sort(&sorted_exts, extension_name_cmp); + zend_llist_apply(&sorted_exts, (llist_apply_func_t) print_extension_info); zend_llist_destroy(&sorted_exts); } /* }}} */ @@ -233,7 +237,7 @@ static void print_extensions(TSRMLS_D) /* {{{ */ #define STDOUT_FILENO 1 #endif -static inline int sapi_cli_select(int fd TSRMLS_DC) +static inline int sapi_cli_select(int fd) { fd_set wfd, dfd; struct timeval tv; @@ -244,7 +248,7 @@ static inline int sapi_cli_select(int fd TSRMLS_DC) PHP_SAFE_FD_SET(fd, &wfd); - tv.tv_sec = FG(default_socket_timeout); + tv.tv_sec = (long)FG(default_socket_timeout); tv.tv_usec = 0; ret = php_select(fd+1, &dfd, &wfd, &dfd, &tv); @@ -252,17 +256,17 @@ static inline int sapi_cli_select(int fd TSRMLS_DC) return ret != -1; } -PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS_DC) /* {{{ */ +PHP_CLI_API size_t sapi_cli_single_write(const char *str, size_t str_length) /* {{{ */ { #ifdef PHP_WRITE_STDOUT - long ret; + zend_long ret; #else size_t ret; #endif if (cli_shell_callbacks.cli_shell_write) { size_t shell_wrote; - shell_wrote = cli_shell_callbacks.cli_shell_write(str, str_length TSRMLS_CC); + shell_wrote = cli_shell_callbacks.cli_shell_write(str, str_length); if (shell_wrote > -1) { return shell_wrote; } @@ -271,7 +275,7 @@ PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS #ifdef PHP_WRITE_STDOUT do { ret = write(STDOUT_FILENO, str, str_length); - } while (ret <= 0 && errno == EAGAIN && sapi_cli_select(STDOUT_FILENO TSRMLS_CC)); + } while (ret <= 0 && errno == EAGAIN && sapi_cli_select(STDOUT_FILENO)); if (ret <= 0) { return 0; @@ -285,10 +289,10 @@ PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS } /* }}} */ -static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ */ +static size_t sapi_cli_ub_write(const char *str, size_t str_length) /* {{{ */ { const char *ptr = str; - uint remaining = str_length; + size_t remaining = str_length; size_t ret; if (!str_length) { @@ -296,8 +300,8 @@ static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ } if (cli_shell_callbacks.cli_shell_ub_write) { - int ub_wrote; - ub_wrote = cli_shell_callbacks.cli_shell_ub_write(str, str_length TSRMLS_CC); + size_t ub_wrote; + ub_wrote = cli_shell_callbacks.cli_shell_ub_write(str, str_length); if (ub_wrote > -1) { return ub_wrote; } @@ -305,7 +309,7 @@ static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ while (remaining > 0) { - ret = sapi_cli_single_write(ptr, remaining TSRMLS_CC); + ret = sapi_cli_single_write(ptr, remaining); if (!ret) { #ifndef PHP_CLI_WIN32_NO_CONSOLE php_handle_aborted_connection(); @@ -336,47 +340,47 @@ static void sapi_cli_flush(void *server_context) /* {{{ */ static char *php_self = ""; static char *script_filename = ""; -static void sapi_cli_register_variables(zval *track_vars_array TSRMLS_DC) /* {{{ */ +static void sapi_cli_register_variables(zval *track_vars_array) /* {{{ */ { - unsigned int len; + size_t len; char *docroot = ""; /* In CGI mode, we consider the environment to be a part of the server * variables */ - php_import_environment_variables(track_vars_array TSRMLS_CC); + php_import_environment_variables(track_vars_array); /* Build the special-case PHP_SELF variable for the CLI version */ len = strlen(php_self); - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, len, &len TSRMLS_CC)) { - php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, len, &len)) { + php_register_variable("PHP_SELF", php_self, track_vars_array); } - if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_NAME", &php_self, len, &len TSRMLS_CC)) { - php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_NAME", &php_self, len, &len)) { + php_register_variable("SCRIPT_NAME", php_self, track_vars_array); } /* filenames are empty for stdin */ len = strlen(script_filename); - if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_FILENAME", &script_filename, len, &len TSRMLS_CC)) { - php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_FILENAME", &script_filename, len, &len)) { + php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array); } - if (sapi_module.input_filter(PARSE_SERVER, "PATH_TRANSLATED", &script_filename, len, &len TSRMLS_CC)) { - php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PATH_TRANSLATED", &script_filename, len, &len)) { + php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array); } /* just make it available */ len = 0U; - if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT", &docroot, len, &len TSRMLS_CC)) { - php_register_variable("DOCUMENT_ROOT", docroot, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT", &docroot, len, &len)) { + php_register_variable("DOCUMENT_ROOT", docroot, track_vars_array); } } /* }}} */ -static void sapi_cli_log_message(char *message TSRMLS_DC) /* {{{ */ +static void sapi_cli_log_message(char *message) /* {{{ */ { fprintf(stderr, "%s\n", message); } /* }}} */ -static int sapi_cli_deactivate(TSRMLS_D) /* {{{ */ +static int sapi_cli_deactivate(void) /* {{{ */ { fflush(stdout); if(SG(request_info).argv0) { @@ -387,19 +391,19 @@ static int sapi_cli_deactivate(TSRMLS_D) /* {{{ */ } /* }}} */ -static char* sapi_cli_read_cookies(TSRMLS_D) /* {{{ */ +static char* sapi_cli_read_cookies(void) /* {{{ */ { return NULL; } /* }}} */ -static int sapi_cli_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s TSRMLS_DC) /* {{{ */ +static int sapi_cli_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s) /* {{{ */ { return 0; } /* }}} */ -static int sapi_cli_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ */ +static int sapi_cli_send_headers(sapi_headers_struct *sapi_headers) /* {{{ */ { /* We do nothing here, this function is needed to prevent that the fallback * header handling is called. */ @@ -407,7 +411,7 @@ static int sapi_cli_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* } /* }}} */ -static void sapi_cli_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) /* {{{ */ +static void sapi_cli_send_header(sapi_header_struct *sapi_header, void *server_context) /* {{{ */ { } /* }}} */ @@ -425,10 +429,8 @@ static int php_cli_startup(sapi_module_struct *sapi_module) /* {{{ */ /* overwriteable ini defaults must be set in sapi_cli_ini_defaults() */ #define INI_DEFAULT(name,value)\ - Z_SET_REFCOUNT(tmp, 0);\ - Z_UNSET_ISREF(tmp); \ - ZVAL_STRINGL(&tmp, zend_strndup(value, sizeof(value)-1), sizeof(value)-1, 0);\ - zend_hash_update(configuration_hash, name, sizeof(name), &tmp, sizeof(zval), NULL);\ + ZVAL_NEW_STR(&tmp, zend_string_init(value, sizeof(value)-1, 1));\ + zend_hash_str_update(configuration_hash, name, sizeof(name)-1, &tmp);\ static void sapi_cli_ini_defaults(HashTable *configuration_hash) { @@ -468,7 +470,7 @@ static sapi_module_struct cli_sapi_module = { sapi_cli_log_message, /* Log message */ NULL, /* Get request time */ NULL, /* Child terminate */ - + STANDARD_SAPI_MODULE_PROPERTIES }; /* }}} */ @@ -498,7 +500,7 @@ static void php_cli_usage(char *argv0) } else { prog = "php"; } - + printf( "Usage: %s [options] [-f] <file> [--] [args...]\n" " %s [options] -r <code> [--] [args...]\n" " %s [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]\n" @@ -551,31 +553,24 @@ static void php_cli_usage(char *argv0) static php_stream *s_in_process = NULL; -static void cli_register_file_handles(TSRMLS_D) /* {{{ */ +static void cli_register_file_handles(void) /* {{{ */ { - zval *zin, *zout, *zerr; + zval zin, zout, zerr; php_stream *s_in, *s_out, *s_err; php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL; zend_constant ic, oc, ec; - - MAKE_STD_ZVAL(zin); - MAKE_STD_ZVAL(zout); - MAKE_STD_ZVAL(zerr); s_in = php_stream_open_wrapper_ex("php://stdin", "rb", 0, NULL, sc_in); s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out); s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err); if (s_in==NULL || s_out==NULL || s_err==NULL) { - FREE_ZVAL(zin); - FREE_ZVAL(zout); - FREE_ZVAL(zerr); if (s_in) php_stream_close(s_in); if (s_out) php_stream_close(s_out); if (s_err) php_stream_close(s_err); return; } - + #if PHP_DEBUG /* do not close stdout and stderr */ s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE; @@ -584,34 +579,27 @@ static void cli_register_file_handles(TSRMLS_D) /* {{{ */ s_in_process = s_in; - php_stream_to_zval(s_in, zin); - php_stream_to_zval(s_out, zout); - php_stream_to_zval(s_err, zerr); - - ic.value = *zin; + php_stream_to_zval(s_in, &zin); + php_stream_to_zval(s_out, &zout); + php_stream_to_zval(s_err, &zerr); + + ZVAL_COPY_VALUE(&ic.value, &zin); ic.flags = CONST_CS; - ic.name = zend_strndup(ZEND_STRL("STDIN")); - ic.name_len = sizeof("STDIN"); + ic.name = zend_string_init("STDIN", sizeof("STDIN")-1, 1); ic.module_number = 0; - zend_register_constant(&ic TSRMLS_CC); + zend_register_constant(&ic); - oc.value = *zout; + ZVAL_COPY_VALUE(&oc.value, &zout); oc.flags = CONST_CS; - oc.name = zend_strndup(ZEND_STRL("STDOUT")); - oc.name_len = sizeof("STDOUT"); + oc.name = zend_string_init("STDOUT", sizeof("STDOUT")-1, 1); oc.module_number = 0; - zend_register_constant(&oc TSRMLS_CC); + zend_register_constant(&oc); - ec.value = *zerr; + ZVAL_COPY_VALUE(&ec.value, &zerr); ec.flags = CONST_CS; - ec.name = zend_strndup(ZEND_STRL("STDERR")); - ec.name_len = sizeof("STDERR"); + ec.name = zend_string_init("STDERR", sizeof("STDERR")-1, 1); ec.module_number = 0; - zend_register_constant(&ec TSRMLS_CC); - - FREE_ZVAL(zin); - FREE_ZVAL(zout); - FREE_ZVAL(zerr); + zend_register_constant(&ec); } /* }}} */ @@ -619,7 +607,7 @@ static const char *param_mode_conflict = "Either execute direct code, process st /* {{{ cli_seek_file_begin */ -static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno TSRMLS_DC) +static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno) { int c; @@ -643,8 +631,8 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, /* handle situations where line is terminated by \r\n */ if (c == '\r') { if (fgetc(file_handle->handle.fp) != '\n') { - long pos = ftell(file_handle->handle.fp); - fseek(file_handle->handle.fp, pos - 1, SEEK_SET); + zend_long pos = zend_ftell(file_handle->handle.fp); + zend_fseek(file_handle->handle.fp, pos - 1, SEEK_SET); } } *lineno = 2; @@ -656,7 +644,7 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, } /* }}} */ -static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ +static int do_cli(int argc, char **argv) /* {{{ */ { int c; zend_file_handle file_handle; @@ -673,22 +661,22 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ int lineno = 0; const char *param_error=NULL; int hide_argv = 0; + zend_string *key; zend_try { - + CG(in_compilation) = 0; /* not initialized but needed for several options */ - EG(uninitialized_zval_ptr) = NULL; while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { switch (c) { case 'i': /* php info & quit */ - if (php_request_startup(TSRMLS_C)==FAILURE) { + if (php_request_startup()==FAILURE) { goto err; } request_started = 1; - php_print_info(0xFFFFFFFF TSRMLS_CC); - php_output_end_all(TSRMLS_C); + php_print_info(0xFFFFFFFF); + php_output_end_all(); exit_status = (c == '?' && argc > 1 && !strchr(argv[1], c)); goto out; @@ -706,20 +694,20 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ #endif get_zend_version() ); - sapi_deactivate(TSRMLS_C); + sapi_deactivate(); goto out; case 'm': /* list compiled in modules */ - if (php_request_startup(TSRMLS_C)==FAILURE) { + if (php_request_startup()==FAILURE) { goto err; } request_started = 1; php_printf("[PHP Modules]\n"); - print_modules(TSRMLS_C); + print_modules(); php_printf("\n[Zend Modules]\n"); - print_extensions(TSRMLS_C); + print_extensions(); php_printf("\n"); - php_output_end_all(TSRMLS_C); + php_output_end_all(); exit_status=0; goto out; @@ -810,7 +798,7 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ behavior=PHP_MODE_CLI_DIRECT; exec_direct=php_optarg; break; - + case 'R': if (behavior == PHP_MODE_PROCESS_STDIN) { if (exec_run || script_file) { @@ -918,20 +906,18 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ fflush(stdout); } - 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 > php_optind - && !script_file - && behavior!=PHP_MODE_CLI_DIRECT - && behavior!=PHP_MODE_PROCESS_STDIN - && strcmp(argv[php_optind-1],"--")) + if (argc > php_optind + && !script_file + && behavior!=PHP_MODE_CLI_DIRECT + && behavior!=PHP_MODE_PROCESS_STDIN + && strcmp(argv[php_optind-1],"--")) { script_file=argv[php_optind]; php_optind++; } if (script_file) { - if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) { + if (cli_seek_file_begin(&file_handle, script_file, &lineno) != SUCCESS) { goto err; } else { char real_path[MAXPATHLEN]; @@ -962,7 +948,7 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ argv[php_optind-1] = (char*)file_handle.filename; SG(request_info).argv=argv+php_optind-1; - if (php_request_startup(TSRMLS_C)==FAILURE) { + if (php_request_startup()==FAILURE) { *arg_excp = arg_free; fclose(file_handle.handle.fp); PUTS("Could not startup.\n"); @@ -979,24 +965,26 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ } } - zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC); + key = zend_string_init("_SERVER", sizeof("_SERVER")-1, 0); + zend_is_auto_global(key); + zend_string_release(key); PG(during_request_startup) = 0; switch (behavior) { case PHP_MODE_STANDARD: if (strcmp(file_handle.filename, "-")) { - cli_register_file_handles(TSRMLS_C); + cli_register_file_handles(); } if (interactive && cli_shell_callbacks.cli_shell_run) { - exit_status = cli_shell_callbacks.cli_shell_run(TSRMLS_C); + exit_status = cli_shell_callbacks.cli_shell_run(); } else { - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); exit_status = EG(exit_status); } break; case PHP_MODE_LINT: - exit_status = php_lint_script(&file_handle TSRMLS_CC); + exit_status = php_lint_script(&file_handle); if (exit_status==SUCCESS) { zend_printf("No syntax errors detected in %s\n", file_handle.filename); } else { @@ -1004,8 +992,8 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ } break; case PHP_MODE_STRIP: - if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { - zend_strip(TSRMLS_C); + if (open_file_for_scanning(&file_handle)==SUCCESS) { + zend_strip(); } goto out; break; @@ -1013,9 +1001,9 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ { zend_syntax_highlighter_ini syntax_highlighter_ini; - if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { + if (open_file_for_scanning(&file_handle)==SUCCESS) { php_get_highlight_struct(&syntax_highlighter_ini); - zend_highlight(&syntax_highlighter_ini TSRMLS_CC); + zend_highlight(&syntax_highlighter_ini); } goto out; } @@ -1023,77 +1011,71 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ #if 0 /* Zeev might want to do something with this one day */ case PHP_MODE_INDENT: - open_file_for_scanning(&file_handle TSRMLS_CC); + open_file_for_scanning(&file_handle); zend_indent(); - zend_file_handle_dtor(file_handle.handle TSRMLS_CC); + zend_file_handle_dtor(file_handle.handle); goto out; break; #endif case PHP_MODE_CLI_DIRECT: - cli_register_file_handles(TSRMLS_C); - if (zend_eval_string_ex(exec_direct, NULL, "Command line code", 1 TSRMLS_CC) == FAILURE) { + cli_register_file_handles(); + if (zend_eval_string_ex(exec_direct, NULL, "Command line code", 1) == FAILURE) { exit_status=254; } break; - + case PHP_MODE_PROCESS_STDIN: { char *input; size_t len, index = 0; - zval *argn, *argi; + zval argn, argi; - cli_register_file_handles(TSRMLS_C); + cli_register_file_handles(); - if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1 TSRMLS_CC) == FAILURE) { + if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1) == FAILURE) { exit_status=254; } - ALLOC_ZVAL(argi); - Z_TYPE_P(argi) = IS_LONG; - Z_LVAL_P(argi) = index; - INIT_PZVAL(argi); - zend_hash_update(&EG(symbol_table), "argi", sizeof("argi"), &argi, sizeof(zval *), NULL); + ZVAL_LONG(&argi, index); + zend_hash_str_update(&EG(symbol_table).ht, "argi", sizeof("argi")-1, &argi); while (exit_status == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) { len = strlen(input); - while (len-- && (input[len]=='\n' || input[len]=='\r')) { + while (len > 0 && len-- && (input[len]=='\n' || input[len]=='\r')) { input[len] = '\0'; } - ALLOC_ZVAL(argn); - Z_TYPE_P(argn) = IS_STRING; - Z_STRLEN_P(argn) = ++len; - Z_STRVAL_P(argn) = estrndup(input, len); - INIT_PZVAL(argn); - zend_hash_update(&EG(symbol_table), "argn", sizeof("argn"), &argn, sizeof(zval *), NULL); - Z_LVAL_P(argi) = ++index; + ZVAL_STRINGL(&argn, input, len); + zend_hash_str_update(&EG(symbol_table).ht, "argn", sizeof("argn")-1, &argn); + Z_LVAL(argi) = ++index; if (exec_run) { - if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1 TSRMLS_CC) == FAILURE) { + if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1) == FAILURE) { exit_status=254; } } else { if (script_file) { - if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) { + if (cli_seek_file_begin(&file_handle, script_file, &lineno) != SUCCESS) { exit_status = 1; } else { CG(start_lineno) = lineno; - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); exit_status = EG(exit_status); } } } efree(input); } - if (exec_end && zend_eval_string_ex(exec_end, NULL, "Command line end code", 1 TSRMLS_CC) == FAILURE) { + if (exec_end && zend_eval_string_ex(exec_end, NULL, "Command line end code", 1) == FAILURE) { exit_status=254; } break; } + case PHP_MODE_REFLECTION_FUNCTION: case PHP_MODE_REFLECTION_CLASS: case PHP_MODE_REFLECTION_EXTENSION: case PHP_MODE_REFLECTION_ZEND_EXTENSION: { zend_class_entry *pce = NULL; - zval *arg, *ref; + zval arg, ref; zend_execute_data execute_data; switch (behavior) { @@ -1116,25 +1098,24 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ pce = reflection_zend_extension_ptr; break; } - - MAKE_STD_ZVAL(arg); - ZVAL_STRING(arg, reflection_what, 1); - ALLOC_ZVAL(ref); - object_init_ex(ref, pce); - INIT_PZVAL(ref); + + ZVAL_STRING(&arg, reflection_what); + object_init_ex(&ref, pce); memset(&execute_data, 0, sizeof(zend_execute_data)); EG(current_execute_data) = &execute_data; - EX(function_state).function = pce->constructor; - zend_call_method_with_1_params(&ref, pce, &pce->constructor, "__construct", NULL, arg); + zend_call_method_with_1_params(&ref, pce, &pce->constructor, "__construct", NULL, &arg); if (EG(exception)) { - zval *msg = zend_read_property(zend_exception_get_default(TSRMLS_C), EG(exception), "message", sizeof("message")-1, 0 TSRMLS_CC); + zval tmp, *msg, rv; + + ZVAL_OBJ(&tmp, EG(exception)); + msg = zend_read_property(zend_exception_get_default(), &tmp, "message", sizeof("message")-1, 0, &rv); zend_printf("Exception: %s\n", Z_STRVAL_P(msg)); - zval_ptr_dtor(&EG(exception)); + zval_ptr_dtor(&tmp); EG(exception) = NULL; } else { - zend_call_method_with_1_params(NULL, reflection_ptr, NULL, "export", NULL, ref); + zend_call_method_with_1_params(NULL, reflection_ptr, NULL, "export", NULL, &ref); } zval_ptr_dtor(&ref); zval_ptr_dtor(&arg); @@ -1143,11 +1124,11 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ } case PHP_MODE_REFLECTION_EXT_INFO: { - int len = strlen(reflection_what); + int len = (int)strlen(reflection_what); char *lcname = zend_str_tolower_dup(reflection_what, len); zend_module_entry *module; - if (zend_hash_find(&module_registry, lcname, len+1, (void**)&module) == FAILURE) { + if ((module = zend_hash_str_find_ptr(&module_registry, lcname, len)) == NULL) { if (!strcmp(reflection_what, "main")) { display_ini_entries(NULL); } else { @@ -1155,12 +1136,13 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ exit_status = 1; } } else { - php_info_print_module(module TSRMLS_CC); + php_info_print_module(module); } - + efree(lcname); break; } + case PHP_MODE_SHOW_INI_CONFIG: { zend_printf("Configuration File (php.ini) Path: %s\n", PHP_CONFIG_FILE_PATH); @@ -1184,8 +1166,8 @@ out: } return exit_status; err: - sapi_deactivate(TSRMLS_C); - zend_ini_deactivate(TSRMLS_C); + sapi_deactivate(); + zend_ini_deactivate(); exit_status = 1; goto out; } @@ -1258,6 +1240,7 @@ int main(int argc, char *argv[]) #ifdef ZTS tsrm_startup(1, 1, 0, NULL); tsrm_ls = ts_resource(0); + ZEND_TSRMLS_CACHE_UPDATE; #endif #ifdef PHP_WIN32 @@ -1280,7 +1263,7 @@ int main(int argc, char *argv[]) break; case 'd': { /* define ini entries on command line */ - int len = strlen(php_optarg); + int len = (int)strlen(php_optarg); char *val; if ((val = strchr(php_optarg, '='))) { @@ -1288,11 +1271,11 @@ int main(int argc, char *argv[]) if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') { ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\"\"\n\0")); memcpy(ini_entries + ini_entries_len, php_optarg, (val - php_optarg)); - ini_entries_len += (val - php_optarg); + ini_entries_len += (int)(val - php_optarg); memcpy(ini_entries + ini_entries_len, "\"", 1); ini_entries_len++; memcpy(ini_entries + ini_entries_len, val, len - (val - php_optarg)); - ini_entries_len += len - (val - php_optarg); + ini_entries_len += len - (int)(val - php_optarg); memcpy(ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0")); ini_entries_len += sizeof("\n\0\"") - 2; } else { @@ -1365,7 +1348,7 @@ exit_loop: goto out; } module_started = 1; - + /* -e option */ if (use_extended_info) { CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; @@ -1375,10 +1358,10 @@ exit_loop: #ifndef PHP_CLI_WIN32_NO_CONSOLE if (sapi_module == &cli_sapi_module) { #endif - exit_status = do_cli(argc, argv TSRMLS_CC); + exit_status = do_cli(argc, argv); #ifndef PHP_CLI_WIN32_NO_CONSOLE } else { - exit_status = do_cli_server(argc, argv TSRMLS_CC); + exit_status = do_cli_server(argc, argv); } #endif } zend_end_try(); @@ -1390,7 +1373,7 @@ out: free(ini_entries); } if (module_started) { - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); } if (sapi_started) { sapi_shutdown(); diff --git a/sapi/cli/php_cli_process_title.c b/sapi/cli/php_cli_process_title.c index 3677c84e44..db614d4323 100644 --- a/sapi/cli/php_cli_process_title.c +++ b/sapi/cli/php_cli_process_title.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -31,10 +31,10 @@ PHP_FUNCTION(cli_set_process_title) { char *title = NULL; - int title_len; + size_t title_len; int rc; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &title, &title_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &title, &title_len) == FAILURE) { return; } @@ -43,7 +43,7 @@ PHP_FUNCTION(cli_set_process_title) RETURN_TRUE; } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cli_set_process_title had an error: %s", ps_title_errno(rc)); + php_error_docref(NULL, E_WARNING, "cli_set_process_title had an error: %s", ps_title_errno(rc)); RETURN_FALSE; } /* }}} */ @@ -62,11 +62,11 @@ PHP_FUNCTION(cli_get_process_title) rc = get_ps_title(&length, &title); if (rc != PS_TITLE_SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cli_get_process_title had an error: %s", ps_title_errno(rc)); + php_error_docref(NULL, E_WARNING, "cli_get_process_title had an error: %s", ps_title_errno(rc)); RETURN_NULL(); } - RETURN_STRINGL(title, length, 1); + RETURN_STRINGL(title, length); } /* }}} */ diff --git a/sapi/cli/php_cli_process_title.h b/sapi/cli/php_cli_process_title.h index 3cfcb70f7d..30091fe2fb 100644 --- a/sapi/cli/php_cli_process_title.h +++ b/sapi/cli/php_cli_process_title.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 3b5fe05945..64acd9a682 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -68,6 +68,7 @@ #include "zend_hash.h" #include "zend_modules.h" #include "fopen_wrappers.h" +#include "http_status_codes.h" #include "zend_compile.h" #include "zend_execute.h" @@ -96,7 +97,7 @@ #endif #include "ext/standard/file.h" /* for php_set_sock_blocking() :-( */ -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" #include "ext/standard/html.h" #include "ext/standard/url.h" /* for php_url_decode() */ #include "ext/standard/php_string.h" /* for php_dirname() */ @@ -104,6 +105,7 @@ #include "php_http_parser.h" #include "php_cli_server.h" +#include "mime_type_map.h" #include "php_cli_process_title.h" @@ -138,7 +140,7 @@ typedef struct php_cli_server_request { size_t content_len; const char *ext; size_t ext_len; - struct stat sb; + zend_stat_t sb; } php_cli_server_request; typedef struct php_cli_server_chunk { @@ -194,6 +196,7 @@ typedef struct php_cli_server { size_t router_len; socklen_t socklen; HashTable clients; + HashTable extension_mime_types; } php_cli_server; typedef struct php_cli_server_http_response_status_code_pair { @@ -201,60 +204,6 @@ typedef struct php_cli_server_http_response_status_code_pair { const char *str; } php_cli_server_http_response_status_code_pair; -typedef struct php_cli_server_ext_mime_type_pair { - const char *ext; - const char *mime_type; -} php_cli_server_ext_mime_type_pair; - -static php_cli_server_http_response_status_code_pair status_map[] = { - { 100, "Continue" }, - { 101, "Switching Protocols" }, - { 200, "OK" }, - { 201, "Created" }, - { 202, "Accepted" }, - { 203, "Non-Authoritative Information" }, - { 204, "No Content" }, - { 205, "Reset Content" }, - { 206, "Partial Content" }, - { 300, "Multiple Choices" }, - { 301, "Moved Permanently" }, - { 302, "Found" }, - { 303, "See Other" }, - { 304, "Not Modified" }, - { 305, "Use Proxy" }, - { 307, "Temporary Redirect" }, - { 308, "Permanent Redirect" }, - { 400, "Bad Request" }, - { 401, "Unauthorized" }, - { 402, "Payment Required" }, - { 403, "Forbidden" }, - { 404, "Not Found" }, - { 405, "Method Not Allowed" }, - { 406, "Not Acceptable" }, - { 407, "Proxy Authentication Required" }, - { 408, "Request Timeout" }, - { 409, "Conflict" }, - { 410, "Gone" }, - { 411, "Length Required" }, - { 412, "Precondition Failed" }, - { 413, "Request Entity Too Large" }, - { 414, "Request-URI Too Long" }, - { 415, "Unsupported Media Type" }, - { 416, "Requested Range Not Satisfiable" }, - { 417, "Expectation Failed" }, - { 426, "Upgrade Required" }, - { 428, "Precondition Required" }, - { 429, "Too Many Requests" }, - { 431, "Request Header Fields Too Large" }, - { 500, "Internal Server Error" }, - { 501, "Not Implemented" }, - { 502, "Bad Gateway" }, - { 503, "Service Unavailable" }, - { 504, "Gateway Timeout" }, - { 505, "HTTP Version Not Supported" }, - { 511, "Network Authentication Required" }, -}; - static php_cli_server_http_response_status_code_pair template_map[] = { { 400, "<h1>%s</h1><p>Your browser sent a request that this server could not understand.</p>" }, { 404, "<h1>%s</h1><p>The requested resource <code class=\"url\">%s</code> was not found on this server.</p>" }, @@ -262,71 +211,15 @@ static php_cli_server_http_response_status_code_pair template_map[] = { { 501, "<h1>%s</h1><p>Request method not supported.</p>" } }; -static php_cli_server_ext_mime_type_pair mime_type_map[] = { - { "html", "text/html" }, - { "htm", "text/html" }, - { "js", "text/javascript" }, - { "css", "text/css" }, - { "gif", "image/gif" }, - { "jpg", "image/jpeg" }, - { "jpeg", "image/jpeg" }, - { "jpe", "image/jpeg" }, - { "pdf", "application/pdf" }, - { "png", "image/png" }, - { "svg", "image/svg+xml" }, - { "txt", "text/plain" }, - { "webm", "video/webm" }, - { "ogv", "video/ogg" }, - { "ogg", "audio/ogg" }, - { "3gp", "video/3gpp" }, /* This is standard video format used for MMS in phones */ - { "apk", "application/vnd.android.package-archive" }, - { "avi", "video/x-msvideo" }, - { "bmp", "image/x-ms-bmp" }, - { "csv", "text/comma-separated-values" }, - { "doc", "application/msword" }, - { "docx", "application/msword" }, - { "flac", "audio/flac" }, - { "gz", "application/x-gzip" }, - { "gzip", "application/x-gzip" }, - { "ics", "text/calendar" }, - { "kml", "application/vnd.google-earth.kml+xml" }, - { "kmz", "application/vnd.google-earth.kmz" }, - { "m4a", "audio/mp4" }, - { "mp3", "audio/mpeg" }, - { "mp4", "video/mp4" }, - { "mpg", "video/mpeg" }, - { "mpeg", "video/mpeg" }, - { "mov", "video/quicktime" }, - { "odp", "application/vnd.oasis.opendocument.presentation" }, - { "ods", "application/vnd.oasis.opendocument.spreadsheet" }, - { "odt", "application/vnd.oasis.opendocument.text" }, - { "oga", "audio/ogg" }, - { "pdf", "application/pdf" }, - { "pptx", "application/vnd.ms-powerpoint" }, - { "pps", "application/vnd.ms-powerpoint" }, - { "qt", "video/quicktime" }, - { "swf", "application/x-shockwave-flash" }, - { "tar", "application/x-tar" }, - { "text", "text/plain" }, - { "tif", "image/tiff" }, - { "wav", "audio/wav" }, - { "wmv", "video/x-ms-wmv" }, - { "xls", "application/vnd.ms-excel" }, - { "xlsx", "application/vnd.ms-excel" }, - { "zip", "application/x-zip-compressed" }, - { "xml", "application/xml" }, - { "xsl", "application/xml" }, - { "xsd", "application/xml" }, - { NULL, NULL } -}; - +#if HAVE_UNISTD_H static int php_cli_output_is_tty = OUTPUT_NOT_CHECKED; +#endif static size_t php_cli_server_client_send_through(php_cli_server_client *client, const char *str, size_t str_len); static php_cli_server_chunk *php_cli_server_chunk_heap_new_self_contained(size_t len); static void php_cli_server_buffer_append(php_cli_server_buffer *buffer, php_cli_server_chunk *chunk); -static void php_cli_server_logf(const char *format TSRMLS_DC, ...); -static void php_cli_server_log_response(php_cli_server_client *client, int status, const char *message TSRMLS_DC); +static void php_cli_server_logf(const char *format, ...); +static void php_cli_server_log_response(php_cli_server_client *client, int status, const char *message); ZEND_DECLARE_MODULE_GLOBALS(cli_server); @@ -371,9 +264,9 @@ int php_cli_server_get_system_time(char *buf) { } #endif -static void char_ptr_dtor_p(char **p) /* {{{ */ +static void char_ptr_dtor_p(zval *zv) /* {{{ */ { - pefree(*p, 1); + pefree(Z_PTR_P(zv), 1); } /* }}} */ static char *get_last_error() /* {{{ */ @@ -383,8 +276,8 @@ static char *get_last_error() /* {{{ */ static int status_comp(const void *a, const void *b) /* {{{ */ { - const php_cli_server_http_response_status_code_pair *pa = (const php_cli_server_http_response_status_code_pair *) a; - const php_cli_server_http_response_status_code_pair *pb = (const php_cli_server_http_response_status_code_pair *) b; + const http_response_status_code_pair *pa = (const http_response_status_code_pair *) a; + const http_response_status_code_pair *pb = (const http_response_status_code_pair *) b; if (pa->code < pb->code) { return -1; @@ -397,12 +290,10 @@ static int status_comp(const void *a, const void *b) /* {{{ */ static const char *get_status_string(int code) /* {{{ */ { - php_cli_server_http_response_status_code_pair needle, *result = NULL; + http_response_status_code_pair needle = {code, NULL}, + *result = NULL; - needle.code = code; - needle.str = NULL; - - result = bsearch(&needle, status_map, sizeof(status_map) / sizeof(needle), sizeof(needle), status_comp); + result = bsearch(&needle, http_status_map, http_status_map_len, sizeof(needle), status_comp); if (result) { return result->str; @@ -441,11 +332,11 @@ static void append_http_status_line(smart_str *buffer, int protocol_version, int } smart_str_appendl_ex(buffer, "HTTP", 4, persistent); smart_str_appendc_ex(buffer, '/', persistent); - smart_str_append_generic_ex(buffer, protocol_version / 100, persistent, int, _unsigned); + smart_str_append_long_ex(buffer, protocol_version / 100, persistent); smart_str_appendc_ex(buffer, '.', persistent); - smart_str_append_generic_ex(buffer, protocol_version % 100, persistent, int, _unsigned); + smart_str_append_long_ex(buffer, protocol_version % 100, persistent); smart_str_appendc_ex(buffer, ' ', persistent); - smart_str_append_generic_ex(buffer, response_code, persistent, int, _unsigned); + smart_str_append_long_ex(buffer, response_code, persistent); smart_str_appendc_ex(buffer, ' ', persistent); smart_str_appends_ex(buffer, get_status_string(response_code), persistent); smart_str_appendl_ex(buffer, "\r\n", 2, persistent); @@ -454,37 +345,29 @@ static void append_http_status_line(smart_str *buffer, int protocol_version, int static void append_essential_headers(smart_str* buffer, php_cli_server_client *client, int persistent) /* {{{ */ { { - char **val; - if (SUCCESS == zend_hash_find(&client->request.headers, "host", sizeof("host"), (void**)&val)) { + char *val; + if (NULL != (val = zend_hash_str_find_ptr(&client->request.headers, "host", sizeof("host")-1))) { smart_str_appendl_ex(buffer, "Host", sizeof("Host") - 1, persistent); smart_str_appendl_ex(buffer, ": ", sizeof(": ") - 1, persistent); - smart_str_appends_ex(buffer, *val, persistent); + smart_str_appends_ex(buffer, val, persistent); smart_str_appendl_ex(buffer, "\r\n", 2, persistent); } } smart_str_appendl_ex(buffer, "Connection: close\r\n", sizeof("Connection: close\r\n") - 1, persistent); } /* }}} */ -static const char *get_mime_type(const char *ext, size_t ext_len) /* {{{ */ +static const char *get_mime_type(const php_cli_server *server, const char *ext, size_t ext_len) /* {{{ */ { - php_cli_server_ext_mime_type_pair *pair; - for (pair = mime_type_map; pair->ext; pair++) { - size_t len = strlen(pair->ext); - if (len == ext_len && memcmp(pair->ext, ext, len) == 0) { - return pair->mime_type; - } - } - return NULL; + return (const char*)zend_hash_str_find_ptr(&server->extension_mime_types, ext, ext_len); } /* }}} */ PHP_FUNCTION(apache_request_headers) /* {{{ */ { php_cli_server_client *client; HashTable *headers; - char *key; - uint key_len; - char **value_pointer; - HashPosition pos; + zend_string *key; + char *value; + zval tmp; if (zend_parse_parameters_none() == FAILURE) { return; @@ -495,19 +378,17 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ array_init_size(return_value, zend_hash_num_elements(headers)); - zend_hash_internal_pointer_reset_ex(headers, &pos); - while (zend_hash_get_current_data_ex(headers, (void **)&value_pointer, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(headers, &key, &key_len, NULL, 0, &pos); - add_assoc_string_ex(return_value, key, key_len, *value_pointer, 1); - zend_hash_move_forward_ex(headers, &pos); - } + ZEND_HASH_FOREACH_STR_KEY_PTR(headers, key, value) { + ZVAL_STRING(&tmp, value); + zend_symtable_update(Z_ARRVAL_P(return_value), key, &tmp); + } ZEND_HASH_FOREACH_END(); } /* }}} */ -static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS_DC) /* {{{ */ +static void add_response_header(sapi_header_struct *h, zval *return_value) /* {{{ */ { char *s, *p; - int len; + ptrdiff_t len; ALLOCA_FLAG(use_heap) if (h->header_len > 0) { @@ -524,7 +405,7 @@ static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS do { p++; } while (*p == ' ' || *p == '\t'); - add_assoc_stringl_ex(return_value, s, len+1, p, h->header_len - (p - h->header), 1); + add_assoc_stringl_ex(return_value, s, (uint)len, p, h->header_len - (p - h->header)); free_alloca(s, use_heap); } } @@ -542,14 +423,14 @@ PHP_FUNCTION(apache_response_headers) /* {{{ */ RETURN_FALSE; } array_init(return_value); - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t)add_response_header, return_value TSRMLS_CC); + zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t)add_response_header, return_value); } /* }}} */ /* {{{ cli_server module */ -static void cli_server_init_globals(zend_cli_server_globals *cg TSRMLS_DC) +static void cli_server_init_globals(zend_cli_server_globals *cg) { cg->color = 0; } @@ -610,7 +491,7 @@ static int sapi_cli_server_startup(sapi_module_struct *sapi_module) /* {{{ */ return SUCCESS; } /* }}} */ -static int sapi_cli_server_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ */ +static size_t sapi_cli_server_ub_write(const char *str, size_t str_length) /* {{{ */ { php_cli_server_client *client = SG(server_context); if (!client) { @@ -622,29 +503,28 @@ static int sapi_cli_server_ub_write(const char *str, uint str_length TSRMLS_DC) static void sapi_cli_server_flush(void *server_context) /* {{{ */ { php_cli_server_client *client = server_context; - TSRMLS_FETCH(); if (!client) { return; } - if (client->sock < 0) { + if (!ZEND_VALID_SOCKET(client->sock)) { php_handle_aborted_connection(); return; } if (!SG(headers_sent)) { - sapi_send_headers(TSRMLS_C); + sapi_send_headers(); SG(headers_sent) = 1; } } /* }}} */ -static int sapi_cli_server_discard_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ */{ +static int sapi_cli_server_discard_headers(sapi_headers_struct *sapi_headers) /* {{{ */{ return SAPI_HEADER_SENT_SUCCESSFULLY; } /* }}} */ -static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ */ +static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers) /* {{{ */ { php_cli_server_client *client = SG(server_context); smart_str buffer = { 0 }; @@ -674,24 +554,24 @@ static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers TSRMLS } smart_str_appendl(&buffer, "\r\n", 2); - php_cli_server_client_send_through(client, buffer.c, buffer.len); + php_cli_server_client_send_through(client, buffer.s->val, buffer.s->len); smart_str_free(&buffer); return SAPI_HEADER_SENT_SUCCESSFULLY; } /* }}} */ -static char *sapi_cli_server_read_cookies(TSRMLS_D) /* {{{ */ +static char *sapi_cli_server_read_cookies(void) /* {{{ */ { php_cli_server_client *client = SG(server_context); - char **val; - if (FAILURE == zend_hash_find(&client->request.headers, "cookie", sizeof("cookie"), (void**)&val)) { + char *val; + if (NULL == (val = zend_hash_str_find_ptr(&client->request.headers, "cookie", sizeof("cookie")-1))) { return NULL; } - return *val; + return val; } /* }}} */ -static int sapi_cli_server_read_post(char *buf, uint count_bytes TSRMLS_DC) /* {{{ */ +static size_t sapi_cli_server_read_post(char *buf, size_t count_bytes) /* {{{ */ { php_cli_server_client *client = SG(server_context); if (client->request.content) { @@ -704,27 +584,27 @@ static int sapi_cli_server_read_post(char *buf, uint count_bytes TSRMLS_DC) /* { return 0; } /* }}} */ -static void sapi_cli_server_register_variable(zval *track_vars_array, const char *key, const char *val TSRMLS_DC) /* {{{ */ +static void sapi_cli_server_register_variable(zval *track_vars_array, const char *key, const char *val) /* {{{ */ { char *new_val = (char *)val; - uint new_val_len; + size_t new_val_len; if (NULL == val) { return; } - if (sapi_module.input_filter(PARSE_SERVER, (char*)key, &new_val, strlen(val), &new_val_len TSRMLS_CC)) { - php_register_variable_safe((char *)key, new_val, new_val_len, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, (char*)key, &new_val, strlen(val), &new_val_len)) { + php_register_variable_safe((char *)key, new_val, new_val_len, track_vars_array); } } /* }}} */ -static int sapi_cli_server_register_entry_cb(char **entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { +static int sapi_cli_server_register_entry_cb(char **entry, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { zval *track_vars_array = va_arg(args, zval *); - if (hash_key->nKeyLength) { + if (hash_key->key) { char *real_key, *key; uint i; - key = estrndup(hash_key->arKey, hash_key->nKeyLength); - for(i=0; i<hash_key->nKeyLength; i++) { + key = estrndup(hash_key->key->val, hash_key->key->len); + for(i=0; i<hash_key->key->len; i++) { if (key[i] == '-') { key[i] = '_'; } else { @@ -732,7 +612,7 @@ static int sapi_cli_server_register_entry_cb(char **entry TSRMLS_DC, int num_arg } } spprintf(&real_key, 0, "%s_%s", "HTTP", key); - sapi_cli_server_register_variable(track_vars_array, real_key, *entry TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, real_key, *entry); efree(key); efree(real_key); } @@ -741,10 +621,10 @@ static int sapi_cli_server_register_entry_cb(char **entry TSRMLS_DC, int num_arg } /* }}} */ -static void sapi_cli_server_register_variables(zval *track_vars_array TSRMLS_DC) /* {{{ */ +static void sapi_cli_server_register_variables(zval *track_vars_array) /* {{{ */ { php_cli_server_client *client = SG(server_context); - sapi_cli_server_register_variable(track_vars_array, "DOCUMENT_ROOT", client->server->document_root TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "DOCUMENT_ROOT", client->server->document_root); { char *tmp; if ((tmp = strrchr(client->addr_str, ':'))) { @@ -753,61 +633,61 @@ static void sapi_cli_server_register_variables(zval *track_vars_array TSRMLS_DC) port[7] = '\0'; strncpy(addr, client->addr_str, tmp - client->addr_str); addr[tmp - client->addr_str] = '\0'; - sapi_cli_server_register_variable(track_vars_array, "REMOTE_ADDR", addr TSRMLS_CC); - sapi_cli_server_register_variable(track_vars_array, "REMOTE_PORT", port TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "REMOTE_ADDR", addr); + sapi_cli_server_register_variable(track_vars_array, "REMOTE_PORT", port); } else { - sapi_cli_server_register_variable(track_vars_array, "REMOTE_ADDR", client->addr_str TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "REMOTE_ADDR", client->addr_str); } } { char *tmp; spprintf(&tmp, 0, "PHP %s Development Server", PHP_VERSION); - sapi_cli_server_register_variable(track_vars_array, "SERVER_SOFTWARE", tmp TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SERVER_SOFTWARE", tmp); efree(tmp); } { char *tmp; spprintf(&tmp, 0, "HTTP/%d.%d", client->request.protocol_version / 100, client->request.protocol_version % 100); - sapi_cli_server_register_variable(track_vars_array, "SERVER_PROTOCOL", tmp TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SERVER_PROTOCOL", tmp); efree(tmp); } - sapi_cli_server_register_variable(track_vars_array, "SERVER_NAME", client->server->host TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SERVER_NAME", client->server->host); { char *tmp; spprintf(&tmp, 0, "%i", client->server->port); - sapi_cli_server_register_variable(track_vars_array, "SERVER_PORT", tmp TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SERVER_PORT", tmp); efree(tmp); } - sapi_cli_server_register_variable(track_vars_array, "REQUEST_URI", client->request.request_uri TSRMLS_CC); - sapi_cli_server_register_variable(track_vars_array, "REQUEST_METHOD", SG(request_info).request_method TSRMLS_CC); - sapi_cli_server_register_variable(track_vars_array, "SCRIPT_NAME", client->request.vpath TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "REQUEST_URI", client->request.request_uri); + sapi_cli_server_register_variable(track_vars_array, "REQUEST_METHOD", SG(request_info).request_method); + sapi_cli_server_register_variable(track_vars_array, "SCRIPT_NAME", client->request.vpath); if (SG(request_info).path_translated) { - sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", SG(request_info).path_translated TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", SG(request_info).path_translated); } else if (client->server->router) { char *temp; spprintf(&temp, 0, "%s/%s", client->server->document_root, client->server->router); - sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", temp TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", temp); efree(temp); } if (client->request.path_info) { - sapi_cli_server_register_variable(track_vars_array, "PATH_INFO", client->request.path_info TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "PATH_INFO", client->request.path_info); } if (client->request.path_info_len) { char *tmp; spprintf(&tmp, 0, "%s%s", client->request.vpath, client->request.path_info); - sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", tmp TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", tmp); efree(tmp); } else { - sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", client->request.vpath TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", client->request.vpath); } if (client->request.query_string) { - sapi_cli_server_register_variable(track_vars_array, "QUERY_STRING", client->request.query_string TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "QUERY_STRING", client->request.query_string); } - zend_hash_apply_with_arguments(&client->request.headers TSRMLS_CC, (apply_func_args_t)sapi_cli_server_register_entry_cb, 1, track_vars_array); + zend_hash_apply_with_arguments(&client->request.headers, (apply_func_args_t)sapi_cli_server_register_entry_cb, 1, track_vars_array); } /* }}} */ -static void sapi_cli_server_log_message(char *msg TSRMLS_DC) /* {{{ */ +static void sapi_cli_server_log_message(char *msg) /* {{{ */ { char buf[52]; @@ -866,7 +746,7 @@ static int php_cli_server_poller_ctor(php_cli_server_poller *poller) /* {{{ */ return SUCCESS; } /* }}} */ -static void php_cli_server_poller_add(php_cli_server_poller *poller, int mode, int fd) /* {{{ */ +static void php_cli_server_poller_add(php_cli_server_poller *poller, int mode, php_socket_t fd) /* {{{ */ { if (mode & POLLIN) { PHP_SAFE_FD_SET(fd, &poller->rfds); @@ -879,7 +759,7 @@ static void php_cli_server_poller_add(php_cli_server_poller *poller, int mode, i } } /* }}} */ -static void php_cli_server_poller_remove(php_cli_server_poller *poller, int mode, int fd) /* {{{ */ +static void php_cli_server_poller_remove(php_cli_server_poller *poller, int mode, php_socket_t fd) /* {{{ */ { if (mode & POLLIN) { PHP_SAFE_FD_CLR(fd, &poller->rfds); @@ -907,7 +787,7 @@ static int php_cli_server_poller_poll(php_cli_server_poller *poller, struct time return php_select(poller->max_fd + 1, &poller->active.rfds, &poller->active.wfds, NULL, tv); } /* }}} */ -static int php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, void *opaque, int(*callback)(void *, int fd, int events)) /* {{{ */ +static int php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, void *opaque, int(*callback)(void *, php_socket_t fd, int events)) /* {{{ */ { int retval = SUCCESS; #ifdef PHP_WIN32 @@ -915,7 +795,6 @@ static int php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, v SOCKET fd; int events; } entries[FD_SETSIZE * 2]; - php_socket_t fd = 0; size_t i; struct socket_entry *n = entries, *m; @@ -1058,7 +937,7 @@ static php_cli_server_chunk *php_cli_server_chunk_immortal_new(const char *buf, return chunk; } /* }}} */ -static php_cli_server_chunk *php_cli_server_chunk_heap_new(char *block, char *buf, size_t len) /* {{{ */ +static php_cli_server_chunk *php_cli_server_chunk_heap_new(void *block, char *buf, size_t len) /* {{{ */ { php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk), 1); if (!chunk) { @@ -1104,12 +983,20 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen size_t _nbytes_sent_total = 0; for (chunk = sender->buffer.first; chunk; chunk = next) { +#ifdef PHP_WIN32 + int nbytes_sent; +#else ssize_t nbytes_sent; +#endif next = chunk->next; switch (chunk->type) { case PHP_CLI_SERVER_CHUNK_HEAP: +#ifdef PHP_WIN32 + nbytes_sent = send(fd, chunk->data.heap.p, (int)chunk->data.heap.len, 0); +#else nbytes_sent = send(fd, chunk->data.heap.p, chunk->data.heap.len, 0); +#endif if (nbytes_sent < 0) { *nbytes_sent_total = _nbytes_sent_total; return php_socket_errno(); @@ -1128,7 +1015,11 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen break; case PHP_CLI_SERVER_CHUNK_IMMORTAL: +#ifdef PHP_WIN32 + nbytes_sent = send(fd, chunk->data.immortal.p, (int)chunk->data.immortal.len, 0); +#else nbytes_sent = send(fd, chunk->data.immortal.p, chunk->data.immortal.len, 0); +#endif if (nbytes_sent < 0) { *nbytes_sent_total = _nbytes_sent_total; return php_socket_errno(); @@ -1153,14 +1044,21 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen static int php_cli_server_content_sender_pull(php_cli_server_content_sender *sender, int fd, size_t *nbytes_read) /* {{{ */ { +#ifdef PHP_WIN32 + int _nbytes_read; +#else ssize_t _nbytes_read; +#endif php_cli_server_chunk *chunk = php_cli_server_chunk_heap_new_self_contained(131072); +#ifdef PHP_WIN32 + _nbytes_read = read(fd, chunk->data.heap.p, (unsigned int)chunk->data.heap.len); +#else _nbytes_read = read(fd, chunk->data.heap.p, chunk->data.heap.len); +#endif if (_nbytes_read < 0) { char *errstr = get_last_error(); - TSRMLS_FETCH(); - php_cli_server_logf("%s" TSRMLS_CC, errstr); + php_cli_server_logf("%s", errstr); pefree(errstr, 1); php_cli_server_chunk_dtor(chunk); pefree(chunk, 1); @@ -1182,7 +1080,7 @@ static int php_cli_is_output_tty() /* {{{ */ } /* }}} */ #endif -static void php_cli_server_log_response(php_cli_server_client *client, int status, const char *message TSRMLS_DC) /* {{{ */ +static void php_cli_server_log_response(php_cli_server_client *client, int status, const char *message) /* {{{ */ { int color = 0, effective_status = status; char *basic_buf, *message_buf = "", *error_buf = ""; @@ -1248,9 +1146,9 @@ static void php_cli_server_log_response(php_cli_server_client *client, int statu } if (color) { - php_cli_server_logf("\x1b[3%dm%s%s%s\x1b[0m" TSRMLS_CC, color, basic_buf, message_buf, error_buf); + php_cli_server_logf("\x1b[3%dm%s%s%s\x1b[0m", color, basic_buf, message_buf, error_buf); } else { - php_cli_server_logf("%s%s%s" TSRMLS_CC, basic_buf, message_buf, error_buf); + php_cli_server_logf("%s%s%s", basic_buf, message_buf, error_buf); } efree(basic_buf); @@ -1262,15 +1160,12 @@ static void php_cli_server_log_response(php_cli_server_client *client, int statu } } /* }}} */ -static void php_cli_server_logf(const char *format TSRMLS_DC, ...) /* {{{ */ +static void php_cli_server_logf(const char *format, ...) /* {{{ */ { char *buf = NULL; va_list ap; -#ifdef ZTS - va_start(ap, tsrm_ls); -#else + va_start(ap, format); -#endif vspprintf(&buf, 0, format, ap); va_end(ap); @@ -1279,19 +1174,19 @@ static void php_cli_server_logf(const char *format TSRMLS_DC, ...) /* {{{ */ } if (sapi_module.log_message) { - sapi_module.log_message(buf TSRMLS_CC); + sapi_module.log_message(buf); } efree(buf); } /* }}} */ -static int php_network_listen_socket(const char *host, int *port, int socktype, int *af, socklen_t *socklen, char **errstr TSRMLS_DC) /* {{{ */ +static php_socket_t php_network_listen_socket(const char *host, int *port, int socktype, int *af, socklen_t *socklen, zend_string **errstr) /* {{{ */ { - int retval = SOCK_ERR; + php_socket_t retval = SOCK_ERR; int err = 0; struct sockaddr *sa = NULL, **p, **sal; - int num_addrs = php_network_getaddresses(host, socktype, &sal, errstr TSRMLS_CC); + int num_addrs = php_network_getaddresses(host, socktype, &sal, errstr); if (num_addrs == 0) { return -1; } @@ -1396,11 +1291,11 @@ out: php_network_freeaddresses(sal); } if (err) { - if (retval >= 0) { + if (ZEND_VALID_SOCKET(retval)) { closesocket(retval); } if (errstr) { - *errstr = php_socket_strerror(err, NULL, 0); + *errstr = php_socket_error_str(err); } return SOCK_ERR; } @@ -1409,6 +1304,9 @@ out: static int php_cli_server_request_ctor(php_cli_server_request *req) /* {{{ */ { +#ifdef ZTS +ZEND_TSRMLS_CACHE_UPDATE; +#endif req->protocol_version = 0; req->request_uri = NULL; req->request_uri_len = 0; @@ -1420,7 +1318,7 @@ static int php_cli_server_request_ctor(php_cli_server_request *req) /* {{{ */ req->path_info_len = 0; req->query_string = NULL; req->query_string_len = 0; - zend_hash_init(&req->headers, 0, NULL, (void(*)(void*))char_ptr_dtor_p, 1); + zend_hash_init(&req->headers, 0, NULL, char_ptr_dtor_p, 1); zend_hash_init(&req->headers_original_case, 0, NULL, NULL, 1); req->content = NULL; req->content_len = 0; @@ -1455,7 +1353,7 @@ static void php_cli_server_request_dtor(php_cli_server_request *req) /* {{{ */ static void php_cli_server_request_translate_vpath(php_cli_server_request *request, const char *document_root, size_t document_root_len) /* {{{ */ { - struct stat sb; + zend_stat_t sb; static const char *index_files[] = { "index.php", "index.html", NULL }; char *buf = safe_pemalloc(1, request->vpath_len, 1 + document_root_len + 1 + sizeof("index.html"), 1); char *p = buf, *prev_path = NULL, *q, *vpath; @@ -1492,7 +1390,7 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque *p = '\0'; q = p; while (q > buf) { - if (!stat(buf, &sb)) { + if (!zend_stat(buf, &sb)) { if (sb.st_mode & S_IFDIR) { const char **file = index_files; if (q[-1] != DEFAULT_SLASH) { @@ -1501,7 +1399,7 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque while (*file) { size_t l = strlen(*file); memmove(q, *file, l + 1); - if (!stat(buf, &sb) && (sb.st_mode & S_IFREG)) { + if (!zend_stat(buf, &sb) && (sb.st_mode & S_IFREG)) { q += l; break; } @@ -1574,7 +1472,7 @@ static void normalize_vpath(char **retval, size_t *retval_len, const char *vpath return; } - decoded_vpath_end = decoded_vpath + php_url_decode(decoded_vpath, vpath_len); + decoded_vpath_end = decoded_vpath + php_url_decode(decoded_vpath, (int)vpath_len); p = decoded_vpath; @@ -1691,13 +1589,12 @@ static int php_cli_server_client_read_request_on_header_value(php_http_parser *p } { /* strip off the colon */ - char *orig_header_name = estrndup(client->current_header_name, client->current_header_name_len); + zend_string *orig_header_name = zend_string_init(client->current_header_name, client->current_header_name_len, 1); char *lc_header_name = zend_str_tolower_dup(client->current_header_name, client->current_header_name_len); - - zend_hash_add(&client->request.headers, lc_header_name, client->current_header_name_len + 1, &value, sizeof(char *), NULL); - zend_hash_add(&client->request.headers_original_case, orig_header_name, client->current_header_name_len + 1, &value, sizeof(char *), NULL); + zend_hash_str_add_ptr(&client->request.headers, lc_header_name, client->current_header_name_len, value); + zend_hash_add_ptr(&client->request.headers_original_case, orig_header_name, value); efree(lc_header_name); - efree(orig_header_name); + zend_string_release(orig_header_name); } if (client->current_header_name_allocated) { @@ -1757,7 +1654,7 @@ static int php_cli_server_client_read_request_on_message_complete(php_http_parse return 0; } -static int php_cli_server_client_read_request(php_cli_server_client *client, char **errstr TSRMLS_DC) +static int php_cli_server_client_read_request(php_cli_server_client *client, char **errstr) { char buf[16384]; static const php_http_parser_settings settings = { @@ -1815,9 +1712,19 @@ static int php_cli_server_client_read_request(php_cli_server_client *client, cha static size_t php_cli_server_client_send_through(php_cli_server_client *client, const char *str, size_t str_len) /* {{{ */ { struct timeval tv = { 10, 0 }; - ssize_t nbytes_left = str_len; +#ifdef PHP_WIN32 + int nbytes_left = (int)str_len; +#else + ssize_t nbytes_left = (ssize_t)str_len; +#endif do { - ssize_t nbytes_sent = send(client->sock, str + str_len - nbytes_left, nbytes_left, 0); +#ifdef PHP_WIN32 + int nbytes_sent; +#else + ssize_t nbytes_sent; +#endif + + nbytes_sent = send(client->sock, str + str_len - nbytes_left, nbytes_left, 0); if (nbytes_sent < 0) { int err = php_socket_errno(); if (err == SOCK_EAGAIN) { @@ -1846,7 +1753,7 @@ static size_t php_cli_server_client_send_through(php_cli_server_client *client, static void php_cli_server_client_populate_request_info(const php_cli_server_client *client, sapi_request_info *request_info) /* {{{ */ { - char **val; + char *val; request_info->request_method = php_http_method_str(client->request.request_method); request_info->proto_num = client->request.protocol_version; @@ -1855,8 +1762,8 @@ static void php_cli_server_client_populate_request_info(const php_cli_server_cli request_info->query_string = client->request.query_string; request_info->content_length = client->request.content_len; request_info->auth_user = request_info->auth_password = request_info->auth_digest = NULL; - if (SUCCESS == zend_hash_find(&client->request.headers, "content-type", sizeof("content-type"), (void**)&val)) { - request_info->content_type = *val; + if (NULL != (val = zend_hash_str_find_ptr(&client->request.headers, "content-type", sizeof("content-type")-1))) { + request_info->content_type = val; } } /* }}} */ @@ -1864,19 +1771,19 @@ static void destroy_request_info(sapi_request_info *request_info) /* {{{ */ { } /* }}} */ -static int php_cli_server_client_ctor(php_cli_server_client *client, php_cli_server *server, int client_sock, struct sockaddr *addr, socklen_t addr_len TSRMLS_DC) /* {{{ */ +static int php_cli_server_client_ctor(php_cli_server_client *client, php_cli_server *server, php_socket_t client_sock, struct sockaddr *addr, socklen_t addr_len) /* {{{ */ { client->server = server; client->sock = client_sock; client->addr = addr; client->addr_len = addr_len; { - char *addr_str = 0; - long addr_str_len = 0; - php_network_populate_name_from_sockaddr(addr, addr_len, &addr_str, &addr_str_len, NULL, 0 TSRMLS_CC); - client->addr_str = pestrndup(addr_str, addr_str_len, 1); - client->addr_str_len = addr_str_len; - efree(addr_str); + zend_string *addr_str = 0; + + php_network_populate_name_from_sockaddr(addr, addr_len, &addr_str, NULL, 0); + client->addr_str = pestrndup(addr_str->val, addr_str->len, 1); + client->addr_str_len = addr_str->len; + zend_string_release(addr_str); } php_http_parser_init(&client->parser, PHP_HTTP_REQUEST); client->request_read = 0; @@ -1906,18 +1813,17 @@ static void php_cli_server_client_dtor(php_cli_server_client *client) /* {{{ */ } } /* }}} */ -static void php_cli_server_close_connection(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static void php_cli_server_close_connection(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { #ifdef DEBUG - php_cli_server_logf("%s Closing" TSRMLS_CC, client->addr_str); + php_cli_server_logf("%s Closing", client->addr_str); #endif zend_hash_index_del(&server->clients, client->sock); } /* }}} */ -static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server_client *client, int status TSRMLS_DC) /* {{{ */ +static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server_client *client, int status) /* {{{ */ { - char *escaped_request_uri = NULL; - size_t escaped_request_uri_len; + zend_string *escaped_request_uri = NULL; const char *status_string = get_status_string(status); const char *content_template = get_template_string(status); char *errstr = get_last_error(); @@ -1926,7 +1832,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server php_cli_server_content_sender_ctor(&client->content_sender); client->content_sender_initialized = 1; - escaped_request_uri = php_escape_html_entities_ex((unsigned char *)client->request.request_uri, client->request.request_uri_len, &escaped_request_uri_len, 0, ENT_QUOTES, NULL, 0 TSRMLS_CC); + escaped_request_uri = php_escape_html_entities_ex((unsigned char *)client->request.request_uri, client->request.request_uri_len, 0, ENT_QUOTES, NULL, 0); { static const char prologue_template[] = "<!doctype html><html><head><title>%d %s</title>"; @@ -1934,7 +1840,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server if (!chunk) { goto fail; } - snprintf(chunk->data.heap.p, chunk->data.heap.len, prologue_template, status, status_string, escaped_request_uri); + snprintf(chunk->data.heap.p, chunk->data.heap.len, prologue_template, status, status_string, escaped_request_uri->val); chunk->data.heap.len = strlen(chunk->data.heap.p); php_cli_server_buffer_append(&client->content_sender.buffer, chunk); } @@ -1954,11 +1860,11 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server php_cli_server_buffer_append(&client->content_sender.buffer, chunk); } { - php_cli_server_chunk *chunk = php_cli_server_chunk_heap_new_self_contained(strlen(content_template) + escaped_request_uri_len + 3 + strlen(status_string) + 1); + php_cli_server_chunk *chunk = php_cli_server_chunk_heap_new_self_contained(strlen(content_template) + escaped_request_uri->len + 3 + strlen(status_string) + 1); if (!chunk) { goto fail; } - snprintf(chunk->data.heap.p, chunk->data.heap.len, content_template, status_string, escaped_request_uri); + snprintf(chunk->data.heap.p, chunk->data.heap.len, content_template, status_string, escaped_request_uri->val); chunk->data.heap.len = strlen(chunk->data.heap.p); php_cli_server_buffer_append(&client->content_sender.buffer, chunk); } @@ -1975,46 +1881,46 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server php_cli_server_chunk *chunk; smart_str buffer = { 0 }; append_http_status_line(&buffer, client->request.protocol_version, status, 1); - if (!buffer.c) { + if (!buffer.s) { /* out of memory */ goto fail; } append_essential_headers(&buffer, client, 1); smart_str_appends_ex(&buffer, "Content-Type: text/html; charset=UTF-8\r\n", 1); smart_str_appends_ex(&buffer, "Content-Length: ", 1); - smart_str_append_generic_ex(&buffer, php_cli_server_buffer_size(&client->content_sender.buffer), 1, size_t, _unsigned); + smart_str_append_unsigned_ex(&buffer, php_cli_server_buffer_size(&client->content_sender.buffer), 1); smart_str_appendl_ex(&buffer, "\r\n", 2, 1); smart_str_appendl_ex(&buffer, "\r\n", 2, 1); - chunk = php_cli_server_chunk_heap_new(buffer.c, buffer.c, buffer.len); + chunk = php_cli_server_chunk_heap_new(buffer.s, buffer.s->val, buffer.s->len); if (!chunk) { - smart_str_free_ex(&buffer, 1); + smart_str_free(&buffer); goto fail; } php_cli_server_buffer_prepend(&client->content_sender.buffer, chunk); } - php_cli_server_log_response(client, status, errstr ? errstr : "?" TSRMLS_CC); + php_cli_server_log_response(client, status, errstr ? errstr : "?"); php_cli_server_poller_add(&server->poller, POLLOUT, client->sock); if (errstr) { pefree(errstr, 1); } - efree(escaped_request_uri); + zend_string_free(escaped_request_uri); return SUCCESS; fail: if (errstr) { pefree(errstr, 1); } - efree(escaped_request_uri); + zend_string_free(escaped_request_uri); return FAILURE; } /* }}} */ -static int php_cli_server_dispatch_script(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_dispatch_script(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { if (strlen(client->request.path_translated) != client->request.path_translated_len) { /* can't handle paths that contain nul bytes */ - return php_cli_server_send_error_page(server, client, 400 TSRMLS_CC); + return php_cli_server_send_error_page(server, client, 400); } { zend_file_handle zfd; @@ -2024,27 +1930,27 @@ static int php_cli_server_dispatch_script(php_cli_server *server, php_cli_server zfd.free_filename = 0; zfd.opened_path = NULL; zend_try { - php_execute_script(&zfd TSRMLS_CC); + php_execute_script(&zfd); } zend_end_try(); } - php_cli_server_log_response(client, SG(sapi_headers).http_response_code, NULL TSRMLS_CC); + php_cli_server_log_response(client, SG(sapi_headers).http_response_code, NULL); return SUCCESS; } /* }}} */ -static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { int fd; int status = 200; if (client->request.path_translated && strlen(client->request.path_translated) != client->request.path_translated_len) { /* can't handle paths that contain nul bytes */ - return php_cli_server_send_error_page(server, client, 400 TSRMLS_CC); + return php_cli_server_send_error_page(server, client, 400); } fd = client->request.path_translated ? open(client->request.path_translated, O_RDONLY): -1; if (fd < 0) { - return php_cli_server_send_error_page(server, client, 404 TSRMLS_CC); + return php_cli_server_send_error_page(server, client, 404); } php_cli_server_content_sender_ctor(&client->content_sender); @@ -2054,15 +1960,15 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv { php_cli_server_chunk *chunk; smart_str buffer = { 0 }; - const char *mime_type = get_mime_type(client->request.ext, client->request.ext_len); + const char *mime_type = get_mime_type(server, client->request.ext, client->request.ext_len); if (!mime_type) { mime_type = "application/octet-stream"; } append_http_status_line(&buffer, client->request.protocol_version, status, 1); - if (!buffer.c) { + if (!buffer.s) { /* out of memory */ - php_cli_server_log_response(client, 500, NULL TSRMLS_CC); + php_cli_server_log_response(client, 500, NULL); return FAILURE; } append_essential_headers(&buffer, client, 1); @@ -2073,31 +1979,31 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv } smart_str_appendl_ex(&buffer, "\r\n", 2, 1); smart_str_appends_ex(&buffer, "Content-Length: ", 1); - smart_str_append_generic_ex(&buffer, client->request.sb.st_size, 1, size_t, _unsigned); + smart_str_append_unsigned_ex(&buffer, client->request.sb.st_size, 1); smart_str_appendl_ex(&buffer, "\r\n", 2, 1); smart_str_appendl_ex(&buffer, "\r\n", 2, 1); - chunk = php_cli_server_chunk_heap_new(buffer.c, buffer.c, buffer.len); + chunk = php_cli_server_chunk_heap_new(buffer.s, buffer.s->val, buffer.s->len); if (!chunk) { - smart_str_free_ex(&buffer, 1); - php_cli_server_log_response(client, 500, NULL TSRMLS_CC); + smart_str_free(&buffer); + php_cli_server_log_response(client, 500, NULL); return FAILURE; } php_cli_server_buffer_append(&client->content_sender.buffer, chunk); } - php_cli_server_log_response(client, 200, NULL TSRMLS_CC); + php_cli_server_log_response(client, 200, NULL); php_cli_server_poller_add(&server->poller, POLLOUT, client->sock); return SUCCESS; } /* }}} */ -static int php_cli_server_request_startup(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) { /* {{{ */ - char **auth; +static int php_cli_server_request_startup(php_cli_server *server, php_cli_server_client *client) { /* {{{ */ + char *auth; php_cli_server_client_populate_request_info(client, &SG(request_info)); - if (SUCCESS == zend_hash_find(&client->request.headers, "authorization", sizeof("authorization"), (void**)&auth)) { - php_handle_auth_data(*auth TSRMLS_CC); + if (NULL != (auth = zend_hash_str_find_ptr(&client->request.headers, "authorization", sizeof("authorization")-1))) { + php_handle_auth_data(auth); } SG(sapi_headers).http_response_code = 200; - if (FAILURE == php_request_startup(TSRMLS_C)) { + if (FAILURE == php_request_startup()) { /* should never be happen */ destroy_request_info(&SG(request_info)); return FAILURE; @@ -2108,9 +2014,9 @@ static int php_cli_server_request_startup(php_cli_server *server, php_cli_server } /* }}} */ -static int php_cli_server_request_shutdown(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) { /* {{{ */ +static int php_cli_server_request_shutdown(php_cli_server *server, php_cli_server_client *client) { /* {{{ */ php_request_shutdown(0); - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); destroy_request_info(&SG(request_info)); SG(server_context) = NULL; SG(rfc1867_uploaded_files) = NULL; @@ -2118,7 +2024,7 @@ static int php_cli_server_request_shutdown(php_cli_server *server, php_cli_serve } /* }}} */ -static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { int decline = 0; zend_file_handle zfd; @@ -2136,10 +2042,10 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server zfd.opened_path = NULL; zend_try { - zval *retval = NULL; - if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, &retval, 1, &zfd)) { - if (retval) { - decline = Z_TYPE_P(retval) == IS_BOOL && !Z_LVAL_P(retval); + zval retval; + if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE, &retval, 1, &zfd)) { + if (Z_TYPE(retval) != IS_UNDEF) { + decline = Z_TYPE(retval) == IS_FALSE; zval_ptr_dtor(&retval); } } else { @@ -2157,7 +2063,7 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server } /* }}} */ -static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { int is_static_file = 0; @@ -2167,30 +2073,30 @@ static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client } if (server->router || !is_static_file) { - if (FAILURE == php_cli_server_request_startup(server, client TSRMLS_CC)) { + if (FAILURE == php_cli_server_request_startup(server, client)) { SG(server_context) = NULL; - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); destroy_request_info(&SG(request_info)); return SUCCESS; } } if (server->router) { - if (!php_cli_server_dispatch_router(server, client TSRMLS_CC)) { - php_cli_server_request_shutdown(server, client TSRMLS_CC); + if (!php_cli_server_dispatch_router(server, client)) { + php_cli_server_request_shutdown(server, client); return SUCCESS; } } if (!is_static_file) { - if (SUCCESS == php_cli_server_dispatch_script(server, client TSRMLS_CC) - || SUCCESS != php_cli_server_send_error_page(server, client, 500 TSRMLS_CC)) { - php_cli_server_request_shutdown(server, client TSRMLS_CC); + if (SUCCESS == php_cli_server_dispatch_script(server, client) + || SUCCESS != php_cli_server_send_error_page(server, client, 500)) { + php_cli_server_request_shutdown(server, client); return SUCCESS; } } else { if (server->router) { - static int (*send_header_func)(sapi_headers_struct * TSRMLS_DC); + static int (*send_header_func)(sapi_headers_struct *); send_header_func = sapi_module.send_headers; /* do not generate default content type header */ SG(sapi_headers).send_default_content_type = 0; @@ -2201,8 +2107,8 @@ static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client SG(sapi_headers).send_default_content_type = 1; SG(rfc1867_uploaded_files) = NULL; } - if (SUCCESS != php_cli_server_begin_send_static(server, client TSRMLS_CC)) { - php_cli_server_close_connection(server, client TSRMLS_CC); + if (SUCCESS != php_cli_server_begin_send_static(server, client)) { + php_cli_server_close_connection(server, client); } SG(server_context) = NULL; return SUCCESS; @@ -2214,10 +2120,29 @@ static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client } /* }}} */ -static void php_cli_server_dtor(php_cli_server *server TSRMLS_DC) /* {{{ */ +static int php_cli_server_mime_type_ctor(php_cli_server *server, const php_cli_server_ext_mime_type_pair *mime_type_map) /* {{{ */ +{ + const php_cli_server_ext_mime_type_pair *pair; + + zend_hash_init(&server->extension_mime_types, 0, NULL, NULL, 1); + + for (pair = mime_type_map; pair->ext; pair++) { + size_t ext_len = 0, mime_type_len = 0; + + ext_len = strlen(pair->ext); + mime_type_len = strlen(pair->mime_type); + + zend_hash_str_add_mem(&server->extension_mime_types, pair->ext, ext_len, (void*)pair->mime_type, mime_type_len + 1); + } + + return SUCCESS; +} /* }}} */ + +static void php_cli_server_dtor(php_cli_server *server) /* {{{ */ { zend_hash_destroy(&server->clients); - if (server->server_sock >= 0) { + zend_hash_destroy(&server->extension_mime_types); + if (ZEND_VALID_SOCKET(server->server_sock)) { closesocket(server->server_sock); } if (server->host) { @@ -2231,19 +2156,21 @@ static void php_cli_server_dtor(php_cli_server *server TSRMLS_DC) /* {{{ */ } } /* }}} */ -static void php_cli_server_client_dtor_wrapper(php_cli_server_client **p) /* {{{ */ +static void php_cli_server_client_dtor_wrapper(zval *zv) /* {{{ */ { - closesocket((*p)->sock); - php_cli_server_poller_remove(&(*p)->server->poller, POLLIN | POLLOUT, (*p)->sock); - php_cli_server_client_dtor(*p); - pefree(*p, 1); + php_cli_server_client *p = Z_PTR_P(zv); + + closesocket(p->sock); + php_cli_server_poller_remove(&p->server->poller, POLLIN | POLLOUT, p->sock); + php_cli_server_client_dtor(p); + pefree(p, 1); } /* }}} */ -static int php_cli_server_ctor(php_cli_server *server, const char *addr, const char *document_root, const char *router TSRMLS_DC) /* {{{ */ +static int php_cli_server_ctor(php_cli_server *server, const char *addr, const char *document_root, const char *router) /* {{{ */ { int retval = SUCCESS; char *host = NULL; - char *errstr = NULL; + zend_string *errstr = NULL; char *_document_root = NULL; char *_router = NULL; int err = 0; @@ -2288,10 +2215,12 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c goto out; } - server_sock = php_network_listen_socket(host, &port, SOCK_STREAM, &server->address_family, &server->socklen, &errstr TSRMLS_CC); + server_sock = php_network_listen_socket(host, &port, SOCK_STREAM, &server->address_family, &server->socklen, &errstr); if (server_sock == SOCK_ERR) { - php_cli_server_logf("Failed to listen on %s:%d (reason: %s)" TSRMLS_CC, host, port, errstr ? errstr: "?"); - efree(errstr); + php_cli_server_logf("Failed to listen on %s:%d (reason: %s)", host, port, errstr ? errstr->val : "?"); + if (errstr) { + zend_string_release(errstr); + } retval = FAILURE; goto out; } @@ -2307,7 +2236,7 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c server->host = host; server->port = port; - zend_hash_init(&server->clients, 0, NULL, (void(*)(void*))php_cli_server_client_dtor_wrapper, 1); + zend_hash_init(&server->clients, 0, NULL, php_cli_server_client_dtor_wrapper, 1); { size_t document_root_len = strlen(document_root); @@ -2334,6 +2263,11 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c server->router_len = 0; } + if (php_cli_server_mime_type_ctor(server, mime_type_map) == FAILURE) { + retval = FAILURE; + goto out; + } + server->is_running = 1; out: if (retval != SUCCESS) { @@ -2353,20 +2287,20 @@ out: return retval; } /* }}} */ -static int php_cli_server_recv_event_read_request(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_recv_event_read_request(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { char *errstr = NULL; - int status = php_cli_server_client_read_request(client, &errstr TSRMLS_CC); + int status = php_cli_server_client_read_request(client, &errstr); if (status < 0) { - php_cli_server_logf("%s Invalid request (%s)" TSRMLS_CC, client->addr_str, errstr); + php_cli_server_logf("%s Invalid request (%s)", client->addr_str, errstr); efree(errstr); - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); return FAILURE; } else if (status == 1 && client->request.request_method == PHP_HTTP_NOT_IMPLEMENTED) { - return php_cli_server_send_error_page(server, client, 501 TSRMLS_CC); + return php_cli_server_send_error_page(server, client, 501); } else if (status == 1) { php_cli_server_poller_remove(&server->poller, POLLIN, client->sock); - php_cli_server_dispatch(server, client TSRMLS_CC); + php_cli_server_dispatch(server, client); } else { php_cli_server_poller_add(&server->poller, POLLIN, client->sock); } @@ -2374,13 +2308,13 @@ static int php_cli_server_recv_event_read_request(php_cli_server *server, php_cl return SUCCESS; } /* }}} */ -static int php_cli_server_send_event(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_send_event(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { if (client->content_sender_initialized) { if (client->file_fd >= 0 && !client->content_sender.buffer.first) { size_t nbytes_read; if (php_cli_server_content_sender_pull(&client->content_sender, client->file_fd, &nbytes_read)) { - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); return FAILURE; } if (nbytes_read == 0) { @@ -2392,12 +2326,12 @@ static int php_cli_server_send_event(php_cli_server *server, php_cli_server_clie size_t nbytes_sent; int err = php_cli_server_content_sender_send(&client->content_sender, client->sock, &nbytes_sent); if (err && err != SOCK_EAGAIN) { - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); return FAILURE; } } if (!client->content_sender.buffer.first && client->file_fd < 0) { - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); } } return SUCCESS; @@ -2405,20 +2339,14 @@ static int php_cli_server_send_event(php_cli_server *server, php_cli_server_clie /* }}} */ typedef struct php_cli_server_do_event_for_each_fd_callback_params { -#ifdef ZTS - void ***tsrm_ls; -#endif php_cli_server *server; - int(*rhandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC); - int(*whandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC); + int(*rhandler)(php_cli_server*, php_cli_server_client*); + int(*whandler)(php_cli_server*, php_cli_server_client*); } php_cli_server_do_event_for_each_fd_callback_params; -static int php_cli_server_do_event_for_each_fd_callback(void *_params, int fd, int event) /* {{{ */ +static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socket_t fd, int event) /* {{{ */ { php_cli_server_do_event_for_each_fd_callback_params *params = _params; -#ifdef ZTS - void ***tsrm_ls = params->tsrm_ls; -#endif php_cli_server *server = params->server; if (server->server_sock == fd) { php_cli_server_client *client = NULL; @@ -2429,50 +2357,47 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, int fd, i return FAILURE; } client_sock = accept(server->server_sock, sa, &socklen); - if (client_sock < 0) { + if (!ZEND_VALID_SOCKET(client_sock)) { char *errstr; errstr = php_socket_strerror(php_socket_errno(), NULL, 0); - php_cli_server_logf("Failed to accept a client (reason: %s)" TSRMLS_CC, errstr); + php_cli_server_logf("Failed to accept a client (reason: %s)", errstr); efree(errstr); pefree(sa, 1); return SUCCESS; } - if (SUCCESS != php_set_sock_blocking(client_sock, 0 TSRMLS_CC)) { + if (SUCCESS != php_set_sock_blocking(client_sock, 0)) { pefree(sa, 1); closesocket(client_sock); return SUCCESS; } - if (!(client = pemalloc(sizeof(php_cli_server_client), 1)) || FAILURE == php_cli_server_client_ctor(client, server, client_sock, sa, socklen TSRMLS_CC)) { - php_cli_server_logf("Failed to create a new request object" TSRMLS_CC); + if (!(client = pemalloc(sizeof(php_cli_server_client), 1)) || FAILURE == php_cli_server_client_ctor(client, server, client_sock, sa, socklen)) { + php_cli_server_logf("Failed to create a new request object"); pefree(sa, 1); closesocket(client_sock); return SUCCESS; } #ifdef DEBUG - php_cli_server_logf("%s Accepted" TSRMLS_CC, client->addr_str); + php_cli_server_logf("%s Accepted", client->addr_str); #endif - zend_hash_index_update(&server->clients, client_sock, &client, sizeof(client), NULL); - php_cli_server_recv_event_read_request(server, client TSRMLS_CC); + zend_hash_index_update_ptr(&server->clients, client_sock, client); + php_cli_server_recv_event_read_request(server, client); } else { - php_cli_server_client **client; - if (SUCCESS == zend_hash_index_find(&server->clients, fd, (void **)&client)) { + php_cli_server_client *client; + if (NULL != (client = zend_hash_index_find_ptr(&server->clients, fd))) { if (event & POLLIN) { - params->rhandler(server, *client TSRMLS_CC); + params->rhandler(server, client); } if (event & POLLOUT) { - params->whandler(server, *client TSRMLS_CC); + params->whandler(server, client); } } } return SUCCESS; } /* }}} */ -static void php_cli_server_do_event_for_each_fd(php_cli_server *server, int(*rhandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC), int(*whandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC) TSRMLS_DC) /* {{{ */ +static void php_cli_server_do_event_for_each_fd(php_cli_server *server, int(*rhandler)(php_cli_server*, php_cli_server_client*), int(*whandler)(php_cli_server*, php_cli_server_client*)) /* {{{ */ { php_cli_server_do_event_for_each_fd_callback_params params = { -#ifdef ZTS - tsrm_ls, -#endif server, rhandler, whandler @@ -2481,7 +2406,7 @@ static void php_cli_server_do_event_for_each_fd(php_cli_server *server, int(*rha php_cli_server_poller_iter_on_active(&server->poller, ¶ms, php_cli_server_do_event_for_each_fd_callback); } /* }}} */ -static int php_cli_server_do_event_loop(php_cli_server *server TSRMLS_DC) /* {{{ */ +static int php_cli_server_do_event_loop(php_cli_server *server) /* {{{ */ { int retval = SUCCESS; while (server->is_running) { @@ -2490,14 +2415,14 @@ static int php_cli_server_do_event_loop(php_cli_server *server TSRMLS_DC) /* {{{ if (n > 0) { php_cli_server_do_event_for_each_fd(server, php_cli_server_recv_event_read_request, - php_cli_server_send_event TSRMLS_CC); + php_cli_server_send_event); } else if (n == 0) { /* do nothing */ } else { int err = php_socket_errno(); if (err != SOCK_EINTR) { char *errstr = php_socket_strerror(err, NULL, 0); - php_cli_server_logf("%s" TSRMLS_CC, errstr); + php_cli_server_logf("%s", errstr); efree(errstr); retval = FAILURE; goto out; @@ -2516,7 +2441,7 @@ static void php_cli_server_sigint_handler(int sig) /* {{{ */ } /* }}} */ -int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ +int do_cli_server(int argc, char **argv) /* {{{ */ { char *php_optarg = NULL; int php_optind = 1; @@ -2539,9 +2464,9 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ } if (document_root) { - struct stat sb; + zend_stat_t sb; - if (stat(document_root, &sb)) { + if (zend_stat(document_root, &sb)) { fprintf(stderr, "Directory %s does not exist.\n", document_root); return 1; } @@ -2567,7 +2492,7 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ router = argv[php_optind]; } - if (FAILURE == php_cli_server_ctor(&server, server_bind_address, document_root, router TSRMLS_CC)) { + if (FAILURE == php_cli_server_ctor(&server, server_bind_address, document_root, router)) { return 1; } sapi_module.phpinfo_as_text = 0; @@ -2589,8 +2514,8 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ #if defined(HAVE_SIGNAL_H) && defined(SIGINT) signal(SIGINT, php_cli_server_sigint_handler); #endif - php_cli_server_do_event_loop(&server TSRMLS_CC); - php_cli_server_dtor(&server TSRMLS_CC); + php_cli_server_do_event_loop(&server); + php_cli_server_dtor(&server); return 0; } /* }}} */ diff --git a/sapi/cli/php_cli_server.h b/sapi/cli/php_cli_server.h index 116d3b1c90..6d9f46c7ed 100644 --- a/sapi/cli/php_cli_server.h +++ b/sapi/cli/php_cli_server.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -25,14 +25,15 @@ extern const zend_function_entry server_additional_functions[]; extern sapi_module_struct cli_server_sapi_module; -extern int do_cli_server(int argc, char **argv TSRMLS_DC); +extern int do_cli_server(int argc, char **argv); ZEND_BEGIN_MODULE_GLOBALS(cli_server) short color; ZEND_END_MODULE_GLOBALS(cli_server) #ifdef ZTS -#define CLI_SERVER_G(v) TSRMG(cli_server_globals_id, zend_cli_server_globals *, v) +#define CLI_SERVER_G(v) ZEND_TSRMG(cli_server_globals_id, zend_cli_server_globals *, v) +ZEND_TSRMLS_CACHE_EXTERN; #else #define CLI_SERVER_G(v) (cli_server_globals.v) #endif diff --git a/sapi/cli/php_http_parser.c b/sapi/cli/php_http_parser.c index 2fc0405499..31ae4167d1 100644 --- a/sapi/cli/php_http_parser.c +++ b/sapi/cli/php_http_parser.c @@ -1431,7 +1431,9 @@ size_t php_http_parser_execute (php_http_parser *parser, } case s_body_identity: - to_read = MIN(pe - p, (size_t)parser->content_length); + assert(pe >= p); + + to_read = MIN((size_t)(pe - p), (size_t)parser->content_length); if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); p += to_read - 1; @@ -1515,8 +1517,9 @@ size_t php_http_parser_execute (php_http_parser *parser, case s_chunk_data: { assert(parser->flags & F_CHUNKED); + assert(pe >= p); - to_read = MIN(pe - p, (size_t)(parser->content_length)); + to_read = MIN((size_t)(pe - p), (size_t)(parser->content_length)); if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); diff --git a/sapi/cli/ps_title.c b/sapi/cli/ps_title.c index 3db77f76dc..9685666b1b 100644 --- a/sapi/cli/ps_title.c +++ b/sapi/cli/ps_title.c @@ -125,11 +125,13 @@ static size_t ps_buffer_cur_len; /* actual string length in ps_buffer */ static int save_argc; static char** save_argv; -/* +/* * This holds the 'locally' allocated environ from the save_ps_args method. * This is subsequently free'd at exit. */ +#if defined(PS_USE_CLOBBER_ARGV) static char** frozen_environ, **new_environ; +#endif /* * Call this method early, before any code has used the original argv passed in @@ -311,7 +313,7 @@ const char* ps_title_errno(int rc) #ifdef PS_USE_WIN32 case PS_TITLE_WINDOWS_ERROR: - sprintf(windows_error_details, "Windows error code: %d", GetLastError()); + sprintf(windows_error_details, "Windows error code: %lu", GetLastError()); return windows_error_details; #endif } @@ -386,7 +388,7 @@ int get_ps_title(int *displen, const char** string) return rc; #ifdef PS_USE_WIN32 - if (!(ps_buffer_cur_len = GetConsoleTitle(ps_buffer, ps_buffer_size))) + if (!(ps_buffer_cur_len = GetConsoleTitle(ps_buffer, (DWORD)ps_buffer_size))) return PS_TITLE_WINDOWS_ERROR; #endif *displen = (int)ps_buffer_cur_len; diff --git a/sapi/cli/ps_title.h b/sapi/cli/ps_title.h index 93f575b0bb..4a8f6f7002 100644 --- a/sapi/cli/ps_title.h +++ b/sapi/cli/ps_title.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt index 3d5c916e9c..e9e8b7e219 100644 --- a/sapi/cli/tests/006.phpt +++ b/sapi/cli/tests/006.phpt @@ -34,6 +34,9 @@ string(%d) "Extension [ <persistent> extension #%d pcre version <no_version> ] { Entry [ pcre.recursion_limit <ALL> ] Current = '%d' } + Entry [ pcre.jit <ALL> ] + Current = '%d' + } } - Constants [14] { diff --git a/sapi/cli/tests/bug61977.phpt b/sapi/cli/tests/bug61977.phpt index d897737c3c..218641a511 100644 --- a/sapi/cli/tests/bug61977.phpt +++ b/sapi/cli/tests/bug61977.phpt @@ -48,7 +48,7 @@ foo.html => Content-Type: text/html; charset=UTF-8 foo.htm => Content-Type: text/html; charset=UTF-8 foo.svg => Content-Type: image/svg+xml foo.css => Content-Type: text/css; charset=UTF-8 -foo.js => Content-Type: text/javascript; charset=UTF-8 +foo.js => Content-Type: application/javascript foo.png => Content-Type: image/png foo.webm => Content-Type: video/webm foo.ogv => Content-Type: video/ogg diff --git a/sapi/continuity/capi.c b/sapi/continuity/capi.c index fc46547db5..2f943e3be0 100644 --- a/sapi/continuity/capi.c +++ b/sapi/continuity/capi.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -75,7 +75,7 @@ PHP_MSHUTDOWN_FUNCTION(continuity); PHP_RINIT_FUNCTION(continuity); PHP_RSHUTDOWN_FUNCTION(continuity); PHP_MINFO_FUNCTION(continuity); - + PHP_FUNCTION(continuity_virtual); PHP_FUNCTION(continuity_request_headers); PHP_FUNCTION(continuity_response_headers); @@ -87,7 +87,7 @@ const zend_function_entry continuity_functions[] = { zend_module_entry continuity_module_entry = { STANDARD_MODULE_HEADER, "continuity", - continuity_functions, + continuity_functions, PHP_MINIT(continuity), PHP_MSHUTDOWN(continuity), NULL, @@ -118,7 +118,7 @@ PHP_MINFO_FUNCTION(continuity) php_info_print_table_row(2,"CDP Extensions", "disabled"); #endif php_info_print_table_end(); - + /* DISPLAY_INI_ENTRIES(); */ } @@ -127,7 +127,7 @@ PHP_MINFO_FUNCTION(continuity) /* * sapi_capi_ub_write: Write len bytes to the connection output. */ -static int sapi_capi_ub_write(const char *str, unsigned int str_length TSRMLS_DC) +static int sapi_capi_ub_write(const char *str, unsigned int str_length) { int retval; capi_request_context *rc; @@ -143,7 +143,7 @@ static int sapi_capi_ub_write(const char *str, unsigned int str_length TSRMLS_DC * sapi_capi_header_handler: Add/update response headers with those provided * by the PHP engine. */ -static int sapi_capi_header_handler(sapi_header_struct * sapi_header, sapi_headers_struct * sapi_headers TSRMLS_DC) +static int sapi_capi_header_handler(sapi_header_struct * sapi_header, sapi_headers_struct * sapi_headers) { char *header_name, *header_content, *p; capi_request_context *rc = (capi_request_context *) SG(server_context); @@ -174,7 +174,7 @@ static int sapi_capi_header_handler(sapi_header_struct * sapi_header, sapi_heade * sapi_capi_send_headers: Transmit the headers to the client. This has the * effect of starting the response under Continuity. */ -static int sapi_capi_send_headers(sapi_headers_struct * sapi_headers TSRMLS_DC) +static int sapi_capi_send_headers(sapi_headers_struct * sapi_headers) { int retval; capi_request_context *rc = (capi_request_context *) SG(server_context); @@ -195,7 +195,7 @@ static int sapi_capi_send_headers(sapi_headers_struct * sapi_headers TSRMLS_DC) } -static int sapi_capi_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static int sapi_capi_read_post(char *buffer, uint count_bytes) { unsigned int max_read, total_read = 0; capi_request_context *rc = (capi_request_context *) SG(server_context); @@ -221,7 +221,7 @@ static int sapi_capi_read_post(char *buffer, uint count_bytes TSRMLS_DC) /* * sapi_capi_read_cookies: Return cookie information into PHP. */ -static char *sapi_capi_read_cookies(TSRMLS_D) +static char *sapi_capi_read_cookies(void) { char *cookie_string; capi_request_context *rc = (capi_request_context *) SG(server_context); @@ -230,7 +230,7 @@ static char *sapi_capi_read_cookies(TSRMLS_D) return cookie_string; } -static void sapi_capi_register_server_variables(zval * track_vars_array TSRMLS_DC) +static void sapi_capi_register_server_variables(zval * track_vars_array) { capi_request_context *rc = (capi_request_context *) SG(server_context); size_t i; @@ -240,101 +240,101 @@ static void sapi_capi_register_server_variables(zval * track_vars_array TSRMLS_D /* PHP_SELF and REQUEST_URI */ value = lstFset_get(rc->t->vars, "uri"); if (value != NULL) { - php_register_variable("PHP_SELF", value, track_vars_array TSRMLS_CC); - php_register_variable("REQUEST_URI", value, track_vars_array TSRMLS_CC); + php_register_variable("PHP_SELF", value, track_vars_array); + php_register_variable("REQUEST_URI", value, track_vars_array); } - + /* COUNTRY CODE */ value = lstFset_get(rc->t->vars, "ccode"); if(value!=NULL) - php_register_variable("COUNTRY_CODE", value, track_vars_array TSRMLS_CC); + php_register_variable("COUNTRY_CODE", value, track_vars_array); /* argv */ value = lstFset_get(rc->t->vars, "query"); if (value != NULL) - php_register_variable("argv", value, track_vars_array TSRMLS_CC); + php_register_variable("argv", value, track_vars_array); /* GATEWAY_INTERFACE */ - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array TSRMLS_CC); + php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array); /* SERVER_NAME and HTTP_HOST */ value = lstFset_get(rc->t->req_hdrs, "host"); if (value != NULL) { - php_register_variable("HTTP_HOST", value, track_vars_array TSRMLS_CC); + php_register_variable("HTTP_HOST", value, track_vars_array); /* TODO: This should probably scrub the port value if one is present. */ - php_register_variable("SERVER_NAME", value, track_vars_array TSRMLS_CC); + php_register_variable("SERVER_NAME", value, track_vars_array); } /* SERVER_SOFTWARE */ value = lstFset_get(rc->t->res_hdrs, "Server"); if (value != NULL) - php_register_variable("SERVER_SOFTWARE", value, track_vars_array TSRMLS_CC); + php_register_variable("SERVER_SOFTWARE", value, track_vars_array); /* SERVER_PROTOCOL */ value = lstFset_get(rc->t->vars, "protocol"); if (value != NULL) - php_register_variable("SERVER_PROTOCOL", value, track_vars_array TSRMLS_CC); + php_register_variable("SERVER_PROTOCOL", value, track_vars_array); /* REQUEST_METHOD */ value = lstFset_get(rc->t->vars, "method"); if (value != NULL) - php_register_variable("REQUEST_METHOD", value, track_vars_array TSRMLS_CC); + php_register_variable("REQUEST_METHOD", value, track_vars_array); /* QUERY_STRING */ value = lstFset_get(rc->t->vars, "query"); if (value != NULL) - php_register_variable("QUERY_STRING", value, track_vars_array TSRMLS_CC); + php_register_variable("QUERY_STRING", value, track_vars_array); /* DOCUMENT_ROOT */ value = lstFset_get(rc->t->vars, "docroot"); if (value != NULL) - php_register_variable("DOCUMENT_ROOT", value, track_vars_array TSRMLS_CC); + php_register_variable("DOCUMENT_ROOT", value, track_vars_array); /* HTTP_ACCEPT */ value = lstFset_get(rc->t->req_hdrs, "accept"); if (value != NULL) - php_register_variable("HTTP_ACCEPT", value, track_vars_array TSRMLS_CC); + php_register_variable("HTTP_ACCEPT", value, track_vars_array); /* HTTP_ACCEPT_CHARSET */ value = lstFset_get(rc->t->req_hdrs, "accept-charset"); if (value != NULL) - php_register_variable("HTTP_ACCEPT_CHARSET", value, track_vars_array TSRMLS_CC); + php_register_variable("HTTP_ACCEPT_CHARSET", value, track_vars_array); /* HTTP_ACCEPT_ENCODING */ value = lstFset_get(rc->t->req_hdrs, "accept-encoding"); if (value != NULL) - php_register_variable("HTTP_ACCEPT_ENCODING", value, track_vars_array TSRMLS_CC); + php_register_variable("HTTP_ACCEPT_ENCODING", value, track_vars_array); /* HTTP_ACCEPT_LANGUAGE */ value = lstFset_get(rc->t->req_hdrs, "accept-language"); if (value != NULL) - php_register_variable("HTTP_ACCEPT_LANGUAGE", value, track_vars_array TSRMLS_CC); + php_register_variable("HTTP_ACCEPT_LANGUAGE", value, track_vars_array); /* HTTP_CONNECTION */ value = lstFset_get(rc->t->req_hdrs, "connection"); if (value != NULL) - php_register_variable("HTTP_CONNECTION", value, track_vars_array TSRMLS_CC); + php_register_variable("HTTP_CONNECTION", value, track_vars_array); /* HTTP_REFERER */ value = lstFset_get(rc->t->req_hdrs, "referer"); if (value != NULL) - php_register_variable("HTTP_REFERER", value, track_vars_array TSRMLS_CC); + php_register_variable("HTTP_REFERER", value, track_vars_array); /* HTTP_USER_AGENT */ value = lstFset_get(rc->t->req_hdrs, "user-agent"); if (value != NULL) - php_register_variable("HTTP_USER_AGENT", value, track_vars_array TSRMLS_CC); + php_register_variable("HTTP_USER_AGENT", value, track_vars_array); /* REMOTE_ADDR */ utlFip_to_str(rc->t->cli_ipv4_addr, buf, sizeof(buf)); - php_register_variable("REMOTE_ADDR", buf, track_vars_array TSRMLS_CC); + php_register_variable("REMOTE_ADDR", buf, track_vars_array); /* REMOTE_PORT */ /* SCRIPT_FILENAME and PATH_TRANSLATED */ value = lstFset_get(rc->t->vars, "path"); if (value != NULL) { - php_register_variable("SCRIPT_FILENAME", value, track_vars_array TSRMLS_CC); - php_register_variable("PATH_TRANSLATED", value, track_vars_array TSRMLS_CC); + php_register_variable("SCRIPT_FILENAME", value, track_vars_array); + php_register_variable("PATH_TRANSLATED", value, track_vars_array); } /* SERVER_ADMIN */ /* Not applicable */ @@ -343,7 +343,7 @@ static void sapi_capi_register_server_variables(zval * track_vars_array TSRMLS_D } -static void capi_log_message(char *message TSRMLS_DC) +static void capi_log_message(char *message) { capi_request_context *rc = (capi_request_context *) SG(server_context); logFmsg(0, "mod/php: %s", message); @@ -408,7 +408,7 @@ static void capi_free(void *addr) free(addr); } -static void capi_request_ctor(NSLS_D TSRMLS_DC) +static void capi_request_ctor(NSLS_D) { char *query_string = lstFset_get(NSG(t->vars), "query"); char *uri = lstFset_get(NSG(t->vars), "uri"); @@ -427,7 +427,7 @@ static void capi_request_ctor(NSLS_D TSRMLS_DC) SG(sapi_headers).http_response_code = 200; } -static void capi_request_dtor(NSLS_D TSRMLS_DC) +static void capi_request_dtor(NSLS_D) { capi_free(SG(request_info).query_string); capi_free(SG(request_info).request_uri); @@ -436,11 +436,11 @@ static void capi_request_dtor(NSLS_D TSRMLS_DC) capi_free(SG(request_info).content_type); } -int capi_module_main(NSLS_D TSRMLS_DC) +int capi_module_main(NSLS_D) { zend_file_handle file_handle; - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { return FAILURE; } file_handle.type = ZEND_HANDLE_FILENAME; @@ -448,7 +448,7 @@ int capi_module_main(NSLS_D TSRMLS_DC) file_handle.free_filename = 0; file_handle.opened_path = NULL; - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); php_request_shutdown(NULL); return SUCCESS; @@ -462,7 +462,7 @@ int phpFinit(lstTset * opt) core_globals = ts_resource(core_globals_id); logFmsg(0, "mod/php: PHP Interface v3 (module)"); - logFmsg(0, "mod/php: Copyright (c) 1999-2005 The PHP Group. All rights reserved."); + logFmsg(0, "mod/php: Copyright (c) 1999-2015 The PHP Group. All rights reserved."); sapi_startup(&capi_sapi_module); capi_sapi_module.startup(&capi_sapi_module); @@ -475,7 +475,6 @@ int phpFservice(httpTtrans * t, lstTset * opts) int retval; capi_request_context *request_context; - TSRMLS_FETCH(); request_context = (capi_request_context *) malloc(sizeof(capi_request_context)); request_context->t = t; @@ -483,9 +482,9 @@ int phpFservice(httpTtrans * t, lstTset * opts) SG(server_context) = request_context; - capi_request_ctor(NSLS_C TSRMLS_CC); - retval = capi_module_main(NSLS_C TSRMLS_CC); - capi_request_dtor(NSLS_C TSRMLS_CC); + capi_request_ctor(NSLS_C); + retval = capi_module_main(NSLS_C); + capi_request_dtor(NSLS_C); free(request_context); diff --git a/sapi/embed/config.m4 b/sapi/embed/config.m4 index 5ffb9b39bd..5be7af48f4 100644 --- a/sapi/embed/config.m4 +++ b/sapi/embed/config.m4 @@ -23,7 +23,7 @@ if test "$PHP_EMBED" != "no"; then ;; esac if test "$PHP_EMBED_TYPE" != "no"; then - PHP_SELECT_SAPI(embed, $PHP_EMBED_TYPE, php_embed.c) + PHP_SELECT_SAPI(embed, $PHP_EMBED_TYPE, php_embed.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) PHP_INSTALL_HEADERS([sapi/embed/php_embed.h]) fi AC_MSG_RESULT([$PHP_EMBED_TYPE]) diff --git a/sapi/embed/config.w32 b/sapi/embed/config.w32 index 64e44bdd94..ce41e253f0 100644 --- a/sapi/embed/config.w32 +++ b/sapi/embed/config.w32 @@ -6,6 +6,6 @@ ARG_ENABLE('embed', 'Embedded SAPI library', 'no'); var PHP_EMBED_PGO = false; if (PHP_EMBED != "no") { - SAPI('embed', 'php_embed.c', 'php' + PHP_VERSION + 'embed.lib'); + SAPI('embed', 'php_embed.c', 'php' + PHP_VERSION + 'embed.lib', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); PHP_INSTALL_HEADERS("sapi/embed", "php_embed.h"); } diff --git a/sapi/embed/php5embed.dsp b/sapi/embed/php5embed.dsp deleted file mode 100644 index 8564b11797..0000000000 --- a/sapi/embed/php5embed.dsp +++ /dev/null @@ -1,100 +0,0 @@ -# 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 index bfeb2c0ba1..d12e5e4793 100644 --- a/sapi/embed/php_embed.c +++ b/sapi/embed/php_embed.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -33,21 +33,25 @@ const char HARDCODED_INI[] = "max_execution_time=0\n" "max_input_time=-1\n\0"; -static char* php_embed_read_cookies(TSRMLS_D) +#if defined(PHP_WIN32) && defined(ZTS) +ZEND_TSRMLS_CACHE_DEFINE; +#endif + +static char* php_embed_read_cookies(void) { return NULL; } -static int php_embed_deactivate(TSRMLS_D) +static int php_embed_deactivate(void) { fflush(stdout); return SUCCESS; } -static inline size_t php_embed_single_write(const char *str, uint str_length) +static inline size_t php_embed_single_write(const char *str, size_t str_length) { #ifdef PHP_WRITE_STDOUT - long ret; + zend_long ret; ret = write(STDOUT_FILENO, str, str_length); if (ret <= 0) return 0; @@ -61,10 +65,10 @@ static inline size_t php_embed_single_write(const char *str, uint str_length) } -static int php_embed_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t php_embed_ub_write(const char *str, size_t str_length) { const char *ptr = str; - uint remaining = str_length; + size_t remaining = str_length; size_t ret; while (remaining > 0) { @@ -86,18 +90,18 @@ static void php_embed_flush(void *server_context) } } -static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) +static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_context) { } -static void php_embed_log_message(char *message TSRMLS_DC) +static void php_embed_log_message(char *message) { fprintf (stderr, "%s\n", message); } -static void php_embed_register_variables(zval *track_vars_array TSRMLS_DC) +static void php_embed_register_variables(zval *track_vars_array) { - php_import_environment_variables(track_vars_array TSRMLS_CC); + php_import_environment_variables(track_vars_array); } static int php_embed_startup(sapi_module_struct *sapi_module) @@ -108,35 +112,35 @@ static int php_embed_startup(sapi_module_struct *sapi_module) return SUCCESS; } -extern EMBED_SAPI_API sapi_module_struct php_embed_module = { +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 }; /* }}} */ @@ -152,12 +156,9 @@ static const zend_function_entry additional_functions[] = { {NULL, NULL, NULL} }; -EMBED_SAPI_API int php_embed_init(int argc, char **argv PTSRMLS_DC) +EMBED_SAPI_API int php_embed_init(int argc, char **argv) { zend_llist global_vars; -#ifdef ZTS - void ***tsrm_ls = NULL; -#endif #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) @@ -172,8 +173,8 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv PTSRMLS_DC) #ifdef ZTS tsrm_startup(1, 1, 0, NULL); - tsrm_ls = ts_resource(0); - *ptsrm_ls = tsrm_ls; + (void)ts_resource(0); + ZEND_TSRMLS_CACHE_UPDATE; #endif sapi_startup(&php_embed_module); @@ -197,30 +198,30 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv PTSRMLS_DC) if (php_embed_module.startup(&php_embed_module)==FAILURE) { return FAILURE; } - - zend_llist_init(&global_vars, sizeof(char *), NULL, 0); + + 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); + if (php_request_startup()==FAILURE) { + php_module_shutdown(); return FAILURE; } - + SG(headers_sent) = 1; SG(request_info).no_headers = 1; - php_register_variable("PHP_SELF", "-", NULL TSRMLS_CC); + php_register_variable("PHP_SELF", "-", NULL); return SUCCESS; } -EMBED_SAPI_API void php_embed_shutdown(TSRMLS_D) +EMBED_SAPI_API void php_embed_shutdown(void) { php_request_shutdown((void *) 0); - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); sapi_shutdown(); #ifdef ZTS tsrm_shutdown(); diff --git a/sapi/embed/php_embed.h b/sapi/embed/php_embed.h index f8432d62d9..77558770c1 100644 --- a/sapi/embed/php_embed.h +++ b/sapi/embed/php_embed.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -27,45 +27,30 @@ #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); \ + php_embed_shutdown(); \ } #ifndef PHP_WIN32 #define EMBED_SAPI_API SAPI_API #else - #define EMBED_SAPI_API -#endif + #define EMBED_SAPI_API +#endif + +#ifdef ZTS +ZEND_TSRMLS_CACHE_EXTERN; +#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); +BEGIN_EXTERN_C() +EMBED_SAPI_API int php_embed_init(int argc, char **argv); +EMBED_SAPI_API void php_embed_shutdown(void); extern EMBED_SAPI_API sapi_module_struct php_embed_module; END_EXTERN_C() diff --git a/sapi/fpm/Makefile.frag b/sapi/fpm/Makefile.frag index 6ed9e4a249..8e3b5e9316 100644 --- a/sapi/fpm/Makefile.frag +++ b/sapi/fpm/Makefile.frag @@ -11,8 +11,9 @@ install-fpm: $(SAPI_FPM_PATH) @$(INSTALL) -m 0755 $(SAPI_FPM_PATH) $(INSTALL_ROOT)$(sbindir)/$(program_prefix)php-fpm$(program_suffix)$(EXEEXT) @echo "Installing PHP FPM config: $(INSTALL_ROOT)$(sysconfdir)/" && \ - $(mkinstalldirs) $(INSTALL_ROOT)$(sysconfdir) || : + $(mkinstalldirs) $(INSTALL_ROOT)$(sysconfdir)/php-fpm.d || : @$(INSTALL_DATA) sapi/fpm/php-fpm.conf $(INSTALL_ROOT)$(sysconfdir)/php-fpm.conf.default || : + @$(INSTALL_DATA) sapi/fpm/www.conf $(INSTALL_ROOT)$(sysconfdir)/php-fpm.d/www.conf.default || : @echo "Installing PHP FPM man page: $(INSTALL_ROOT)$(mandir)/man8/" @$(mkinstalldirs) $(INSTALL_ROOT)$(mandir)/man8 diff --git a/sapi/fpm/config.m4 b/sapi/fpm/config.m4 index f87776aa24..b4a4f4fb33 100644 --- a/sapi/fpm/config.m4 +++ b/sapi/fpm/config.m4 @@ -667,7 +667,7 @@ if test "$PHP_FPM" != "no"; then PHP_ADD_BUILD_DIR(sapi/fpm/fpm) PHP_ADD_BUILD_DIR(sapi/fpm/fpm/events) - PHP_OUTPUT(sapi/fpm/php-fpm.conf sapi/fpm/init.d.php-fpm sapi/fpm/php-fpm.service sapi/fpm/php-fpm.8 sapi/fpm/status.html) + PHP_OUTPUT(sapi/fpm/php-fpm.conf sapi/fpm/www.conf sapi/fpm/init.d.php-fpm sapi/fpm/php-fpm.service sapi/fpm/php-fpm.8 sapi/fpm/status.html) PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/fpm/Makefile.frag]) SAPI_FPM_PATH=sapi/fpm/php-fpm diff --git a/sapi/fpm/fpm/events/devpoll.c b/sapi/fpm/fpm/events/devpoll.c index c8a1defabd..729af6c486 100644 --- a/sapi/fpm/fpm/events/devpoll.c +++ b/sapi/fpm/fpm/events/devpoll.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -45,7 +45,7 @@ static struct fpm_event_module_s devpoll_module = { .clean = fpm_event_devpoll_clean, .wait = fpm_event_devpoll_wait, .add = fpm_event_devpoll_add, - .remove = fpm_event_devpoll_remove, + .remove = fpm_event_devpoll_remove, }; int dpfd = -1; @@ -76,7 +76,7 @@ static int fpm_event_devpoll_init(int max) /* {{{ */ /* open /dev/poll for future usages */ dpfd = open("/dev/poll", O_RDWR); - if (dpfd < 0) { + if (dpfd < 0) { zlog(ZLOG_ERROR, "Unable to open /dev/poll"); return -1; } @@ -120,7 +120,7 @@ static int fpm_event_devpoll_init(int max) /* {{{ */ static int fpm_event_devpoll_clean() /* {{{ */ { /* close /dev/poll if open */ - if (dpfd > -1) { + if (dpfd > -1) { close(dpfd); dpfd = -1; } @@ -176,7 +176,7 @@ static int fpm_event_devpoll_wait(struct fpm_event_queue_s *queue, unsigned long while (q) { /* found */ - if (q->ev && q->ev->fd == active_pollfds[i].fd) { + if (q->ev && q->ev->fd == active_pollfds[i].fd) { /* fire the event */ fpm_event_fire(q->ev); diff --git a/sapi/fpm/fpm/events/devpoll.h b/sapi/fpm/fpm/events/devpoll.h index 717bbe94f7..12a8ea834f 100644 --- a/sapi/fpm/fpm/events/devpoll.h +++ b/sapi/fpm/fpm/events/devpoll.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/fpm/fpm/events/epoll.c b/sapi/fpm/fpm/events/epoll.c index c50da87dfb..8b7e476ff4 100644 --- a/sapi/fpm/fpm/events/epoll.c +++ b/sapi/fpm/fpm/events/epoll.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -41,7 +41,7 @@ static struct fpm_event_module_s epoll_module = { .clean = fpm_event_epoll_clean, .wait = fpm_event_epoll_wait, .add = fpm_event_epoll_add, - .remove = fpm_event_epoll_remove, + .remove = fpm_event_epoll_remove, }; static struct epoll_event *epollfds = NULL; diff --git a/sapi/fpm/fpm/events/epoll.h b/sapi/fpm/fpm/events/epoll.h index eb4bd72afb..2ef5e941a5 100644 --- a/sapi/fpm/fpm/events/epoll.h +++ b/sapi/fpm/fpm/events/epoll.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/fpm/fpm/events/kqueue.c b/sapi/fpm/fpm/events/kqueue.c index 2188cd298d..1e0999ee81 100644 --- a/sapi/fpm/fpm/events/kqueue.c +++ b/sapi/fpm/fpm/events/kqueue.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -44,7 +44,7 @@ static struct fpm_event_module_s kqueue_module = { .clean = fpm_event_kqueue_clean, .wait = fpm_event_kqueue_wait, .add = fpm_event_kqueue_add, - .remove = fpm_event_kqueue_remove, + .remove = fpm_event_kqueue_remove, }; static struct kevent *kevents = NULL; diff --git a/sapi/fpm/fpm/events/kqueue.h b/sapi/fpm/fpm/events/kqueue.h index 2109a187da..f9329c4666 100644 --- a/sapi/fpm/fpm/events/kqueue.h +++ b/sapi/fpm/fpm/events/kqueue.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/fpm/fpm/events/poll.c b/sapi/fpm/fpm/events/poll.c index 6e2d014cf4..638513e9d9 100644 --- a/sapi/fpm/fpm/events/poll.c +++ b/sapi/fpm/fpm/events/poll.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -42,7 +42,7 @@ static struct fpm_event_module_s poll_module = { .clean = fpm_event_poll_clean, .wait = fpm_event_poll_wait, .add = fpm_event_poll_add, - .remove = fpm_event_poll_remove, + .remove = fpm_event_poll_remove, }; static struct pollfd *pollfds = NULL; @@ -150,7 +150,7 @@ static int fpm_event_poll_wait(struct fpm_event_queue_s *queue, unsigned long in return -1; } } - + /* events have been triggered */ if (ret > 0) { diff --git a/sapi/fpm/fpm/events/poll.h b/sapi/fpm/fpm/events/poll.h index 21a2b0fd98..4471895aa1 100644 --- a/sapi/fpm/fpm/events/poll.h +++ b/sapi/fpm/fpm/events/poll.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/fpm/fpm/events/port.c b/sapi/fpm/fpm/events/port.c index 12e3678b7c..f60aaeca06 100644 --- a/sapi/fpm/fpm/events/port.c +++ b/sapi/fpm/fpm/events/port.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -42,7 +42,7 @@ static struct fpm_event_module_s port_module = { .clean = fpm_event_port_clean, .wait = fpm_event_port_wait, .add = fpm_event_port_add, - .remove = fpm_event_port_remove, + .remove = fpm_event_port_remove, }; port_event_t *events = NULL; diff --git a/sapi/fpm/fpm/events/port.h b/sapi/fpm/fpm/events/port.h index a5771fab56..3b550757d0 100644 --- a/sapi/fpm/fpm/events/port.h +++ b/sapi/fpm/fpm/events/port.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/fpm/fpm/events/select.c b/sapi/fpm/fpm/events/select.c index e59ecd4a4f..3714454213 100644 --- a/sapi/fpm/fpm/events/select.c +++ b/sapi/fpm/fpm/events/select.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/fpm/fpm/events/select.h b/sapi/fpm/fpm/events/select.h index fe6d30edcd..4562fd9bfd 100644 --- a/sapi/fpm/fpm/events/select.h +++ b/sapi/fpm/fpm/events/select.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/fpm/fpm/fastcgi.c b/sapi/fpm/fpm/fastcgi.c index 8b081b2be1..0e3ec18023 100644 --- a/sapi/fpm/fpm/fastcgi.c +++ b/sapi/fpm/fpm/fastcgi.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -472,7 +472,7 @@ static int fcgi_get_params(fcgi_request *req, unsigned char *p, unsigned char *e break; } if (eff_name_len >= buf_size-1) { - if (eff_name_len > ((uint)-1)-64) { + if (eff_name_len > ((uint)-1)-64) { ret = 0; break; } @@ -486,11 +486,7 @@ static int fcgi_get_params(fcgi_request *req, unsigned char *p, unsigned char *e memcpy(tmp, p, eff_name_len); tmp[eff_name_len] = 0; s = estrndup((char*)p + name_len, val_len); - if (s == NULL) { - ret = 0; - break; - } - zend_hash_update(req->env, tmp, eff_name_len+1, &s, sizeof(char*), NULL); + zend_hash_str_update_ptr(req->env, tmp, eff_name_len, s); p += name_len + val_len; } if (tmp != buf && tmp != NULL) { @@ -499,9 +495,9 @@ static int fcgi_get_params(fcgi_request *req, unsigned char *p, unsigned char *e return ret; } -static void fcgi_free_var(char **s) +static void fcgi_free_var(zval *zv) { - efree(*s); + efree(Z_PTR_P(zv)); } static int fcgi_read_request(fcgi_request *req) @@ -516,7 +512,7 @@ static int fcgi_read_request(fcgi_request *req) req->out_hdr = NULL; req->out_pos = req->out_buf; ALLOC_HASHTABLE(req->env); - zend_hash_init(req->env, 0, NULL, (void (*)(void *)) fcgi_free_var, 0); + zend_hash_init(req->env, 0, NULL, fcgi_free_var, 0); if (safe_read(req, &hdr, sizeof(fcgi_header)) != sizeof(fcgi_header) || hdr.version < FCGI_VERSION_1) { @@ -553,15 +549,15 @@ static int fcgi_read_request(fcgi_request *req) switch ((((fcgi_begin_request*)buf)->roleB1 << 8) + ((fcgi_begin_request*)buf)->roleB0) { case FCGI_RESPONDER: val = estrdup("RESPONDER"); - zend_hash_update(req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL); + zend_hash_str_update_ptr(req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), val); break; case FCGI_AUTHORIZER: val = estrdup("AUTHORIZER"); - zend_hash_update(req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL); + zend_hash_str_update_ptr(req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), val); break; case FCGI_FILTER: val = estrdup("FILTER"); - zend_hash_update(req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL); + zend_hash_str_update_ptr(req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), val); break; default: return 0; @@ -600,12 +596,8 @@ static int fcgi_read_request(fcgi_request *req) } } else if (hdr.type == FCGI_GET_VALUES) { unsigned char *p = buf + sizeof(fcgi_header); - HashPosition pos; - char * str_index; - uint str_length; - ulong num_index; - int key_type; - zval ** value; + zend_string *key; + zval *value; if (safe_read(req, buf, len+padding) != len+padding) { req->keep = 0; @@ -617,28 +609,26 @@ static int fcgi_read_request(fcgi_request *req) return 0; } - zend_hash_internal_pointer_reset_ex(req->env, &pos); - while ((key_type = zend_hash_get_current_key_ex(req->env, &str_index, &str_length, &num_index, 0, &pos)) != HASH_KEY_NON_EXISTENT) { + ZEND_HASH_FOREACH_STR_KEY(req->env, key) { int zlen; - zend_hash_move_forward_ex(req->env, &pos); - if (key_type != HASH_KEY_IS_STRING) { + if (!key) { continue; } - if (zend_hash_find(&fcgi_mgmt_vars, str_index, str_length, (void**) &value) != SUCCESS) { + value = zend_hash_find(&fcgi_mgmt_vars, key); + if (!value) { continue; } - --str_length; - zlen = Z_STRLEN_PP(value); - if ((p + 4 + 4 + str_length + zlen) >= (buf + sizeof(buf))) { + zlen = Z_STRLEN_P(value); + if ((p + 4 + 4 + key->len + zlen) >= (buf + sizeof(buf))) { break; } - if (str_length < 0x80) { - *p++ = str_length; + if (key->len < 0x80) { + *p++ = key->len; } else { - *p++ = ((str_length >> 24) & 0xff) | 0x80; - *p++ = (str_length >> 16) & 0xff; - *p++ = (str_length >> 8) & 0xff; - *p++ = str_length & 0xff; + *p++ = ((key->len >> 24) & 0xff) | 0x80; + *p++ = (key->len >> 16) & 0xff; + *p++ = (key->len >> 8) & 0xff; + *p++ = key->len & 0xff; } if (zlen < 0x80) { *p++ = zlen; @@ -648,11 +638,11 @@ static int fcgi_read_request(fcgi_request *req) *p++ = (zlen >> 8) & 0xff; *p++ = zlen & 0xff; } - memcpy(p, str_index, str_length); - p += str_length; - memcpy(p, Z_STRVAL_PP(value), zlen); + memcpy(p, key->val, key->len); + p += key->len; + memcpy(p, Z_STRVAL_P(value), zlen); p += zlen; - } + } ZEND_HASH_FOREACH_END(); len = p - buf - sizeof(fcgi_header); len += fcgi_make_header((fcgi_header*)buf, FCGI_GET_VALUES_RESULT, 0, len); if (safe_write(req, buf, sizeof(fcgi_header)+len) != (int)sizeof(fcgi_header)+len) { @@ -1041,8 +1031,8 @@ ssize_t fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, i return -1; } pos += 0xfff8; - } - + } + pad = (((len - pos) + 7) & ~7) - (len - pos); rest = pad ? 8 - pad : 0; @@ -1082,28 +1072,22 @@ int fcgi_finish_request(fcgi_request *req, int force_close) char* fcgi_getenv(fcgi_request *req, const char* var, int var_len) { - char **val; - - if (!req) return NULL; - - if (zend_hash_find(req->env, (char*)var, var_len+1, (void**)&val) == SUCCESS) { - return *val; + if (!req) { + return NULL; } - return NULL; + + return zend_hash_str_find_ptr(req->env, var, var_len); } char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val) { if (var && req) { if (val == NULL) { - zend_hash_del(req->env, var, var_len+1); + zend_hash_str_del(req->env, var, var_len); } else { - char **ret; - val = estrdup(val); - if (zend_hash_update(req->env, var, var_len+1, &val, sizeof(char*), (void**)&ret) == SUCCESS) { - return *ret; - } + zend_hash_str_update_ptr(req->env, var, var_len, val); + return val; } } return NULL; @@ -1111,19 +1095,14 @@ char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val) void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len) { - zval * zvalue; - zvalue = pemalloc(sizeof(*zvalue), 1); - Z_TYPE_P(zvalue) = IS_STRING; - Z_STRVAL_P(zvalue) = pestrndup(value, value_len, 1); - Z_STRLEN_P(zvalue) = value_len; - zend_hash_add(&fcgi_mgmt_vars, name, name_len + 1, &zvalue, sizeof(zvalue), NULL); + zval zvalue; + ZVAL_NEW_STR(&zvalue, zend_string_init(value, value_len, 1)); + zend_hash_str_add(&fcgi_mgmt_vars, name, name_len, &zvalue); } -void fcgi_free_mgmt_var_cb(void * ptr) +void fcgi_free_mgmt_var_cb(zval *zv) { - zval ** var = (zval **)ptr; - pefree(Z_STRVAL_PP(var), 1); - pefree(*var, 1); + zend_string_free(Z_STR_P(zv)); } const char *fcgi_get_last_client_ip() /* {{{ */ diff --git a/sapi/fpm/fpm/fastcgi.h b/sapi/fpm/fpm/fastcgi.h index ccea6c2b5e..fb7385afcc 100644 --- a/sapi/fpm/fpm/fastcgi.h +++ b/sapi/fpm/fpm/fastcgi.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -131,7 +131,7 @@ ssize_t fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, i int fcgi_flush(fcgi_request *req, int close); void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len); -void fcgi_free_mgmt_var_cb(void * ptr); +void fcgi_free_mgmt_var_cb(zval *ptr); const char *fcgi_get_last_client_ip(); diff --git a/sapi/fpm/fpm/fpm.c b/sapi/fpm/fpm/fpm.c index 96a29c5f10..e43eb5a86d 100644 --- a/sapi/fpm/fpm/fpm.c +++ b/sapi/fpm/fpm/fpm.c @@ -24,7 +24,7 @@ #include "zlog.h" struct fpm_globals_s fpm_globals = { - .parent_pid = 0, + .parent_pid = 0, .argc = 0, .argv = NULL, .config = NULL, diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index d812452e43..9a619ce887 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -55,7 +55,7 @@ #define GO(field) offsetof(struct fpm_global_config_s, field) #define WPO(field) offsetof(struct fpm_worker_pool_config_s, field) -static int fpm_conf_load_ini_file(char *filename TSRMLS_DC); +static int fpm_conf_load_ini_file(char *filename); static char *fpm_conf_set_integer(zval *value, void **config, intptr_t offset); #if 0 /* not used for now */ static char *fpm_conf_set_long(zval *value, void **config, intptr_t offset); @@ -88,7 +88,7 @@ static char *ini_filename = NULL; static int ini_lineno = 0; static char *ini_include = NULL; -/* +/* * Please keep the same order as in fpm_conf.h and in php-fpm.conf.in */ static struct ini_value_parser_s ini_fpm_global_options[] = { @@ -114,7 +114,7 @@ static struct ini_value_parser_s ini_fpm_global_options[] = { { 0, 0, 0 } }; -/* +/* * Please keep the same order as in fpm_conf.h and in php-fpm.conf.in */ static struct ini_value_parser_s ini_fpm_pool_options[] = { @@ -510,7 +510,7 @@ static char *fpm_conf_set_rlimit_core(zval *value, void **config, intptr_t offse error = fpm_conf_set_integer(value, &subconf, 0); - if (error) { + if (error) { return error; } @@ -604,7 +604,7 @@ static void *fpm_worker_pool_config_alloc() /* {{{ */ wp->config = malloc(sizeof(struct fpm_worker_pool_config_s)); - if (!wp->config) { + if (!wp->config) { fpm_worker_pool_free(wp); return 0; } @@ -1151,7 +1151,7 @@ int fpm_conf_write_pid() /* {{{ */ } /* }}} */ -static int fpm_conf_post_process(int force_daemon TSRMLS_DC) /* {{{ */ +static int fpm_conf_post_process(int force_daemon) /* {{{ */ { struct fpm_worker_pool_s *wp; @@ -1222,7 +1222,7 @@ static int fpm_conf_post_process(int force_daemon TSRMLS_DC) /* {{{ */ if (!wp->config->access_log || !*wp->config->access_log) { continue; } - if (0 > fpm_log_write(wp->config->access_format TSRMLS_CC)) { + if (0 > fpm_log_write(wp->config->access_format)) { zlog(ZLOG_ERROR, "[pool %s] wrong format for access.format '%s'", wp->config->name, wp->config->access_format); return -1; } @@ -1247,7 +1247,7 @@ static void fpm_conf_cleanup(int which, void *arg) /* {{{ */ } /* }}} */ -static void fpm_conf_ini_parser_include(char *inc, void *arg TSRMLS_DC) /* {{{ */ +static void fpm_conf_ini_parser_include(char *inc, void *arg) /* {{{ */ { char *filename; int *error = (int *)arg;; @@ -1258,7 +1258,7 @@ static void fpm_conf_ini_parser_include(char *inc, void *arg TSRMLS_DC) /* {{{ * if (!inc || !arg) return; if (*error) return; /* We got already an error. Switch to the end. */ - spprintf(&filename, 0, "%s", ini_filename); + spprintf(&filename, 0, "%s", ini_filename); #ifdef HAVE_GLOB { @@ -1269,7 +1269,7 @@ static void fpm_conf_ini_parser_include(char *inc, void *arg TSRMLS_DC) /* {{{ * zlog(ZLOG_WARNING, "Nothing matches the include pattern '%s' from %s at line %d.", inc, filename, ini_lineno); efree(filename); return; - } + } #endif /* GLOB_NOMATCH */ zlog(ZLOG_ERROR, "Unable to globalize '%s' (ret=%d) from %s at line %d.", inc, i, filename, ini_lineno); *error = 1; @@ -1281,7 +1281,7 @@ static void fpm_conf_ini_parser_include(char *inc, void *arg TSRMLS_DC) /* {{{ * int len = strlen(g.gl_pathv[i]); if (len < 1) continue; if (g.gl_pathv[i][len - 1] == '/') continue; /* don't parse directories */ - if (0 > fpm_conf_load_ini_file(g.gl_pathv[i] TSRMLS_CC)) { + if (0 > fpm_conf_load_ini_file(g.gl_pathv[i])) { zlog(ZLOG_ERROR, "Unable to include %s from %s at line %d", g.gl_pathv[i], filename, ini_lineno); *error = 1; efree(filename); @@ -1291,7 +1291,7 @@ static void fpm_conf_ini_parser_include(char *inc, void *arg TSRMLS_DC) /* {{{ * globfree(&g); } #else /* HAVE_GLOB */ - if (0 > fpm_conf_load_ini_file(inc TSRMLS_CC)) { + if (0 > fpm_conf_load_ini_file(inc)) { zlog(ZLOG_ERROR, "Unable to include %s from %s at line %d", inc, filename, ini_lineno); *error = 1; efree(filename); @@ -1303,7 +1303,7 @@ static void fpm_conf_ini_parser_include(char *inc, void *arg TSRMLS_DC) /* {{{ * } /* }}} */ -static void fpm_conf_ini_parser_section(zval *section, void *arg TSRMLS_DC) /* {{{ */ +static void fpm_conf_ini_parser_section(zval *section, void *arg) /* {{{ */ { struct fpm_worker_pool_s *wp; struct fpm_worker_pool_config_s *config; @@ -1341,7 +1341,7 @@ static void fpm_conf_ini_parser_section(zval *section, void *arg TSRMLS_DC) /* { } /* }}} */ -static void fpm_conf_ini_parser_entry(zval *name, zval *value, void *arg TSRMLS_DC) /* {{{ */ +static void fpm_conf_ini_parser_entry(zval *name, zval *value, void *arg) /* {{{ */ { struct ini_value_parser_s *parser; void *config = NULL; @@ -1398,7 +1398,7 @@ static void fpm_conf_ini_parser_entry(zval *name, zval *value, void *arg TSRMLS_ } /* }}} */ -static void fpm_conf_ini_parser_array(zval *name, zval *key, zval *value, void *arg TSRMLS_DC) /* {{{ */ +static void fpm_conf_ini_parser_array(zval *name, zval *key, zval *value, void *arg) /* {{{ */ { int *error = (int *)arg; char *err = NULL; @@ -1454,7 +1454,7 @@ static void fpm_conf_ini_parser_array(zval *name, zval *key, zval *value, void * } /* }}} */ -static void fpm_conf_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg TSRMLS_DC) /* {{{ */ +static void fpm_conf_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg) /* {{{ */ { int *error; @@ -1464,13 +1464,13 @@ static void fpm_conf_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback switch(callback_type) { case ZEND_INI_PARSER_ENTRY: - fpm_conf_ini_parser_entry(arg1, arg2, error TSRMLS_CC); + fpm_conf_ini_parser_entry(arg1, arg2, error); break;; case ZEND_INI_PARSER_SECTION: - fpm_conf_ini_parser_section(arg1, error TSRMLS_CC); + fpm_conf_ini_parser_section(arg1, error); break;; case ZEND_INI_PARSER_POP_ENTRY: - fpm_conf_ini_parser_array(arg1, arg3, arg2, error TSRMLS_CC); + fpm_conf_ini_parser_array(arg1, arg3, arg2, error); break;; default: zlog(ZLOG_ERROR, "[%s:%d] Unknown INI syntax", ini_filename, ini_lineno); @@ -1480,10 +1480,11 @@ static void fpm_conf_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback } /* }}} */ -int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */ +int fpm_conf_load_ini_file(char *filename) /* {{{ */ { int error = 0; - char buf[1024+1]; + char *buf = NULL, *newbuf = NULL; + int bufsize = 0; int fd, n; int nb_read = 1; char c = '*'; @@ -1510,40 +1511,58 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */ ini_lineno = 0; while (nb_read > 0) { int tmp; - memset(buf, 0, sizeof(char) * (1024 + 1)); - for (n = 0; n < 1024 && (nb_read = read(fd, &c, sizeof(char))) == sizeof(char) && c != '\n'; n++) { + ini_lineno++; + ini_filename = filename; + for (n = 0; (nb_read = read(fd, &c, sizeof(char))) == sizeof(char) && c != '\n'; n++) { + if (n == bufsize) { + bufsize += 1024; + newbuf = (char*) realloc(buf, sizeof(char) * (bufsize + 2)); + if (newbuf == NULL) { + ini_recursion--; + close(fd); + free(buf); + return -1; + } + buf = newbuf; + } + buf[n] = c; } + if (n == 0) { + continue; + } + /* always append newline and null terminate */ buf[n++] = '\n'; - ini_lineno++; - ini_filename = filename; - tmp = zend_parse_ini_string(buf, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t)fpm_conf_ini_parser, &error TSRMLS_CC); + buf[n] = '\0'; + tmp = zend_parse_ini_string(buf, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t)fpm_conf_ini_parser, &error); ini_filename = filename; if (error || tmp == FAILURE) { if (ini_include) free(ini_include); ini_recursion--; close(fd); + free(buf); return -1; } if (ini_include) { char *tmp = ini_include; ini_include = NULL; fpm_evaluate_full_path(&tmp, NULL, NULL, 0); - fpm_conf_ini_parser_include(tmp, &error TSRMLS_CC); + fpm_conf_ini_parser_include(tmp, &error); if (error) { free(tmp); ini_recursion--; close(fd); + free(buf); return -1; } free(tmp); } } + free(buf); ini_recursion--; close(fd); return ret; - } /* }}} */ @@ -1644,7 +1663,6 @@ static void fpm_conf_dump() /* {{{ */ int fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */ { int ret; - TSRMLS_FETCH(); if (fpm_globals.prefix && *fpm_globals.prefix) { if (!fpm_conf_is_dir(fpm_globals.prefix)) { @@ -1680,14 +1698,14 @@ int fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */ } } - ret = fpm_conf_load_ini_file(fpm_globals.config TSRMLS_CC); + ret = fpm_conf_load_ini_file(fpm_globals.config); if (0 > ret) { zlog(ZLOG_ERROR, "failed to load configuration file '%s'", fpm_globals.config); return -1; } - if (0 > fpm_conf_post_process(force_daemon TSRMLS_CC)) { + if (0 > fpm_conf_post_process(force_daemon)) { zlog(ZLOG_ERROR, "failed to post process the configuration"); return -1; } diff --git a/sapi/fpm/fpm/fpm_env.c b/sapi/fpm/fpm/fpm_env.c index 3bdb346341..73affab236 100644 --- a/sapi/fpm/fpm/fpm_env.c +++ b/sapi/fpm/fpm/fpm_env.c @@ -32,7 +32,7 @@ int setenv(char *name, char *value, int clobber) /* {{{ */ if (clobber == 0 && getenv(name) != 0) { return 0; } - + if ((cp = malloc(strlen(name) + strlen(value) + 2)) == 0) { return 1; } @@ -106,11 +106,11 @@ static char * nvmatch(char *s1, char *s2) /* {{{ */ { while(*s1 == *s2++) { - if(*s1++ == '=') { + if(*s1++ == '=') { return s2; } } - if(*s1 == '\0' && *(s2-1) == '=') { + if(*s1 == '\0' && *(s2-1) == '=') { return s2; } return NULL; @@ -270,7 +270,7 @@ int fpm_env_init_main() /* {{{ */ #endif spprintf(&title, 0, "master process (%s)", fpm_globals.config); - fpm_env_setproctitle(title); + fpm_env_setproctitle(title); efree(title); return 0; } diff --git a/sapi/fpm/fpm/fpm_events.c b/sapi/fpm/fpm/fpm_events.c index ce5d543f9b..ca45cb1665 100644 --- a/sapi/fpm/fpm/fpm_events.c +++ b/sapi/fpm/fpm/fpm_events.c @@ -171,7 +171,7 @@ static int fpm_event_queue_add(struct fpm_event_queue_s **queue, struct fpm_even module->add(ev); } - return 0; + return 0; } /* }}} */ @@ -464,7 +464,7 @@ void fpm_event_fire(struct fpm_event_s *ev) /* {{{ */ return; } - (*ev->callback)( (struct fpm_event_s *) ev, ev->which, ev->arg); + (*ev->callback)( (struct fpm_event_s *) ev, ev->which, ev->arg); } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_log.c b/sapi/fpm/fpm/fpm_log.c index b0bf32ac16..86332c4c80 100644 --- a/sapi/fpm/fpm/fpm_log.c +++ b/sapi/fpm/fpm/fpm_log.c @@ -34,14 +34,14 @@ int fpm_log_open(int reopen) /* {{{ */ { struct fpm_worker_pool_s *wp; int ret = 1; - + int fd; for (wp = fpm_worker_all_pools; wp; wp = wp->next) { if (!wp->config->access_log) { continue; } ret = 0; - + fd = open(wp->config->access_log, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR); if (0 > fd) { zlog(ZLOG_SYSERROR, "failed to open access log (%s)", wp->config->access_log); @@ -97,7 +97,7 @@ int fpm_log_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ } /* }}} */ -int fpm_log_write(char *log_format TSRMLS_DC) /* {{{ */ +int fpm_log_write(char *log_format) /* {{{ */ { char *s, *b; char buffer[FPM_LOG_BUFFER+1]; @@ -410,7 +410,7 @@ int fpm_log_write(char *log_format TSRMLS_DC) /* {{{ */ { char *start; size_t l; - + start = ++s; while (*s != '\0') { diff --git a/sapi/fpm/fpm/fpm_log.h b/sapi/fpm/fpm/fpm_log.h index f0199d9cb6..d85d368da5 100644 --- a/sapi/fpm/fpm/fpm_log.h +++ b/sapi/fpm/fpm/fpm_log.h @@ -7,7 +7,7 @@ #include "fpm_worker_pool.h" int fpm_log_init_child(struct fpm_worker_pool_s *wp); -int fpm_log_write(char *log_format TSRMLS_DC); +int fpm_log_write(char *log_format); int fpm_log_open(int reopen); #endif diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index c217d7af44..c4ebc8bd3b 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -97,6 +97,8 @@ int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS; #include "php_getopt.h" +#include "http_status_codes.h" + #include "fastcgi.h" #include <php_config.h> @@ -113,7 +115,7 @@ int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS; struct sigaction act, old_term, old_quit, old_int; #endif -static void (*php_php_import_environment_variables)(zval *array_ptr TSRMLS_DC); +static void (*php_php_import_environment_variables)(zval *array_ptr); #ifndef PHP_WIN32 /* these globals used for forking children on unix systems */ @@ -127,8 +129,8 @@ static int parent = 1; static int request_body_fd; static int fpm_is_running = 0; -static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC); -static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg TSRMLS_DC); +static char *sapi_cgibin_getenv(char *name, size_t name_len); +static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg); #define PHP_MODE_STANDARD 1 #define PHP_MODE_HIGHLIGHT 2 @@ -188,10 +190,12 @@ typedef struct _user_config_cache_entry { HashTable *user_config; } user_config_cache_entry; -static void user_config_cache_entry_dtor(user_config_cache_entry *entry) +static void user_config_cache_entry_dtor(zval *el) { + user_config_cache_entry *entry = (user_config_cache_entry *)Z_PTR_P(el); zend_hash_destroy(entry->user_config); free(entry->user_config); + free(entry); } /* }}} */ @@ -216,61 +220,61 @@ static php_cgi_globals_struct php_cgi_globals; #define TRANSLATE_SLASHES(path) #endif -static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC) +static int print_module_info(zval *zv) { + zend_module_entry *module = Z_PTR_P(zv); php_printf("%s\n", module->name); return 0; } -static int module_name_cmp(const void *a, const void *b TSRMLS_DC) +static int module_name_cmp(const void *a, const void *b) { - Bucket *f = *((Bucket **) a); - Bucket *s = *((Bucket **) b); + Bucket *f = (Bucket *) a; + Bucket *s = (Bucket *) b; - return strcasecmp( ((zend_module_entry *)f->pData)->name, - ((zend_module_entry *)s->pData)->name); + return strcasecmp( ((zend_module_entry *) Z_PTR(f->val))->name, + ((zend_module_entry *) Z_PTR(s->val))->name); } -static void print_modules(TSRMLS_D) +static void print_modules(void) { HashTable sorted_registry; - zend_module_entry tmp; zend_hash_init(&sorted_registry, 50, NULL, NULL, 1); - zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry)); - zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC); - zend_hash_apply_with_argument(&sorted_registry, (apply_func_arg_t) print_module_info, NULL TSRMLS_CC); + zend_hash_copy(&sorted_registry, &module_registry, NULL); + zend_hash_sort(&sorted_registry, module_name_cmp, 0); + zend_hash_apply(&sorted_registry, print_module_info); zend_hash_destroy(&sorted_registry); } -static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC) +static int print_extension_info(zend_extension *ext, void *arg) { php_printf("%s\n", ext->name); return 0; } -static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s TSRMLS_DC) +static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s) { return strcmp( ((zend_extension *)(*f)->data)->name, ((zend_extension *)(*s)->data)->name); } -static void print_extensions(TSRMLS_D) +static void print_extensions(void) { zend_llist sorted_exts; zend_llist_copy(&sorted_exts, &zend_extensions); sorted_exts.dtor = NULL; - zend_llist_sort(&sorted_exts, extension_name_cmp TSRMLS_CC); - zend_llist_apply_with_argument(&sorted_exts, (llist_apply_with_arg_func_t) print_extension_info, NULL TSRMLS_CC); + zend_llist_sort(&sorted_exts, extension_name_cmp); + zend_llist_apply_with_argument(&sorted_exts, (llist_apply_with_arg_func_t) print_extension_info, NULL); zend_llist_destroy(&sorted_exts); } -#ifndef STDOUT_FILENO -#define STDOUT_FILENO 1 +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 #endif -static inline size_t sapi_cgibin_single_write(const char *str, uint str_length TSRMLS_DC) +static inline size_t sapi_cgibin_single_write(const char *str, uint str_length) { ssize_t ret; @@ -285,8 +289,8 @@ static inline size_t sapi_cgibin_single_write(const char *str, uint str_length T } /* sapi has not started, output to stdout instead of fcgi */ -#ifdef PHP_WRITE_STDOUT - ret = write(STDOUT_FILENO, str, str_length); +#ifdef PHP_WRITE_STDOUT + ret = write(STDOUT_FILENO, str, str_length); if (ret <= 0) { return 0; } @@ -296,14 +300,14 @@ static inline size_t sapi_cgibin_single_write(const char *str, uint str_length T #endif } -static int sapi_cgibin_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t sapi_cgibin_ub_write(const char *str, size_t str_length) { const char *ptr = str; uint remaining = str_length; size_t ret; while (remaining > 0) { - ret = sapi_cgibin_single_write(ptr, remaining TSRMLS_CC); + ret = sapi_cgibin_single_write(ptr, remaining); if (!ret) { php_handle_aborted_connection(); return str_length - remaining; @@ -339,57 +343,7 @@ static void sapi_cgibin_flush(void *server_context) #define SAPI_CGI_MAX_HEADER_LENGTH 1024 -typedef struct _http_error { - int code; - const char* msg; -} http_error; - -static const http_error http_error_codes[] = { - {100, "Continue"}, - {101, "Switching Protocols"}, - {200, "OK"}, - {201, "Created"}, - {202, "Accepted"}, - {203, "Non-Authoritative Information"}, - {204, "No Content"}, - {205, "Reset Content"}, - {206, "Partial Content"}, - {300, "Multiple Choices"}, - {301, "Moved Permanently"}, - {302, "Moved Temporarily"}, - {303, "See Other"}, - {304, "Not Modified"}, - {305, "Use Proxy"}, - {400, "Bad Request"}, - {401, "Unauthorized"}, - {402, "Payment Required"}, - {403, "Forbidden"}, - {404, "Not Found"}, - {405, "Method Not Allowed"}, - {406, "Not Acceptable"}, - {407, "Proxy Authentication Required"}, - {408, "Request Time-out"}, - {409, "Conflict"}, - {410, "Gone"}, - {411, "Length Required"}, - {412, "Precondition Failed"}, - {413, "Request Entity Too Large"}, - {414, "Request-URI Too Large"}, - {415, "Unsupported Media Type"}, - {428, "Precondition Required"}, - {429, "Too Many Requests"}, - {431, "Request Header Fields Too Large"}, - {500, "Internal Server Error"}, - {501, "Not Implemented"}, - {502, "Bad Gateway"}, - {503, "Service Unavailable"}, - {504, "Gateway Time-out"}, - {505, "HTTP Version not supported"}, - {511, "Network Authentication Required"}, - {0, NULL} -}; - -static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers) { char buf[SAPI_CGI_MAX_HEADER_LENGTH]; sapi_header_struct *h; @@ -439,7 +393,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos); } if (!has_status) { - http_error *err = (http_error*)http_error_codes; + http_response_status_code_pair *err = (http_response_status_code_pair*)http_status_map; while (err->code != 0) { if (err->code == SG(sapi_headers).http_response_code) { @@ -447,8 +401,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) } err++; } - if (err->msg) { - len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg); + if (err->str) { + len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->str); } else { len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code); } @@ -466,7 +420,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) while (h) { /* prevent CRLFCRLF */ if (h->header_len) { - if (h->header_len > sizeof("Status:") - 1 && + if (h->header_len > sizeof("Status:") - 1 && strncasecmp(h->header, "Status:", sizeof("Status:") - 1) == 0 ) { if (!ignore_status) { @@ -495,7 +449,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) # define STDIN_FILENO 0 #endif -static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static size_t sapi_cgi_read_post(char *buffer, size_t count_bytes) { uint read_bytes = 0; int tmp_read_bytes; @@ -508,7 +462,7 @@ static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) fcgi_request *request = (fcgi_request*) SG(server_context); if (request_body_fd == -1) { char *request_body_filename = sapi_cgibin_getenv((char *) "REQUEST_BODY_FILE", - sizeof("REQUEST_BODY_FILE") - 1 TSRMLS_CC); + sizeof("REQUEST_BODY_FILE") - 1); if (request_body_filename && *request_body_filename) { request_body_fd = open(request_body_filename, O_RDONLY); @@ -535,7 +489,7 @@ static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) return read_bytes; } -static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC) +static char *sapi_cgibin_getenv(char *name, size_t name_len) { /* if fpm has started, use fcgi env */ if (fpm_is_running) { @@ -547,7 +501,7 @@ static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC) return getenv(name); } -static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) +static char *_sapi_cgibin_putenv(char *name, char *value) { int name_len; @@ -560,76 +514,64 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) return fcgi_putenv(request, name, name_len, value); } -static char *sapi_cgi_read_cookies(TSRMLS_D) +static char *sapi_cgi_read_cookies(void) { - return sapi_cgibin_getenv((char *) "HTTP_COOKIE", sizeof("HTTP_COOKIE") - 1 TSRMLS_CC); + return sapi_cgibin_getenv((char *) "HTTP_COOKIE", sizeof("HTTP_COOKIE") - 1); } -void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC) +void cgi_php_import_environment_variables(zval *array_ptr) { fcgi_request *request; - HashPosition pos; - char *var, **val; - uint var_len; - ulong idx; + zend_string *var; + char *val; int filter_arg; - - if (PG(http_globals)[TRACK_VARS_ENV] && - array_ptr != PG(http_globals)[TRACK_VARS_ENV] && - Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY && - zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0 + if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY && + Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV]) && + zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_ENV])) > 0 ) { zval_dtor(array_ptr); - *array_ptr = *PG(http_globals)[TRACK_VARS_ENV]; - INIT_PZVAL(array_ptr); - zval_copy_ctor(array_ptr); + ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_ENV]); return; - } else if (PG(http_globals)[TRACK_VARS_SERVER] && - array_ptr != PG(http_globals)[TRACK_VARS_SERVER] && - Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY && - zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0 + } else if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY && + Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_SERVER]) && + zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])) > 0 ) { zval_dtor(array_ptr); - *array_ptr = *PG(http_globals)[TRACK_VARS_SERVER]; - INIT_PZVAL(array_ptr); - zval_copy_ctor(array_ptr); + ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_SERVER]); return; } /* call php's original import as a catch-all */ - php_php_import_environment_variables(array_ptr TSRMLS_CC); + php_php_import_environment_variables(array_ptr); request = (fcgi_request*) SG(server_context); - filter_arg = (array_ptr == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER; + filter_arg = Z_ARR_P(array_ptr) == Z_ARR(PG(http_globals)[TRACK_VARS_ENV]) + ? PARSE_ENV : PARSE_SERVER; - for (zend_hash_internal_pointer_reset_ex(request->env, &pos); - zend_hash_get_current_key_ex(request->env, &var, &var_len, &idx, 0, &pos) == HASH_KEY_IS_STRING && - zend_hash_get_current_data_ex(request->env, (void **) &val, &pos) == SUCCESS; - zend_hash_move_forward_ex(request->env, &pos) - ) { - unsigned int new_val_len; + ZEND_HASH_FOREACH_STR_KEY_PTR(request->env, var, val) { + size_t new_val_len; - if (sapi_module.input_filter(filter_arg, var, val, strlen(*val), &new_val_len TSRMLS_CC)) { - php_register_variable_safe(var, *val, new_val_len, array_ptr TSRMLS_CC); + if (var && sapi_module.input_filter(filter_arg, var->val, &val, strlen(val), &new_val_len)) { + php_register_variable_safe(var->val, val, new_val_len, array_ptr); } - } + } ZEND_HASH_FOREACH_END(); } -static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_cgi_register_variables(zval *track_vars_array) { - unsigned int php_self_len; + size_t php_self_len; char *php_self; /* In CGI mode, we consider the environment to be a part of the server * variables */ - php_import_environment_variables(track_vars_array TSRMLS_CC); + php_import_environment_variables(track_vars_array); if (CGIG(fix_pathinfo)) { char *script_name = SG(request_info).request_uri; unsigned int script_name_len = script_name ? strlen(script_name) : 0; - char *path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO") - 1 TSRMLS_CC); + char *path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO") - 1); unsigned int path_info_len = path_info ? strlen(path_info) : 0; php_self_len = script_name_len + path_info_len; @@ -644,15 +586,15 @@ static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) } /* Build the special-case PHP_SELF variable for the CGI version */ - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len TSRMLS_CC)) { - php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len)) { + php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array); } efree(php_self); } else { php_self = SG(request_info).request_uri ? SG(request_info).request_uri : ""; php_self_len = strlen(php_self); - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len TSRMLS_CC)) { - php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len)) { + php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array); } } } @@ -663,7 +605,6 @@ static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) */ void sapi_cgi_log_fastcgi(int level, char *message, size_t len) { - TSRMLS_FETCH(); fcgi_request *request = (fcgi_request*) SG(server_context); @@ -696,20 +637,19 @@ static void sapi_cgi_log_message(char *message) /* {{{ php_cgi_ini_activate_user_config */ -static void php_cgi_ini_activate_user_config(char *path, int path_len, const char *doc_root, int doc_root_len, int start TSRMLS_DC) +static void php_cgi_ini_activate_user_config(char *path, int path_len, const char *doc_root, int doc_root_len, int start) { char *ptr; - user_config_cache_entry *new_entry, *entry; - time_t request_time = sapi_get_request_time(TSRMLS_C); + time_t request_time = sapi_get_request_time(); + user_config_cache_entry *entry = zend_hash_str_find_ptr(&CGIG(user_config_cache), path, path_len); /* Find cached config entry: If not found, create one */ - if (zend_hash_find(&CGIG(user_config_cache), path, path_len + 1, (void **) &entry) == FAILURE) { - new_entry = pemalloc(sizeof(user_config_cache_entry), 1); - new_entry->expires = 0; - new_entry->user_config = (HashTable *) pemalloc(sizeof(HashTable), 1); - zend_hash_init(new_entry->user_config, 0, NULL, (dtor_func_t) config_zval_dtor, 1); - zend_hash_update(&CGIG(user_config_cache), path, path_len + 1, new_entry, sizeof(user_config_cache_entry), (void **) &entry); - free(new_entry); + if (!entry) { + entry = pemalloc(sizeof(user_config_cache_entry), 1); + entry->expires = 0; + entry->user_config = (HashTable *) pemalloc(sizeof(HashTable), 1); + zend_hash_init(entry->user_config, 0, NULL, config_zval_dtor, 1); + zend_hash_str_update_ptr(&CGIG(user_config_cache), path, path_len, entry); } /* Check whether cache entry has expired and rescan if it is */ @@ -723,7 +663,7 @@ static void php_cgi_ini_activate_user_config(char *path, int path_len, const cha zend_hash_clean(entry->user_config); if (!IS_ABSOLUTE_PATH(path, path_len)) { - real_path = tsrm_realpath(path, NULL TSRMLS_CC); + real_path = tsrm_realpath(path, NULL); if (real_path == NULL) { return; } @@ -743,34 +683,34 @@ static void php_cgi_ini_activate_user_config(char *path, int path_len, const cha } /* we have to test if path is part of DOCUMENT_ROOT. - if it is inside the docroot, we scan the tree up to the docroot + if it is inside the docroot, we scan the tree up to the docroot to find more user.ini, if not we only scan the current path. */ #ifdef PHP_WIN32 if (strnicmp(s1, s2, s_len) == 0) { -#else +#else if (strncmp(s1, s2, s_len) == 0) { #endif ptr = s2 + start; /* start is the point where doc_root ends! */ while ((ptr = strchr(ptr, DEFAULT_SLASH)) != NULL) { *ptr = 0; - php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config TSRMLS_CC); + php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config); *ptr = '/'; ptr++; } } else { - php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config TSRMLS_CC); + php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config); } entry->expires = request_time + PG(user_ini_cache_ttl); } /* Activate ini entries with values from the user config hash */ - php_ini_activate_config(entry->user_config, PHP_INI_PERDIR, PHP_INI_STAGE_HTACCESS TSRMLS_CC); + php_ini_activate_config(entry->user_config, PHP_INI_PERDIR, PHP_INI_STAGE_HTACCESS); } /* }}} */ -static int sapi_cgi_activate(TSRMLS_D) +static int sapi_cgi_activate(void) { char *path, *doc_root, *server_name; uint path_len, doc_root_len, server_name_len; @@ -782,13 +722,13 @@ static int sapi_cgi_activate(TSRMLS_D) if (php_ini_has_per_host_config()) { /* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */ - server_name = sapi_cgibin_getenv("SERVER_NAME", sizeof("SERVER_NAME") - 1 TSRMLS_CC); + server_name = sapi_cgibin_getenv("SERVER_NAME", sizeof("SERVER_NAME") - 1); /* SERVER_NAME should also be defined at this stage..but better check it anyway */ if (server_name) { server_name_len = strlen(server_name); server_name = estrndup(server_name, server_name_len); zend_str_tolower(server_name, server_name_len); - php_ini_activate_per_host_config(server_name, server_name_len + 1 TSRMLS_CC); + php_ini_activate_per_host_config(server_name, server_name_len); efree(server_name); } } @@ -812,11 +752,11 @@ static int sapi_cgi_activate(TSRMLS_D) path[path_len] = 0; /* Activate per-dir-system-configuration defined in php.ini and stored into configuration_hash during startup */ - php_ini_activate_per_dir_config(path, path_len TSRMLS_CC); /* Note: for global settings sake we check from root to path */ + php_ini_activate_per_dir_config(path, path_len); /* Note: for global settings sake we check from root to path */ /* Load and activate user ini files in path starting from DOCUMENT_ROOT */ if (PG(user_ini_filename) && *PG(user_ini_filename)) { - doc_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT") - 1 TSRMLS_CC); + doc_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT") - 1); /* DOCUMENT_ROOT should also be defined at this stage..but better check it anyway */ if (doc_root) { doc_root_len = strlen(doc_root); @@ -828,7 +768,7 @@ static int sapi_cgi_activate(TSRMLS_D) doc_root = estrndup(doc_root, doc_root_len); zend_str_tolower(doc_root, doc_root_len); #endif - php_cgi_ini_activate_user_config(path, path_len, doc_root, doc_root_len, doc_root_len - 1 TSRMLS_CC); + php_cgi_ini_activate_user_config(path, path_len, doc_root, doc_root_len, doc_root_len - 1); } } @@ -841,7 +781,7 @@ static int sapi_cgi_activate(TSRMLS_D) return SUCCESS; } -static int sapi_cgi_deactivate(TSRMLS_D) +static int sapi_cgi_deactivate(void) { /* flush only when SAPI was started. The reasons are: 1. SAPI Deactivate is called from two places: module init and request shutdown @@ -902,17 +842,6 @@ static sapi_module_struct cgi_sapi_module = { }; /* }}} */ -/* {{{ 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} -}; - /* {{{ php_cgi_usage */ static void php_cgi_usage(char *argv0) @@ -1054,10 +983,10 @@ static int is_valid_path(const char *path) Comments in the code below refer to using the above URL in a request */ -static void init_request_info(TSRMLS_D) +static void init_request_info(void) { - char *env_script_filename = sapi_cgibin_getenv("SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME") - 1 TSRMLS_CC); - char *env_path_translated = sapi_cgibin_getenv("PATH_TRANSLATED", sizeof("PATH_TRANSLATED") - 1 TSRMLS_CC); + char *env_script_filename = sapi_cgibin_getenv("SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME") - 1); + char *env_path_translated = sapi_cgibin_getenv("PATH_TRANSLATED", sizeof("PATH_TRANSLATED") - 1); char *script_path_translated = env_script_filename; char *ini; int apache_was_here = 0; @@ -1085,25 +1014,25 @@ static void init_request_info(TSRMLS_D) * of the script will be retreived later via argc/argv */ if (script_path_translated) { const char *auth; - char *content_length = sapi_cgibin_getenv("CONTENT_LENGTH", sizeof("CONTENT_LENGTH") - 1 TSRMLS_CC); - char *content_type = sapi_cgibin_getenv("CONTENT_TYPE", sizeof("CONTENT_TYPE") - 1 TSRMLS_CC); - char *env_path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO") - 1 TSRMLS_CC); - char *env_script_name = sapi_cgibin_getenv("SCRIPT_NAME", sizeof("SCRIPT_NAME") - 1 TSRMLS_CC); + char *content_length = sapi_cgibin_getenv("CONTENT_LENGTH", sizeof("CONTENT_LENGTH") - 1); + char *content_type = sapi_cgibin_getenv("CONTENT_TYPE", sizeof("CONTENT_TYPE") - 1); + char *env_path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO") - 1); + char *env_script_name = sapi_cgibin_getenv("SCRIPT_NAME", sizeof("SCRIPT_NAME") - 1); /* Hack for buggy IIS that sets incorrect PATH_INFO */ - char *env_server_software = sapi_cgibin_getenv("SERVER_SOFTWARE", sizeof("SERVER_SOFTWARE") - 1 TSRMLS_CC); + char *env_server_software = sapi_cgibin_getenv("SERVER_SOFTWARE", sizeof("SERVER_SOFTWARE") - 1); if (env_server_software && env_script_name && env_path_info && strncmp(env_server_software, "Microsoft-IIS", sizeof("Microsoft-IIS") - 1) == 0 && strncmp(env_path_info, env_script_name, strlen(env_script_name)) == 0 ) { - env_path_info = _sapi_cgibin_putenv("ORIG_PATH_INFO", env_path_info TSRMLS_CC); + env_path_info = _sapi_cgibin_putenv("ORIG_PATH_INFO", env_path_info); env_path_info += strlen(env_script_name); if (*env_path_info == 0) { env_path_info = NULL; } - env_path_info = _sapi_cgibin_putenv("PATH_INFO", env_path_info TSRMLS_CC); + env_path_info = _sapi_cgibin_putenv("PATH_INFO", env_path_info); } #define APACHE_PROXY_FCGI_PREFIX "proxy:fcgi://" @@ -1138,8 +1067,8 @@ static void init_request_info(TSRMLS_D) if (CGIG(fix_pathinfo)) { struct stat st; char *real_path = NULL; - char *env_redirect_url = sapi_cgibin_getenv("REDIRECT_URL", sizeof("REDIRECT_URL") - 1 TSRMLS_CC); - char *env_document_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT") - 1 TSRMLS_CC); + char *env_redirect_url = sapi_cgibin_getenv("REDIRECT_URL", sizeof("REDIRECT_URL") - 1); + char *env_document_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT") - 1); char *orig_path_translated = env_path_translated; char *orig_path_info = env_path_info; char *orig_script_name = env_script_name; @@ -1147,7 +1076,7 @@ static void init_request_info(TSRMLS_D) int script_path_translated_len; if (!env_document_root && PG(doc_root)) { - env_document_root = _sapi_cgibin_putenv("DOCUMENT_ROOT", PG(doc_root) TSRMLS_CC); + env_document_root = _sapi_cgibin_putenv("DOCUMENT_ROOT", PG(doc_root)); /* fix docroot */ TRANSLATE_SLASHES(env_document_root); } @@ -1185,7 +1114,7 @@ static void init_request_info(TSRMLS_D) #ifdef PHP_WIN32 script_path_translated[script_path_translated_len-1] == '\\' || #endif - (real_path = tsrm_realpath(script_path_translated, NULL TSRMLS_CC)) == NULL) + (real_path = tsrm_realpath(script_path_translated, NULL)) == NULL) ) { char *pt = estrndup(script_path_translated, script_path_translated_len); int len = script_path_translated_len; @@ -1228,15 +1157,15 @@ static void init_request_info(TSRMLS_D) if (orig_path_info) { char old; - _sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info); old = path_info[0]; path_info[0] = 0; if (!orig_script_name || strcmp(orig_script_name, env_path_info) != 0) { if (orig_script_name) { - _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name); } - SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_path_info TSRMLS_CC); + SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_path_info); } else { SG(request_info).request_uri = orig_script_name; } @@ -1248,19 +1177,19 @@ static void init_request_info(TSRMLS_D) */ int snlen = strlen(env_script_name); if (snlen>slen && !strcmp(env_script_name+snlen-slen, path_info)) { - _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name); env_script_name[snlen-slen] = 0; - SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name TSRMLS_CC); + SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name); } } - env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC); + env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info); } if (!orig_script_filename || strcmp(orig_script_filename, pt) != 0) { if (orig_script_filename) { - _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename); } - script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", pt TSRMLS_CC); + script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", pt); } TRANSLATE_SLASHES(pt); @@ -1290,9 +1219,9 @@ static void init_request_info(TSRMLS_D) } path_translated[path_translated_len] = '\0'; if (orig_path_translated) { - _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated); } - env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC); + env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated); efree(path_translated); } else if ( env_script_name && strstr(pt, env_script_name) @@ -1309,9 +1238,9 @@ static void init_request_info(TSRMLS_D) } path_translated[path_translated_len] = '\0'; if (orig_path_translated) { - _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated); } - env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC); + env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated); efree(path_translated); } break; @@ -1327,18 +1256,18 @@ static void init_request_info(TSRMLS_D) * have failed anyway... we output 'no input file' now. */ if (orig_script_filename) { - _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename); } - script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", NULL TSRMLS_CC); + script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", NULL); SG(sapi_headers).http_response_code = 404; } if (!SG(request_info).request_uri) { if (!orig_script_name || strcmp(orig_script_name, env_script_name) != 0) { if (orig_script_name) { - _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name); } - SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name TSRMLS_CC); + SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name); } else { SG(request_info).request_uri = orig_script_name; } @@ -1352,27 +1281,27 @@ static void init_request_info(TSRMLS_D) (script_path_translated != orig_script_filename && strcmp(script_path_translated, orig_script_filename) != 0)) { if (orig_script_filename) { - _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename); } - script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", script_path_translated TSRMLS_CC); + script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", script_path_translated); } if (!apache_was_here && env_redirect_url) { /* if we used PATH_TRANSLATED to work around Apache mod_fastcgi (but not mod_proxy_fcgi, * hence !apache_was_here) weirdness, strip info accordingly */ if (orig_path_info) { - _sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info TSRMLS_CC); - _sapi_cgibin_putenv("PATH_INFO", NULL TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info); + _sapi_cgibin_putenv("PATH_INFO", NULL); } if (orig_path_translated) { - _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC); - _sapi_cgibin_putenv("PATH_TRANSLATED", NULL TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated); + _sapi_cgibin_putenv("PATH_TRANSLATED", NULL); } } if (env_script_name != orig_script_name) { if (orig_script_name) { - _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name); } - SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name TSRMLS_CC); + SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name); } else { SG(request_info).request_uri = env_script_name; } @@ -1394,39 +1323,39 @@ static void init_request_info(TSRMLS_D) SG(request_info).path_translated = estrdup(script_path_translated); } - SG(request_info).request_method = sapi_cgibin_getenv("REQUEST_METHOD", sizeof("REQUEST_METHOD") - 1 TSRMLS_CC); + SG(request_info).request_method = sapi_cgibin_getenv("REQUEST_METHOD", sizeof("REQUEST_METHOD") - 1); /* FIXME - Work out proto_num here */ - SG(request_info).query_string = sapi_cgibin_getenv("QUERY_STRING", sizeof("QUERY_STRING") - 1 TSRMLS_CC); + SG(request_info).query_string = sapi_cgibin_getenv("QUERY_STRING", sizeof("QUERY_STRING") - 1); SG(request_info).content_type = (content_type ? content_type : "" ); SG(request_info).content_length = (content_length ? atol(content_length) : 0); /* The CGI RFC allows servers to pass on unvalidated Authorization data */ - auth = sapi_cgibin_getenv("HTTP_AUTHORIZATION", sizeof("HTTP_AUTHORIZATION") - 1 TSRMLS_CC); - php_handle_auth_data(auth TSRMLS_CC); + auth = sapi_cgibin_getenv("HTTP_AUTHORIZATION", sizeof("HTTP_AUTHORIZATION") - 1); + php_handle_auth_data(auth); } /* INI stuff */ - ini = sapi_cgibin_getenv("PHP_VALUE", sizeof("PHP_VALUE") - 1 TSRMLS_CC); + ini = sapi_cgibin_getenv("PHP_VALUE", sizeof("PHP_VALUE") - 1); if (ini) { int mode = ZEND_INI_USER; char *tmp; spprintf(&tmp, 0, "%s\n", ini); - zend_parse_ini_string(tmp, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t)fastcgi_ini_parser, &mode TSRMLS_CC); + zend_parse_ini_string(tmp, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t)fastcgi_ini_parser, &mode); efree(tmp); } - ini = sapi_cgibin_getenv("PHP_ADMIN_VALUE", sizeof("PHP_ADMIN_VALUE") - 1 TSRMLS_CC); + ini = sapi_cgibin_getenv("PHP_ADMIN_VALUE", sizeof("PHP_ADMIN_VALUE") - 1); if (ini) { int mode = ZEND_INI_SYSTEM; char *tmp; spprintf(&tmp, 0, "%s\n", ini); - zend_parse_ini_string(tmp, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t)fastcgi_ini_parser, &mode TSRMLS_CC); + zend_parse_ini_string(tmp, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t)fastcgi_ini_parser, &mode); efree(tmp); } } /* }}} */ -static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg TSRMLS_DC) /* {{{ */ +static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg) /* {{{ */ { int *mode = (int *)arg; char *key; @@ -1479,7 +1408,7 @@ PHP_INI_END() /* {{{ php_cgi_globals_ctor */ -static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals TSRMLS_DC) +static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals) { php_cgi_globals->rfc2616_headers = 0; php_cgi_globals->nph = 0; @@ -1488,7 +1417,7 @@ static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals TSRMLS_ php_cgi_globals->fix_pathinfo = 1; php_cgi_globals->discard_path = 0; php_cgi_globals->fcgi_logging = 1; - zend_hash_init(&php_cgi_globals->user_config_cache, 0, NULL, (dtor_func_t) user_config_cache_entry_dtor, 1); + zend_hash_init(&php_cgi_globals->user_config_cache, 0, NULL, user_config_cache_entry_dtor, 1); php_cgi_globals->error_header = NULL; php_cgi_globals->fpm_config = NULL; } @@ -1501,7 +1430,7 @@ static PHP_MINIT_FUNCTION(cgi) #ifdef ZTS ts_allocate_id(&php_cgi_globals_id, sizeof(php_cgi_globals_struct), (ts_allocate_ctor) php_cgi_globals_ctor, NULL); #else - php_cgi_globals_ctor(&php_cgi_globals TSRMLS_CC); + php_cgi_globals_ctor(&php_cgi_globals); #endif REGISTER_INI_ENTRIES(); return SUCCESS; @@ -1537,8 +1466,8 @@ PHP_FUNCTION(fastcgi_finish_request) /* {{{ */ if (request->fd >= 0) { - php_output_end_all(TSRMLS_C); - php_header(TSRMLS_C); + php_output_end_all(); + php_header(); fcgi_flush(request, 1); fcgi_close(request, 0, 0); @@ -1618,7 +1547,7 @@ int main(int argc, char *argv[]) sapi_startup(&cgi_sapi_module); cgi_sapi_module.php_ini_path_override = NULL; cgi_sapi_module.php_ini_ignore_cwd = 1; - + fcgi_init(); #ifdef PHP_WIN32 @@ -1689,21 +1618,21 @@ int main(int argc, char *argv[]) use_extended_info = 1; break; - case 't': + case 't': test_conf++; break; case 'm': /* list compiled in modules */ cgi_sapi_module.startup(&cgi_sapi_module); - php_output_activate(TSRMLS_C); + php_output_activate(); SG(headers_sent) = 1; php_printf("[PHP Modules]\n"); - print_modules(TSRMLS_C); + print_modules(); php_printf("\n[Zend Modules]\n"); - print_extensions(TSRMLS_C); + print_extensions(); php_printf("\n"); - php_output_end_all(TSRMLS_C); - php_output_deactivate(TSRMLS_C); + php_output_end_all(); + php_output_deactivate(); fcgi_shutdown(); exit_status = FPM_EXIT_OK; goto out; @@ -1732,20 +1661,20 @@ int main(int argc, char *argv[]) case 'h': case '?': cgi_sapi_module.startup(&cgi_sapi_module); - php_output_activate(TSRMLS_C); + php_output_activate(); SG(headers_sent) = 1; php_cgi_usage(argv[0]); - php_output_end_all(TSRMLS_C); - php_output_deactivate(TSRMLS_C); + php_output_end_all(); + php_output_deactivate(); fcgi_shutdown(); exit_status = (c == 'h') ? FPM_EXIT_OK : FPM_EXIT_USAGE; goto out; case 'v': /* show php version & quit */ cgi_sapi_module.startup(&cgi_sapi_module); - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { SG(server_context) = NULL; - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); return FPM_EXIT_SOFTWARE; } SG(headers_sent) = 1; @@ -1766,14 +1695,14 @@ int main(int argc, char *argv[]) if (php_information) { cgi_sapi_module.phpinfo_as_text = 1; cgi_sapi_module.startup(&cgi_sapi_module); - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { SG(server_context) = NULL; - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); return FPM_EXIT_SOFTWARE; } SG(headers_sent) = 1; SG(request_info).no_headers = 1; - php_print_info(0xFFFFFFFF TSRMLS_CC); + php_print_info(0xFFFFFFFF); php_request_shutdown((void *) 0); fcgi_shutdown(); exit_status = FPM_EXIT_OK; @@ -1783,11 +1712,11 @@ int main(int argc, char *argv[]) /* No other args are permitted here as there is no interactive mode */ if (argc != php_optind) { cgi_sapi_module.startup(&cgi_sapi_module); - php_output_activate(TSRMLS_C); + php_output_activate(); SG(headers_sent) = 1; php_cgi_usage(argv[0]); - php_output_end_all(TSRMLS_C); - php_output_deactivate(TSRMLS_C); + php_output_end_all(); + php_output_deactivate(); fcgi_shutdown(); exit_status = FPM_EXIT_USAGE; goto out; @@ -1800,7 +1729,7 @@ int main(int argc, char *argv[]) SG(request_info).path_translated = NULL; #endif - cgi_sapi_module.additional_functions = additional_functions; + cgi_sapi_module.additional_functions = NULL; cgi_sapi_module.executable_location = argv[0]; /* startup after we get the above ini override se we get things right */ @@ -1810,7 +1739,7 @@ int main(int argc, char *argv[]) #endif return FPM_EXIT_SOFTWARE; } - + if (use_extended_info) { CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; } @@ -1891,18 +1820,17 @@ consult the installation file that came with this distribution, or visit \n\ while (fcgi_accept_request(&request) >= 0) { request_body_fd = -1; SG(server_context) = (void *) &request; - init_request_info(TSRMLS_C); - CG(interactive) = 0; + init_request_info(); char *primary_script = NULL; fpm_request_info(); /* request startup only after we've done all we can to * get path_translated */ - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { fcgi_finish_request(&request, 1); SG(server_context) = NULL; - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); return FPM_EXIT_SOFTWARE; } @@ -1912,7 +1840,7 @@ consult the installation file that came with this distribution, or visit \n\ goto fastcgi_request_done; } - if (fpm_status_handle_request(TSRMLS_C)) { + if (fpm_status_handle_request()) { goto fastcgi_request_done; } @@ -1933,14 +1861,14 @@ consult the installation file that came with this distribution, or visit \n\ goto fastcgi_request_done; } - /* + /* * have to duplicate SG(request_info).path_translated to be able to log errrors * php_fopen_primary_script seems to delete SG(request_info).path_translated on failure */ primary_script = estrdup(SG(request_info).path_translated); /* path_translated exists, we can continue ! */ - if (php_fopen_primary_script(&file_handle TSRMLS_CC) == FAILURE) { + if (php_fopen_primary_script(&file_handle) == FAILURE) { zend_try { zlog(ZLOG_ERROR, "Unable to open primary script: %s (%s)", primary_script, strerror(errno)); if (errno == EACCES) { @@ -1961,7 +1889,7 @@ consult the installation file that came with this distribution, or visit \n\ fpm_request_executing(); - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); fastcgi_request_done: if (primary_script) { @@ -1979,14 +1907,14 @@ fastcgi_request_done: ctr.line = CGIG(error_header); ctr.line_len = strlen(CGIG(error_header)); - sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC); + sapi_header_op(SAPI_HEADER_REPLACE, &ctr); } } - fpm_request_end(TSRMLS_C); - fpm_log_write(NULL TSRMLS_CC); + fpm_request_end(); + fpm_log_write(NULL); - STR_FREE(SG(request_info).path_translated); + efree(SG(request_info).path_translated); SG(request_info).path_translated = NULL; php_request_shutdown((void *) 0); @@ -2013,7 +1941,7 @@ fastcgi_request_done: out: SG(server_context) = NULL; - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); if (parent) { sapi_shutdown(); diff --git a/sapi/fpm/fpm/fpm_php.c b/sapi/fpm/fpm/fpm_php.c index cd4d3aef3a..6dc99d04c9 100644 --- a/sapi/fpm/fpm/fpm_php.c +++ b/sapi/fpm/fpm/fpm_php.c @@ -23,32 +23,31 @@ static char **limit_extensions = NULL; -static int fpm_php_zend_ini_alter_master(char *name, int name_length, char *new_value, int new_value_length, int mode, int stage TSRMLS_DC) /* {{{ */ +static int fpm_php_zend_ini_alter_master(char *name, int name_length, char *new_value, int new_value_length, int mode, int stage) /* {{{ */ { zend_ini_entry *ini_entry; - char *duplicate; + zend_string *duplicate; - if (zend_hash_find(EG(ini_directives), name, name_length, (void **) &ini_entry) == FAILURE) { + if ((ini_entry = zend_hash_str_find_ptr(EG(ini_directives), name, name_length)) == NULL) { return FAILURE; } - duplicate = strdup(new_value); + duplicate = zend_string_init(new_value, new_value_length, 1); if (!ini_entry->on_modify - || ini_entry->on_modify(ini_entry, duplicate, new_value_length, - ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage TSRMLS_CC) == SUCCESS) { + || ini_entry->on_modify(ini_entry, duplicate, + ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage) == SUCCESS) { ini_entry->value = duplicate; - ini_entry->value_length = new_value_length; ini_entry->modifiable = mode; } else { - free(duplicate); + zend_string_release(duplicate); } return SUCCESS; } /* }}} */ -static void fpm_php_disable(char *value, int (*zend_disable)(char *, uint TSRMLS_DC) TSRMLS_DC) /* {{{ */ +static void fpm_php_disable(char *value, int (*zend_disable)(char *, size_t)) /* {{{ */ { char *s = 0, *e = value; @@ -58,7 +57,7 @@ static void fpm_php_disable(char *value, int (*zend_disable)(char *, uint TSRMLS case ',': if (s) { *e = '\0'; - zend_disable(s, e - s TSRMLS_CC); + zend_disable(s, e - s); s = 0; } break; @@ -72,14 +71,13 @@ static void fpm_php_disable(char *value, int (*zend_disable)(char *, uint TSRMLS } if (s) { - zend_disable(s, e - s TSRMLS_CC); + zend_disable(s, e - s); } } /* }}} */ int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */ { - TSRMLS_FETCH(); char *name = kv->key; char *value = kv->value; @@ -88,25 +86,25 @@ int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */ if (!strcmp(name, "extension") && *value) { zval zv; - php_dl(value, MODULE_PERSISTENT, &zv, 1 TSRMLS_CC); - return Z_BVAL(zv) ? 1 : -1; + php_dl(value, MODULE_PERSISTENT, &zv, 1); + return Z_TYPE(zv) == IS_TRUE; } - if (fpm_php_zend_ini_alter_master(name, name_len+1, value, value_len, mode, PHP_INI_STAGE_ACTIVATE TSRMLS_CC) == FAILURE) { + if (fpm_php_zend_ini_alter_master(name, name_len, value, value_len, mode, PHP_INI_STAGE_ACTIVATE) == FAILURE) { return -1; } if (!strcmp(name, "disable_functions") && *value) { char *v = strdup(value); PG(disable_functions) = v; - fpm_php_disable(v, zend_disable_function TSRMLS_CC); + fpm_php_disable(v, zend_disable_function); return 1; } if (!strcmp(name, "disable_classes") && *value) { char *v = strdup(value); PG(disable_classes) = v; - fpm_php_disable(v, zend_disable_class TSRMLS_CC); + fpm_php_disable(v, zend_disable_class); return 1; } @@ -132,6 +130,7 @@ static int fpm_php_apply_defines(struct fpm_worker_pool_s *wp) /* {{{ */ return 0; } +/* }}} */ static int fpm_php_set_allowed_clients(struct fpm_worker_pool_s *wp) /* {{{ */ { @@ -157,37 +156,37 @@ static int fpm_php_set_fcgi_mgmt_vars(struct fpm_worker_pool_s *wp) /* {{{ */ /* }}} */ #endif -char *fpm_php_script_filename(TSRMLS_D) /* {{{ */ +char *fpm_php_script_filename(void) /* {{{ */ { return SG(request_info).path_translated; } /* }}} */ -char *fpm_php_request_uri(TSRMLS_D) /* {{{ */ +char *fpm_php_request_uri(void) /* {{{ */ { return (char *) SG(request_info).request_uri; } /* }}} */ -char *fpm_php_request_method(TSRMLS_D) /* {{{ */ +char *fpm_php_request_method(void) /* {{{ */ { return (char *) SG(request_info).request_method; } /* }}} */ -char *fpm_php_query_string(TSRMLS_D) /* {{{ */ +char *fpm_php_query_string(void) /* {{{ */ { return SG(request_info).query_string; } /* }}} */ -char *fpm_php_auth_user(TSRMLS_D) /* {{{ */ +char *fpm_php_auth_user(void) /* {{{ */ { return SG(request_info).auth_user; } /* }}} */ -size_t fpm_php_content_length(TSRMLS_D) /* {{{ */ +size_t fpm_php_content_length(void) /* {{{ */ { return SG(request_info).content_length; } @@ -195,8 +194,7 @@ size_t fpm_php_content_length(TSRMLS_D) /* {{{ */ static void fpm_php_cleanup(int which, void *arg) /* {{{ */ { - TSRMLS_FETCH(); - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); sapi_shutdown(); } /* }}} */ @@ -258,39 +256,30 @@ int fpm_php_limit_extensions(char *path) /* {{{ */ } /* }}} */ -char* fpm_php_get_string_from_table(char *table, char *key TSRMLS_DC) /* {{{ */ +char* fpm_php_get_string_from_table(zend_string *table, char *key) /* {{{ */ { - zval **data, **tmp; - char *string_key; - uint string_len; - ulong num_key; + zval *data, *tmp; + zend_string *str; if (!table || !key) { return NULL; } /* inspired from ext/standard/info.c */ - zend_is_auto_global(table, strlen(table) TSRMLS_CC); + zend_is_auto_global(table); /* find the table and ensure it's an array */ - if (zend_hash_find(&EG(symbol_table), table, strlen(table) + 1, (void **) &data) == SUCCESS && Z_TYPE_PP(data) == IS_ARRAY) { - - /* reset the internal pointer */ - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data)); - - /* parse the array to look for our key */ - while (zend_hash_get_current_data(Z_ARRVAL_PP(data), (void **) &tmp) == SUCCESS) { - /* ensure the key is a string */ - if (zend_hash_get_current_key_ex(Z_ARRVAL_PP(data), &string_key, &string_len, &num_key, 0, NULL) == HASH_KEY_IS_STRING) { - /* compare to our key */ - if (!strncmp(string_key, key, string_len)) { - return Z_STRVAL_PP(tmp); - } - } - zend_hash_move_forward(Z_ARRVAL_PP(data)); - } + data = zend_hash_find(&EG(symbol_table).ht, table); + if (!data || Z_TYPE_P(data) != IS_ARRAY) { + return NULL; } + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(data), str, tmp) { + if (str && !strncmp(str->val, key, str->len)) { + return Z_STRVAL_P(tmp); + } + } ZEND_HASH_FOREACH_END(); + return NULL; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_php.h b/sapi/fpm/fpm/fpm_php.h index d6054737d6..a2f2138d23 100644 --- a/sapi/fpm/fpm/fpm_php.h +++ b/sapi/fpm/fpm/fpm_php.h @@ -34,17 +34,17 @@ struct fpm_worker_pool_s; int fpm_php_init_child(struct fpm_worker_pool_s *wp); -char *fpm_php_script_filename(TSRMLS_D); -char *fpm_php_request_uri(TSRMLS_D); -char *fpm_php_request_method(TSRMLS_D); -char *fpm_php_query_string(TSRMLS_D); -char *fpm_php_auth_user(TSRMLS_D); -size_t fpm_php_content_length(TSRMLS_D); +char *fpm_php_script_filename(void); +char *fpm_php_request_uri(void); +char *fpm_php_request_method(void); +char *fpm_php_query_string(void); +char *fpm_php_auth_user(void); +size_t fpm_php_content_length(void); void fpm_php_soft_quit(); int fpm_php_init_main(); int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode); int fpm_php_limit_extensions(char *path); -char* fpm_php_get_string_from_table(char *table, char *key TSRMLS_DC); +char* fpm_php_get_string_from_table(zend_string *table, char *key); #endif diff --git a/sapi/fpm/fpm/fpm_php_trace.c b/sapi/fpm/fpm/fpm_php_trace.c index 925f2de64e..91394a0b47 100644 --- a/sapi/fpm/fpm/fpm_php_trace.c +++ b/sapi/fpm/fpm/fpm_php_trace.c @@ -40,8 +40,10 @@ #endif -static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog TSRMLS_DC) /* {{{ */ +static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ */ { +// TODO: fpm_php_trace_dump() has to be reimplemented ??? +#if 0 int callers_limit = 20; pid_t pid = child->pid; struct timeval tv; @@ -131,13 +133,13 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog TSRMLS_DC break; } } +#endif return 0; } /* }}} */ void fpm_php_trace(struct fpm_child_s *child) /* {{{ */ { - TSRMLS_FETCH(); fpm_scoreboard_update(0, 0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_INC, child->wp->scoreboard); FILE *slowlog; @@ -154,7 +156,7 @@ void fpm_php_trace(struct fpm_child_s *child) /* {{{ */ goto done1; } - if (0 > fpm_php_trace_dump(child, slowlog TSRMLS_CC)) { + if (0 > fpm_php_trace_dump(child, slowlog)) { fprintf(slowlog, "+++ dump failed\n"); } diff --git a/sapi/fpm/fpm/fpm_process_ctl.c b/sapi/fpm/fpm/fpm_process_ctl.c index 76ea4d358e..ca5a6f2e40 100644 --- a/sapi/fpm/fpm/fpm_process_ctl.c +++ b/sapi/fpm/fpm/fpm_process_ctl.c @@ -425,7 +425,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{ return; } - zlog(ZLOG_DEBUG, "[pool %s] %d child(ren) have been created dynamically", wp->config->name, children_to_fork); + zlog(ZLOG_DEBUG, "[pool %s] %d child(ren) have been created dynamically", wp->config->name, children_to_fork); /* Double the spawn rate for the next iteration */ if (wp->idle_spawn_rate < FPM_MAX_SPAWN_RATE) { diff --git a/sapi/fpm/fpm/fpm_request.c b/sapi/fpm/fpm/fpm_request.c index bf431a08d0..1e8016005a 100644 --- a/sapi/fpm/fpm/fpm_request.c +++ b/sapi/fpm/fpm/fpm_request.c @@ -92,7 +92,6 @@ void fpm_request_reading_headers() /* {{{ */ proc->request_method[0] = '\0'; proc->script_filename[0] = '\0'; proc->query_string[0] = '\0'; - proc->query_string[0] = '\0'; proc->auth_user[0] = '\0'; proc->content_length = 0; fpm_scoreboard_proc_release(proc); @@ -104,14 +103,13 @@ void fpm_request_reading_headers() /* {{{ */ void fpm_request_info() /* {{{ */ { - TSRMLS_FETCH(); struct fpm_scoreboard_proc_s *proc; - char *request_uri = fpm_php_request_uri(TSRMLS_C); - char *request_method = fpm_php_request_method(TSRMLS_C); - char *script_filename = fpm_php_script_filename(TSRMLS_C); - char *query_string = fpm_php_query_string(TSRMLS_C); - char *auth_user = fpm_php_auth_user(TSRMLS_C); - size_t content_length = fpm_php_content_length(TSRMLS_C); + char *request_uri = fpm_php_request_uri(); + char *request_method = fpm_php_request_method(); + char *script_filename = fpm_php_script_filename(); + char *query_string = fpm_php_query_string(); + char *auth_user = fpm_php_auth_user(); + size_t content_length = fpm_php_content_length(); struct timeval now; fpm_clock_get(&now); @@ -172,14 +170,14 @@ void fpm_request_executing() /* {{{ */ } /* }}} */ -void fpm_request_end(TSRMLS_D) /* {{{ */ +void fpm_request_end(void) /* {{{ */ { struct fpm_scoreboard_proc_s *proc; struct timeval now; #ifdef HAVE_TIMES struct tms cpu; #endif - size_t memory = zend_memory_peak_usage(1 TSRMLS_CC); + size_t memory = zend_memory_peak_usage(1); fpm_clock_get(&now); #ifdef HAVE_TIMES @@ -258,7 +256,7 @@ void fpm_request_check_timed_out(struct fpm_child_s *child, struct timeval *now, #if HAVE_FPM_TRACE if (child->slow_logged.tv_sec == 0 && slowlog_timeout && proc.request_stage == FPM_REQUEST_EXECUTING && tv.tv_sec >= slowlog_timeout) { - + str_purify_filename(purified_script_filename, proc.script_filename, sizeof(proc.script_filename)); child->slow_logged = proc.accepted; diff --git a/sapi/fpm/fpm/fpm_request.h b/sapi/fpm/fpm/fpm_request.h index aebd36cff4..d9e831d100 100644 --- a/sapi/fpm/fpm/fpm_request.h +++ b/sapi/fpm/fpm/fpm_request.h @@ -9,7 +9,7 @@ void fpm_request_accepting(); /* hanging in accept() */ void fpm_request_reading_headers(); /* start reading fastcgi request from very first byte */ void fpm_request_info(); /* not a stage really but a point in the php code, where all request params have become known to sapi */ void fpm_request_executing(); /* the script is executing */ -void fpm_request_end(TSRMLS_D); /* request ended: script response have been sent to web server */ +void fpm_request_end(void); /* request ended: script response have been sent to web server */ void fpm_request_finished(); /* request processed: cleaning current request */ struct fpm_child_s; diff --git a/sapi/fpm/fpm/fpm_scoreboard.c b/sapi/fpm/fpm/fpm_scoreboard.c index 8d0868182d..eabab8f8e6 100644 --- a/sapi/fpm/fpm/fpm_scoreboard.c +++ b/sapi/fpm/fpm/fpm_scoreboard.c @@ -69,7 +69,7 @@ int fpm_scoreboard_init_main() /* {{{ */ wp->scoreboard->start_epoch = time(NULL); strlcpy(wp->scoreboard->pool, wp->config->name, sizeof(wp->scoreboard->pool)); } - return 0; + return 0; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_sockets.c b/sapi/fpm/fpm/fpm_sockets.c index 46ce161844..b5639fece7 100644 --- a/sapi/fpm/fpm/fpm_sockets.c +++ b/sapi/fpm/fpm/fpm_sockets.c @@ -265,6 +265,8 @@ static int fpm_socket_af_inet_listening_socket(struct fpm_worker_pool_s *wp) /* } else if (strlen(dup_address) == strspn(dup_address, "0123456789")) { /* this is port */ port = atoi(dup_address); port_str = dup_address; + /* IPv6 catch-all + IPv4-mapped */ + addr = "::"; } if (port == 0) { @@ -272,18 +274,6 @@ static int fpm_socket_af_inet_listening_socket(struct fpm_worker_pool_s *wp) /* return -1; } - if (!addr) { - /* no address: default documented behavior, all IPv4 addresses */ - struct sockaddr_in sa_in; - - memset(&sa_in, 0, sizeof(sa_in)); - sa_in.sin_family = AF_INET; - sa_in.sin_port = htons(port); - sa_in.sin_addr.s_addr = htonl(INADDR_ANY); - free(dup_address); - return fpm_sockets_get_listening_socket(wp, (struct sockaddr *) &sa_in, sizeof(struct sockaddr_in)); - } - /* strip brackets from address for getaddrinfo */ addr_len = strlen(addr); if (addr[0] == '[' && addr[addr_len - 1] == ']') { @@ -305,10 +295,10 @@ static int fpm_socket_af_inet_listening_socket(struct fpm_worker_pool_s *wp) /* inet_ntop(p->ai_family, fpm_get_in_addr(p->ai_addr), tmpbuf, INET6_ADDRSTRLEN); if (sock < 0) { if ((sock = fpm_sockets_get_listening_socket(wp, p->ai_addr, p->ai_addrlen)) != -1) { - zlog(ZLOG_DEBUG, "Found address for %s, socket opened on %s", dup_address, tmpbuf); + zlog(ZLOG_DEBUG, "Found address for %s, socket opened on %s", addr, tmpbuf); } } else { - zlog(ZLOG_WARNING, "Found multiple addresses for %s, %s ignored", dup_address, tmpbuf); + zlog(ZLOG_WARNING, "Found multiple addresses for %s, %s ignored", addr, tmpbuf); } } diff --git a/sapi/fpm/fpm/fpm_sockets.h b/sapi/fpm/fpm/fpm_sockets.h index 446c78e410..2bd3d58249 100644 --- a/sapi/fpm/fpm/fpm_sockets.h +++ b/sapi/fpm/fpm/fpm_sockets.h @@ -19,7 +19,7 @@ #if (__FreeBSD__) || (__OpenBSD__) #define FPM_BACKLOG_DEFAULT -1 #else -#define FPM_BACKLOG_DEFAULT 65535 +#define FPM_BACKLOG_DEFAULT 511 #endif enum fpm_address_domain fpm_sockets_domain_from_address(char *addr); diff --git a/sapi/fpm/fpm/fpm_status.c b/sapi/fpm/fpm/fpm_status.c index 2363b57f80..7a8a7825c6 100644 --- a/sapi/fpm/fpm/fpm_status.c +++ b/sapi/fpm/fpm/fpm_status.c @@ -46,7 +46,7 @@ int fpm_status_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ } /* }}} */ -int fpm_status_handle_request(TSRMLS_D) /* {{{ */ +int fpm_status_handle_request(void) /* {{{ */ { struct fpm_scoreboard_s scoreboard, *scoreboard_p; struct fpm_scoreboard_proc_s proc; @@ -55,6 +55,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ int full, encode; char *short_syntax, *short_post; char *full_pre, *full_syntax, *full_post, *full_separator; + zend_string *_GET_str; if (!SG(request_info).request_uri) { return 0; @@ -63,9 +64,9 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ /* PING */ if (fpm_status_ping_uri && fpm_status_ping_response && !strcmp(fpm_status_ping_uri, SG(request_info).request_uri)) { fpm_request_executing(); - sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC); - sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1 TSRMLS_CC); - sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1); + sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1); + sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1); SG(sapi_headers).http_response_code = 200; /* handle HEAD */ @@ -85,9 +86,9 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ if (!scoreboard_p) { zlog(ZLOG_ERROR, "status: unable to find or access status shared memory"); SG(sapi_headers).http_response_code = 500; - sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC); - sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1 TSRMLS_CC); - sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1); + sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1); + sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1); PUTS("Internal error. Please review log file for errors."); return 1; } @@ -95,9 +96,9 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ if (!fpm_spinlock(&scoreboard_p->lock, 1)) { zlog(ZLOG_NOTICE, "[pool %s] status: scoreboard already in used.", scoreboard_p->pool); SG(sapi_headers).http_response_code = 503; - sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC); - sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1 TSRMLS_CC); - sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1); + sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1); + sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1); PUTS("Server busy. Please try again later."); return 1; } @@ -108,16 +109,16 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ if (scoreboard.idle < 0 || scoreboard.active < 0) { zlog(ZLOG_ERROR, "[pool %s] invalid status values", scoreboard.pool); SG(sapi_headers).http_response_code = 500; - sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC); - sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1 TSRMLS_CC); - sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1); + sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1); + sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1); PUTS("Internal error. Please review log file for errors."); return 1; } /* send common headers */ - sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1 TSRMLS_CC); - sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1); + sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1); SG(sapi_headers).http_response_code = 200; /* handle HEAD */ @@ -126,14 +127,15 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ } /* full status ? */ - full = (fpm_php_get_string_from_table("_GET", "full" TSRMLS_CC) != NULL); + _GET_str = zend_string_init("_GET", sizeof("_GET")-1, 0); + full = (fpm_php_get_string_from_table(_GET_str, "full") != NULL); short_syntax = short_post = NULL; full_separator = full_pre = full_syntax = full_post = NULL; encode = 0; /* HTML */ - if (fpm_php_get_string_from_table("_GET", "html" TSRMLS_CC)) { - sapi_add_header_ex(ZEND_STRL("Content-Type: text/html"), 1, 1 TSRMLS_CC); + if (fpm_php_get_string_from_table(_GET_str, "html")) { + sapi_add_header_ex(ZEND_STRL("Content-Type: text/html"), 1, 1); time_format = "%d/%b/%Y:%H:%M:%S %z"; encode = 1; @@ -207,8 +209,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ } /* XML */ - } else if (fpm_php_get_string_from_table("_GET", "xml" TSRMLS_CC)) { - sapi_add_header_ex(ZEND_STRL("Content-Type: text/xml"), 1, 1 TSRMLS_CC); + } else if (fpm_php_get_string_from_table(_GET_str, "xml")) { + sapi_add_header_ex(ZEND_STRL("Content-Type: text/xml"), 1, 1); time_format = "%s"; encode = 1; @@ -236,7 +238,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ short_post = "</status>"; } else { full_pre = "<processes>\n"; - full_syntax = + full_syntax = "<process>" "<pid>%d</pid>" "<state>%s</state>" @@ -259,8 +261,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ } /* JSON */ - } else if (fpm_php_get_string_from_table("_GET", "json" TSRMLS_CC)) { - sapi_add_header_ex(ZEND_STRL("Content-Type: application/json"), 1, 1 TSRMLS_CC); + } else if (fpm_php_get_string_from_table(_GET_str, "json")) { + sapi_add_header_ex(ZEND_STRL("Content-Type: application/json"), 1, 1); time_format = "%s"; short_syntax = @@ -311,7 +313,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ /* TEXT */ } else { - sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1); time_format = "%d/%b/%Y:%H:%M:%S %z"; short_syntax = @@ -376,6 +378,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ PUTS(buffer); efree(buffer); + zend_string_release(_GET_str); if (short_post) { PUTS(short_post); @@ -384,7 +387,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ /* no need to test the var 'full' */ if (full_syntax) { int i, first; - size_t len; + zend_string *tmp_query_string; char *query_string; struct timeval duration, now; #ifdef HAVE_FPM_LQ @@ -413,12 +416,13 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ } query_string = NULL; - len = 0; + tmp_query_string = NULL; if (proc.query_string[0] != '\0') { if (!encode) { query_string = proc.query_string; } else { - query_string = php_escape_html_entities_ex((unsigned char *)proc.query_string, strlen(proc.query_string), &len, 1, ENT_HTML_IGNORE_ERRORS & ENT_COMPAT, NULL, 1 TSRMLS_CC); + tmp_query_string = php_escape_html_entities_ex((unsigned char *)proc.query_string, strlen(proc.query_string), 1, ENT_HTML_IGNORE_ERRORS & ENT_COMPAT, NULL, 1); + query_string = tmp_query_string->val; } } @@ -458,8 +462,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ PUTS(buffer); efree(buffer); - if (len > 0 && query_string) { - efree(query_string); + if (tmp_query_string) { + zend_string_free(tmp_query_string); } } diff --git a/sapi/fpm/fpm/fpm_status.h b/sapi/fpm/fpm/fpm_status.h index 8f3daf9c72..c6c27cd031 100644 --- a/sapi/fpm/fpm/fpm_status.h +++ b/sapi/fpm/fpm/fpm_status.h @@ -28,7 +28,7 @@ void fpm_status_increment_accepted_conn(struct fpm_shm_s *shm); void fpm_status_set_pm(struct fpm_shm_s *shm, int pm); void fpm_status_update_max_children_reached(struct fpm_shm_s *shm, unsigned int max_children_reached); void fpm_status_increment_max_children_reached(struct fpm_shm_s *shm); -int fpm_status_handle_request(TSRMLS_D); +int fpm_status_handle_request(void); extern struct fpm_shm_s *fpm_status_shm; diff --git a/sapi/fpm/fpm/fpm_systemd.c b/sapi/fpm/fpm/fpm_systemd.c index c4d7ec15a4..95d12c97f2 100644 --- a/sapi/fpm/fpm/fpm_systemd.c +++ b/sapi/fpm/fpm/fpm_systemd.c @@ -29,7 +29,7 @@ static void fpm_systemd() /* {{{ */ } /* - zlog(ZLOG_DEBUG, "systemd %s (Processes active:%d, idle:%d, Requests:%lu, slow:%lu, Traffic:%.3greq/sec)", + zlog(ZLOG_DEBUG, "systemd %s (Processes active:%d, idle:%d, Requests:%lu, slow:%lu, Traffic:%.3greq/sec)", fpm_global_config.systemd_watchdog ? "watchdog" : "heartbeat", active, idle, requests, slow_req, ((float)requests - last) * 1000.0 / fpm_global_config.systemd_interval); */ diff --git a/sapi/fpm/fpm/fpm_unix.c b/sapi/fpm/fpm/fpm_unix.c index f0d4573483..6089e3109e 100644 --- a/sapi/fpm/fpm/fpm_unix.c +++ b/sapi/fpm/fpm/fpm_unix.c @@ -477,7 +477,7 @@ int fpm_unix_init_main() /* {{{ */ * The parent process has then to wait for the master * process to initialize to return a consistent exit * value. For this pupose, the master process will - * send \"1\" into the pipe if everything went well + * send \"1\" into the pipe if everything went well * and \"0\" otherwise. */ diff --git a/sapi/fpm/fpm/zlog.c b/sapi/fpm/fpm/zlog.c index 80db9d8374..6f17b99133 100644 --- a/sapi/fpm/fpm/zlog.c +++ b/sapi/fpm/fpm/zlog.c @@ -184,7 +184,7 @@ void zlog_ex(const char *function, int line, int flags, const char *fmt, ...) /* buf[len] = '\0'; php_syslog(syslog_priorities[zlog_level], "%s", buf); buf[len++] = '\n'; - } else + } else #endif { buf[len++] = '\n'; diff --git a/sapi/fpm/php-fpm.conf.in b/sapi/fpm/php-fpm.conf.in index dd037db768..9e5b593f83 100644 --- a/sapi/fpm/php-fpm.conf.in +++ b/sapi/fpm/php-fpm.conf.in @@ -6,14 +6,6 @@ ; prefix (@prefix@). This prefix can be dynamically changed by using the ; '-p' argument from the command line. -; Include one or more files. If glob(3) exists, it is used to include a bunch of -; files from a glob(3) pattern. This directive can be used everywhere in the -; file. -; Relative path can also be used. They will be prefixed by: -; - the global prefix if it's been set (-p argument) -; - @prefix@ otherwise -;include=etc/fpm.d/*.conf - ;;;;;;;;;;;;;;;;;; ; Global Options ; ;;;;;;;;;;;;;;;;;; @@ -55,7 +47,7 @@ ; Default Value: 0 ;emergency_restart_threshold = 0 -; Interval of time used by emergency_restart_interval to determine when +; Interval of time used by emergency_restart_interval to determine when ; a graceful restart will be initiated. This can be useful to work around ; accidental corruptions in an accelerator's shared memory. ; Available Units: s(econds), m(inutes), h(ours), or d(ays) @@ -87,11 +79,11 @@ ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging. ; Default Value: yes ;daemonize = yes - + ; Set open file descriptor rlimit for the master process. ; Default Value: system defined value ;rlimit_files = 1024 - + ; Set max core size rlimit for the master process. ; Possible Values: 'unlimited' or an integer greater or equal to 0 ; Default Value: system defined value @@ -116,7 +108,7 @@ ;systemd_interval = 10 ;;;;;;;;;;;;;;;;;;;; -; Pool Definitions ; +; Pool Definitions ; ;;;;;;;;;;;;;;;;;;;; ; Multiple pools of child processes may be started with different listening @@ -124,414 +116,10 @@ ; used in logs and stats. There is no limitation on the number of pools which ; FPM can handle. Your system will tell you anyway :) -; Start a new pool named 'www'. -; the variable $pool can we used in any directive and will be replaced by the -; pool name ('www' here) -[www] - -; Per pool prefix -; It only applies on the following directives: -; - 'access.log' -; - 'slowlog' -; - 'listen' (unixsocket) -; - 'chroot' -; - 'chdir' -; - 'php_values' -; - 'php_admin_values' -; When not set, the global prefix (or @php_fpm_prefix@) applies instead. -; Note: This directive can also be relative to the global prefix. -; Default Value: none -;prefix = /path/to/pools/$pool - -; Unix user/group of processes -; Note: The user is mandatory. If the group is not set, the default user's group -; will be used. -user = @php_fpm_user@ -group = @php_fpm_group@ - -; The address on which to accept FastCGI requests. -; Valid syntaxes are: -; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on -; a specific port; -; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on -; a specific port; -; 'port' - to listen on a TCP socket to all IPv4 addresses on a -; specific port; -; '[::]:port' - to listen on a TCP socket to all addresses -; (IPv6 and IPv4-mapped) on a specific port; -; '/path/to/unix/socket' - to listen on a unix socket. -; Note: This value is mandatory. -listen = 127.0.0.1:9000 - -; Set listen(2) backlog. -; Default Value: 65535 (-1 on FreeBSD and OpenBSD) -;listen.backlog = 65535 - -; Set permissions for unix socket, if one is used. In Linux, read/write -; permissions must be set in order to allow connections from a web server. Many -; BSD-derived systems allow connections regardless of permissions. -; Default Values: user and group are set as the running user -; mode is set to 0660 -;listen.owner = @php_fpm_user@ -;listen.group = @php_fpm_group@ -;listen.mode = 0660 -; When POSIX Access Control Lists are supported you can set them using -; these options, value is a comma separated list of user/group names. -; When set, listen.owner and listen.group are ignored -;listen.acl_users = -;listen.acl_groups = - -; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect. -; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original -; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address -; must be separated by a comma. If this value is left blank, connections will be -; accepted from any ip address. -; Default Value: any -;listen.allowed_clients = 127.0.0.1 - -; Specify the nice(2) priority to apply to the pool processes (only if set) -; The value can vary from -19 (highest priority) to 20 (lower priority) -; Note: - It will only work if the FPM master process is launched as root -; - The pool processes will inherit the master process priority -; unless it specified otherwise -; Default Value: no set -; process.priority = -19 - -; Choose how the process manager will control the number of child processes. -; Possible Values: -; static - a fixed number (pm.max_children) of child processes; -; dynamic - the number of child processes are set dynamically based on the -; following directives. With this process management, there will be -; always at least 1 children. -; pm.max_children - the maximum number of children that can -; be alive at the same time. -; pm.start_servers - the number of children created on startup. -; pm.min_spare_servers - the minimum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is less than this -; number then some children will be created. -; pm.max_spare_servers - the maximum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is greater than this -; number then some children will be killed. -; ondemand - no children are created at startup. Children will be forked when -; new requests will connect. The following parameter are used: -; pm.max_children - the maximum number of children that -; can be alive at the same time. -; pm.process_idle_timeout - The number of seconds after which -; an idle process will be killed. -; Note: This value is mandatory. -pm = dynamic - -; The number of child processes to be created when pm is set to 'static' and the -; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. -; This value sets the limit on the number of simultaneous requests that will be -; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. -; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP -; CGI. The below defaults are based on a server without much resources. Don't -; forget to tweak pm.* to fit your needs. -; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' -; Note: This value is mandatory. -pm.max_children = 5 - -; The number of child processes created on startup. -; Note: Used only when pm is set to 'dynamic' -; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 -pm.start_servers = 2 - -; The desired minimum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.min_spare_servers = 1 - -; The desired maximum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.max_spare_servers = 3 - -; The number of seconds after which an idle process will be killed. -; Note: Used only when pm is set to 'ondemand' -; Default Value: 10s -;pm.process_idle_timeout = 10s; - -; The number of requests each child process should execute before respawning. -; This can be useful to work around memory leaks in 3rd party libraries. For -; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. -; Default Value: 0 -;pm.max_requests = 500 - -; The URI to view the FPM status page. If this value is not set, no URI will be -; recognized as a status page. It shows the following informations: -; pool - the name of the pool; -; process manager - static, dynamic or ondemand; -; start time - the date and time FPM has started; -; start since - number of seconds since FPM has started; -; accepted conn - the number of request accepted by the pool; -; listen queue - the number of request in the queue of pending -; connections (see backlog in listen(2)); -; max listen queue - the maximum number of requests in the queue -; of pending connections since FPM has started; -; listen queue len - the size of the socket queue of pending connections; -; idle processes - the number of idle processes; -; active processes - the number of active processes; -; total processes - the number of idle + active processes; -; max active processes - the maximum number of active processes since FPM -; has started; -; max children reached - number of times, the process limit has been reached, -; when pm tries to start more children (works only for -; pm 'dynamic' and 'ondemand'); -; Value are updated in real time. -; Example output: -; pool: www -; process manager: static -; start time: 01/Jul/2011:17:53:49 +0200 -; start since: 62636 -; accepted conn: 190460 -; listen queue: 0 -; max listen queue: 1 -; listen queue len: 42 -; idle processes: 4 -; active processes: 11 -; total processes: 15 -; max active processes: 12 -; max children reached: 0 -; -; By default the status page output is formatted as text/plain. Passing either -; 'html', 'xml' or 'json' in the query string will return the corresponding -; output syntax. Example: -; http://www.foo.bar/status -; http://www.foo.bar/status?json -; http://www.foo.bar/status?html -; http://www.foo.bar/status?xml -; -; By default the status page only outputs short status. Passing 'full' in the -; query string will also return status for each pool process. -; Example: -; http://www.foo.bar/status?full -; http://www.foo.bar/status?json&full -; http://www.foo.bar/status?html&full -; http://www.foo.bar/status?xml&full -; The Full status returns for each process: -; pid - the PID of the process; -; state - the state of the process (Idle, Running, ...); -; start time - the date and time the process has started; -; start since - the number of seconds since the process has started; -; requests - the number of requests the process has served; -; request duration - the duration in µs of the requests; -; request method - the request method (GET, POST, ...); -; request URI - the request URI with the query string; -; content length - the content length of the request (only with POST); -; user - the user (PHP_AUTH_USER) (or '-' if not set); -; script - the main script called (or '-' if not set); -; last request cpu - the %cpu the last request consumed -; it's always 0 if the process is not in Idle state -; because CPU calculation is done when the request -; processing has terminated; -; last request memory - the max amount of memory the last request consumed -; it's always 0 if the process is not in Idle state -; because memory calculation is done when the request -; processing has terminated; -; If the process is in Idle state, then informations are related to the -; last request the process has served. Otherwise informations are related to -; the current request being served. -; Example output: -; ************************ -; pid: 31330 -; state: Running -; start time: 01/Jul/2011:17:53:49 +0200 -; start since: 63087 -; requests: 12808 -; request duration: 1250261 -; request method: GET -; request URI: /test_mem.php?N=10000 -; content length: 0 -; user: - -; script: /home/fat/web/docs/php/test_mem.php -; last request cpu: 0.00 -; last request memory: 0 -; -; Note: There is a real-time FPM status monitoring sample web page available -; It's available in: @EXPANDED_DATADIR@/fpm/status.html -; -; Note: The value must start with a leading slash (/). The value can be -; anything, but it may not be a good idea to use the .php extension or it -; may conflict with a real PHP file. -; Default Value: not set -;pm.status_path = /status - -; The ping URI to call the monitoring page of FPM. If this value is not set, no -; URI will be recognized as a ping page. This could be used to test from outside -; that FPM is alive and responding, or to -; - create a graph of FPM availability (rrd or such); -; - remove a server from a group if it is not responding (load balancing); -; - trigger alerts for the operating team (24/7). -; Note: The value must start with a leading slash (/). The value can be -; anything, but it may not be a good idea to use the .php extension or it -; may conflict with a real PHP file. -; Default Value: not set -;ping.path = /ping - -; This directive may be used to customize the response of a ping request. The -; response is formatted as text/plain with a 200 response code. -; Default Value: pong -;ping.response = pong - -; The access log file -; Default: not set -;access.log = log/$pool.access.log - -; The access log format. -; The following syntax is allowed -; %%: the '%' character -; %C: %CPU used by the request -; it can accept the following format: -; - %{user}C for user CPU only -; - %{system}C for system CPU only -; - %{total}C for user + system CPU (default) -; %d: time taken to serve the request -; it can accept the following format: -; - %{seconds}d (default) -; - %{miliseconds}d -; - %{mili}d -; - %{microseconds}d -; - %{micro}d -; %e: an environment variable (same as $_ENV or $_SERVER) -; it must be associated with embraces to specify the name of the env -; variable. Some exemples: -; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e -; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e -; %f: script filename -; %l: content-length of the request (for POST request only) -; %m: request method -; %M: peak of memory allocated by PHP -; it can accept the following format: -; - %{bytes}M (default) -; - %{kilobytes}M -; - %{kilo}M -; - %{megabytes}M -; - %{mega}M -; %n: pool name -; %o: output header -; it must be associated with embraces to specify the name of the header: -; - %{Content-Type}o -; - %{X-Powered-By}o -; - %{Transfert-Encoding}o -; - .... -; %p: PID of the child that serviced the request -; %P: PID of the parent of the child that serviced the request -; %q: the query string -; %Q: the '?' character if query string exists -; %r: the request URI (without the query string, see %q and %Q) -; %R: remote IP address -; %s: status (response code) -; %t: server time the request was received -; it can accept a strftime(3) format: -; %d/%b/%Y:%H:%M:%S %z (default) -; %T: time the log has been written (the request has finished) -; it can accept a strftime(3) format: -; %d/%b/%Y:%H:%M:%S %z (default) -; %u: remote user -; -; Default: "%R - %u %t \"%m %r\" %s" -;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" - -; The log file for slow requests -; Default Value: not set -; Note: slowlog is mandatory if request_slowlog_timeout is set -;slowlog = log/$pool.log.slow - -; The timeout for serving a single request after which a PHP backtrace will be -; dumped to the 'slowlog' file. A value of '0s' means 'off'. -; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) -; Default Value: 0 -;request_slowlog_timeout = 0 - -; The timeout for serving a single request after which the worker process will -; be killed. This option should be used when the 'max_execution_time' ini option -; does not stop script execution for some reason. A value of '0' means 'off'. -; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) -; Default Value: 0 -;request_terminate_timeout = 0 - -; Set open file descriptor rlimit. -; Default Value: system defined value -;rlimit_files = 1024 - -; Set max core size rlimit. -; Possible Values: 'unlimited' or an integer greater or equal to 0 -; Default Value: system defined value -;rlimit_core = 0 - -; Chroot to this directory at the start. This value must be defined as an -; absolute path. When this value is not set, chroot is not used. -; Note: you can prefix with '$prefix' to chroot to the pool prefix or one -; of its subdirectories. If the pool prefix is not set, the global prefix -; will be used instead. -; Note: chrooting is a great security feature and should be used whenever -; possible. However, all PHP paths will be relative to the chroot -; (error_log, sessions.save_path, ...). -; Default Value: not set -;chroot = - -; Chdir to this directory at the start. -; Note: relative path can be used. -; Default Value: current directory or / when chroot -;chdir = /var/www - -; Redirect worker stdout and stderr into main error log. If not set, stdout and -; stderr will be redirected to /dev/null according to FastCGI specs. -; Note: on highloaded environement, this can cause some delay in the page -; process time (several ms). -; Default Value: no -;catch_workers_output = yes - -; Clear environment in FPM workers -; Prevents arbitrary environment variables from reaching FPM worker processes -; by clearing the environment in workers before env vars specified in this -; pool configuration are added. -; Setting to "no" will make all environment variables available to PHP code -; via getenv(), $_ENV and $_SERVER. -; Default Value: yes -;clear_env = no - -; Limits the extensions of the main script FPM will allow to parse. This can -; prevent configuration mistakes on the web server side. You should only limit -; FPM to .php extensions to prevent malicious users to use other extensions to -; exectute php code. -; Note: set an empty value to allow all extensions. -; Default Value: .php -;security.limit_extensions = .php .php3 .php4 .php5 - -; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from -; the current environment. -; Default Value: clean env -;env[HOSTNAME] = $HOSTNAME -;env[PATH] = /usr/local/bin:/usr/bin:/bin -;env[TMP] = /tmp -;env[TMPDIR] = /tmp -;env[TEMP] = /tmp - -; Additional php.ini defines, specific to this pool of workers. These settings -; overwrite the values previously defined in the php.ini. The directives are the -; same as the PHP SAPI: -; php_value/php_flag - you can set classic ini defines which can -; be overwritten from PHP call 'ini_set'. -; php_admin_value/php_admin_flag - these directives won't be overwritten by -; PHP call 'ini_set' -; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. - -; Defining 'extension' will load the corresponding shared extension from -; extension_dir. Defining 'disable_functions' or 'disable_classes' will not -; overwrite previously defined php.ini values, but will append the new value -; instead. - -; Note: path INI options can be relative and will be expanded with the prefix -; (pool, global or @prefix@) - -; Default Value: nothing is defined by default except the values in php.ini and -; specified at startup with the -d argument -;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com -;php_flag[display_errors] = off -;php_admin_value[error_log] = /var/log/fpm-php.www.log -;php_admin_flag[log_errors] = on -;php_admin_value[memory_limit] = 32M +; Include one or more files. If glob(3) exists, it is used to include a bunch of +; files from a glob(3) pattern. This directive can be used everywhere in the +; file. +; Relative path can also be used. They will be prefixed by: +; - the global prefix if it's been set (-p argument) +; - @prefix@ otherwise +include=@php_fpm_sysconfdir@/php-fpm.d/*.conf diff --git a/sapi/fpm/tests/003.phpt b/sapi/fpm/tests/003.phpt index f928626ecc..a4c04ae9ce 100644 --- a/sapi/fpm/tests/003.phpt +++ b/sapi/fpm/tests/003.phpt @@ -1,7 +1,10 @@ --TEST-- FPM: Test IPv6 support --SKIPIF-- -<?php include "skipif.inc"; ?> +<?php include "skipif.inc"; + @stream_socket_client('tcp://[::1]:0', $errno); + if ($errno != 111) die('skip IPv6 not supported.'); +?> --FILE-- <?php diff --git a/sapi/fpm/tests/004.phpt b/sapi/fpm/tests/004.phpt index 2a4d666c64..565819aed4 100644 --- a/sapi/fpm/tests/004.phpt +++ b/sapi/fpm/tests/004.phpt @@ -1,7 +1,10 @@ --TEST-- FPM: Test IPv4/IPv6 support --SKIPIF-- -<?php include "skipif.inc"; ?> +<?php include "skipif.inc"; + @stream_socket_client('tcp://[::1]:0', $errno); + if ($errno != 111) die('skip IPv6 not supported.'); +?> --FILE-- <?php diff --git a/sapi/fpm/tests/005.phpt b/sapi/fpm/tests/005.phpt index c565c2a9eb..6c8210ec8e 100644 --- a/sapi/fpm/tests/005.phpt +++ b/sapi/fpm/tests/005.phpt @@ -1,7 +1,10 @@ --TEST-- FPM: Test IPv4 allowed clients --SKIPIF-- -<?php include "skipif.inc"; ?> +<?php include "skipif.inc"; + @stream_socket_client('tcp://[::1]:0', $errno); + if ($errno != 111) die('skip IPv6 not supported.'); +?> --FILE-- <?php diff --git a/sapi/fpm/tests/006.phpt b/sapi/fpm/tests/006.phpt index a12ca253d2..e552087335 100644 --- a/sapi/fpm/tests/006.phpt +++ b/sapi/fpm/tests/006.phpt @@ -1,7 +1,10 @@ --TEST-- FPM: Test IPv6 allowed clients (bug #68428) --SKIPIF-- -<?php include "skipif.inc"; ?> +<?php include "skipif.inc"; + @stream_socket_client('tcp://[::1]:0', $errno); + if ($errno != 111) die('skip IPv6 not supported.'); +?> --FILE-- <?php diff --git a/sapi/fpm/tests/007.phpt b/sapi/fpm/tests/007.phpt index 0d817907cf..6329af209a 100644 --- a/sapi/fpm/tests/007.phpt +++ b/sapi/fpm/tests/007.phpt @@ -1,7 +1,10 @@ --TEST-- FPM: Test IPv6 all addresses and access_log (bug #68421) --SKIPIF-- -<?php include "skipif.inc"; ?> +<?php include "skipif.inc"; + @stream_socket_client('tcp://[::1]:0', $errno); + if ($errno != 111) die('skip IPv6 not supported.'); +?> --FILE-- <?php diff --git a/sapi/fpm/www.conf.in b/sapi/fpm/www.conf.in new file mode 100644 index 0000000000..d69bcf5eee --- /dev/null +++ b/sapi/fpm/www.conf.in @@ -0,0 +1,409 @@ +; Start a new pool named 'www'. +; the variable $pool can we used in any directive and will be replaced by the +; pool name ('www' here) +[www] + +; Per pool prefix +; It only applies on the following directives: +; - 'access.log' +; - 'slowlog' +; - 'listen' (unixsocket) +; - 'chroot' +; - 'chdir' +; - 'php_values' +; - 'php_admin_values' +; When not set, the global prefix (or @php_fpm_prefix@) applies instead. +; Note: This directive can also be relative to the global prefix. +; Default Value: none +;prefix = /path/to/pools/$pool + +; Unix user/group of processes +; Note: The user is mandatory. If the group is not set, the default user's group +; will be used. +user = @php_fpm_user@ +group = @php_fpm_group@ + +; The address on which to accept FastCGI requests. +; Valid syntaxes are: +; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on +; a specific port; +; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on +; a specific port; +; 'port' - to listen on a TCP socket to all addresses +; (IPv6 and IPv4-mapped) on a specific port; +; '/path/to/unix/socket' - to listen on a unix socket. +; Note: This value is mandatory. +listen = 127.0.0.1:9000 + +; Set listen(2) backlog. +; Default Value: 511 (-1 on FreeBSD and OpenBSD) +;listen.backlog = 511 + +; Set permissions for unix socket, if one is used. In Linux, read/write +; permissions must be set in order to allow connections from a web server. Many +; BSD-derived systems allow connections regardless of permissions. +; Default Values: user and group are set as the running user +; mode is set to 0660 +;listen.owner = @php_fpm_user@ +;listen.group = @php_fpm_group@ +;listen.mode = 0660 +; When POSIX Access Control Lists are supported you can set them using +; these options, value is a comma separated list of user/group names. +; When set, listen.owner and listen.group are ignored +;listen.acl_users = +;listen.acl_groups = + +; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect. +; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original +; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address +; must be separated by a comma. If this value is left blank, connections will be +; accepted from any ip address. +; Default Value: any +;listen.allowed_clients = 127.0.0.1 + +; Specify the nice(2) priority to apply to the pool processes (only if set) +; The value can vary from -19 (highest priority) to 20 (lower priority) +; Note: - It will only work if the FPM master process is launched as root +; - The pool processes will inherit the master process priority +; unless it specified otherwise +; Default Value: no set +; process.priority = -19 + +; Choose how the process manager will control the number of child processes. +; Possible Values: +; static - a fixed number (pm.max_children) of child processes; +; dynamic - the number of child processes are set dynamically based on the +; following directives. With this process management, there will be +; always at least 1 children. +; pm.max_children - the maximum number of children that can +; be alive at the same time. +; pm.start_servers - the number of children created on startup. +; pm.min_spare_servers - the minimum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is less than this +; number then some children will be created. +; pm.max_spare_servers - the maximum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is greater than this +; number then some children will be killed. +; ondemand - no children are created at startup. Children will be forked when +; new requests will connect. The following parameter are used: +; pm.max_children - the maximum number of children that +; can be alive at the same time. +; pm.process_idle_timeout - The number of seconds after which +; an idle process will be killed. +; Note: This value is mandatory. +pm = dynamic + +; The number of child processes to be created when pm is set to 'static' and the +; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. +; This value sets the limit on the number of simultaneous requests that will be +; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. +; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP +; CGI. The below defaults are based on a server without much resources. Don't +; forget to tweak pm.* to fit your needs. +; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' +; Note: This value is mandatory. +pm.max_children = 5 + +; The number of child processes created on startup. +; Note: Used only when pm is set to 'dynamic' +; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 +pm.start_servers = 2 + +; The desired minimum number of idle server processes. +; Note: Used only when pm is set to 'dynamic' +; Note: Mandatory when pm is set to 'dynamic' +pm.min_spare_servers = 1 + +; The desired maximum number of idle server processes. +; Note: Used only when pm is set to 'dynamic' +; Note: Mandatory when pm is set to 'dynamic' +pm.max_spare_servers = 3 + +; The number of seconds after which an idle process will be killed. +; Note: Used only when pm is set to 'ondemand' +; Default Value: 10s +;pm.process_idle_timeout = 10s; + +; The number of requests each child process should execute before respawning. +; This can be useful to work around memory leaks in 3rd party libraries. For +; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. +; Default Value: 0 +;pm.max_requests = 500 + +; The URI to view the FPM status page. If this value is not set, no URI will be +; recognized as a status page. It shows the following informations: +; pool - the name of the pool; +; process manager - static, dynamic or ondemand; +; start time - the date and time FPM has started; +; start since - number of seconds since FPM has started; +; accepted conn - the number of request accepted by the pool; +; listen queue - the number of request in the queue of pending +; connections (see backlog in listen(2)); +; max listen queue - the maximum number of requests in the queue +; of pending connections since FPM has started; +; listen queue len - the size of the socket queue of pending connections; +; idle processes - the number of idle processes; +; active processes - the number of active processes; +; total processes - the number of idle + active processes; +; max active processes - the maximum number of active processes since FPM +; has started; +; max children reached - number of times, the process limit has been reached, +; when pm tries to start more children (works only for +; pm 'dynamic' and 'ondemand'); +; Value are updated in real time. +; Example output: +; pool: www +; process manager: static +; start time: 01/Jul/2011:17:53:49 +0200 +; start since: 62636 +; accepted conn: 190460 +; listen queue: 0 +; max listen queue: 1 +; listen queue len: 42 +; idle processes: 4 +; active processes: 11 +; total processes: 15 +; max active processes: 12 +; max children reached: 0 +; +; By default the status page output is formatted as text/plain. Passing either +; 'html', 'xml' or 'json' in the query string will return the corresponding +; output syntax. Example: +; http://www.foo.bar/status +; http://www.foo.bar/status?json +; http://www.foo.bar/status?html +; http://www.foo.bar/status?xml +; +; By default the status page only outputs short status. Passing 'full' in the +; query string will also return status for each pool process. +; Example: +; http://www.foo.bar/status?full +; http://www.foo.bar/status?json&full +; http://www.foo.bar/status?html&full +; http://www.foo.bar/status?xml&full +; The Full status returns for each process: +; pid - the PID of the process; +; state - the state of the process (Idle, Running, ...); +; start time - the date and time the process has started; +; start since - the number of seconds since the process has started; +; requests - the number of requests the process has served; +; request duration - the duration in µs of the requests; +; request method - the request method (GET, POST, ...); +; request URI - the request URI with the query string; +; content length - the content length of the request (only with POST); +; user - the user (PHP_AUTH_USER) (or '-' if not set); +; script - the main script called (or '-' if not set); +; last request cpu - the %cpu the last request consumed +; it's always 0 if the process is not in Idle state +; because CPU calculation is done when the request +; processing has terminated; +; last request memory - the max amount of memory the last request consumed +; it's always 0 if the process is not in Idle state +; because memory calculation is done when the request +; processing has terminated; +; If the process is in Idle state, then informations are related to the +; last request the process has served. Otherwise informations are related to +; the current request being served. +; Example output: +; ************************ +; pid: 31330 +; state: Running +; start time: 01/Jul/2011:17:53:49 +0200 +; start since: 63087 +; requests: 12808 +; request duration: 1250261 +; request method: GET +; request URI: /test_mem.php?N=10000 +; content length: 0 +; user: - +; script: /home/fat/web/docs/php/test_mem.php +; last request cpu: 0.00 +; last request memory: 0 +; +; Note: There is a real-time FPM status monitoring sample web page available +; It's available in: @EXPANDED_DATADIR@/fpm/status.html +; +; Note: The value must start with a leading slash (/). The value can be +; anything, but it may not be a good idea to use the .php extension or it +; may conflict with a real PHP file. +; Default Value: not set +;pm.status_path = /status + +; The ping URI to call the monitoring page of FPM. If this value is not set, no +; URI will be recognized as a ping page. This could be used to test from outside +; that FPM is alive and responding, or to +; - create a graph of FPM availability (rrd or such); +; - remove a server from a group if it is not responding (load balancing); +; - trigger alerts for the operating team (24/7). +; Note: The value must start with a leading slash (/). The value can be +; anything, but it may not be a good idea to use the .php extension or it +; may conflict with a real PHP file. +; Default Value: not set +;ping.path = /ping + +; This directive may be used to customize the response of a ping request. The +; response is formatted as text/plain with a 200 response code. +; Default Value: pong +;ping.response = pong + +; The access log file +; Default: not set +;access.log = log/$pool.access.log + +; The access log format. +; The following syntax is allowed +; %%: the '%' character +; %C: %CPU used by the request +; it can accept the following format: +; - %{user}C for user CPU only +; - %{system}C for system CPU only +; - %{total}C for user + system CPU (default) +; %d: time taken to serve the request +; it can accept the following format: +; - %{seconds}d (default) +; - %{miliseconds}d +; - %{mili}d +; - %{microseconds}d +; - %{micro}d +; %e: an environment variable (same as $_ENV or $_SERVER) +; it must be associated with embraces to specify the name of the env +; variable. Some exemples: +; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e +; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e +; %f: script filename +; %l: content-length of the request (for POST request only) +; %m: request method +; %M: peak of memory allocated by PHP +; it can accept the following format: +; - %{bytes}M (default) +; - %{kilobytes}M +; - %{kilo}M +; - %{megabytes}M +; - %{mega}M +; %n: pool name +; %o: output header +; it must be associated with embraces to specify the name of the header: +; - %{Content-Type}o +; - %{X-Powered-By}o +; - %{Transfert-Encoding}o +; - .... +; %p: PID of the child that serviced the request +; %P: PID of the parent of the child that serviced the request +; %q: the query string +; %Q: the '?' character if query string exists +; %r: the request URI (without the query string, see %q and %Q) +; %R: remote IP address +; %s: status (response code) +; %t: server time the request was received +; it can accept a strftime(3) format: +; %d/%b/%Y:%H:%M:%S %z (default) +; %T: time the log has been written (the request has finished) +; it can accept a strftime(3) format: +; %d/%b/%Y:%H:%M:%S %z (default) +; %u: remote user +; +; Default: "%R - %u %t \"%m %r\" %s" +;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" + +; The log file for slow requests +; Default Value: not set +; Note: slowlog is mandatory if request_slowlog_timeout is set +;slowlog = log/$pool.log.slow + +; The timeout for serving a single request after which a PHP backtrace will be +; dumped to the 'slowlog' file. A value of '0s' means 'off'. +; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) +; Default Value: 0 +;request_slowlog_timeout = 0 + +; The timeout for serving a single request after which the worker process will +; be killed. This option should be used when the 'max_execution_time' ini option +; does not stop script execution for some reason. A value of '0' means 'off'. +; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) +; Default Value: 0 +;request_terminate_timeout = 0 + +; Set open file descriptor rlimit. +; Default Value: system defined value +;rlimit_files = 1024 + +; Set max core size rlimit. +; Possible Values: 'unlimited' or an integer greater or equal to 0 +; Default Value: system defined value +;rlimit_core = 0 + +; Chroot to this directory at the start. This value must be defined as an +; absolute path. When this value is not set, chroot is not used. +; Note: you can prefix with '$prefix' to chroot to the pool prefix or one +; of its subdirectories. If the pool prefix is not set, the global prefix +; will be used instead. +; Note: chrooting is a great security feature and should be used whenever +; possible. However, all PHP paths will be relative to the chroot +; (error_log, sessions.save_path, ...). +; Default Value: not set +;chroot = + +; Chdir to this directory at the start. +; Note: relative path can be used. +; Default Value: current directory or / when chroot +;chdir = /var/www + +; Redirect worker stdout and stderr into main error log. If not set, stdout and +; stderr will be redirected to /dev/null according to FastCGI specs. +; Note: on highloaded environement, this can cause some delay in the page +; process time (several ms). +; Default Value: no +;catch_workers_output = yes + +; Clear environment in FPM workers +; Prevents arbitrary environment variables from reaching FPM worker processes +; by clearing the environment in workers before env vars specified in this +; pool configuration are added. +; Setting to "no" will make all environment variables available to PHP code +; via getenv(), $_ENV and $_SERVER. +; Default Value: yes +;clear_env = no + +; Limits the extensions of the main script FPM will allow to parse. This can +; prevent configuration mistakes on the web server side. You should only limit +; FPM to .php extensions to prevent malicious users to use other extensions to +; exectute php code. +; Note: set an empty value to allow all extensions. +; Default Value: .php +;security.limit_extensions = .php .php3 .php4 .php5 .php7 + +; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from +; the current environment. +; Default Value: clean env +;env[HOSTNAME] = $HOSTNAME +;env[PATH] = /usr/local/bin:/usr/bin:/bin +;env[TMP] = /tmp +;env[TMPDIR] = /tmp +;env[TEMP] = /tmp + +; Additional php.ini defines, specific to this pool of workers. These settings +; overwrite the values previously defined in the php.ini. The directives are the +; same as the PHP SAPI: +; php_value/php_flag - you can set classic ini defines which can +; be overwritten from PHP call 'ini_set'. +; php_admin_value/php_admin_flag - these directives won't be overwritten by +; PHP call 'ini_set' +; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. + +; Defining 'extension' will load the corresponding shared extension from +; extension_dir. Defining 'disable_functions' or 'disable_classes' will not +; overwrite previously defined php.ini values, but will append the new value +; instead. + +; Note: path INI options can be relative and will be expanded with the prefix +; (pool, global or @prefix@) + +; Default Value: nothing is defined by default except the values in php.ini and +; specified at startup with the -d argument +;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com +;php_flag[display_errors] = off +;php_admin_value[error_log] = /var/log/fpm-php.www.log +;php_admin_flag[log_errors] = on +;php_admin_value[memory_limit] = 32M diff --git a/sapi/isapi/config.m4 b/sapi/isapi/config.m4 index 6014bab09f..4073173eaf 100644 --- a/sapi/isapi/config.m4 +++ b/sapi/isapi/config.m4 @@ -15,7 +15,7 @@ if test "$PHP_ISAPI" != "no"; then PHP_BUILD_THREAD_SAFE AC_DEFINE(WITH_ZEUS, 1, [ ]) PHP_ADD_INCLUDE($ZEUSPATH/web/include) - PHP_SELECT_SAPI(isapi, shared, php5isapi.c) + PHP_SELECT_SAPI(isapi, shared, php7isapi.c) INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$ZEUSPATH/web/bin/" fi diff --git a/sapi/isapi/config.w32 b/sapi/isapi/config.w32 index 8012352744..5a359f11b2 100644 --- a/sapi/isapi/config.w32 +++ b/sapi/isapi/config.w32 @@ -7,7 +7,7 @@ if (PHP_ISAPI == "yes") { if (PHP_ZTS == "no") { WARNING("ISAPI module requires an --enable-zts build of PHP"); } else { - SAPI('isapi', 'php5isapi.c', 'php' + PHP_VERSION + 'isapi.dll', '/D PHP5ISAPI_EXPORTS'); - ADD_FLAG('LDFLAGS_ISAPI', '/DEF:sapi\\isapi\\php5isapi.def'); + SAPI('isapi', 'php7isapi.c', 'php' + PHP_VERSION + 'isapi.dll', '/D PHP7ISAPI_EXPORTS'); + ADD_FLAG('LDFLAGS_ISAPI', '/DEF:sapi\\isapi\\php7isapi.def'); } } diff --git a/sapi/isapi/php5isapi.dsp b/sapi/isapi/php5isapi.dsp deleted file mode 100644 index 3dbab11eff..0000000000 --- a/sapi/isapi/php5isapi.dsp +++ /dev/null @@ -1,165 +0,0 @@ -# Microsoft Developer Studio Project File - Name="php5isapi" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php5isapi - 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 "php5isapi.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 "php5isapi.mak" CFG="php5isapi - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php5isapi - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5isapi - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5isapi - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5isapi - 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)" == "php5isapi - 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 "PHP5ISAPI_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 "PHP5ISAPI_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 php5ts_debug.lib /nologo /version:4.0 /dll /debug /machine:I386 /nodefaultlib:"libcmt" /pdbtype:sept /libpath:"..\..\Debug_TS"
-
-!ELSEIF "$(CFG)" == "php5isapi - 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 "PHP5ISAPI_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 "PHP5ISAPI_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 php5ts.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"..\..\Release_TS"
-
-!ELSEIF "$(CFG)" == "php5isapi - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php5isapi___Win32_Release_TS_inline"
-# PROP BASE Intermediate_Dir "php5isapi___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 "PHP5ISAPI_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 "PHP5ISAPI_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 php5ts.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 php5ts.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"..\..\Release_TS_inline"
-
-!ELSEIF "$(CFG)" == "php5isapi - Win32 Release_TSDbg"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php5isapi___Win32_Release_TSDbg"
-# PROP BASE Intermediate_Dir "php5isapi___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 "PHP5ISAPI_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 "PHP5ISAPI_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 php5ts.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 php5ts.lib /nologo /version:4.0 /dll /debug /machine:I386 /libpath:"..\..\Release_TSDbg"
-
-!ENDIF
-
-# Begin Target
-
-# Name "php5isapi - Win32 Debug_TS"
-# Name "php5isapi - Win32 Release_TS"
-# Name "php5isapi - Win32 Release_TS_inline"
-# Name "php5isapi - Win32 Release_TSDbg"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\php5isapi.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\php5isapi.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/php5isapi.c b/sapi/isapi/php7isapi.c index 5d748505b8..627c20c18c 100644 --- a/sapi/isapi/php5isapi.c +++ b/sapi/isapi/php7isapi.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -48,9 +48,9 @@ #define PHP_ENABLE_SEH #endif -/* -uncomment the following lines to turn off -exception trapping when running under a debugger +/* +uncomment the following lines to turn off +exception trapping when running under a debugger #ifdef _DEBUG #undef PHP_ENABLE_SEH @@ -138,7 +138,7 @@ static char *isapi_secure_server_variable_names[] = { "SSL_CLIENT_I_O", "SSL_CLIENT_I_L", "SSL_CLIENT_I_ST", - "SSL_CLIENT_I_C", + "SSL_CLIENT_I_C", #endif NULL }; @@ -202,11 +202,11 @@ static zend_module_entry php_isapi_module = { }; -static int sapi_isapi_ub_write(const char *str, uint str_length TSRMLS_DC) +static int sapi_isapi_ub_write(const char *str, uint str_length) { 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(); @@ -215,20 +215,20 @@ static int sapi_isapi_ub_write(const char *str, uint str_length TSRMLS_DC) } -static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) { return SAPI_HEADER_ADD; } -static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length TSRMLS_DC) +static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length) { *total_length += sapi_header->header_len+2; } -static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr TSRMLS_DC) +static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr) { memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len); *combined_headers_ptr += sapi_header->header_len; @@ -239,7 +239,7 @@ static void concat_header(sapi_header_struct *sapi_header, char **combined_heade } -static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers) { uint total_length = 2; /* account for the trailing \r\n */ char *combined_headers, *combined_headers_ptr; @@ -250,19 +250,19 @@ static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* 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); + sapi_get_default_content_type_header(&default_content_type); + accumulate_header_length(&default_content_type, (void *) &total_length); } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) accumulate_header_length, (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); /* 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); + concat_header(&default_content_type, (void *) &combined_headers_ptr); 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); + zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) concat_header, (void *) &combined_headers_ptr); *combined_headers_ptr++ = '\r'; *combined_headers_ptr++ = '\n'; *combined_headers_ptr = 0; @@ -280,7 +280,7 @@ static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) default: { const char *sline = SG(sapi_headers).http_status_line; int sline_len; - + /* httpd requires that r->status_line is set to the first digit of * the status-code: */ if (sline && ((sline_len = strlen(sline)) > 12) && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ') { @@ -324,7 +324,7 @@ static int php_isapi_startup(sapi_module_struct *sapi_module) } -static int sapi_isapi_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static int sapi_isapi_read_post(char *buffer, uint count_bytes) { LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); DWORD read_from_buf=0; @@ -354,7 +354,7 @@ static int sapi_isapi_read_post(char *buffer, uint count_bytes TSRMLS_DC) } -static char *sapi_isapi_read_cookies(TSRMLS_D) +static char *sapi_isapi_read_cookies(void) { LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; @@ -378,7 +378,7 @@ static char *sapi_isapi_read_cookies(TSRMLS_D) #ifdef WITH_ZEUS -static void sapi_isapi_register_zeus_ssl_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array TSRMLS_DC) +static void sapi_isapi_register_zeus_ssl_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array) { char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; @@ -396,8 +396,8 @@ static void sapi_isapi_register_zeus_ssl_variables(LPEXTENSION_CONTROL_BLOCK lpE if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_ST", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); } - php_register_variable( "SSL_CLIENT_DN", static_cons_buf, track_vars_array TSRMLS_CC ); - + php_register_variable( "SSL_CLIENT_DN", static_cons_buf, track_vars_array ); + 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] ) { @@ -408,10 +408,10 @@ static void sapi_isapi_register_zeus_ssl_variables(LPEXTENSION_CONTROL_BLOCK lpE if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_I_ST", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); } - php_register_variable( "SSL_CLIENT_I_DN", static_cons_buf, track_vars_array TSRMLS_CC ); + php_register_variable( "SSL_CLIENT_I_DN", static_cons_buf, track_vars_array ); } -static void sapi_isapi_register_zeus_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array TSRMLS_DC) +static void sapi_isapi_register_zeus_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array) { char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; @@ -430,11 +430,11 @@ static void sapi_isapi_register_zeus_variables(LPEXTENSION_CONTROL_BLOCK lpECB, 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 ); + php_register_variable( "PHP_SELF", static_variable_buf, track_vars_array ); /* 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 ); + php_register_variable( "PATH_INFO", static_variable_buf + scriptname_len - 1, track_vars_array ); /* 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... */ @@ -442,8 +442,8 @@ static void sapi_isapi_register_zeus_variables(LPEXTENSION_CONTROL_BLOCK lpECB, 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 ); + php_register_variable( "URL", static_variable_buf, track_vars_array ); + php_register_variable( "REQUEST_URI", static_variable_buf, track_vars_array ); } } @@ -451,37 +451,37 @@ static void sapi_isapi_register_zeus_variables(LPEXTENSION_CONTROL_BLOCK lpECB, 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 ); + php_register_variable( "PATH_TRANSLATED", static_variable_buf, track_vars_array ); } /* 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 ); + php_register_variable( "PHP_AUTH_USER", static_variable_buf, track_vars_array ); } 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 ); + php_register_variable( "PHP_AUTH_PW", static_variable_buf, track_vars_array ); } 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( "AUTH_TYPE", static_variable_buf, track_vars_array TSRMLS_CC ); + php_register_variable( "AUTH_TYPE", static_variable_buf, track_vars_array ); } - + /* 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 ); + sapi_isapi_register_zeus_ssl_variables( lpECB, track_vars_array ); } /* 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 ); + php_register_variable( "SERVER_SIGNATURE", static_variable_buf, track_vars_array ); } } #else -static void sapi_isapi_register_iis_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array TSRMLS_DC) +static void sapi_isapi_register_iis_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array) { char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; char path_info_buf[ISAPI_SERVER_VAR_BUF_SIZE]; @@ -494,7 +494,7 @@ static void sapi_isapi_register_iis_variables(LPEXTENSION_CONTROL_BLOCK lpECB, z * belongs in PHP's version of PATH_INFO. SCRIPT_NAME also becomes PHP_SELF. */ lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &scriptname_len); - php_register_variable("SCRIPT_FILENAME", SG(request_info).path_translated, track_vars_array TSRMLS_CC); + php_register_variable("SCRIPT_FILENAME", SG(request_info).path_translated, track_vars_array); /* Adjust IIS' version of PATH_INFO, set PHP_SELF, * and generate REQUEST_URI @@ -503,10 +503,10 @@ static void sapi_isapi_register_iis_variables(LPEXTENSION_CONTROL_BLOCK lpECB, z if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_INFO", static_variable_buf, &variable_len) && static_variable_buf[0] ) { /* Chop off filename to get just the 'real' PATH_INFO' */ - php_register_variable( "ORIG_PATH_INFO", static_variable_buf, track_vars_array TSRMLS_CC ); + php_register_variable( "ORIG_PATH_INFO", static_variable_buf, track_vars_array ); pathinfo_len = variable_len - scriptname_len; strncpy(path_info_buf, static_variable_buf + scriptname_len - 1, sizeof(path_info_buf)-1); - php_register_variable( "PATH_INFO", path_info_buf, track_vars_array TSRMLS_CC ); + php_register_variable( "PATH_INFO", path_info_buf, track_vars_array ); /* 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... */ @@ -514,19 +514,19 @@ static void sapi_isapi_register_iis_variables(LPEXTENSION_CONTROL_BLOCK lpECB, z 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 ); + php_register_variable( "URL", static_variable_buf, track_vars_array ); + php_register_variable( "REQUEST_URI", static_variable_buf, track_vars_array ); } variable_len = ISAPI_SERVER_VAR_BUF_SIZE; if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_TRANSLATED", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "ORIG_PATH_TRANSLATED", static_variable_buf, track_vars_array TSRMLS_CC ); + php_register_variable( "ORIG_PATH_TRANSLATED", static_variable_buf, track_vars_array ); } if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, path_info_buf, &pathinfo_len, (LPDWORD) &humi)) { /* Remove trailing \ */ if (humi.lpszPath[variable_len-2] == '\\') { humi.lpszPath[variable_len-2] = 0; } - php_register_variable("PATH_TRANSLATED", humi.lpszPath, track_vars_array TSRMLS_CC); + php_register_variable("PATH_TRANSLATED", humi.lpszPath, track_vars_array); } } @@ -538,28 +538,28 @@ static void sapi_isapi_register_iis_variables(LPEXTENSION_CONTROL_BLOCK lpECB, z if (humi.lpszPath[variable_len-2] == '\\') { humi.lpszPath[variable_len-2] = 0; } - php_register_variable("DOCUMENT_ROOT", humi.lpszPath, track_vars_array TSRMLS_CC); + php_register_variable("DOCUMENT_ROOT", humi.lpszPath, track_vars_array); } - if (!SG(request_info).auth_user || !SG(request_info).auth_password || + if (!SG(request_info).auth_user || !SG(request_info).auth_password || !SG(request_info).auth_user[0] || !SG(request_info).auth_password[0]) { variable_len = ISAPI_SERVER_VAR_BUF_SIZE; if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_AUTHORIZATION", static_variable_buf, &variable_len) && static_variable_buf[0]) { - php_handle_auth_data(static_variable_buf TSRMLS_CC); + php_handle_auth_data(static_variable_buf); } } if (SG(request_info).auth_user) { - php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, track_vars_array TSRMLS_CC ); + php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, track_vars_array ); } if (SG(request_info).auth_password) { - php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, track_vars_array TSRMLS_CC ); + php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, track_vars_array ); } } #endif -static void sapi_isapi_register_server_variables2(char **server_variables, LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array, char **recorded_values TSRMLS_DC) +static void sapi_isapi_register_server_variables2(char **server_variables, LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array, char **recorded_values) { char **p=server_variables; DWORD variable_len; @@ -570,7 +570,7 @@ static void sapi_isapi_register_server_variables2(char **server_variables, LPEXT 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); + php_register_variable(*p, static_variable_buf, track_vars_array); if (recorded_values) { recorded_values[p-server_variables] = estrndup(static_variable_buf, variable_len); } @@ -578,7 +578,7 @@ static void sapi_isapi_register_server_variables2(char **server_variables, LPEXT 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); + php_register_variable(*p, variable_buf, track_vars_array); } if (recorded_values) { recorded_values[p-server_variables] = variable_buf; @@ -586,14 +586,14 @@ static void sapi_isapi_register_server_variables2(char **server_variables, LPEXT efree(variable_buf); } } else { /* for compatibility with Apache SAPIs */ - php_register_variable(*p, "", track_vars_array TSRMLS_CC); + php_register_variable(*p, "", track_vars_array); } p++; } } -static void sapi_isapi_register_server_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_isapi_register_server_variables(zval *track_vars_array) { DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; char *variable; @@ -605,20 +605,20 @@ static void sapi_isapi_register_server_variables(zval *track_vars_array TSRMLS_D /* 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); + sapi_isapi_register_server_variables2(isapi_special_server_variable_names, lpECB, track_vars_array, isapi_special_server_variables); if (SG(request_info).cookie_data) { - php_register_variable("HTTP_COOKIE", SG(request_info).cookie_data, track_vars_array TSRMLS_CC); + php_register_variable("HTTP_COOKIE", SG(request_info).cookie_data, track_vars_array); } /* Register the standard ISAPI variables */ - sapi_isapi_register_server_variables2(isapi_server_variable_names, lpECB, track_vars_array, NULL TSRMLS_CC); + sapi_isapi_register_server_variables2(isapi_server_variable_names, lpECB, track_vars_array, NULL); if (isapi_special_server_variables[SPECIAL_VAR_HTTPS] && (atoi(isapi_special_server_variables[SPECIAL_VAR_HTTPS]) || !strcasecmp(isapi_special_server_variables[SPECIAL_VAR_HTTPS], "on")) ) { /* Register SSL ISAPI variables */ - sapi_isapi_register_server_variables2(isapi_secure_server_variable_names, lpECB, track_vars_array, NULL TSRMLS_CC); + sapi_isapi_register_server_variables2(isapi_secure_server_variable_names, lpECB, track_vars_array, NULL); } if (isapi_special_server_variables[SPECIAL_VAR_HTTPS]) { @@ -627,14 +627,14 @@ static void sapi_isapi_register_server_variables(zval *track_vars_array TSRMLS_D #ifdef WITH_ZEUS - sapi_isapi_register_zeus_variables(lpECB, track_vars_array TSRMLS_CC); + sapi_isapi_register_zeus_variables(lpECB, track_vars_array); #else - sapi_isapi_register_iis_variables(lpECB, track_vars_array TSRMLS_CC); + sapi_isapi_register_iis_variables(lpECB, track_vars_array); #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); + php_register_variable("PHP_SELF", isapi_special_server_variables[SPECIAL_VAR_PHP_SELF], track_vars_array); efree(isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]); } @@ -651,7 +651,7 @@ static void sapi_isapi_register_server_variables(zval *track_vars_array TSRMLS_D value++; } *colon = 0; - php_register_variable(variable, value, track_vars_array TSRMLS_CC); + php_register_variable(variable, value, track_vars_array); *colon = ':'; } variable = php_strtok_r(NULL, "\r\n", &strtok_buf); @@ -664,7 +664,7 @@ static void sapi_isapi_register_server_variables(zval *track_vars_array TSRMLS_D static sapi_module_struct isapi_sapi_module = { "isapi", /* name */ "ISAPI", /* pretty name */ - + php_isapi_startup, /* startup */ php_module_shutdown_wrapper, /* shutdown */ @@ -706,7 +706,6 @@ BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pFilterVersion) DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LPVOID pvNotification) { - TSRMLS_FETCH(); switch (notificationType) { case SF_NOTIFY_PREPROC_HEADERS: @@ -720,7 +719,7 @@ DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LP 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); } @@ -732,7 +731,7 @@ DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LP } -static void init_request_info(LPEXTENSION_CONTROL_BLOCK lpECB TSRMLS_DC) +static void init_request_info(LPEXTENSION_CONTROL_BLOCK lpECB) { DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; @@ -756,7 +755,7 @@ static void init_request_info(LPEXTENSION_CONTROL_BLOCK lpECB TSRMLS_DC) */ if(lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_FILENAME", static_variable_buf, &variable_len)) { SG(request_info).path_translated = estrdup(static_variable_buf); - } else + } else #else /* happily, IIS gives us SCRIPT_NAME which is correct (without PATH_INFO stuff) so we can just map that to the physical path and we have our filename */ @@ -764,7 +763,7 @@ static void init_request_info(LPEXTENSION_CONTROL_BLOCK lpECB TSRMLS_DC) lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &variable_len); if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, static_variable_buf, &variable_len, (LPDWORD) &humi)) { SG(request_info).path_translated = estrdup(humi.lpszPath); - } else + } else #endif /* if mapping fails, default to what the server tells us */ SG(request_info).path_translated = estrdup(lpECB->lpszPathTranslated); @@ -779,7 +778,7 @@ static void init_request_info(LPEXTENSION_CONTROL_BLOCK lpECB TSRMLS_DC) } -static void php_isapi_report_exception(char *message, int message_len TSRMLS_DC) +static void php_isapi_report_exception(char *message, int message_len) { if (!SG(headers_sent)) { HSE_SEND_HEADER_EX_INFO header_info; @@ -794,7 +793,7 @@ static void php_isapi_report_exception(char *message, int message_len TSRMLS_DC) 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); + sapi_isapi_ub_write(message, message_len); } @@ -838,16 +837,15 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) #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); + init_request_info(lpECB); SG(server_context) = lpECB; - php_request_startup(TSRMLS_C); + php_request_startup(); file_handle.filename = SG(request_info).path_translated; file_handle.free_filename = 0; @@ -856,13 +854,13 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) /* open the script here so we can 404 if it fails */ if (file_handle.filename) - retval = php_fopen_primary_script(&file_handle TSRMLS_CC); + retval = php_fopen_primary_script(&file_handle); if (!file_handle.filename || retval == FAILURE) { SG(sapi_headers).http_response_code = 404; PUTS("No input file specified.\n"); } else { - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); } if (SG(request_info).cookie_data) { @@ -902,14 +900,14 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) CG(unclean_shutdown)=1; _snprintf(buf, sizeof(buf)-1,"PHP has encountered a Stack overflow"); - php_isapi_report_exception(buf, strlen(buf) TSRMLS_CC); + php_isapi_report_exception(buf, strlen(buf)); } 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); + php_isapi_report_exception(buf, strlen(buf)); 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); + php_isapi_report_exception(buf, strlen(buf)); my_endthread(); } } diff --git a/sapi/isapi/php5isapi.def b/sapi/isapi/php7isapi.def index 596023ef55..596023ef55 100644 --- a/sapi/isapi/php5isapi.def +++ b/sapi/isapi/php7isapi.def diff --git a/sapi/isapi/stresstest/getopt.c b/sapi/isapi/stresstest/getopt.c index 57faa0f890..21056bf883 100644 --- a/sapi/isapi/stresstest/getopt.c +++ b/sapi/isapi/stresstest/getopt.c @@ -41,7 +41,7 @@ ap_optiserr(int argc, char * const *argv, int oint, const char *optstr, ap_optopt = argv[oint][optchr]; return('?'); } - + int ap_getopt(int argc, char* const *argv, const char *optstr) { static int optchr = 0; @@ -98,7 +98,7 @@ int ap_getopt(int argc, char* const *argv, const char *optstr) } if (cp[1] == ':') { - /* Check for cases where the value of the argument + /* 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]) { diff --git a/sapi/isapi/stresstest/getopt.h b/sapi/isapi/stresstest/getopt.h index a3e278e3a6..6d4139bfe0 100644 --- a/sapi/isapi/stresstest/getopt.h +++ b/sapi/isapi/stresstest/getopt.h @@ -9,4 +9,4 @@ int ap_getopt(int argc, char* const *argv, const char *optstr); #ifdef __cplusplus } -#endif
\ No newline at end of file +#endif diff --git a/sapi/isapi/stresstest/notes.txt b/sapi/isapi/stresstest/notes.txt index f58ab3c0e9..e6d10dd486 100644 --- a/sapi/isapi/stresstest/notes.txt +++ b/sapi/isapi/stresstest/notes.txt @@ -44,7 +44,7 @@ Run: stresstest L files.txt 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:\php5-source +Run: stresstest T c:\php7-source diff --git a/sapi/isapi/stresstest/stresstest.cpp b/sapi/isapi/stresstest/stresstest.cpp index 9a5964a6ba..ddb06473c2 100644 --- a/sapi/isapi/stresstest/stresstest.cpp +++ b/sapi/isapi/stresstest/stresstest.cpp @@ -84,9 +84,9 @@ char * GetEnv(char *); DWORD CALLBACK IsapiThread(void *); -int stress_main(const char *filename, - const char *arg, - const char *postfile, +int stress_main(const char *filename, + const char *arg, + const char *postfile, const char *matchdata); @@ -354,7 +354,7 @@ BOOL ParseTestFile(const char *path, const char *fn) fputs(line, fe); break; } - } + } fclose(fp); fclose(ft); @@ -520,16 +520,16 @@ int main(int argc, char* argv[]) hDll = LoadLibrary(module); // Load our DLL if (!hDll) { - FormatMessage( + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, - NULL + NULL ); - fprintf(stderr,"Error: Dll 'php5isapi.dll' not found -%d\n%s\n", GetLastError(), lpMsgBuf); + fprintf(stderr,"Error: Dll 'php7isapi.dll' not found -%d\n%s\n", GetLastError(), lpMsgBuf); free (module); free(filelist); LocalFree( lpMsgBuf ); @@ -553,7 +553,7 @@ int main(int argc, char* argv[]) free(filelist); return -1; } - TerminateExtensionProc = (TerminateProc) GetProcAddress(hDll, + TerminateExtensionProc = (TerminateProc) GetProcAddress(hDll, "TerminateExtension"); // This should really check if the version information matches what we @@ -568,7 +568,7 @@ int main(int argc, char* argv[]) if (bUseTestFiles) { char TestPath[MAX_PATH]; - if (filelist != NULL) + if (filelist != NULL) _snprintf(TestPath, sizeof(TestPath)-1, "%s\\tests", filelist); else strcpy(TestPath, "tests"); DoTestFiles(TestPath, environment); @@ -598,8 +598,8 @@ DWORD CALLBACK IsapiThread(void *p) // execute each file CString testname = TestNames.GetAt(i); BOOL ok = FALSE; - if (stress_main(IsapiFileList.GetAt(i), - IsapiGetData.GetAt(i), + if (stress_main(IsapiFileList.GetAt(i), + IsapiGetData.GetAt(i), IsapiPostData.GetAt(i), IsapiMatchData.GetAt(i))) { InterlockedIncrement(&Results[i].ok); @@ -629,10 +629,10 @@ DWORD CALLBACK IsapiThread(void *p) * the DLL to load. There is no recompilation required. * * ======================================================================= * */ -BOOL stress_main(const char *filename, - const char *arg, +BOOL stress_main(const char *filename, + const char *arg, const char *postdata, - const char *matchdata) + const char *matchdata) { EXTENSION_CONTROL_BLOCK ECB; @@ -660,8 +660,8 @@ BOOL stress_main(const char *filename, fprintf(stderr,"Fill Ext Block Failed\n"); return -1; } - - // check for command line argument, + + // check for command line argument, // first arg = filename // this is added for testing php from command line @@ -718,7 +718,7 @@ BOOL stress_main(const char *filename, DeleteFile(fname); return ok; - + } // // GetServerVariable() is how the DLL calls the main program to figure out @@ -764,7 +764,7 @@ BOOL WINAPI ReadClient(HCONN hConn, LPVOID lpBuffer, LPDWORD lpdwSize) { TIsapiContext *c = (TIsapiContext *)hConn; if (!c) return FALSE; - if (c->in != INVALID_HANDLE_VALUE) + if (c->in != INVALID_HANDLE_VALUE) return ReadFile(c->in, lpBuffer, (*lpdwSize), lpdwSize, NULL); return FALSE; @@ -782,7 +782,7 @@ BOOL WINAPI WriteClient(HCONN hConn, LPVOID lpBuffer, LPDWORD lpdwSize, return FALSE; } // -// This is a special callback function used by the DLL for certain extra +// 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, @@ -801,16 +801,16 @@ BOOL WINAPI ServerSupportFunction(HCONN hConn, DWORD dwHSERequest, 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); @@ -828,7 +828,7 @@ BOOL WINAPI ServerSupportFunction(HCONN hConn, DWORD dwHSERequest, SetEvent(c->waitEvent); //ExitThread(0); break; - + // // This sends a redirect (temporary) to the client. // The header construction is similar to RESPONSE_HEADER above. @@ -851,7 +851,7 @@ BOOL WINAPI ServerSupportFunction(HCONN hConn, DWORD dwHSERequest, break; } return bRet; - + } // // Makes a string of the date and time from GetSystemTime(). @@ -877,7 +877,7 @@ char * MakeDateStr(void){ return szDate; } // -// Fill the ECB up +// Fill the ECB up // BOOL WINAPI FillExtensionControlBlock(EXTENSION_CONTROL_BLOCK *ECB, TIsapiContext *context) { @@ -915,18 +915,18 @@ BOOL WINAPI FillExtensionControlBlock(EXTENSION_CONTROL_BLOCK *ECB, TIsapiContex // 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 ""; 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/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index 92a371d560..2b2385ccdf 100644 --- a/sapi/litespeed/lsapi_main.c +++ b/sapi/litespeed/lsapi_main.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -126,7 +126,7 @@ static void sapi_lsapi_ini_defaults(HashTable *configuration_hash) /* {{{ sapi_lsapi_ub_write */ -static int sapi_lsapi_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t sapi_lsapi_ub_write(const char *str, size_t str_length) { int ret; int remain; @@ -155,7 +155,7 @@ static int sapi_lsapi_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ sapi_lsapi_flush */ -static void sapi_lsapi_flush( void * server_context TSRMLS_DC ) +static void sapi_lsapi_flush( void * server_context ) { if ( lsapi_mode ) { if ( LSAPI_Flush() == -1) { @@ -168,7 +168,7 @@ static void sapi_lsapi_flush( void * server_context TSRMLS_DC ) /* {{{ sapi_lsapi_deactivate */ -static int sapi_lsapi_deactivate(TSRMLS_D) +static int sapi_lsapi_deactivate(void) { if ( SG(request_info).path_translated ) { @@ -184,7 +184,7 @@ static int sapi_lsapi_deactivate(TSRMLS_D) /* {{{ sapi_lsapi_getenv */ -static char *sapi_lsapi_getenv( char * name, size_t name_len TSRMLS_DC ) +static char *sapi_lsapi_getenv( char * name, size_t name_len ) { if ( lsapi_mode ) { return LSAPI_GetEnv( name ); @@ -206,10 +206,10 @@ static int add_variable( const char * pKey, int keyLen, const char * pValue, int #else int filter_arg = (arg == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER; #endif - char * new_val = (char *) pValue; - unsigned int new_val_len; + char * new_val = (char *) pValue; + size_t new_val_len; - if (sapi_module.input_filter(filter_arg, (char *)pKey, &new_val, valLen, &new_val_len TSRMLS_CC)) { + if (sapi_module.input_filter(filter_arg, (char *)pKey, &new_val, valLen, &new_val_len)) { php_register_variable_safe((char *)pKey, new_val, new_val_len, (zval *)arg ); } return 1; @@ -236,7 +236,7 @@ static int add_variable( const char * pKey, int keyLen, const char * pValue, int } */ -static void litespeed_php_import_environment_variables(zval *array_ptr TSRMLS_DC) +static void litespeed_php_import_environment_variables(zval *array_ptr) { char buf[128]; char **env, *p, *t = buf; @@ -295,68 +295,35 @@ static void litespeed_php_import_environment_variables(zval *array_ptr TSRMLS_DC } memcpy(t, *env, nlen); t[nlen] = '\0'; - add_variable(t, nlen, p + 1, strlen( p + 1 ), array_ptr TSRMLS_CC); + add_variable(t, nlen, p + 1, strlen( p + 1 ), array_ptr); } if (t != buf && t != NULL) { efree(t); } } - -#if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || PHP_MAJOR_VERSION < 5) -static int add_variable_magic_quote( const char * pKey, int keyLen, const char * pValue, int valLen, - void * arg ) -{ - zval * gpc_element, **gpc_element_p; - HashTable * symtable1 = Z_ARRVAL_P((zval * )arg); - register char * pKey1 = (char *)pKey; - - MAKE_STD_ZVAL(gpc_element); - Z_STRLEN_P( gpc_element ) = valLen; - Z_STRVAL_P( gpc_element ) = php_addslashes((char *)pValue, valLen, &Z_STRLEN_P( gpc_element ), 0 ); - Z_TYPE_P( gpc_element ) = IS_STRING; -#if PHP_MAJOR_VERSION > 4 - zend_symtable_update( symtable1, pKey1, keyLen + 1, &gpc_element, sizeof( zval *), (void **) &gpc_element_p ); -#else - zend_hash_update( symtable1, pKey1, keyLen + 1, &gpc_element, sizeof( zval *), (void **) &gpc_element_p ); -#endif - return 1; -} - -#endif - /* {{{ sapi_lsapi_register_variables */ -static void sapi_lsapi_register_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_lsapi_register_variables(zval *track_vars_array) { char * php_self = ""; if ( lsapi_mode ) { if ( (SG(request_info).request_uri ) ) php_self = (SG(request_info).request_uri ); - litespeed_php_import_environment_variables(track_vars_array TSRMLS_CC); + litespeed_php_import_environment_variables(track_vars_array); -#if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || PHP_MAJOR_VERSION < 5) - if (!PG(magic_quotes_gpc)) { -#endif - LSAPI_ForeachHeader( add_variable, track_vars_array ); - LSAPI_ForeachEnv( add_variable, track_vars_array ); - add_variable("PHP_SELF", 8, php_self, strlen( php_self ), track_vars_array ); -#if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || PHP_MAJOR_VERSION < 5) - } else { - LSAPI_ForeachHeader( add_variable_magic_quote, track_vars_array ); - LSAPI_ForeachEnv( add_variable_magic_quote, track_vars_array ); - add_variable_magic_quote("PHP_SELF", 8, php_self, strlen( php_self ), track_vars_array ); - } -#endif + LSAPI_ForeachHeader( add_variable, track_vars_array ); + LSAPI_ForeachEnv( add_variable, track_vars_array ); + add_variable("PHP_SELF", 8, php_self, strlen( php_self ), track_vars_array ); } else { - php_import_environment_variables(track_vars_array TSRMLS_CC); + php_import_environment_variables(track_vars_array); - php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC); - php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC); - php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC); - php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC); - php_register_variable("DOCUMENT_ROOT", "", track_vars_array TSRMLS_CC); + php_register_variable("PHP_SELF", php_self, track_vars_array); + php_register_variable("SCRIPT_NAME", php_self, track_vars_array); + php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array); + php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array); + php_register_variable("DOCUMENT_ROOT", "", track_vars_array); } } @@ -365,7 +332,7 @@ static void sapi_lsapi_register_variables(zval *track_vars_array TSRMLS_DC) /* {{{ sapi_lsapi_read_post */ -static int sapi_lsapi_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static size_t sapi_lsapi_read_post(char *buffer, size_t count_bytes) { if ( lsapi_mode ) { return LSAPI_ReadReqBody( buffer, (unsigned long long)count_bytes ); @@ -380,7 +347,7 @@ static int sapi_lsapi_read_post(char *buffer, uint count_bytes TSRMLS_DC) /* {{{ sapi_lsapi_read_cookies */ -static char *sapi_lsapi_read_cookies(TSRMLS_D) +static char *sapi_lsapi_read_cookies(void) { if ( lsapi_mode ) { return LSAPI_GetHeader( H_COOKIE ); @@ -393,7 +360,7 @@ static char *sapi_lsapi_read_cookies(TSRMLS_D) /* {{{ sapi_lsapi_send_headers */ -static int sapi_lsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_lsapi_send_headers(sapi_headers_struct *sapi_headers) { sapi_header_struct *h; zend_llist_position pos; @@ -412,7 +379,7 @@ static int sapi_lsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) int len; char headerBuf[SAPI_LSAPI_MAX_HEADER_LENGTH]; - hd = sapi_get_default_content_type(TSRMLS_C); + hd = sapi_get_default_content_type(); len = snprintf( headerBuf, SAPI_LSAPI_MAX_HEADER_LENGTH - 1, "Content-type: %s", hd ); efree(hd); @@ -430,7 +397,7 @@ static int sapi_lsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ sapi_lsapi_send_headers */ -static void sapi_lsapi_log_message(char *message TSRMLS_DC) +static void sapi_lsapi_log_message(char *message) { char buf[8192]; int len = strlen( message ); @@ -489,11 +456,11 @@ static sapi_module_struct lsapi_sapi_module = }; /* }}} */ -static int init_request_info( TSRMLS_D ) +static void init_request_info( void ) { char * pContentType = LSAPI_GetHeader( H_CONTENT_TYPE ); char * pAuth; - + SG(request_info).content_type = pContentType ? pContentType : ""; SG(request_info).request_method = LSAPI_GetRequestMethod(); SG(request_info).query_string = LSAPI_GetQueryString(); @@ -503,9 +470,9 @@ static int init_request_info( TSRMLS_D ) /* It is not reset by zend engine, set it to 200. */ SG(sapi_headers).http_response_code = 200; - + pAuth = LSAPI_GetHeader( H_AUTHORIZATION ); - php_handle_auth_data(pAuth TSRMLS_CC); + php_handle_auth_data(pAuth); } static char s_cur_chdir[4096] = ""; @@ -532,7 +499,7 @@ static int lsapi_chdir_primary_script( zend_file_handle * file_handle ) if ( !CWDG(cwd).cwd || ( strcmp( file_handle->filename, CWDG(cwd).cwd ) != 0 ) ) { CWDG(cwd).cwd_length = p - file_handle->filename; - CWDG(cwd).cwd = (char *) realloc(CWDG(cwd).cwd, CWDG(cwd).cwd_length+1); + CWDG(cwd).cwd = (char *) realloc(CWDG(cwd).cwd, CWDG(cwd).cwd_length+1); memmove( CWDG(cwd).cwd, file_handle->filename, CWDG(cwd).cwd_length+1 ); } *p = ch; @@ -564,7 +531,7 @@ static int lsapi_fopen_primary_script( zend_file_handle * file_handle ) return 0; } -static int lsapi_execute_script( zend_file_handle * file_handle TSRMLS_DC) +static int lsapi_execute_script( zend_file_handle * file_handle) { char *p; int len; @@ -583,26 +550,26 @@ static int lsapi_execute_script( zend_file_handle * file_handle TSRMLS_DC) len = 0; memccpy( p, SG(request_info).path_translated + len, 0, 46 ); - php_execute_script(file_handle TSRMLS_CC); + php_execute_script(file_handle); return 0; } -static int lsapi_module_main(int show_source TSRMLS_DC) +static int lsapi_module_main(int show_source) { zend_file_handle file_handle = {0}; - if (php_request_startup(TSRMLS_C) == FAILURE ) { + if (php_request_startup() == FAILURE ) { return -1; } if (show_source) { zend_syntax_highlighter_ini syntax_highlighter_ini; php_get_highlight_struct(&syntax_highlighter_ini); - highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC); + highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini); } else { - lsapi_execute_script( &file_handle TSRMLS_CC); + lsapi_execute_script( &file_handle); } zend_try { php_request_shutdown(NULL); @@ -616,7 +583,7 @@ static int alter_ini( const char * pKey, int keyLen, const char * pValue, int va void * arg ) { #if PHP_MAJOR_VERSION >= 7 - zend_string * psKey; + zend_string * psKey; #endif int type = ZEND_INI_PERDIR; if ( '\001' == *pKey ) { @@ -634,15 +601,15 @@ static int alter_ini( const char * pKey, int keyLen, const char * pValue, int va else { #if PHP_MAJOR_VERSION >= 7 - psKey = STR_INIT( pKey, keyLen, 1 ); - zend_alter_ini_entry(psKey, + psKey = zend_string_init(pKey, keyLen, 1); + zend_alter_ini_entry_chars(psKey, (char *)pValue, valLen, type, PHP_INI_STAGE_ACTIVATE); - STR_RELEASE( psKey ); + zend_string_release(psKey); #else zend_alter_ini_entry((char *)pKey, keyLen, (char *)pValue, valLen, - type, PHP_INI_STAGE_ACTIVATE); + type, PHP_INI_STAGE_ACTIVATE); #endif } } @@ -658,7 +625,7 @@ static void override_ini() } -static int processReq( TSRMLS_D ) +static int processReq( void ) { int ret = 0; zend_first_try { @@ -670,9 +637,9 @@ static int processReq( TSRMLS_D ) override_ini(); if ( engine ) { - init_request_info( TSRMLS_C ); + init_request_info( ); - if ( lsapi_module_main( source_highlight TSRMLS_CC ) == -1 ) { + if ( lsapi_module_main( source_highlight ) == -1 ) { ret = -1; } } else { @@ -684,7 +651,7 @@ static int processReq( TSRMLS_D ) return ret; } -static void cli_usage( TSRMLS_D ) +static void cli_usage( void ) { static const char * usage = "Usage: php\n" @@ -705,12 +672,12 @@ static void cli_usage( TSRMLS_D ) "\n" " args... Arguments passed to script.\n"; php_output_startup(); - php_output_activate(TSRMLS_C); + php_output_activate(); php_printf( "%s", usage ); #ifdef PHP_OUTPUT_NEWAPI - php_output_end_all(TSRMLS_C); + php_output_end_all(); #else - php_end_ob_buffers(1 TSRMLS_CC); + php_end_ob_buffers(1); #endif } @@ -731,7 +698,7 @@ static int parse_opt( int argc, char * argv[], int *climode, } *php_bind = strdup(*p++); break; - + case 'c': if ( p >= argend ) { fprintf( stderr, "<path> or <file> must be specified following '-c' option.\n"); @@ -786,7 +753,7 @@ static int cli_main( int argc, char * argv[] ) int ret = -1; int c; #if PHP_MAJOR_VERSION >= 7 - zend_string * psKey; + zend_string * psKey; #endif lsapi_mode = 0; /* enter CLI mode */ @@ -807,11 +774,11 @@ static int cli_main( int argc, char * argv[] ) #endif for( ini = ini_defaults; *ini; ini+=2 ) { #if PHP_MAJOR_VERSION >= 7 - psKey = STR_INIT( *ini, strlen( *ini ), 1 ); - zend_alter_ini_entry( psKey, + psKey = zend_string_init(*ini, strlen( *ini ), 1); + zend_alter_ini_entry_chars(psKey, (char *)*(ini+1), strlen( *(ini+1) ), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); - STR_RELEASE( psKey ); + zend_string_release(psKey); #else zend_alter_ini_entry( (char *)*ini, strlen( *ini )+1, (char *)*(ini+1), strlen( *(ini+1) ), @@ -826,28 +793,28 @@ static int cli_main( int argc, char * argv[] ) case 'q': break; case 'i': - if (php_request_startup(TSRMLS_C) != FAILURE) { - php_print_info(0xFFFFFFFF TSRMLS_CC); + if (php_request_startup() != FAILURE) { + php_print_info(0xFFFFFFFF); #ifdef PHP_OUTPUT_NEWAPI - php_output_end_all(TSRMLS_C); + php_output_end_all(); #else - php_end_ob_buffers(1 TSRMLS_CC); + php_end_ob_buffers(1); #endif php_request_shutdown( NULL ); ret = 0; } break; case 'v': - if (php_request_startup(TSRMLS_C) != FAILURE) { + if (php_request_startup() != FAILURE) { #if ZEND_DEBUG php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2015 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #else php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2015 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #endif #ifdef PHP_OUTPUT_NEWAPI - php_output_end_all(TSRMLS_C); + php_output_end_all(); #else - php_end_ob_buffers(1 TSRMLS_CC); + php_end_ob_buffers(1); #endif php_request_shutdown( NULL ); ret = 0; @@ -864,7 +831,7 @@ static int cli_main( int argc, char * argv[] ) case 'h': case '?': default: - cli_usage(TSRMLS_C); + cli_usage(); ret = 0; break; @@ -885,32 +852,32 @@ static int cli_main( int argc, char * argv[] ) SG(request_info).argc = argc - (p - argv); SG(request_info).argv = p; - if (php_request_startup(TSRMLS_C) == FAILURE ) { + if (php_request_startup() == FAILURE ) { fclose( file_handle.handle.fp ); ret = 2; } else { if (source_highlight == 1) { zend_syntax_highlighter_ini syntax_highlighter_ini; - + php_get_highlight_struct(&syntax_highlighter_ini); - highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC); + highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini); } else if (source_highlight == 2) { file_handle.filename = *p; file_handle.free_filename = 0; file_handle.opened_path = NULL; - ret = php_lint_script(&file_handle TSRMLS_CC); + ret = php_lint_script(&file_handle); if (ret==SUCCESS) { zend_printf("No syntax errors detected in %s\n", file_handle.filename); } else { zend_printf("Errors parsing %s\n", file_handle.filename); } - + } else { file_handle.filename = *p; file_handle.free_filename = 0; file_handle.opened_path = NULL; - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); ret = EG(exit_status); } @@ -920,13 +887,13 @@ static int cli_main( int argc, char * argv[] ) php_printf("Could not open input file: %s.\n", *p); } } else { - cli_usage(TSRMLS_C); + cli_usage(); } } }zend_end_try(); - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); #ifdef ZTS tsrm_shutdown(); @@ -982,7 +949,7 @@ void start_children( int children ) running++; break; } - } + } if ( s_stop ) { break; } @@ -1027,7 +994,7 @@ int main( int argc, char * argv[] ) struct timeval tv_req_end; int slow_script_msec = 0; char time_buf[40]; - + #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) signal(SIGPIPE, SIG_IGN); @@ -1039,7 +1006,7 @@ int main( int argc, char * argv[] ) #endif if (argc > 1 ) { - if ( parse_opt( argc, argv, &climode, + if ( parse_opt( argc, argv, &climode, &php_ini_path, &php_bind ) == -1 ) { return 1; } @@ -1063,7 +1030,7 @@ int main( int argc, char * argv[] ) #endif lsapi_sapi_module.executable_location = argv[0]; - + if ( ignore_php_ini ) lsapi_sapi_module.php_ini_ignore = 1; @@ -1099,9 +1066,9 @@ int main( int argc, char * argv[] ) } LSAPI_Init(); - + LSAPI_Init_Env_Parameters( NULL ); - lsapi_mode = 1; + lsapi_mode = 1; slow_script_msec = LSAPI_Get_Slow_Req_Msecs(); @@ -1115,16 +1082,16 @@ int main( int argc, char * argv[] ) if ( slow_script_msec ) { gettimeofday( &tv_req_begin, NULL ); } - ret = processReq(TSRMLS_C); + ret = processReq(); if ( slow_script_msec ) { gettimeofday( &tv_req_end, NULL ); - n = ((long) tv_req_end.tv_sec - tv_req_begin.tv_sec ) * 1000 + n = ((long) tv_req_end.tv_sec - tv_req_begin.tv_sec ) * 1000 + (tv_req_end.tv_usec - tv_req_begin.tv_usec) / 1000; if ( n > slow_script_msec ) { strftime( time_buf, 30, "%d/%b/%Y:%H:%M:%S", localtime( &tv_req_end.tv_sec ) ); fprintf( stderr, "[%s] Slow PHP script: %d ms\n URL: %s %s\n Query String: %s\n Script: %s\n", - time_buf, n, LSAPI_GetRequestMethod(), + time_buf, n, LSAPI_GetRequestMethod(), LSAPI_GetScriptName(), LSAPI_GetQueryString(), LSAPI_GetScriptFileName() ); @@ -1135,7 +1102,7 @@ int main( int argc, char * argv[] ) break; } } - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); #ifdef ZTS tsrm_shutdown(); @@ -1199,7 +1166,7 @@ static int add_associate_array( const char * pKey, int keyLen, const char * pVal add_assoc_string_ex( (zval *)arg, (char *)pKey, keyLen+1, (char *)pValue #if PHP_MAJOR_VERSION < 7 , 1 -#endif +#endif ); return 1; } @@ -1257,13 +1224,13 @@ PHP_FUNCTION(litespeed_response_headers) add_assoc_string_ex(return_value, headerBuf, len+1, p #if PHP_MAJOR_VERSION < 7 , 1 -#endif +#endif ); } } } h = zend_llist_get_next_ex(&SG(sapi_headers).headers, &pos); - } + } } /* }}} */ @@ -1273,7 +1240,7 @@ PHP_FUNCTION(litespeed_response_headers) Fetch all loaded module names */ PHP_FUNCTION(apache_get_modules) { - static const char * mod_names[] = + static const char * mod_names[] = { "mod_rewrite", "mod_mime", "mod_headers", "mod_expires", NULL }; @@ -1285,10 +1252,10 @@ PHP_FUNCTION(apache_get_modules) array_init(return_value); while( *name ) { - add_next_index_string(return_value, *name + add_next_index_string(return_value, *name #if PHP_MAJOR_VERSION < 7 , 1 -#endif +#endif ); ++name; } diff --git a/sapi/litespeed/lsapidef.h b/sapi/litespeed/lsapidef.h index 5210b06a15..02c5ae42e3 100644 --- a/sapi/litespeed/lsapidef.h +++ b/sapi/litespeed/lsapidef.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -22,18 +22,18 @@ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are -met: +met: * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + notice, this list of conditions and the following disclaimer. * 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. + with the distribution. * Neither the name of the Lite Speed Technologies Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior - written permission. + written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -45,7 +45,7 @@ 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. +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -94,7 +94,7 @@ enum /* Values for m_flag in lsapi_packet_header */ #define LSAPI_ENDIAN_LITTLE 0 -#define LSAPI_ENDIAN_BIG 1 +#define LSAPI_ENDIAN_BIG 1 #define LSAPI_ENDIAN_BIT 1 #if defined(__i386__)||defined( __x86_64 )||defined( __x86_64__ ) @@ -137,7 +137,7 @@ struct lsapi_packet_header /* LSAPI request header packet - + 1. struct lsapi_req_header 2. struct lsapi_http_header_index 3. lsapi_header_offset * unknownHeaders @@ -148,7 +148,7 @@ struct lsapi_packet_header struct lsapi_req_header { struct lsapi_packet_header m_pktHeader; - + int32_t m_httpHeaderLen; int32_t m_reqBodyLen; int32_t m_scriptFileOff; /* path to the script file. */ @@ -162,11 +162,11 @@ struct lsapi_req_header struct lsapi_http_header_index -{ +{ int16_t m_headerLen[H_TRANSFER_ENCODING+1]; int32_t m_headerOff[H_TRANSFER_ENCODING+1]; -} ; - +} ; + struct lsapi_header_offset { int32_t nameOff; diff --git a/sapi/litespeed/lsapilib.c b/sapi/litespeed/lsapilib.c index cfd2503777..fdb9ae47ea 100644 --- a/sapi/litespeed/lsapilib.c +++ b/sapi/litespeed/lsapilib.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -22,18 +22,18 @@ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are -met: +met: * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + notice, this list of conditions and the following disclaimer. * 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. + with the distribution. * Neither the name of the Lite Speed Technologies Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior - written permission. + written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -45,7 +45,7 @@ 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. +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -153,7 +153,7 @@ static const char *CGI_HEADERS[H_TRANSFER_ENCODING+1] = "HTTP_VIA", "HTTP_TRANSFER_ENCODING" }; - + static int CGI_HEADER_LEN[H_TRANSFER_ENCODING+1] = { 11, 19, 20, 20, 18, 15, 12, 14, 11, 12, 9, 11, 12, 15, 18, 22, 13, 18, 13, 24, 15, 10, 20, 8, 22 }; @@ -184,7 +184,7 @@ static int HTTP_HEADER_LEN[H_TRANSFER_ENCODING+1] = { 6, 14, 15, 15, 13, 10, 12, 14, 6, 7, 4, 6, 7, 10, //user-agent 13,17, 8, 13, 8, 19, 10, 5, 15, 3, 17 }; - + static void lsapi_sigpipe( int sig ) { } @@ -196,7 +196,7 @@ static void lsapi_siguser1( int sig ) #ifndef sighandler_t typedef void (*sighandler_t)(int); #endif - + static void lsapi_signal(int signo, sighandler_t handler) { struct sigaction sa; @@ -219,7 +219,7 @@ static void lsapi_enable_core_dump() #if defined(__FreeBSD__ ) || defined(__NetBSD__) || defined(__OpenBSD__) \ || defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) int mib[2]; - size_t len; + size_t len; len = 2; if ( sysctlnametomib("kern.sugid_coredump", mib, &len) == 0 ) @@ -230,7 +230,7 @@ static void lsapi_enable_core_dump() "core dump may not be available!"); } - + #endif #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__) @@ -511,7 +511,7 @@ static inline void swapIntEndian( int * pInteger ) b = p[1]; p[1] = p[2]; p[2] = b; - + } static inline void fixEndian( LSAPI_Request * pReq ) @@ -586,7 +586,7 @@ static int lsapi_load_lve_lib() if (s_liblve) { fp_lve_is_available = dlsym(s_liblve, "lve_is_available"); - if (dlerror() == NULL) + if (dlerror() == NULL) { if ( !(*fp_lve_is_available)() ) { @@ -612,7 +612,7 @@ static int init_lve_ex() { int rc; if ( !s_liblve ) - return -1; + return -1; fp_lve_instance_init = dlsym(s_liblve, "lve_instance_init"); fp_lve_destroy = dlsym(s_liblve, "lve_destroy"); fp_lve_enter = dlsym(s_liblve, "lve_enter"); @@ -620,13 +620,13 @@ static int init_lve_ex() if ( s_enable_lve >= LSAPI_CAGEFS_ENABLED ) fp_lve_jail = dlsym(s_liblve, "jail" ); - if ( s_lve == NULL ) + if ( s_lve == NULL ) { rc = (*fp_lve_instance_init)(NULL); s_lve = malloc(rc); } rc = (*fp_lve_instance_init)(s_lve); - if (rc != 0) + if (rc != 0) { perror( "LSAPI: Unable to initialize LVE" ); free( s_lve ); @@ -634,7 +634,7 @@ static int init_lve_ex() return -1; } return 0; - + } #endif @@ -701,7 +701,7 @@ static int LSAPI_perror_r( LSAPI_Request * pReq, const char * pErr1, const char static int lsapi_lve_error( LSAPI_Request * pReq ) { - static const char * headers[] = + static const char * headers[] = { "Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0", "Pragma: no-cache", @@ -717,7 +717,7 @@ static int lsapi_lve_error( LSAPI_Request * pReq ) "Please try again later.\n" "<HR>\n" "</BODY></HTML>\n"; - + LSAPI_ErrResponse_r( pReq, 508, headers, achBody, sizeof( achBody ) - 1 ); return 0; } @@ -751,7 +751,7 @@ static int lsapi_jailLVE( LSAPI_Request * pReq, uid_t uid, struct passwd * pw ) ret = (*fp_lve_jail)( pw, error_msg ); if ( ret < 0 ) { - fprintf( stderr, "LSAPI (%d): LVE jail(%d) ressult: %d, error: %s !\n", + fprintf( stderr, "LSAPI (%d): LVE jail(%d) ressult: %d, error: %s !\n", getpid(), uid, ret, error_msg ); LSAPI_perror_r( pReq, "LSAPI: jail() failure.", NULL ); return -1; @@ -796,7 +796,7 @@ static int setUID_LVE(LSAPI_Request * pReq, uid_t uid, gid_t gid, const char * p pw = getpwuid( uid ); #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__) if ( s_lve ) - { + { if( lsapi_enterLVE( pReq, uid ) == -1 ) return -1; if ( pw && fp_lve_jail) @@ -813,7 +813,7 @@ static int setUID_LVE(LSAPI_Request * pReq, uid_t uid, gid_t gid, const char * p } } #endif - //if ( !uid || !gid ) //do not allow root + //if ( !uid || !gid ) //do not allow root //{ // return -1; //} @@ -869,7 +869,7 @@ static int setUID_LVE(LSAPI_Request * pReq, uid_t uid, gid_t gid, const char * p return 0; } -static int lsapi_suexec_auth( LSAPI_Request *pReq, +static int lsapi_suexec_auth( LSAPI_Request *pReq, char * pAuth, int len, char * pUgid, int ugidLen ) { lsapi_MD5_CTX md5ctx; @@ -901,7 +901,7 @@ static int lsapi_changeUGid( LSAPI_Request * pReq ) //with special ID 0x00 //authenticate the suEXEC request; //first one should be MD5( nonce + lscgid secret ) - //remember to clear the secret after verification + //remember to clear the secret after verification //it should be set at the end of special env i = pReq->m_pHeader->m_cntSpecialEnv - 1; if ( i >= 0 ) @@ -917,7 +917,7 @@ static int lsapi_changeUGid( LSAPI_Request * pReq ) { --pReq->m_pHeader->m_cntSpecialEnv; uid = *(uint32_t *)pEnv->pValue; - gid = *(((uint32_t *)pEnv->pValue) + 1 ); + gid = *(((uint32_t *)pEnv->pValue) + 1 ); //fprintf( stderr, "LSAPI: SUEXEC_UGID set UID: %d, GID: %d\n", uid, gid ); } else @@ -927,8 +927,8 @@ static int lsapi_changeUGid( LSAPI_Request * pReq ) } if ( pEnv&& lsapi_suexec_auth( pReq, pAuth->pValue, pAuth->valLen, pEnv->pValue, pEnv->valLen ) == 0 ) { - //read UID, GID from specialEnv - + //read UID, GID from specialEnv + } else { @@ -956,10 +956,10 @@ static int lsapi_changeUGid( LSAPI_Request * pReq ) return -1; } - s_uid = uid; + s_uid = uid; return 0; - + } static int parseContentLenFromHeader(LSAPI_Request * pReq) @@ -1004,7 +1004,7 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen ) pReq->m_pScriptName = pReq->m_pReqBuf + pReq->m_pHeader->m_scriptNameOff; pReq->m_pQueryString = pReq->m_pReqBuf + pReq->m_pHeader->m_queryStringOff; pReq->m_pRequestMethod = pReq->m_pReqBuf + pReq->m_pHeader->m_requestMethodOff; - + pBegin = pReq->m_pReqBuf + (( pBegin - pReq->m_pReqBuf + 7 ) & (~0x7)); pReq->m_pHeaderIndex = ( struct lsapi_http_header_index * )pBegin; pBegin += sizeof( struct lsapi_http_header_index ); @@ -1030,7 +1030,7 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen ) { parseContentLenFromHeader(pReq); } - + return 0; } @@ -1088,7 +1088,7 @@ static inline int lsapi_notify_pid( int fd ) 8 + LSAPI_PACKET_HEADER_LEN ); memmove( &achBuf[8], "\0PID", 4 ); *((int *)&achBuf[12]) = getpid(); - + if ( write( fd, achBuf, 16 ) < 16 ) return -1; return 0; @@ -1112,7 +1112,7 @@ static inline int init_conn_key( int fd ) < LSAPI_PACKET_HEADER_LEN+8 ) return -1; return 0; - + } @@ -1198,9 +1198,9 @@ int LSAPI_Init(void) #if defined(SIGXFSZ) && defined(SIG_IGN) signal(SIGXFSZ, SIG_IGN); #endif - /* let STDOUT function as STDERR, + /* let STDOUT function as STDERR, just in case writing to STDOUT directly */ - dup2( 2, 1 ); + dup2( 2, 1 ); if ( LSAPI_InitRequest( &g_req, LSAPI_SOCK_FILENO ) == -1 ) return -1; g_inited = 1; @@ -1240,8 +1240,8 @@ int LSAPI_InitRequest( LSAPI_Request * pReq, int fd ) { fd = dup( fd ); newfd = open( "/dev/null", O_RDWR ); - dup2( newfd, STDIN_FILENO ); - } + dup2( newfd, STDIN_FILENO ); + } if ( isPipe( fd ) ) { @@ -1274,7 +1274,7 @@ int LSAPI_Accept_r( LSAPI_Request * pReq ) char achPeer[128]; socklen_t len; int nodelay = 1; - + if ( !pReq ) return -1; if ( LSAPI_Finish_r( pReq ) == -1 ) @@ -1300,7 +1300,7 @@ int LSAPI_Accept_r( LSAPI_Request * pReq ) { lsapi_set_nblock( pReq->m_fd , 0 ); if (((struct sockaddr *)&achPeer)->sa_family == AF_INET ) - { + { setsockopt(pReq->m_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&nodelay, sizeof(nodelay)); } @@ -1344,7 +1344,7 @@ int LSAPI_Finish_r( LSAPI_Request * pReq ) { Flush_RespBuf_r( pReq ); } - + pReq->m_pIovecCur->iov_base = (void *)&finish; pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN; pReq->m_totalLen += LSAPI_PACKET_HEADER_LEN; @@ -1362,7 +1362,7 @@ void LSAPI_Reset_r( LSAPI_Request * pReq ) pReq->m_pRespBufPos = pReq->m_pRespBuf; pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec + 1; pReq->m_pRespHeaderBufPos = pReq->m_pRespHeaderBuf; - + memset( &pReq->m_pHeaderIndex, 0, (char *)(pReq->m_respHeaderLen) - (char *)&pReq->m_pHeaderIndex ); } @@ -1377,7 +1377,7 @@ int LSAPI_Release_r( LSAPI_Request * pReq ) if ( pReq->m_pEnvList ) free( pReq->m_pEnvList ); if ( pReq->m_pRespHeaderBuf ) - free( pReq->m_pRespHeaderBuf ); + free( pReq->m_pRespHeaderBuf ); return 0; } @@ -1390,9 +1390,9 @@ char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex ) off = pReq->m_pHeaderIndex->m_headerOff[ headerIndex ]; if ( !off ) return NULL; - if ( *(pReq->m_pHttpHeader + off + + if ( *(pReq->m_pHttpHeader + off + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) ) - *( pReq->m_pHttpHeader + off + + *( pReq->m_pHttpHeader + off + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0; return pReq->m_pHttpHeader + off; } @@ -1411,7 +1411,7 @@ static int readBodyToReqBuf( LSAPI_Request * pReq ) return -1; if ( len > bodyLeft ) len = bodyLeft; - + len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf + pReq->m_bufRead, len ); if ( len > 0 ) pReq->m_bufRead += len; @@ -1442,12 +1442,12 @@ int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, in char * pBufCur = pBuf; char * pCur; char * p; - if (!pReq || (pReq->m_fd ==-1) ||( !pBuf )||(bufLen < 0 )|| !getLF ) + if (!pReq || (pReq->m_fd ==-1) ||( !pBuf )|| !getLF ) return -1; *getLF = 0; while( (left = pBufEnd - pBufCur ) > 0 ) { - + len = pReq->m_bufRead - pReq->m_bufProcessed; if ( len <= 0 ) { @@ -1468,7 +1468,7 @@ int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, in pReq->m_bufProcessed += len; pReq->m_reqBodyRead += len; - + if ( p ) { *getLF = 1; @@ -1476,7 +1476,7 @@ int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, in } } *pBufCur = 0; - + return pBufCur - pBuf; } @@ -1486,11 +1486,11 @@ ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen ) ssize_t len; off_t total; /* char *pOldBuf = pBuf; */ - if (!pReq || (pReq->m_fd ==-1) || ( !pBuf )||(bufLen < 0 )) + if (!pReq || (pReq->m_fd ==-1) || ( !pBuf )) return -1; total = pReq->m_reqBodyLen - pReq->m_reqBodyRead; - + if ( total <= 0 ) return 0; if ( total < bufLen ) @@ -1526,7 +1526,7 @@ ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen ) } pReq->m_reqBodyRead += total; return total; - + } @@ -1539,7 +1539,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) ssize_t toWrite; ssize_t packetLen; int skip = 0; - + if ( !pReq || !pBuf || (pReq->m_fd == -1) ) return -1; if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) @@ -1564,13 +1564,13 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) pReq->m_pRespBufPos += len - skip; return len; } - - + + pHeader = pReq->m_respPktHeader; p = pBuf + skip; pEnd = pBuf + len; bufLen = pReq->m_pRespBufPos - pReq->m_pRespBuf; - + while( ( toWrite = pEnd - p ) > 0 ) { packetLen = toWrite + bufLen; @@ -1579,7 +1579,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) packetLen = LSAPI_MAX_DATA_PACKET_LEN; toWrite = packetLen - bufLen; } - + lsapi_buildPacketHeader( pHeader, LSAPI_RESP_STREAM, packetLen + LSAPI_PACKET_HEADER_LEN ); pReq->m_totalLen += packetLen + LSAPI_PACKET_HEADER_LEN; @@ -1593,7 +1593,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf; pReq->m_pIovecCur->iov_len = bufLen; pReq->m_pRespBufPos = pReq->m_pRespBuf; - ++pReq->m_pIovecCur; + ++pReq->m_pIovecCur; bufLen = 0; } @@ -1615,7 +1615,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) return p - pBuf; } -#if defined(__FreeBSD__ ) || defined(__NetBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__ ) || defined(__NetBSD__) || defined(__OpenBSD__) ssize_t gsendfile( int fdOut, int fdIn, off_t* off, size_t size ) { ssize_t ret; @@ -1644,7 +1644,7 @@ ssize_t gsendfile( int fdOut, int fdIn, off_t* off, size_t size ) return ret; } #endif - + #if defined(sun) || defined(__sun) #include <sys/sendfile.h> ssize_t gsendfile( int fdOut, int fdIn, off_t *off, size_t size ) @@ -1690,16 +1690,16 @@ ssize_t LSAPI_sendfile_r( LSAPI_Request * pReq, int fdIn, off_t* off, size_t siz LSAPI_FinalizeRespHeaders_r( pReq ); } pReq->m_reqState |= LSAPI_ST_RESP_BODY; - + LSAPI_Flush_r(pReq); - + lsapi_buildPacketHeader( pHeader, LSAPI_RESP_STREAM, size + LSAPI_PACKET_HEADER_LEN ); - + if (write(pReq->m_fd, (const char *) pHeader, LSAPI_PACKET_HEADER_LEN ) != LSAPI_PACKET_HEADER_LEN) return -1; - + return gsendfile( pReq->m_fd, fdIn, off, size ); } @@ -1722,7 +1722,7 @@ void Flush_RespBuf_r( LSAPI_Request * pReq ) pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf; pReq->m_pIovecCur->iov_len = bufLen; pReq->m_pRespBufPos = pReq->m_pRespBuf; - ++pReq->m_pIovecCur; + ++pReq->m_pIovecCur; bufLen = 0; } } @@ -1754,11 +1754,11 @@ int LSAPI_Flush_r( LSAPI_Request * pReq ) { Flush_RespBuf_r( pReq ); } - + n = pReq->m_pIovecCur - pReq->m_pIovecToWrite; if ( n > 0 ) { - + ret = lsapi_writev( pReq->m_fd, &pReq->m_pIovecToWrite, n, pReq->m_totalLen ); if ( ret < pReq->m_totalLen ) @@ -1784,7 +1784,7 @@ ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t le int ret; struct iovec iov[2]; struct iovec *pIov; - + if ( !pReq ) return -1; if (( pReq->m_fd == -1 )||(pReq->m_fd == pReq->m_fdListen )) @@ -1793,7 +1793,7 @@ ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t le { LSAPI_Flush_r( pReq ); } - + p = pBuf; pEnd = pBuf + len; @@ -1900,7 +1900,7 @@ struct _headerInfo int compareValueLocation(const void * v1, const void *v2 ) { return ((const struct _headerInfo *)v1)->_value - - ((const struct _headerInfo *)v2)->_value; + ((const struct _headerInfo *)v2)->_value; } int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, @@ -1931,7 +1931,7 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, headers[count]._value = pValue; headers[count]._valueLen = len; ++count; - + //ret = (*fn)( HTTP_HEADERS[i], HTTP_HEADER_LEN[i], // pValue, len, arg ); //if ( ret <= 0 ) @@ -1960,7 +1960,7 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, ++count; if ( count == 512 ) break; - //ret = (*fn)( pKey, keyLen, + //ret = (*fn)( pKey, keyLen, // pValue, pCur->valueLen, arg ); //if ( ret <= 0 ) // return ret; @@ -1970,13 +1970,13 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, qsort( headers, count, sizeof( struct _headerInfo ), compareValueLocation ); for( i = 0; i < count; ++i ) { - ret = (*fn)( headers[i]._name, headers[i]._nameLen, + ret = (*fn)( headers[i]._name, headers[i]._nameLen, headers[i]._value, headers[i]._valueLen, arg ); if ( ret <= 0 ) return ret; } return count; - + } @@ -2037,7 +2037,7 @@ int LSAPI_ForeachHeader_r( LSAPI_Request * pReq, pValue = pReq->m_pHttpHeader + pCur->valueOff; *(pValue + pCur->valueLen ) = 0; - ret = (*fn)( achHeaderName, keyLen, + ret = (*fn)( achHeaderName, keyLen, pValue, pCur->valueLen, arg ); if ( ret <= 0 ) return ret; @@ -2045,7 +2045,7 @@ int LSAPI_ForeachHeader_r( LSAPI_Request * pReq, } } return count + pReq->m_pHeader->m_cntUnknownHeaders; - + } static int EnvForeach( struct LSAPI_key_value_pair * pEnv, @@ -2114,7 +2114,7 @@ int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq ) pReq->m_totalLen += pReq->m_pIovecCur->iov_len; ++pReq->m_pIovecCur; } - + pReq->m_pIovec->iov_len = sizeof( struct lsapi_resp_header) + pReq->m_respHeader.m_respInfo.m_cntHeaders * sizeof( short ); pReq->m_totalLen += pReq->m_pIovec->iov_len; @@ -2127,11 +2127,11 @@ int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq ) } -int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName, +int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName, const char * pHeaderValue ) { int nameLen, valLen, len; - if ( !pReq || !pHeaderName || !pHeaderValue ) + if ( !pReq || !pHeaderName || !pHeaderValue ) return -1; if ( pReq->m_reqState & LSAPI_ST_RESP_BODY ) return -1; @@ -2275,7 +2275,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr ) struct addrinfo *res, hints; int doAddrInfo = 0; int port; - + if ( !pBind ) return -1; @@ -2299,7 +2299,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr ) if ( !pEnd ) return -1; *pEnd++ = 0; - + if ( *p == '*' ) { strcpy( achAddr, "::" ); @@ -2314,7 +2314,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr ) if ( !pEnd ) return -1; *pEnd++ = 0; - + doAddrInfo = 0; if ( *p == '*' ) { @@ -2334,7 +2334,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr ) } if ( *pEnd == ':' ) ++pEnd; - + port = atoi( pEnd ); if (( port <= 0 )||( port > 65535 )) return -1; @@ -2355,13 +2355,13 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr ) memcpy(pAddr, res->ai_addr, res->ai_addrlen); freeaddrinfo(res); } - + if ( pAddr->sa_family == AF_INET ) ((struct sockaddr_in *)pAddr)->sin_port = htons( port ); else ((struct sockaddr_in6 *)pAddr)->sin6_port = htons( port ); return 0; - + } int LSAPI_CreateListenSock( const char * pBind, int backlog ) @@ -2407,11 +2407,11 @@ typedef struct _lsapi_prefork_server int m_iChildrenMaxIdleTime; int m_iMaxReqProcessTime; int m_iAvoidFork; - + lsapi_child_status * m_pChildrenStatus; lsapi_child_status * m_pChildrenStatusCur; lsapi_child_status * m_pChildrenStatusEnd; - + }lsapi_prefork_server; static lsapi_prefork_server * g_prefork_server = NULL; @@ -2426,7 +2426,7 @@ int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork ) if ( max_children >= 10000) max_children = 10000; - + g_prefork_server = (lsapi_prefork_server *)malloc( sizeof( lsapi_prefork_server ) ); if ( !g_prefork_server ) return -1; @@ -2440,14 +2440,14 @@ int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork ) setpgid( pid, pid ); g_prefork_server->m_iAvoidFork = avoidFork; g_prefork_server->m_iMaxChildren = max_children; - + g_prefork_server->m_iExtraChildren = ( avoidFork ) ? 0 : (max_children / 3) ; g_prefork_server->m_iMaxIdleChildren = ( avoidFork ) ? (max_children + 1) : (max_children / 3); if ( g_prefork_server->m_iMaxIdleChildren == 0 ) g_prefork_server->m_iMaxIdleChildren = 1; g_prefork_server->m_iChildrenMaxIdleTime = 300; g_prefork_server->m_iMaxReqProcessTime = 3600; - return 0; + return 0; } void LSAPI_Set_Server_fd( int fd ) @@ -2554,7 +2554,7 @@ static void lsapi_sigchild( int signal ) static int lsapi_init_children_status() { int size = 4096; - + char * pBuf; size = (g_prefork_server->m_iMaxChildren + g_prefork_server->m_iExtraChildren ) * sizeof( lsapi_child_status ) * 2; size = (size + 4095 ) / 4096 * 4096; @@ -2582,9 +2582,9 @@ static void dump_debug_info( lsapi_child_status * pStatus, long tmCur ) } s_pid_dump_debug_info = fork(); - fprintf( stderr, "[%s] Possible runaway process, PPID: %d, PID: %d, reqCount: %d, process time: %ld, checkpoint time: %ld, start time: %ld\n", - ctime(&tmCur), getpid(), pStatus->m_pid, pStatus->m_iReqCounter, - tmCur - pStatus->m_tmReqBegin, tmCur - pStatus->m_tmLastCheckPoint, tmCur - pStatus->m_tmStart ); + fprintf( stderr, "[%s] Possible runaway process, PPID: %d, PID: %d, reqCount: %d, process time: %ld, checkpoint time: %ld, start time: %ld\n", + ctime(&tmCur), getpid(), pStatus->m_pid, pStatus->m_iReqCounter, + tmCur - pStatus->m_tmReqBegin, tmCur - pStatus->m_tmLastCheckPoint, tmCur - pStatus->m_tmStart ); snprintf( achCmd, 1024, "gdb --batch -ex \"attach %d\" -ex \"set height 0\" -ex \"bt\" >&2;PATH=$PATH:/usr/sbin lsof -p %d >&2", pStatus->m_pid, pStatus->m_pid ); if ( system( achCmd ) == -1 ) perror( "system()" ); @@ -2607,7 +2607,7 @@ static void lsapi_check_child_status( long tmCur ) ++count; if ( !pStatus->m_inProcess ) { - + if (( g_prefork_server->m_iCurChildren - dying > g_prefork_server->m_iMaxChildren)|| ( idle > g_prefork_server->m_iMaxIdleChildren )) { @@ -2627,7 +2627,7 @@ static void lsapi_check_child_status( long tmCur ) } else { - if ( tmCur - pStatus->m_tmReqBegin > + if ( tmCur - pStatus->m_tmReqBegin > g_prefork_server->m_iMaxReqProcessTime ) { if (( ( pStatus->m_iKillSent % 5 ) == 0 )&&( s_dump_debug_info )) @@ -2662,7 +2662,7 @@ static void lsapi_check_child_status( long tmCur ) } if ( abs( g_prefork_server->m_iCurChildren - count ) > 1 ) { - fprintf( stderr, "Children tracking is wrong: PID: %d, Cur Children: %d, count: %d, idle: %d, dying: %d\n", getpid(), + fprintf( stderr, "Children tracking is wrong: PID: %d, Cur Children: %d, count: %d, idle: %d, dying: %d\n", getpid(), g_prefork_server->m_iCurChildren, count, idle, dying ); } @@ -2706,7 +2706,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re sigset_t orig_mask; lsapi_init_children_status(); - + setsid(); act.sa_flags = 0; @@ -2796,17 +2796,17 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re sigemptyset( &mask ); sigaddset( &mask, SIGCHLD ); - - if ( sigprocmask(SIG_BLOCK, &mask, &orig_mask) < 0 ) + + if ( sigprocmask(SIG_BLOCK, &mask, &orig_mask) < 0 ) { perror( "sigprocmask(SIG_BLOCK) to block SIGCHLD" ); } pid = fork(); - + if ( !pid ) { - if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) + if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) perror( "sigprocmask( SIG_SETMASK ) to restore SIGMASK in child" ); g_prefork_server = NULL; s_ppid = getppid(); @@ -2848,7 +2848,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re close( pReq->m_fd ); pReq->m_fd = -1; - if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) + if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) perror( "sigprocmask( SIG_SETMASK ) to restore SIGMASK" ); } @@ -2897,7 +2897,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq ) s_pChildStatus->m_tmWaitBegin = time( NULL ); } - + while( g_running ) { if ( pReq->m_fd != -1 ) @@ -2916,7 +2916,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq ) if ( !g_running ) return -1; if ((s_req_processed)&&( s_pChildStatus )&&( s_pChildStatus->m_iKillSent )) - return -1; + return -1; FD_ZERO( &readfds ); FD_SET( fd, &readfds ); timeout.tv_sec = 1; @@ -2944,7 +2944,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq ) else if ( ret >= 1 ) { if (s_req_processed && ( s_pChildStatus )&&( s_pChildStatus->m_iKillSent )) - return -1; + return -1; if ( fd == pReq->m_fdListen ) { pReq->m_fd = lsapi_accept( pReq->m_fdListen ); @@ -2992,7 +2992,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq ) LSAPI_Reset_r( pReq ); } return -1; - + } void LSAPI_Set_Max_Reqs( int reqs ) @@ -3061,19 +3061,19 @@ static void unset_lsapi_envs() #else env = environ; #endif - while( env != NULL && *env != NULL ) + while( env != NULL && *env != NULL ) { - if (!strncmp(*env, "LSAPI_", 6) || !strncmp( *env, "PHP_LSAPI_", 10 ) - || (!strncmp( *env, "PHPRC=", 6 )&&(!s_uid))) - { + if (!strncmp(*env, "LSAPI_", 6) || !strncmp( *env, "PHP_LSAPI_", 10 ) + || (!strncmp( *env, "PHPRC=", 6 )&&(!s_uid))) + { char ** del = env; - do + do *del = del[1]; while( *del++ ); } else ++env; - } + } } static int lsapi_initSuEXEC() @@ -3100,7 +3100,7 @@ static int lsapi_initSuEXEC() } p = getenv( "LSAPI_SECRET" ); if (( !p )||( readSecret(p) == -1 )) - return -1; + return -1; if ( g_prefork_server ) { if ( g_prefork_server->m_iMaxChildren < 100 ) @@ -3140,7 +3140,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp ) if ( p ) { avoidFork = atoi( p ); - } + } p = getenv( "LSAPI_ACCEPT_NOTIFY" ); if ( p ) @@ -3149,7 +3149,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp ) } p = getenv( "LSAPI_SLOW_REQ_MSECS" ); - if ( p ) + if ( p ) { n = atoi( p ); LSAPI_Set_Slow_Req_Msecs( n ); @@ -3199,26 +3199,26 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp ) p = getenv( "LSAPI_EXTRA_CHILDREN" ); if ( p ) LSAPI_Set_Extra_Children( atoi( p ) ); - + p = getenv( "LSAPI_MAX_IDLE_CHILDREN" ); if ( p ) LSAPI_Set_Max_Idle_Children( atoi( p ) ); - + p = getenv( "LSAPI_PGRP_MAX_IDLE" ); if ( p ) { LSAPI_Set_Server_Max_Idle_Secs( atoi( p ) ); } - + p = getenv( "LSAPI_MAX_PROCESS_TIME" ); - if ( p ) + if ( p ) LSAPI_Set_Max_Process_Time( atoi( p ) ); - + if ( getenv( "LSAPI_PPID_NO_CHECK" ) ) { LSAPI_No_Check_ppid(); } - + p = getenv( "LSAPI_DUMP_DEBUG_INFO" ); if ( p ) s_dump_debug_info = atoi( p ); @@ -3234,7 +3234,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp ) } -int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders, +int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders, const char * pBody, int bodyLen ) { LSAPI_SetRespStatus_r( pReq, code ); diff --git a/sapi/litespeed/lsapilib.h b/sapi/litespeed/lsapilib.h index bb5cf9b674..cd69990314 100644 --- a/sapi/litespeed/lsapilib.h +++ b/sapi/litespeed/lsapilib.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -22,18 +22,18 @@ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are -met: +met: * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + notice, this list of conditions and the following disclaimer. * 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. + with the distribution. * Neither the name of the Lite Speed Technologies Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior - written permission. + written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -45,7 +45,7 @@ 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. +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -83,7 +83,7 @@ typedef struct lsapi_request char * m_pReqBuf; int m_reqBufSize; - + char * m_pRespBuf; char * m_pRespBufEnd; char * m_pRespBufPos; @@ -96,7 +96,7 @@ typedef struct lsapi_request struct iovec * m_pIovec; struct iovec * m_pIovecEnd; struct iovec * m_pIovecCur; - struct iovec * m_pIovecToWrite; + struct iovec * m_pIovecToWrite; struct lsapi_packet_header * m_respPktHeaderEnd; @@ -108,7 +108,7 @@ typedef struct lsapi_request struct lsapi_http_header_index * m_pHeaderIndex; struct lsapi_header_offset * m_pUnknownHeader; - + char * m_pScriptFile; char * m_pScriptName; char * m_pQueryString; @@ -120,9 +120,9 @@ typedef struct lsapi_request off_t m_reqBodyRead; int m_bufProcessed; int m_bufRead; - + struct lsapi_packet_header m_respPktHeader[5]; - + struct lsapi_resp_header m_respHeader; short m_respHeaderLen[LSAPI_MAX_RESP_HEADERS]; void * m_pAppData; @@ -168,7 +168,7 @@ int LSAPI_ForeachSpecialEnv_r( LSAPI_Request * pReq, LSAPI_CB_EnvHandler fn, void * arg ); char * LSAPI_GetEnv_r( LSAPI_Request * pReq, const char * name ); - + ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t len ); @@ -189,7 +189,7 @@ int LSAPI_Flush_r( LSAPI_Request * pReq ); int LSAPI_AppendRespHeader_r( LSAPI_Request * pReq, const char * pBuf, int len ); -int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName, +int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName, const char * pHeaderValue ); int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders, @@ -331,7 +331,7 @@ static inline ssize_t LSAPI_Write( const char * pBuf, ssize_t len ) static inline ssize_t LSAPI_sendfile( int fdIn, off_t* off, size_t size ) { - return LSAPI_sendfile_r(&g_req, fdIn, off, size ); + return LSAPI_sendfile_r(&g_req, fdIn, off, size ); } static inline ssize_t LSAPI_Write_Stderr( const char * pBuf, ssize_t len ) diff --git a/sapi/milter/getopt.c b/sapi/milter/getopt.c index f5874d577e..df2c77f94c 100644 --- a/sapi/milter/getopt.c +++ b/sapi/milter/getopt.c @@ -39,7 +39,7 @@ ap_php_optiserr(int argc, char * const *argv, int oint, const char *optstr, } return('?'); } - + int ap_php_getopt(int argc, char* const *argv, const char *optstr) { static int optchr = 0; @@ -96,7 +96,7 @@ int ap_php_getopt(int argc, char* const *argv, const char *optstr) } if (cp[1] == ':') { - /* Check for cases where the value of the argument + /* 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]) { diff --git a/sapi/milter/php_milter.c b/sapi/milter/php_milter.c index 1721ea4351..73a0667326 100644 --- a/sapi/milter/php_milter.c +++ b/sapi/milter/php_milter.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -113,21 +113,20 @@ static int mlfi_init() zend_file_handle file_handle; zval function_name, retval; int status; - TSRMLS_FETCH(); /* request startup */ - if (php_request_startup(TSRMLS_C)==FAILURE) { + if (php_request_startup()==FAILURE) { SG(headers_sent) = 1; SG(request_info).no_headers = 1; php_request_shutdown((void *) 0); return -1; } - + /* disable headers */ SG(headers_sent) = 1; SG(request_info).no_headers = 1; - + if (filename == NULL) { php_printf("No input file specified"); return SMFIS_TEMPFAIL; @@ -143,8 +142,8 @@ static int mlfi_init() file_handle.free_filename = 0; file_handle.opened_path = NULL; - php_execute_script(&file_handle TSRMLS_CC); - + php_execute_script(&file_handle); + /* call userland */ INIT_ZVAL(function_name); @@ -153,7 +152,7 @@ static int mlfi_init() /* set the milter context for possible use in API functions */ MG(state) = MLFI_INIT; - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); MG(state) = MLFI_NONE; MG(initialized) = 1; @@ -161,9 +160,9 @@ static int mlfi_init() if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { ret = Z_LVAL(retval); } - + php_request_shutdown((void *) 0); - + return ret; } /* }}} */ @@ -179,26 +178,25 @@ static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) zend_file_handle file_handle; zval function_name, retval, *param[1]; int status; - TSRMLS_FETCH(); /* request startup */ - if (php_request_startup(TSRMLS_C)==FAILURE) { + if (php_request_startup()==FAILURE) { SG(headers_sent) = 1; SG(request_info).no_headers = 1; php_request_shutdown((void *) 0); return SMFIS_TEMPFAIL; } - + /* disable headers */ SG(headers_sent) = 1; SG(request_info).no_headers = 1; - + if (filename == NULL) { php_printf("No input file specified"); return SMFIS_TEMPFAIL; } - + if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) { php_printf("Could not open input file: %s\n", filename); return SMFIS_TEMPFAIL; @@ -209,8 +207,8 @@ static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) file_handle.free_filename = 0; file_handle.opened_path = NULL; - php_execute_script(&file_handle TSRMLS_CC); - + php_execute_script(&file_handle); + /* call userland */ INIT_ZVAL(function_name); @@ -224,14 +222,14 @@ static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) MG(ctx) = ctx; MG(state) = MLFI_CONNECT; - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); MG(state) = MLFI_NONE; zval_ptr_dtor(param); if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } - + return SMFIS_CONTINUE; } /* }}} */ @@ -243,11 +241,10 @@ static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost) { zval function_name, retval, *param[1]; int status; - TSRMLS_FETCH(); /* call userland */ INIT_ZVAL(function_name); - + ALLOC_ZVAL(param[0]); INIT_PZVAL(param[0]); @@ -257,16 +254,16 @@ static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost) /* set the milter context for possible use in API functions */ MG(ctx) = ctx; MG(state) = MLFI_HELO; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); + + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); MG(state) = MLFI_NONE; zval_ptr_dtor(param); - + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } - + return SMFIS_CONTINUE; } /* }}} */ @@ -278,11 +275,10 @@ static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv) { zval function_name, retval, *param[1]; int status; - TSRMLS_FETCH(); /* call userland */ INIT_ZVAL(function_name); - + ALLOC_ZVAL(param[0]); INIT_PZVAL(param[0]); @@ -290,19 +286,19 @@ static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv) array_init(param[0]); while (*argv) { - add_next_index_string(param[0], *argv, 1); + add_next_index_string(param[0], *argv); argv++; } /* set the milter context for possible use in API functions */ MG(ctx) = ctx; MG(state) = MLFI_ENVFROM; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); + + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); MG(state) = MLFI_NONE; zval_ptr_dtor(param); - + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -318,11 +314,10 @@ static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv) { zval function_name, retval, *param[1]; int status; - TSRMLS_FETCH(); /* call userland */ INIT_ZVAL(function_name); - + ALLOC_ZVAL(param[0]); INIT_PZVAL(param[0]); @@ -330,20 +325,20 @@ static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv) array_init(param[0]); while (*argv) { - add_next_index_string(param[0], *argv, 1); + add_next_index_string(param[0], *argv); argv++; } /* set the milter context for possible use in API functions */ MG(ctx) = ctx; MG(state) = MLFI_ENVRCPT; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); + + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); MG(state) = MLFI_NONE; - + zval_ptr_dtor(param); - + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -359,16 +354,15 @@ static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv) { zval function_name, retval, *param[2]; int status; - TSRMLS_FETCH(); /* call userland */ INIT_ZVAL(function_name); - + ALLOC_ZVAL(param[0]); ALLOC_ZVAL(param[1]); INIT_PZVAL(param[0]); INIT_PZVAL(param[1]); - + ZVAL_STRING(&function_name, "milter_header", 0); ZVAL_STRING(param[0], headerf, 1); ZVAL_STRING(param[1], headerv, 1); @@ -376,18 +370,18 @@ static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv) /* set the milter context for possible use in API functions */ MG(ctx) = ctx; MG(state) = MLFI_HEADER; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 2, param TSRMLS_CC); + + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 2, param); MG(state) = MLFI_NONE; - + zval_ptr_dtor(¶m[0]); - zval_ptr_dtor(¶m[1]); - + zval_ptr_dtor(¶m[1]); + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } - + return SMFIS_CONTINUE; } /* }}} */ @@ -399,7 +393,6 @@ static sfsistat mlfi_eoh(SMFICTX *ctx) { zval function_name, retval; int status; - TSRMLS_FETCH(); /* call userland */ INIT_ZVAL(function_name); @@ -408,11 +401,11 @@ static sfsistat mlfi_eoh(SMFICTX *ctx) /* set the milter context for possible use in API functions */ MG(ctx) = ctx; MG(state) = MLFI_EOH; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); + + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); MG(state) = MLFI_NONE; - + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -428,26 +421,25 @@ static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len) { zval function_name, retval, *param[1]; int status; - TSRMLS_FETCH(); /* call userland */ INIT_ZVAL(function_name); - + ALLOC_ZVAL(param[0]); INIT_PZVAL(param[0]); ZVAL_STRING(&function_name, "milter_body", 0); ZVAL_STRINGL(param[0], (char*)bodyp, len, 1); /*alex*/ - + /* set the milter context for possible use in API functions */ MG(ctx) = ctx; MG(state) = MLFI_BODY; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); + + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); MG(state) = MLFI_NONE; - - zval_ptr_dtor(param); + + zval_ptr_dtor(param); if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); @@ -464,20 +456,19 @@ static sfsistat mlfi_eom(SMFICTX *ctx) { zval function_name, retval; int status; - TSRMLS_FETCH(); /* call userland */ INIT_ZVAL(function_name); ZVAL_STRING(&function_name, "milter_eom", 0); - + /* set the milter context for possible use in API functions */ MG(ctx) = ctx; MG(state) = MLFI_EOM; - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); MG(state) = MLFI_NONE; - + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -493,20 +484,19 @@ static sfsistat mlfi_abort(SMFICTX *ctx) { zval function_name, retval; int status; - TSRMLS_FETCH(); /* call userland */ INIT_ZVAL(function_name); ZVAL_STRING(&function_name, "milter_abort", 0); - + /* set the milter context for possible use in API functions */ MG(ctx) = ctx; MG(state) = MLFI_ABORT; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); + + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); MG(state) = MLFI_NONE; - + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -523,28 +513,27 @@ static sfsistat mlfi_close(SMFICTX *ctx) int ret = SMFIS_CONTINUE; zval function_name, retval; int status; - TSRMLS_FETCH(); - if (!SG(sapi_started) && SUCCESS != php_request_startup(TSRMLS_C)) { + if (!SG(sapi_started) && SUCCESS != php_request_startup()) { return ret; } /* call userland */ INIT_ZVAL(function_name); ZVAL_STRING(&function_name, "milter_close", 0); - + /* set the milter context for possible use in API functions */ MG(ctx) = ctx; MG(state) = MLFI_CLOSE; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); + + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); MG(state) = MLFI_NONE; - + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { ret = Z_LVAL(retval); } - + php_request_shutdown((void *) 0); return ret; @@ -575,38 +564,38 @@ static struct smfiDesc smfilter = { */ /* {{{ proto void smfi_setflags(long flags) - Sets the flags describing the actions the filter may take. */ + Sets the flags describing the actions the filter may take. */ PHP_FUNCTION(smfi_setflags) { long flags; - + /* valid only in the init callback */ if (MG(state) != MLFI_INIT) { - php_error(E_WARNING, NOT_INIT, get_active_function_name(TSRMLS_C)); - } else if (zend_parse_parameters(1 TSRMLS_CC, "l", &flags) == SUCCESS) { + php_error(E_WARNING, NOT_INIT, get_active_function_name()); + } else if (zend_parse_parameters(1, "l", &flags) == SUCCESS) { flags = flags & (SMFIF_ADDHDRS|SMFIF_CHGHDRS|SMFIF_CHGBODY|SMFIF_ADDRCPT|SMFIF_DELRCPT); smfilter.xxfi_flags = flags; - } + } } /* }}} */ /* {{{ proto void smfi_settimeout(long timeout) - Sets the number of seconds libmilter will wait for an MTA connection before timing out a socket. */ + Sets the number of seconds libmilter will wait for an MTA connection before timing out a socket. */ PHP_FUNCTION(smfi_settimeout) { long timeout; - + /* valid only in the init callback */ if (MG(state) != MLFI_INIT) { - php_error(E_WARNING, NOT_INIT, get_active_function_name(TSRMLS_C)); - } else if (zend_parse_parameters(1 TSRMLS_CC, "l", &timeout) == SUCCESS) { + php_error(E_WARNING, NOT_INIT, get_active_function_name()); + } else if (zend_parse_parameters(1, "l", &timeout) == SUCCESS) { smfi_settimeout(timeout); - } + } } /* }}} */ /* {{{ proto string smfi_getsymval(string macro) - Returns the value of the given macro or NULL if the macro is not defined. */ + Returns the value of the given macro or NULL if the macro is not defined. */ PHP_FUNCTION(smfi_getsymval) { char *symname, *ret; @@ -614,8 +603,8 @@ PHP_FUNCTION(smfi_getsymval) /* valid in any callback */ if (MG(state) == MLFI_NONE) { - php_error(E_WARNING, IS_NONE, get_active_function_name(TSRMLS_C)); - } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &symname, &len) == SUCCESS) { + php_error(E_WARNING, IS_NONE, get_active_function_name()); + } else if (zend_parse_parameters(1, "s", &symname, &len) == SUCCESS) { if ((ret = smfi_getsymval(MG(ctx), symname)) != NULL) { RETURN_STRING(ret, 1); } @@ -627,123 +616,123 @@ PHP_FUNCTION(smfi_getsymval) /* {{{ proto bool smfi_setreply(string rcode, string xcode, string message) Directly set the SMTP error reply code for this connection. - This code will be used on subsequent error replies resulting from actions taken by this filter. */ + This code will be used on subsequent error replies resulting from actions taken by this filter. */ PHP_FUNCTION(smfi_setreply) { char *rcode, *xcode, *message; int len; - + /* valid in any callback */ if (MG(state) == MLFI_NONE) { - php_error(E_WARNING, IS_NONE, get_active_function_name(TSRMLS_C)); - } else if (zend_parse_parameters(3 TSRMLS_CC, "sss", &rcode, &len, &xcode, &len, &message, &len) == SUCCESS) { + php_error(E_WARNING, IS_NONE, get_active_function_name()); + } else if (zend_parse_parameters(3, "sss", &rcode, &len, &xcode, &len, &message, &len) == SUCCESS) { if (smfi_setreply(MG(ctx), rcode, xcode, message) == MI_SUCCESS) { RETURN_TRUE; } } - + RETURN_FALSE; } /* }}} */ /* {{{ proto bool smfi_addheader(string headerf, string headerv) - Adds a header to the current message. */ + Adds a header to the current message. */ PHP_FUNCTION(smfi_addheader) { char *f, *v; int len; - + /* valid only in milter_eom */ if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C)); - } else if (zend_parse_parameters(2 TSRMLS_CC, "ss", &f, &len, &v, &len) == SUCCESS) { + php_error(E_WARNING, NOT_EOM, get_active_function_name()); + } else if (zend_parse_parameters(2, "ss", &f, &len, &v, &len) == SUCCESS) { if (smfi_addheader(MG(ctx), f, v) == MI_SUCCESS) { RETURN_TRUE; } } - + RETURN_FALSE; } /* }}} */ /* {{{ proto bool smfi_chgheader(string headerf, string headerv) - Changes a header's value for the current message. */ + Changes a header's value for the current message. */ PHP_FUNCTION(smfi_chgheader) { char *f, *v; long idx; int len; - + /* valid only in milter_eom */ if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C)); - } else if (zend_parse_parameters(3 TSRMLS_CC, "sls", &f, &len, &idx, &v, &len) == SUCCESS) { + php_error(E_WARNING, NOT_EOM, get_active_function_name()); + } else if (zend_parse_parameters(3, "sls", &f, &len, &idx, &v, &len) == SUCCESS) { if (smfi_chgheader(MG(ctx), f, idx, v) == MI_SUCCESS) { RETURN_TRUE; } } - + RETURN_FALSE; } /* }}} */ /* {{{ proto bool smfi_addrcpt(string rcpt) - Add a recipient to the message envelope. */ + Add a recipient to the message envelope. */ PHP_FUNCTION(smfi_addrcpt) { char *rcpt; int len; - + /* valid only in milter_eom */ if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C)); - } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) { + php_error(E_WARNING, NOT_EOM, get_active_function_name()); + } else if (zend_parse_parameters(1, "s", &rcpt, &len) == SUCCESS) { if (smfi_addrcpt(MG(ctx), rcpt) == MI_SUCCESS) { RETURN_TRUE; } } - + RETURN_FALSE; } /* }}} */ /* {{{ proto bool smfi_delrcpt(string rcpt) - Removes the named recipient from the current message's envelope. */ + Removes the named recipient from the current message's envelope. */ PHP_FUNCTION(smfi_delrcpt) { char *rcpt; int len; - + /* valid only in milter_eom */ if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C)); - } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) { + php_error(E_WARNING, NOT_EOM, get_active_function_name()); + } else if (zend_parse_parameters(1, "s", &rcpt, &len) == SUCCESS) { if (smfi_delrcpt(MG(ctx), rcpt) == MI_SUCCESS) { RETURN_TRUE; } } - + RETURN_FALSE; } /* }}} */ /* {{{ proto bool smfi_replacebody(string body) Replaces the body of the current message. If called more than once, - subsequent calls result in data being appended to the new body. */ + subsequent calls result in data being appended to the new body. */ PHP_FUNCTION(smfi_replacebody) { char *body; int len; - + /* valid only in milter_eom */ if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C)); - } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &body, &len) == SUCCESS) { + php_error(E_WARNING, NOT_EOM, get_active_function_name()); + } else if (zend_parse_parameters(1, "s", &body, &len) == SUCCESS) { if (smfi_replacebody(MG(ctx), (u_char*)body, len) == MI_SUCCESS) { RETURN_TRUE; } } - + RETURN_FALSE; } /* }}} */ @@ -859,31 +848,27 @@ static zend_module_entry php_milter_module = { /* {{{ Milter SAPI */ -static int sapi_milter_ub_write(const char *str, uint str_length TSRMLS_DC) +static int sapi_milter_ub_write(const char *str, uint str_length) { return str_length; } -static void sapi_milter_flush(void *server_context) +static void sapi_milter_register_variables(zval *track_vars_array) { + php_register_variable ("SERVER_SOFTWARE", "Sendmail Milter", track_vars_array); } -static void sapi_milter_register_variables(zval *track_vars_array TSRMLS_DC) -{ - php_register_variable ("SERVER_SOFTWARE", "Sendmail Milter", track_vars_array TSRMLS_CC); -} - -static int sapi_milter_post_read(char *buf, uint count_bytes TSRMLS_DC) +static int sapi_milter_post_read(char *buf, uint count_bytes) { return 0; } -static char* sapi_milter_read_cookies(TSRMLS_D) +static char* sapi_milter_read_cookies(void) { return NULL; } -static int sapi_milter_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_milter_send_headers(sapi_headers_struct *sapi_headers) { return SAPI_HEADER_SENT_SUCCESSFULLY; } @@ -910,7 +895,7 @@ static sapi_module_struct milter_sapi_module = { NULL, /* deactivate */ sapi_milter_ub_write, /* unbuffered write */ - sapi_milter_flush, /* flush */ + NULL, /* flush */ NULL, /* get uid */ NULL, /* getenv */ @@ -1021,7 +1006,7 @@ int main(int argc, char *argv[]) tsrm_startup(1, 1, 0, NULL); tsrm_ls = ts_resource(0); sapi_startup(&milter_sapi_module); - + while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { switch (c) { case 'c': @@ -1103,9 +1088,9 @@ int main(int argc, char *argv[]) break; case 'v': /* show php version & quit */ - if (php_request_startup(TSRMLS_C)==FAILURE) { - zend_ini_deactivate(TSRMLS_C); - php_module_shutdown(TSRMLS_C); + if (php_request_startup()==FAILURE) { + zend_ini_deactivate(); + php_module_shutdown(); sapi_shutdown(); tsrm_shutdown(); @@ -1138,8 +1123,6 @@ int main(int argc, char *argv[]) exit(1); } - CG(interactive) = interactive; - /* only set script_file if not set already and not in direct mode and not at end of parameter list */ if (argc > ap_php_optind && !filename) { filename=argv[ap_php_optind]; @@ -1147,7 +1130,7 @@ int main(int argc, char *argv[]) } /* check if file exists, exit else */ - + if (dofork) { switch(fork()) { case -1: /* Uh-oh, we have a problem forking. */ @@ -1160,14 +1143,14 @@ int main(int argc, char *argv[]) exit(0); } } - + if (sock) { struct stat junk; if (stat(sock,&junk) == 0) unlink(sock); } openlog("php-milter", LOG_PID, LOG_MAIL); - + if ((exit_status = mlfi_init())) { syslog(1, "mlfi_init failed."); closelog(); @@ -1182,7 +1165,7 @@ int main(int argc, char *argv[]) goto err; } else { exit_status = smfi_main(); - } + } closelog(); @@ -1195,7 +1178,7 @@ int main(int argc, char *argv[]) } zend_end_try(); err: - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); sapi_shutdown(); tsrm_shutdown(); diff --git a/sapi/nsapi/nsapi-readme.txt b/sapi/nsapi/nsapi-readme.txt index 10ad9f7eed..6bf4afb83d 100644 --- a/sapi/nsapi/nsapi-readme.txt +++ b/sapi/nsapi/nsapi-readme.txt @@ -1,4 +1,4 @@ -Configuration of your Netscape/iPlanet/Sun Webserver for PHP5 +Configuration of your Netscape/iPlanet/Sun Webserver for PHP7 ----------------------------------------------------------------- These instructions are targeted at Netscape Enterprise Web Server and @@ -28,13 +28,13 @@ Place the following two lines after mime.types init in for iPlanet/Sun Webserver 6.0 and above however at the end of the <path-to-server>/https-servername/config/magnus.conf file: - Init fn="load-modules" funcs="php5_init,php5_execute,php5_auth_trans" shlib="/path/to/phplibrary" - Init fn=php5_init errorString="Failed to initialize PHP!" [php_ini="/path/to/php.ini"] + Init fn="load-modules" funcs="php7_init,php7_execute,php7_auth_trans" shlib="/path/to/phplibrary" + Init fn=php7_init errorString="Failed to initialize PHP!" [php_ini="/path/to/php.ini"] The "shlib" will vary depending on your OS: - Unix: "<path-to-server>/bin/libphp5.so". - Windows: "c:/path/to/php5/php5nsapi.dll" + Unix: "<path-to-server>/bin/libphp7.so". + Windows: "c:/path/to/php7/php7nsapi.dll" In obj.conf (for virtual server classes [Sun 6.0+] in their vserver.obj.conf): @@ -50,7 +50,7 @@ In obj.conf (for virtual server classes [Sun 6.0+] in their vserver.obj.conf): # For boolean ini-keys please use 0/1 as value, NOT "On","Off",... (this will not work # correctly), e.g. zlib.output_compression=1 instead of zlib.output_compression="On" - Service fn="php5_execute" type="magnus-internal/x-httpd-php" [inikey=value ...] + Service fn="php7_execute" type="magnus-internal/x-httpd-php" [inikey=value ...] . . . @@ -61,7 +61,7 @@ PHP scripts (same like a cgi-bin directory): <Object name="x-httpd-php"> ObjectType fn="force-type" type="magnus-internal/x-httpd-php" - Service fn="php5_execute" [inikey=value ...] + Service fn="php7_execute" [inikey=value ...] </Object> After that you can configure a directory in the Administration server and assign it @@ -81,7 +81,7 @@ AUTHENTICATION IS PASSED TO YOUR PHP SCRIPT. To configure PHP Authentication for the entire server, add the following line: <Object name="default"> - AuthTrans fn=php5_auth_trans + AuthTrans fn=php7_auth_trans . . . @@ -92,7 +92,7 @@ Authentication for the entire server, add the following line: To use PHP Authentication on a single directory, add the following: <Object ppath="d:\path\to\authenticated\dir\*"> - AuthTrans fn=php5_auth_trans + AuthTrans fn=php7_auth_trans </Object> @@ -103,7 +103,7 @@ You can use PHP to generate the error pages for "404 Not Found" or similar. Add the following line to the object in obj.conf for every error page you want to overwrite: - Error fn="php5_execute" code=XXX script="/path/to/script.php" [inikey=value inikey=value...] + Error fn="php7_execute" code=XXX script="/path/to/script.php" [inikey=value inikey=value...] where XXX ist the HTTP error code. Please delete any other Error directives which could interfere with yours. @@ -116,7 +116,7 @@ Just generate a PHP script which displays a directory listing and replace the corresponding default Service line for type="magnus-internal/directory" in obj.conf with the following: - Service fn="php5_execute" type="magnus-internal/directory" script="/path/to/script.php" [inikey=value inikey=value...] + Service fn="php7_execute" type="magnus-internal/directory" script="/path/to/script.php" [inikey=value inikey=value...] For both error and directory listing pages the original URI and translated URI are in the variables $_SERVER['PATH_INFO'] and @@ -141,9 +141,9 @@ till version 6.1. If a newer version of the Sun server is used, the detection fails and nsapi_virtual() is disabled. If this is the case, try the following: -Add the following parameter to php5_init in magnus.conf: +Add the following parameter to php7_init in magnus.conf: - Init fn=php5_init ... server_lib="ns-httpdXX.dll" + Init fn=php7_init ... server_lib="ns-httpdXX.dll" where XX is the correct DLL version number. To get it, look in the server-root for the correct DLL name. The DLL with the biggest filesize is the right one. diff --git a/sapi/nsapi/nsapi.c b/sapi/nsapi/nsapi.c index 6f7773f879..4c625794c7 100644 --- a/sapi/nsapi/nsapi.c +++ b/sapi/nsapi/nsapi.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -62,7 +62,7 @@ #ifdef __hpux #define HPUX #endif - + /* * NSAPI includes */ @@ -233,7 +233,7 @@ nsapi_servact_prototype nsapi_servact_service = NULL; * the server only by wrapping the function table nothing else. So choose * the newest one found in process space for dynamic linking */ static char *nsapi_dlls[] = { "ns-httpd40.dll", "ns-httpd36.dll", "ns-httpd35.dll", "ns-httpd30.dll", NULL }; -/* if user specifies an other dll name by server_lib parameter +/* if user specifies an other dll name by server_lib parameter * it is placed in the following variable and only this DLL is * checked for the servact_* functions */ char *nsapi_dll = NULL; @@ -251,7 +251,7 @@ static void php_nsapi_init_dynamic_symbols(void) /* try user specified server_lib */ module = GetModuleHandle(nsapi_dll); if (!module) { - log_error(LOG_WARN, "php5_init", NULL, NULL, "Cannot find DLL specified by server_lib parameter: %s", nsapi_dll); + log_error(LOG_WARN, "php7_init", NULL, NULL, "Cannot find DLL specified by server_lib parameter: %s", nsapi_dll); } } else { /* find a LOADED dll module from nsapi_dlls */ @@ -336,24 +336,24 @@ PHP_FUNCTION(nsapi_virtual) Request *rq; nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &uri, &uri_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &uri, &uri_len) == FAILURE) { return; } if (!nsapi_servact_service) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include uri '%s' - Sub-requests not supported on this platform", uri); + php_error_docref(NULL, E_WARNING, "Unable to include uri '%s' - Sub-requests not supported on this platform", uri); RETURN_FALSE; } else if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include uri '%s' - Sub-requests do not work with zlib.output_compression", uri); + php_error_docref(NULL, E_WARNING, "Unable to include uri '%s' - Sub-requests do not work with zlib.output_compression", uri); RETURN_FALSE; } else { - php_output_end_all(TSRMLS_C); - php_header(TSRMLS_C); + php_output_end_all(); + php_header(); /* do the sub-request */ /* thanks to Chris Elving from Sun for this code sniplet */ if ((rq = request_restart_internal(uri, NULL)) == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include uri '%s' - Internal request creation failed", uri); + php_error_docref(NULL, E_WARNING, "Unable to include uri '%s' - Internal request creation failed", uri); RETURN_FALSE; } @@ -385,7 +385,7 @@ PHP_FUNCTION(nsapi_virtual) } while (rv == REQ_RESTART); if (rq->status_num != 200) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include uri '%s' - HTTP status code %d during subrequest", uri, rq->status_num); + php_error_docref(NULL, E_WARNING, "Unable to include uri '%s' - HTTP status code %d during subrequest", uri, rq->status_num); request_free(rq); RETURN_FALSE; } @@ -408,13 +408,13 @@ PHP_FUNCTION(nsapi_request_headers) if (zend_parse_parameters_none() == FAILURE) { return; } - + array_init(return_value); for (i=0; i < rc->rq->headers->hsize; i++) { entry=rc->rq->headers->ht[i]; while (entry) { - add_assoc_string(return_value, entry->param->name, entry->param->value, 1); + add_assoc_string(return_value, entry->param->name, entry->param->value); entry=entry->next; } } @@ -432,13 +432,13 @@ PHP_FUNCTION(nsapi_response_headers) if (zend_parse_parameters_none() == FAILURE) { return; } - + array_init(return_value); for (i=0; i < rc->rq->srvhdrs->hsize; i++) { entry=rc->rq->srvhdrs->ht[i]; while (entry) { - add_assoc_string(return_value, entry->param->name, entry->param->value, 1); + add_assoc_string(return_value, entry->param->name, entry->param->value); entry=entry->next; } } @@ -450,13 +450,13 @@ PHP_FUNCTION(nsapi_response_headers) /* SAPI part */ /*************/ -static int sapi_nsapi_ub_write(const char *str, unsigned int str_length TSRMLS_DC) +static int sapi_nsapi_ub_write(const char *str, unsigned int str_length) { int retval; nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); - + if (!SG(headers_sent)) { - sapi_send_headers(TSRMLS_C); + sapi_send_headers(); } retval = net_write(rc->sn->csd, (char *)str, str_length); @@ -470,15 +470,14 @@ static int sapi_nsapi_ub_write(const char *str, unsigned int str_length TSRMLS_D static void sapi_nsapi_flush(void *server_context) { nsapi_request_context *rc = (nsapi_request_context *)server_context; - TSRMLS_FETCH(); - + if (!rc) { /* we have no context, so no flushing needed. This fixes a SIGSEGV on shutdown */ return; } if (!SG(headers_sent)) { - sapi_send_headers(TSRMLS_C); + sapi_send_headers(); } /* flushing is only supported in iPlanet servers from version 6.1 on, make it conditional */ @@ -490,11 +489,11 @@ static void sapi_nsapi_flush(void *server_context) } /* callback for zend_llist_apply on SAPI_HEADER_DELETE_ALL operation */ -static int php_nsapi_remove_header(sapi_header_struct *sapi_header TSRMLS_DC) +static int php_nsapi_remove_header(sapi_header_struct *sapi_header) { char *header_name, *p; nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); - + /* copy the header, because NSAPI needs reformatting and we do not want to change the parameter */ header_name = pool_strdup(rc->sn->pool, sapi_header->header); @@ -502,20 +501,20 @@ static int php_nsapi_remove_header(sapi_header_struct *sapi_header TSRMLS_DC) if (p = strchr(header_name, ':')) { *p = 0; } - + /* header_name to lower case because NSAPI reformats the headers and wants lowercase */ for (p=header_name; *p; p++) { *p=tolower(*p); } - + /* remove the header */ param_free(pblock_remove(header_name, rc->rq->srvhdrs)); pool_free(rc->sn->pool, header_name); - + return ZEND_HASH_APPLY_KEEP; } -static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) { char *header_name, *header_content, *p; nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); @@ -523,12 +522,12 @@ static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_heade switch(op) { case SAPI_HEADER_DELETE_ALL: /* this only deletes headers set or overwritten by PHP, headers previously set by NSAPI are left intact */ - zend_llist_apply(&sapi_headers->headers, (llist_apply_func_t) php_nsapi_remove_header TSRMLS_CC); + zend_llist_apply(&sapi_headers->headers, (llist_apply_func_t) php_nsapi_remove_header); return 0; case SAPI_HEADER_DELETE: /* reuse the zend_llist_apply callback function for this, too */ - php_nsapi_remove_header(sapi_header TSRMLS_CC); + php_nsapi_remove_header(sapi_header); return 0; case SAPI_HEADER_ADD: @@ -543,7 +542,7 @@ static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_heade do { header_content++; } while (*header_content==' '); - + /* header_name to lower case because NSAPI reformats the headers and wants lowercase */ for (p=header_name; *p; p++) { *p=tolower(*p); @@ -556,16 +555,16 @@ static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_heade /* ADD header to nsapi table */ pblock_nvinsert(header_name, header_content, rc->rq->srvhdrs); } - + pool_free(rc->sn->pool, header_name); return SAPI_HEADER_ADD; - + default: return 0; } } -static int sapi_nsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_nsapi_send_headers(sapi_headers_struct *sapi_headers) { int retval; nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); @@ -573,7 +572,7 @@ static int sapi_nsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) if (SG(sapi_headers).send_default_content_type) { char *hd; param_free(pblock_remove("content-type", rc->rq->srvhdrs)); - hd = sapi_get_default_content_type(TSRMLS_C); + hd = sapi_get_default_content_type(); pblock_nvinsert("content-type", hd, rc->rq->srvhdrs); efree(hd); } @@ -588,7 +587,7 @@ static int sapi_nsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) } } -static int sapi_nsapi_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static int sapi_nsapi_read_post(char *buffer, uint count_bytes) { nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); char *read_ptr = buffer, *content_length_str = NULL; @@ -646,7 +645,7 @@ static int sapi_nsapi_read_post(char *buffer, uint count_bytes TSRMLS_DC) return bytes_read; } -static char *sapi_nsapi_read_cookies(TSRMLS_D) +static char *sapi_nsapi_read_cookies(void) { char *cookie_string; nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); @@ -655,7 +654,7 @@ static char *sapi_nsapi_read_cookies(TSRMLS_D) return cookie_string; } -static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_nsapi_register_server_variables(zval *track_vars_array) { nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); register size_t i; @@ -667,7 +666,7 @@ static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_D 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); + php_register_variable((char *)nsapi_reqpb[i].env_var, value, track_vars_array); } } @@ -688,7 +687,7 @@ static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_D *p = '_'; } } - php_register_variable(value, entry->param->value, track_vars_array TSRMLS_CC); + php_register_variable(value, entry->param->value, track_vars_array); efree(value); } entry=entry->next; @@ -698,64 +697,64 @@ static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_D 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); + php_register_variable((char *)nsapi_vars[i].env_var, value, track_vars_array); } } 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); + php_register_variable((char *)nsapi_client[i].env_var, value, track_vars_array); } } if (value = session_dns(rc->sn)) { - php_register_variable("REMOTE_HOST", value, track_vars_array TSRMLS_CC); + php_register_variable("REMOTE_HOST", value, track_vars_array); nsapi_free(value); } slprintf(buf, sizeof(buf), "%d", conf_getglobals()->Vport); - php_register_variable("SERVER_PORT", buf, track_vars_array TSRMLS_CC); - php_register_variable("SERVER_NAME", conf_getglobals()->Vserver_hostname, track_vars_array TSRMLS_CC); + php_register_variable("SERVER_PORT", buf, track_vars_array); + php_register_variable("SERVER_NAME", conf_getglobals()->Vserver_hostname, track_vars_array); value = http_uri2url_dynamic("", "", rc->sn, rc->rq); - php_register_variable("SERVER_URL", value, track_vars_array TSRMLS_CC); + php_register_variable("SERVER_URL", value, track_vars_array); nsapi_free(value); - php_register_variable("SERVER_SOFTWARE", system_version(), track_vars_array TSRMLS_CC); + php_register_variable("SERVER_SOFTWARE", system_version(), track_vars_array); if (security_active) { - php_register_variable("HTTPS", "ON", track_vars_array TSRMLS_CC); + php_register_variable("HTTPS", "ON", track_vars_array); } - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array TSRMLS_CC); + php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array); /* DOCUMENT_ROOT */ if (value = request_translate_uri("/", rc->sn)) { pos = strlen(value); - php_register_variable_safe("DOCUMENT_ROOT", value, pos-1, track_vars_array TSRMLS_CC); + php_register_variable_safe("DOCUMENT_ROOT", value, pos-1, track_vars_array); nsapi_free(value); } /* PATH_INFO / PATH_TRANSLATED */ if (rc->path_info) { if (value = request_translate_uri(rc->path_info, rc->sn)) { - php_register_variable("PATH_TRANSLATED", value, track_vars_array TSRMLS_CC); + php_register_variable("PATH_TRANSLATED", value, track_vars_array); nsapi_free(value); } - php_register_variable("PATH_INFO", rc->path_info, track_vars_array TSRMLS_CC); + php_register_variable("PATH_INFO", rc->path_info, track_vars_array); } /* Create full Request-URI & Script-Name */ if (SG(request_info).request_uri) { pos = strlen(SG(request_info).request_uri); - + if (SG(request_info).query_string) { spprintf(&value, 0, "%s?%s", SG(request_info).request_uri, SG(request_info).query_string); if (value) { - php_register_variable("REQUEST_URI", value, track_vars_array TSRMLS_CC); + php_register_variable("REQUEST_URI", value, track_vars_array); efree(value); } } else { - php_register_variable_safe("REQUEST_URI", SG(request_info).request_uri, pos, track_vars_array TSRMLS_CC); + php_register_variable_safe("REQUEST_URI", SG(request_info).request_uri, pos, track_vars_array); } if (rc->path_info) { @@ -764,29 +763,29 @@ static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_D pos = 0; } } - php_register_variable_safe("SCRIPT_NAME", SG(request_info).request_uri, pos, track_vars_array TSRMLS_CC); + php_register_variable_safe("SCRIPT_NAME", SG(request_info).request_uri, pos, track_vars_array); } - php_register_variable("SCRIPT_FILENAME", SG(request_info).path_translated, track_vars_array TSRMLS_CC); + php_register_variable("SCRIPT_FILENAME", SG(request_info).path_translated, track_vars_array); /* special variables in error mode */ if (rc->http_error) { slprintf(buf, sizeof(buf), "%d", rc->http_error); - php_register_variable("ERROR_TYPE", buf, track_vars_array TSRMLS_CC); + php_register_variable("ERROR_TYPE", buf, track_vars_array); } } -static void nsapi_log_message(char *message TSRMLS_DC) +static void nsapi_log_message(char *message) { nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); if (rc) { log_error(LOG_INFORM, pblock_findval("fn", rc->pb), rc->sn, rc->rq, "%s", message); } else { - log_error(LOG_INFORM, "php5", NULL, NULL, "%s", message); + log_error(LOG_INFORM, "php7", NULL, NULL, "%s", message); } } -static double sapi_nsapi_get_request_time(TSRMLS_D) +static double sapi_nsapi_get_request_time(void) { return REQ_TIME( ((nsapi_request_context *)SG(server_context))->rq ); } @@ -799,7 +798,7 @@ static int php_nsapi_startup(sapi_module_struct *sapi_module) return SUCCESS; } -static struct stat* sapi_nsapi_get_stat(TSRMLS_D) +static struct stat* sapi_nsapi_get_stat(void) { return request_stat_path( SG(request_info).path_translated, @@ -842,7 +841,7 @@ static sapi_module_struct nsapi_sapi_module = { STANDARD_SAPI_MODULE_PROPERTIES }; -static void nsapi_php_ini_entries(NSLS_D TSRMLS_DC) +static void nsapi_php_ini_entries(NSLS_D) { struct pb_entry *entry; register int i,j,ok; @@ -869,7 +868,7 @@ static void nsapi_php_ini_entries(NSLS_D TSRMLS_DC) } } -void NSAPI_PUBLIC php5_close(void *vparam) +void NSAPI_PUBLIC php7_close(void *vparam) { if (nsapi_sapi_module.shutdown) { nsapi_sapi_module.shutdown(&nsapi_sapi_module); @@ -878,24 +877,24 @@ void NSAPI_PUBLIC php5_close(void *vparam) if (nsapi_sapi_module.php_ini_path_override) { free(nsapi_sapi_module.php_ini_path_override); } - + #ifdef PHP_WIN32 if (nsapi_dll) { free(nsapi_dll); nsapi_dll = NULL; } -#endif +#endif sapi_shutdown(); tsrm_shutdown(); - log_error(LOG_INFORM, "php5_close", NULL, NULL, "Shutdown PHP Module"); + log_error(LOG_INFORM, "php7_close", NULL, NULL, "Shutdown PHP Module"); } /********************************************************* / init SAF / -/ Init fn="php5_init" [php_ini="/path/to/php.ini"] [server_lib="ns-httpdXX.dll"] +/ Init fn="php7_init" [php_ini="/path/to/php.ini"] [server_lib="ns-httpdXX.dll"] / Initialize the NSAPI module in magnus.conf / / php_ini: gives path to php.ini file @@ -903,7 +902,7 @@ void NSAPI_PUBLIC php5_close(void *vparam) / servact_* functions / /*********************************************************/ -int NSAPI_PUBLIC php5_init(pblock *pb, Session *sn, Request *rq) +int NSAPI_PUBLIC php7_init(pblock *pb, Session *sn, Request *rq) { php_core_globals *core_globals; char *strval; @@ -918,24 +917,24 @@ int NSAPI_PUBLIC php5_init(pblock *pb, Session *sn, Request *rq) core_globals = ts_resource(core_globals_id); - /* look if php_ini parameter is given to php5_init */ + /* look if php_ini parameter is given to php7_init */ if (strval = pblock_findval("php_ini", pb)) { nsapi_sapi_module.php_ini_path_override = strdup(strval); } - + #ifdef PHP_WIN32 - /* look if server_lib parameter is given to php5_init + /* look if server_lib parameter is given to php7_init * (this disables the automatic search for the newest ns-httpdXX.dll) */ if (strval = pblock_findval("server_lib", pb)) { nsapi_dll = strdup(strval); } -#endif +#endif /* start SAPI */ sapi_startup(&nsapi_sapi_module); nsapi_sapi_module.startup(&nsapi_sapi_module); - daemon_atrestart(&php5_close, NULL); + daemon_atrestart(&php7_close, NULL); log_error(LOG_INFORM, pblock_findval("fn", pb), sn, rq, "Initialized PHP Module (%d threads expected)", threads); return REQ_PROCEED; @@ -944,19 +943,19 @@ int NSAPI_PUBLIC php5_init(pblock *pb, Session *sn, Request *rq) /********************************************************* / normal use in Service directive: / -/ Service fn="php5_execute" type=... method=... [inikey=inivalue inikey=inivalue...] +/ Service fn="php7_execute" type=... method=... [inikey=inivalue inikey=inivalue...] / / use in Service for a directory to supply a php-made directory listing instead of server default: / -/ Service fn="php5_execute" type="magnus-internal/directory" script="/path/to/script.php" [inikey=inivalue inikey=inivalue...] +/ Service fn="php7_execute" type="magnus-internal/directory" script="/path/to/script.php" [inikey=inivalue inikey=inivalue...] / / use in Error SAF to display php script as error page: / -/ Error fn="php5_execute" code=XXX script="/path/to/script.php" [inikey=inivalue inikey=inivalue...] -/ Error fn="php5_execute" reason="Reason" script="/path/to/script.php" [inikey=inivalue inikey=inivalue...] +/ Error fn="php7_execute" code=XXX script="/path/to/script.php" [inikey=inivalue inikey=inivalue...] +/ Error fn="php7_execute" reason="Reason" script="/path/to/script.php" [inikey=inivalue inikey=inivalue...] / /*********************************************************/ -int NSAPI_PUBLIC php5_execute(pblock *pb, Session *sn, Request *rq) +int NSAPI_PUBLIC php7_execute(pblock *pb, Session *sn, Request *rq) { int retval; nsapi_request_context *request_context; @@ -976,7 +975,6 @@ int NSAPI_PUBLIC php5_execute(pblock *pb, Session *sn, Request *rq) /* try to use script parameter -> Error or Service for directory listing */ char *path_translated = pblock_findval("script", pb); - TSRMLS_FETCH(); /* if script parameter is missing: normal use as Service SAF */ if (!path_translated) { @@ -1027,10 +1025,10 @@ int NSAPI_PUBLIC php5_execute(pblock *pb, Session *sn, Request *rq) SG(request_info).content_type = content_type; SG(request_info).content_length = (content_length == NULL) ? 0 : strtoul(content_length, 0, 0); SG(sapi_headers).http_response_code = (error_directive) ? rq->status_num : 200; - - nsapi_php_ini_entries(NSLS_C TSRMLS_CC); - php_handle_auth_data(pblock_findval("authorization", rq->headers) TSRMLS_CC); + nsapi_php_ini_entries(NSLS_C); + + php_handle_auth_data(pblock_findval("authorization", rq->headers)); file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = SG(request_info).path_translated; @@ -1039,8 +1037,8 @@ int NSAPI_PUBLIC php5_execute(pblock *pb, Session *sn, Request *rq) fst = request_stat_path(SG(request_info).path_translated, rq); if (fst && S_ISREG(fst->st_mode)) { - if (php_request_startup(TSRMLS_C) == SUCCESS) { - php_execute_script(&file_handle TSRMLS_CC); + if (php_request_startup() == SUCCESS) { + php_execute_script(&file_handle); php_request_shutdown(NULL); retval=REQ_PROCEED; } else { @@ -1077,15 +1075,15 @@ int NSAPI_PUBLIC php5_execute(pblock *pb, Session *sn, Request *rq) / will pass authentication through to php, and allow us to / check authentication with our scripts. / -/ php5_auth_trans +/ php7_auth_trans / main function called from netscape server to authenticate / a line in obj.conf: -/ funcs=php5_auth_trans shlib="path/to/this/phpnsapi.dll" +/ funcs=php7_auth_trans shlib="path/to/this/phpnsapi.dll" / and: / <Object ppath="path/to/be/authenticated/by/php/*"> -/ AuthTrans fn="php5_auth_trans" +/ AuthTrans fn="php7_auth_trans" /*********************************************************/ -int NSAPI_PUBLIC php5_auth_trans(pblock * pb, Session * sn, Request * rq) +int NSAPI_PUBLIC php7_auth_trans(pblock * pb, Session * sn, Request * rq) { /* This is a DO NOTHING function that allows authentication * information diff --git a/sapi/nsapi/php5nsapi.dsp b/sapi/nsapi/php5nsapi.dsp deleted file mode 100644 index 6cd0079b43..0000000000 --- a/sapi/nsapi/php5nsapi.dsp +++ /dev/null @@ -1,135 +0,0 @@ -# Microsoft Developer Studio Project File - Name="php5nsapi" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=php5nsapi - 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 "php5nsapi.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 "php5nsapi.mak" CFG="php5nsapi - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "php5nsapi - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5nsapi - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "php5nsapi - 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)" == "php5nsapi - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php5nsapi___Win32_Release_TS"
-# PROP BASE Intermediate_Dir "php5nsapi___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 "php5nsapi_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 "php5nsapi_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 php5ts.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)" == "php5nsapi - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "php5nsapi___Win32_Release_TS_inline"
-# PROP BASE Intermediate_Dir "php5nsapi___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 "php5nsapi_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 "php5nsapi_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 php5ts.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)" == "php5nsapi - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "php5nsapi___Win32_Debug_TS"
-# PROP BASE Intermediate_Dir "php5nsapi___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 "php5nsapi_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 "php5nsapi_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 php5ts_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 "php5nsapi - Win32 Release_TS"
-# Name "php5nsapi - Win32 Release_TS_inline"
-# Name "php5nsapi - 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/phpdbg/.travis.yml b/sapi/phpdbg/.travis.yml index d5b492e7cf..2e777fbe13 100644 --- a/sapi/phpdbg/.travis.yml +++ b/sapi/phpdbg/.travis.yml @@ -4,7 +4,6 @@ env: - PHP="PHP-5.4" - PHP="PHP-5.5" - PHP="PHP-5.6" -- PHP="master" before_script: ./travis/ci.sh diff --git a/sapi/phpdbg/README.md b/sapi/phpdbg/README.md index e7e5c731a8..a2a84deb7b 100644 --- a/sapi/phpdbg/README.md +++ b/sapi/phpdbg/README.md @@ -1,7 +1,7 @@ The interactive PHP debugger ============================ -Implemented as a SAPI module, phpdbg can excert complete control over the environment without impacting the functionality or performance of your code. +Implemented as a SAPI module, phpdbg can exert complete control over the environment without impacting the functionality or performance of your code. phpdbg aims to be a lightweight, powerful, easy to use debugging platform for PHP 5.4+ diff --git a/sapi/phpdbg/config.m4 b/sapi/phpdbg/config.m4 index d78a439af0..87d38ea8c5 100644 --- a/sapi/phpdbg/config.m4 +++ b/sapi/phpdbg/config.m4 @@ -3,12 +3,15 @@ dnl $Id$ dnl PHP_ARG_ENABLE(phpdbg, for phpdbg support, -[ --enable-phpdbg Build phpdbg], no, no) +[ --enable-phpdbg Build phpdbg], no, no) + +PHP_ARG_ENABLE(phpdbg-webhelper, for phpdbg web SAPI support, +[ --enable-phpdbg-webhelper Build phpdbg web SAPI support], yes, yes) PHP_ARG_ENABLE(phpdbg-debug, for phpdbg debug build, -[ --enable-phpdbg-debug Build phpdbg in debug mode], no, no) +[ --enable-phpdbg-debug Build phpdbg in debug mode], no, no) -if test "$PHP_PHPDBG" != "no"; then +if test "$BUILD_PHPDBG" == "" && test "$PHP_PHPDBG" != "no"; then AC_HEADER_TIOCGWINSZ AC_DEFINE(HAVE_PHPDBG, 1, [ ]) @@ -18,8 +21,15 @@ if test "$PHP_PHPDBG" != "no"; then AC_DEFINE(PHPDBG_DEBUG, 0, [ ]) fi + if test "$PHP_PHPDBG_WEBHELPER" != "no"; then + if ! test -d $abs_srcdir/ext/phpdbg_webhelper; then + ln -s ../sapi/phpdbg $abs_srcdir/ext/phpdbg_webhelper + fi + PHP_NEW_EXTENSION(phpdbg_webhelper, phpdbg_rinit_hook.c phpdbg_webdata_transfer.c, $ext_shared) + fi + PHP_PHPDBG_CFLAGS="-D_GNU_SOURCE" - PHP_PHPDBG_FILES="phpdbg.c phpdbg_parser.c phpdbg_lexer.c phpdbg_prompt.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_info.c phpdbg_cmd.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_btree.c" + PHP_PHPDBG_FILES="phpdbg.c phpdbg_parser.c phpdbg_lexer.c phpdbg_prompt.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_info.c phpdbg_cmd.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_btree.c phpdbg_sigsafe.c phpdbg_wait.c phpdbg_io.c phpdbg_eol.c phpdbg_out.c" if test "$PHP_READLINE" != "no" -o "$PHP_LIBEDIT" != "no"; then PHPDBG_EXTRA_LIBS="$PHP_READLINE_LIBS" diff --git a/sapi/phpdbg/config.w32 b/sapi/phpdbg/config.w32 index 17e15b6ced..8a685d3347 100644 --- a/sapi/phpdbg/config.w32 +++ b/sapi/phpdbg/config.w32 @@ -1,7 +1,12 @@ ARG_ENABLE('phpdbg', 'Build phpdbg', 'no'); ARG_ENABLE('phpdbgs', 'Build phpdbg shared', 'no'); +ARG_ENABLE('phpdbg-webhelper', 'Build phpdbg webhelper', 'yes'); -PHPDBG_SOURCES='phpdbg.c phpdbg_prompt.c phpdbg_cmd.c phpdbg_info.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_win.c phpdbg_btree.c phpdbg_parser.c phpdbg_lexer.c'; +PHPDBG_SOURCES='phpdbg.c phpdbg_prompt.c phpdbg_cmd.c phpdbg_info.c phpdbg_help.c phpdbg_break.c ' + + 'phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c ' + + 'phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_win.c phpdbg_btree.c '+ + 'phpdbg_parser.c phpdbg_lexer.c phpdbg_sigsafe.c phpdbg_wait.c phpdbg_io.c ' + + 'phpdbg_sigio_win32.c phpdbg_eol.c phpdbg_out.c'; PHPDBG_DLL='php' + PHP_VERSION + 'phpdbg.dll'; PHPDBG_EXE='phpdbg.exe'; @@ -9,6 +14,11 @@ if (PHP_PHPDBG == "yes") { SAPI('phpdbg', PHPDBG_SOURCES, PHPDBG_EXE); ADD_FLAG("LIBS_PHPDBG", "ws2_32.lib user32.lib"); ADD_FLAG("CFLAGS_PHPDBG", "/D YY_NO_UNISTD_H"); + ADD_FLAG("LDFLAGS_PHPDBG", "/stack:8388608"); + + if (PHP_PHPDBG_WEBHELPER == "yes") { + EXTENSION('phpdbg_webhelper', 'phpdbg_rinit_hook.c phpdbg_webdata_transfer.c'); + } } if (PHP_PHPDBGS == "yes") { diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 6fce7f4a42..f2f18b944e 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -28,7 +28,9 @@ #include "phpdbg_list.h" #include "phpdbg_utils.h" #include "phpdbg_set.h" +#include "phpdbg_io.h" #include "zend_alloc.h" +#include "phpdbg_eol.h" /* {{{ remote console headers */ #ifndef _WIN32 @@ -36,19 +38,35 @@ # include <sys/select.h> # include <sys/time.h> # include <sys/types.h> +# include <sys/poll.h> # include <netinet/in.h> # include <unistd.h> # include <arpa/inet.h> #endif /* }}} */ ZEND_DECLARE_MODULE_GLOBALS(phpdbg); +int phpdbg_startup_run = 0; + +static PHP_INI_MH(OnUpdateEol) +{ + if (!new_value) { + return FAILURE; + } + + return phpdbg_eol_global_update(new_value->val); +} + +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY("phpdbg.path", "", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdateString, socket_path, zend_phpdbg_globals, phpdbg_globals) + STD_PHP_INI_ENTRY("phpdbg.eol", "2", PHP_INI_ALL, OnUpdateEol, socket_path, zend_phpdbg_globals, phpdbg_globals) +PHP_INI_END() static zend_bool phpdbg_booted = 0; #if PHP_VERSION_ID >= 50500 -void (*zend_execute_old)(zend_execute_data *execute_data TSRMLS_DC); +void (*zend_execute_old)(zend_execute_data *execute_data); #else -void (*zend_execute_old)(zend_op_array *op_array TSRMLS_DC); +void (*zend_execute_old)(zend_op_array *op_array); #endif static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */ @@ -63,20 +81,40 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */ pg->exec = NULL; pg->exec_len = 0; pg->buffer = NULL; + pg->last_was_newline = 1; pg->ops = NULL; pg->vmret = 0; + pg->in_execution = 0; pg->bp_count = 0; pg->flags = PHPDBG_DEFAULT_FLAGS; pg->oplog = NULL; - pg->io[PHPDBG_STDIN] = NULL; - pg->io[PHPDBG_STDOUT] = NULL; - pg->io[PHPDBG_STDERR] = NULL; + memset(pg->io, 0, sizeof(pg->io)); pg->frame.num = 0; + pg->sapi_name_ptr = NULL; + pg->socket_fd = -1; + pg->socket_server_fd = -1; + + pg->req_id = 0; + pg->err_buf.active = 0; + pg->err_buf.type = 0; + + pg->input_buflen = 0; + pg->sigsafe_mem.mem = NULL; + pg->sigsegv_bailout = NULL; + +#ifdef PHP_WIN32 + pg->sigio_watcher_thread = INVALID_HANDLE_VALUE; + memset(&pg->swd, 0, sizeof(struct win32_sigio_watcher_data)); +#endif + + pg->eol = PHPDBG_EOL_LF; } /* }}} */ static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */ { ZEND_INIT_MODULE_GLOBALS(phpdbg, php_phpdbg_globals_ctor, NULL); + REGISTER_INI_ENTRIES(); + #if PHP_VERSION_ID >= 50500 zend_execute_old = zend_execute_ex; zend_execute_ex = phpdbg_execute_ex; @@ -86,7 +124,7 @@ static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */ #endif REGISTER_STRINGL_CONSTANT("PHPDBG_VERSION", PHPDBG_VERSION, sizeof(PHPDBG_VERSION)-1, CONST_CS|CONST_PERSISTENT); - + REGISTER_LONG_CONSTANT("PHPDBG_FILE", FILE_PARAM, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PHPDBG_METHOD", METHOD_PARAM, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PHPDBG_LINENO", NUMERIC_PARAM, CONST_CS|CONST_PERSISTENT); @@ -99,56 +137,54 @@ static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */ return SUCCESS; } /* }}} */ -static void php_phpdbg_destroy_bp_file(void *brake) /* {{{ */ +static void php_phpdbg_destroy_bp_file(zval *brake) /* {{{ */ { - zend_hash_destroy((HashTable*)brake); + zend_hash_destroy(Z_ARRVAL_P(brake)); } /* }}} */ -static void php_phpdbg_destroy_bp_symbol(void *brake) /* {{{ */ +static void php_phpdbg_destroy_bp_symbol(zval *brake) /* {{{ */ { - efree((char*)((phpdbg_breaksymbol_t*)brake)->symbol); + efree((char *) ((phpdbg_breaksymbol_t *) Z_PTR_P(brake))->symbol); } /* }}} */ -static void php_phpdbg_destroy_bp_opcode(void *brake) /* {{{ */ +static void php_phpdbg_destroy_bp_opcode(zval *brake) /* {{{ */ { - efree((char*)((phpdbg_breakop_t*)brake)->name); + efree((char *) ((phpdbg_breakop_t *) Z_PTR_P(brake))->name); } /* }}} */ -static void php_phpdbg_destroy_bp_methods(void *brake) /* {{{ */ +static void php_phpdbg_destroy_bp_methods(zval *brake) /* {{{ */ { - zend_hash_destroy((HashTable*)brake); + zend_hash_destroy(Z_ARRVAL_P(brake)); } /* }}} */ -static void php_phpdbg_destroy_bp_condition(void *data) /* {{{ */ +static void php_phpdbg_destroy_bp_condition(zval *data) /* {{{ */ { - phpdbg_breakcond_t *brake = (phpdbg_breakcond_t*) data; + phpdbg_breakcond_t *brake = (phpdbg_breakcond_t *) Z_PTR_P(data); if (brake) { if (brake->ops) { - TSRMLS_FETCH(); - destroy_op_array( - brake->ops TSRMLS_CC); + destroy_op_array(brake->ops); efree(brake->ops); } - efree((char*)brake->code); + efree((char*) brake->code); } } /* }}} */ -static void php_phpdbg_destroy_registered(void *data) /* {{{ */ +static void php_phpdbg_destroy_registered(zval *data) /* {{{ */ { - zend_function *function = (zend_function*) data; - TSRMLS_FETCH(); + zend_function *function = (zend_function *) Z_PTR_P(data); + - destroy_zend_function( - function TSRMLS_CC); + destroy_zend_function(function); } /* }}} */ static PHP_RINIT_FUNCTION(phpdbg) /* {{{ */ { - zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], 8, NULL, php_phpdbg_destroy_bp_file, 0); + zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], 8, NULL, php_phpdbg_destroy_bp_file, 0); + zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], 8, NULL, php_phpdbg_destroy_bp_file, 0); zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], 8, NULL, php_phpdbg_destroy_bp_symbol, 0); zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], 8, NULL, php_phpdbg_destroy_bp_methods, 0); zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], 8, NULL, php_phpdbg_destroy_bp_methods, 0); @@ -178,6 +214,7 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */ zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_COND]); zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP]); zend_hash_destroy(&PHPDBG_G(seek)); + zend_hash_destroy(&PHPDBG_G(file_sources)); zend_hash_destroy(&PHPDBG_G(registered)); zend_hash_destroy(&PHPDBG_G(watchpoints)); zend_llist_destroy(&PHPDBG_G(watchlist_mem)); @@ -186,7 +223,7 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */ efree(PHPDBG_G(buffer)); PHPDBG_G(buffer) = NULL; } - + if (PHPDBG_G(exec)) { efree(PHPDBG_G(exec)); PHPDBG_G(exec) = NULL; @@ -209,7 +246,7 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */ } if (PHPDBG_G(ops)) { - destroy_op_array(PHPDBG_G(ops) TSRMLS_CC); + destroy_op_array(PHPDBG_G(ops)); efree(PHPDBG_G(ops)); PHPDBG_G(ops) = NULL; } @@ -224,10 +261,9 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */ If the request to set the context fails, boolean false is returned, and an E_WARNING raised */ static PHP_FUNCTION(phpdbg_exec) { - char *exec = NULL; - int exec_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &exec, &exec_len) == FAILURE) { + zend_string *exec; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &exec) == FAILURE) { return; } @@ -235,88 +271,81 @@ static PHP_FUNCTION(phpdbg_exec) struct stat sb; zend_bool result = 1; - if (VCWD_STAT(exec, &sb) != FAILURE) { + if (VCWD_STAT(exec->val, &sb) != FAILURE) { if (sb.st_mode & (S_IFREG|S_IFLNK)) { if (PHPDBG_G(exec)) { - ZVAL_STRINGL(return_value, PHPDBG_G(exec), PHPDBG_G(exec_len), 1); + ZVAL_STRINGL(return_value, PHPDBG_G(exec), PHPDBG_G(exec_len)); efree(PHPDBG_G(exec)); result = 0; } - PHPDBG_G(exec) = estrndup(exec, exec_len); - PHPDBG_G(exec_len) = exec_len; + PHPDBG_G(exec) = estrndup(exec->val, exec->len); + PHPDBG_G(exec_len) = exec->len; - if (result) - ZVAL_BOOL(return_value, 1); + if (result) { + ZVAL_TRUE(return_value); + } } else { - zend_error( - E_WARNING, "Failed to set execution context (%s), not a regular file or symlink", exec); - ZVAL_BOOL(return_value, 0); + zend_error(E_WARNING, "Failed to set execution context (%s), not a regular file or symlink", exec); + ZVAL_FALSE(return_value); } } else { - zend_error( - E_WARNING, "Failed to set execution context (%s) the file does not exist", exec); + zend_error(E_WARNING, "Failed to set execution context (%s) the file does not exist", exec); - ZVAL_BOOL(return_value, 0); + ZVAL_FALSE(return_value); } } } /* }}} */ -/* {{{ proto void phpdbg_break_next() +/* {{{ proto void phpdbg_break() instructs phpdbg to insert a breakpoint at the next opcode */ static PHP_FUNCTION(phpdbg_break_next) { - if (zend_parse_parameters_none() != SUCCESS) { + if (zend_parse_parameters_none() == FAILURE && EG(current_execute_data)) { return; - } else if (EG(current_execute_data) && EG(active_op_array)) { - zend_ulong opline_num = (EG(current_execute_data)->opline - - EG(active_op_array)->opcodes); - - phpdbg_set_breakpoint_opline_ex( - &EG(active_op_array)->opcodes[opline_num+1] TSRMLS_CC); } + + phpdbg_set_breakpoint_opline_ex((phpdbg_opline_ptr_t) EG(current_execute_data)->opline + 1); } /* }}} */ /* {{{ proto void phpdbg_break_file(string file, integer line) */ static PHP_FUNCTION(phpdbg_break_file) { - char *file = NULL; - int flen = 0; - long line; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &file, &flen, &line) == FAILURE) { - return; - } - - phpdbg_set_breakpoint_file(file, line TSRMLS_CC); + char *file = NULL; + size_t flen = 0; + long line; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &file, &flen, &line) == FAILURE) { + return; + } + + phpdbg_set_breakpoint_file(file, line); } /* }}} */ /* {{{ proto void phpdbg_break_method(string class, string method) */ static PHP_FUNCTION(phpdbg_break_method) { - char *class = NULL, - *method = NULL; - int clen = 0, - mlen = 0; + char *class = NULL, *method = NULL; + size_t clen = 0, mlen = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &class, &clen, &method, &mlen) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &class, &clen, &method, &mlen) == FAILURE) { + return; + } - phpdbg_set_breakpoint_method(class, method TSRMLS_CC); + phpdbg_set_breakpoint_method(class, method); } /* }}} */ /* {{{ proto void phpdbg_break_function(string function) */ static PHP_FUNCTION(phpdbg_break_function) { - char *function = NULL; - int function_len; + char *function = NULL; + size_t function_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &function, &function_len) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &function, &function_len) == FAILURE) { + return; + } - phpdbg_set_breakpoint_symbol(function, function_len TSRMLS_CC); + phpdbg_set_breakpoint_symbol(function, function_len); } /* }}} */ /* {{{ proto void phpdbg_clear(void) @@ -324,6 +353,7 @@ static PHP_FUNCTION(phpdbg_break_function) static PHP_FUNCTION(phpdbg_clear) { zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]); + zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING]); zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]); zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE]); zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE]); @@ -338,9 +368,9 @@ static PHP_FUNCTION(phpdbg_color) { long element = 0L; char *color = NULL; - int color_len = 0; + size_t color_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &element, &color, &color_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &element, &color, &color_len) == FAILURE) { return; } @@ -348,7 +378,7 @@ static PHP_FUNCTION(phpdbg_color) case PHPDBG_COLOR_NOTICE: case PHPDBG_COLOR_ERROR: case PHPDBG_COLOR_PROMPT: - phpdbg_set_color_ex(element, color, color_len TSRMLS_CC); + phpdbg_set_color_ex(element, color, color_len); break; default: zend_error(E_ERROR, "phpdbg detected an incorrect color constant"); @@ -359,30 +389,30 @@ static PHP_FUNCTION(phpdbg_color) static PHP_FUNCTION(phpdbg_prompt) { char *prompt = NULL; - int prompt_len = 0; + size_t prompt_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &prompt, &prompt_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &prompt, &prompt_len) == FAILURE) { return; } - phpdbg_set_prompt(prompt TSRMLS_CC); + phpdbg_set_prompt(prompt); } /* }}} */ ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_next_arginfo, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_file_arginfo, 0, 0, 2) - ZEND_ARG_INFO(0, file) - ZEND_ARG_INFO(0, line) + ZEND_ARG_INFO(0, file) + ZEND_ARG_INFO(0, line) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_method_arginfo, 0, 0, 2) - ZEND_ARG_INFO(0, class) - ZEND_ARG_INFO(0, method) + ZEND_ARG_INFO(0, class) + ZEND_ARG_INFO(0, method) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_function_arginfo, 0, 0, 1) - ZEND_ARG_INFO(0, function) + ZEND_ARG_INFO(0, function) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(phpdbg_color_arginfo, 0, 0, 0) @@ -441,18 +471,18 @@ static inline int php_sapi_phpdbg_module_startup(sapi_module_struct *module) /* return SUCCESS; } /* }}} */ -static char* php_sapi_phpdbg_read_cookies(TSRMLS_D) /* {{{ */ +static char* php_sapi_phpdbg_read_cookies(void) /* {{{ */ { return NULL; } /* }}} */ -static int php_sapi_phpdbg_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s TSRMLS_DC) /* {{{ */ +static int php_sapi_phpdbg_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s) /* {{{ */ { return 0; } /* }}} */ -static int php_sapi_phpdbg_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ */ +static int php_sapi_phpdbg_send_headers(sapi_headers_struct *sapi_headers) /* {{{ */ { /* We do nothing here, this function is needed to prevent that the fallback * header handling is called. */ @@ -460,18 +490,23 @@ static int php_sapi_phpdbg_send_headers(sapi_headers_struct *sapi_headers TSRMLS } /* }}} */ -static void php_sapi_phpdbg_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) /* {{{ */ +static void php_sapi_phpdbg_send_header(sapi_header_struct *sapi_header, void *server_context) /* {{{ */ { } /* }}} */ -static void php_sapi_phpdbg_log_message(char *message TSRMLS_DC) /* {{{ */ +static void php_sapi_phpdbg_log_message(char *message) /* {{{ */ { /* * We must not request TSRM before being boot */ if (phpdbg_booted) { - phpdbg_error("%s", message); + if (PHPDBG_G(flags) & PHPDBG_IN_EVAL) { + phpdbg_error("eval", "msg=\"%s\"", "%s", message); + return; + } + + phpdbg_error("php", "msg=\"%s\"", "%s", message); switch (PG(last_error_type)) { case E_ERROR: @@ -479,123 +514,154 @@ static void php_sapi_phpdbg_log_message(char *message TSRMLS_DC) /* {{{ */ case E_COMPILE_ERROR: case E_USER_ERROR: case E_PARSE: - case E_RECOVERABLE_ERROR: - if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { - phpdbg_list_file( - zend_get_executed_filename(TSRMLS_C), - 3, - zend_get_executed_lineno(TSRMLS_C)-1, - zend_get_executed_lineno(TSRMLS_C) - TSRMLS_CC - ); - } + case E_RECOVERABLE_ERROR: { + const char *file_char = zend_get_executed_filename(); + zend_string *file = zend_string_init(file_char, strlen(file_char), 0); + phpdbg_list_file(file, 3, zend_get_executed_lineno() - 1, zend_get_executed_lineno()); + efree(file); do { - switch (phpdbg_interactive(TSRMLS_C)) { + switch (phpdbg_interactive(1)) { case PHPDBG_LEAVE: case PHPDBG_FINISH: case PHPDBG_UNTIL: case PHPDBG_NEXT: return; } - } while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)); - + } while (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)); + } } - } else fprintf(stdout, "%s\n", message); + } else { + fprintf(stdout, "%s\n", message); + } } /* }}} */ -static int php_sapi_phpdbg_deactivate(TSRMLS_D) /* {{{ */ +static int php_sapi_phpdbg_deactivate(void) /* {{{ */ { + if ((PHPDBG_G(flags) & PHPDBG_IS_STOPPING) == PHPDBG_IS_CLEANING) { + zend_phpdbg_globals *pg = PHPDBG_G(backup) = calloc(1, sizeof(zend_phpdbg_globals)); + + php_phpdbg_globals_ctor(pg); + + pg->exec = zend_strndup(PHPDBG_G(exec), PHPDBG_G(exec_len)); + pg->exec_len = PHPDBG_G(exec_len); + pg->oplog = PHPDBG_G(oplog); + pg->prompt[0] = PHPDBG_G(prompt)[0]; + pg->prompt[1] = PHPDBG_G(prompt)[1]; + memcpy(pg->colors, PHPDBG_G(colors), sizeof(pg->colors)); + pg->eol = PHPDBG_G(eol); + pg->flags = PHPDBG_G(flags) & PHPDBG_PRESERVE_FLAGS_MASK; + } + fflush(stdout); if(SG(request_info).argv0) { free(SG(request_info).argv0); SG(request_info).argv0 = NULL; } + return SUCCESS; } /* }}} */ -static void php_sapi_phpdbg_register_vars(zval *track_vars_array TSRMLS_DC) /* {{{ */ +static void php_sapi_phpdbg_register_vars(zval *track_vars_array) /* {{{ */ { - unsigned int len; - char *docroot = ""; + size_t len; + char *docroot = ""; /* In phpdbg mode, we consider the environment to be a part of the server variables */ - php_import_environment_variables(track_vars_array TSRMLS_CC); + php_import_environment_variables(track_vars_array); if (PHPDBG_G(exec)) { len = PHPDBG_G(exec_len); - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", - &PHPDBG_G(exec), PHPDBG_G(exec_len), &len TSRMLS_CC)) { - php_register_variable("PHP_SELF", PHPDBG_G(exec), - track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &PHPDBG_G(exec), PHPDBG_G(exec_len), &len)) { + php_register_variable("PHP_SELF", PHPDBG_G(exec), track_vars_array); } - if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_NAME", - &PHPDBG_G(exec), PHPDBG_G(exec_len), &len TSRMLS_CC)) { - php_register_variable("SCRIPT_NAME", PHPDBG_G(exec), - track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_NAME", &PHPDBG_G(exec), PHPDBG_G(exec_len), &len)) { + php_register_variable("SCRIPT_NAME", PHPDBG_G(exec), track_vars_array); } - if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_FILENAME", - &PHPDBG_G(exec), PHPDBG_G(exec_len), &len TSRMLS_CC)) { - php_register_variable("SCRIPT_FILENAME", PHPDBG_G(exec), - track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_FILENAME", &PHPDBG_G(exec), PHPDBG_G(exec_len), &len)) { + php_register_variable("SCRIPT_FILENAME", PHPDBG_G(exec), track_vars_array); } - if (sapi_module.input_filter(PARSE_SERVER, "PATH_TRANSLATED", - &PHPDBG_G(exec), PHPDBG_G(exec_len), &len TSRMLS_CC)) { - php_register_variable("PATH_TRANSLATED", PHPDBG_G(exec), - track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PATH_TRANSLATED", &PHPDBG_G(exec), PHPDBG_G(exec_len), &len)) { + php_register_variable("PATH_TRANSLATED", PHPDBG_G(exec), track_vars_array); } } - /* any old docroot will doo */ - len = 0U; - if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT", - &docroot, len, &len TSRMLS_CC)) { - php_register_variable("DOCUMENT_ROOT", docroot, track_vars_array TSRMLS_CC); + /* any old docroot will do */ + len = 0; + if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT", &docroot, len, &len)) { + php_register_variable("DOCUMENT_ROOT", docroot, track_vars_array); } } /* }}} */ -static inline int php_sapi_phpdbg_ub_write(const char *message, unsigned int length TSRMLS_DC) /* {{{ */ +static inline size_t php_sapi_phpdbg_ub_write(const char *message, size_t length) /* {{{ */ { - return phpdbg_write("%s", message); + if (PHPDBG_G(socket_fd) != -1 && !(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) { + send(PHPDBG_G(socket_fd), message, length, 0); + } + return phpdbg_script(P_STDOUT, "%.*s", length, message); } /* }}} */ +/* beginning of struct, see main/streams/plain_wrapper.c line 111 */ +typedef struct { + FILE *file; + int fd; +} php_stdio_stream_data; + +static size_t phpdbg_stdiop_write(php_stream *stream, const char *buf, size_t count) { + php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; + + while (data->fd >= 0) { + struct stat stat[3]; + memset(stat, 0, sizeof(stat)); + if (((fstat(fileno(stderr), &stat[2]) < 0) & (fstat(fileno(stdout), &stat[0]) < 0)) | (fstat(data->fd, &stat[1]) < 0)) { + break; + } + + if (stat[0].st_dev == stat[1].st_dev && stat[0].st_ino == stat[1].st_ino) { + phpdbg_script(P_STDOUT, "%.*s", (int) count, buf); + return count; + } + if (stat[2].st_dev == stat[1].st_dev && stat[2].st_ino == stat[1].st_ino) { + phpdbg_script(P_STDERR, "%.*s", (int) count, buf); + return count; + } + break; + } + + return PHPDBG_G(php_stdiop_write)(stream, buf, count); +} + #if PHP_VERSION_ID >= 50700 -static inline void php_sapi_phpdbg_flush(void *context TSRMLS_DC) /* {{{ */ +static inline void php_sapi_phpdbg_flush(void *context) /* {{{ */ { #else static inline void php_sapi_phpdbg_flush(void *context) /* {{{ */ { - TSRMLS_FETCH(); #endif - fflush(PHPDBG_G(io)[PHPDBG_STDOUT]); + if (!phpdbg_active_sigsafe_mem()) { + fflush(PHPDBG_G(io)[PHPDBG_STDOUT].ptr); + } } /* }}} */ /* copied from sapi/cli/php_cli.c cli_register_file_handles */ -static void phpdbg_register_file_handles(TSRMLS_D) /* {{{ */ +static void phpdbg_register_file_handles(void) /* {{{ */ { - zval *zin, *zout, *zerr; + zval zin, zout, zerr; php_stream *s_in, *s_out, *s_err; php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL; zend_constant ic, oc, ec; - MAKE_STD_ZVAL(zin); - MAKE_STD_ZVAL(zout); - MAKE_STD_ZVAL(zerr); - s_in = php_stream_open_wrapper_ex("php://stdin", "rb", 0, NULL, sc_in); s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out); s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err); if (s_in==NULL || s_out==NULL || s_err==NULL) { - FREE_ZVAL(zin); - FREE_ZVAL(zout); - FREE_ZVAL(zerr); if (s_in) php_stream_close(s_in); if (s_out) php_stream_close(s_out); if (s_err) php_stream_close(s_err); @@ -608,34 +674,27 @@ static void phpdbg_register_file_handles(TSRMLS_D) /* {{{ */ s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE; #endif - php_stream_to_zval(s_in, zin); - php_stream_to_zval(s_out, zout); - php_stream_to_zval(s_err, zerr); + php_stream_to_zval(s_in, &zin); + php_stream_to_zval(s_out, &zout); + php_stream_to_zval(s_err, &zerr); - ic.value = *zin; + ic.value = zin; ic.flags = CONST_CS; - ic.name = zend_strndup(ZEND_STRL("STDIN")); - ic.name_len = sizeof("STDIN"); + ic.name = zend_string_init(ZEND_STRL("STDIN"), 0); ic.module_number = 0; - zend_register_constant(&ic TSRMLS_CC); + zend_register_constant(&ic); - oc.value = *zout; + oc.value = zout; oc.flags = CONST_CS; - oc.name = zend_strndup(ZEND_STRL("STDOUT")); - oc.name_len = sizeof("STDOUT"); + oc.name = zend_string_init(ZEND_STRL("STDOUT"), 0); oc.module_number = 0; - zend_register_constant(&oc TSRMLS_CC); + zend_register_constant(&oc); - ec.value = *zerr; + ec.value = zerr; ec.flags = CONST_CS; - ec.name = zend_strndup(ZEND_STRL("STDERR")); - ec.name_len = sizeof("STDERR"); + ec.name = zend_string_init(ZEND_STRL("STDERR"), 0); ec.module_number = 0; - zend_register_constant(&ec TSRMLS_CC); - - FREE_ZVAL(zin); - FREE_ZVAL(zout); - FREE_ZVAL(zerr); + zend_register_constant(&ec); } /* }}} */ @@ -693,6 +752,7 @@ const opt_struct OPTIONS[] = { /* {{{ */ {'l', 1, "listen"}, {'a', 1, "address-or-any"}, #endif + {'x', 0, "xml output"}, {'V', 0, "version"}, {'-', 0, NULL} }; /* }}} */ @@ -706,14 +766,13 @@ const char phpdbg_ini_hardcoded[] = "max_execution_time=0\n" "max_input_time=-1\n" "error_log=\n" -"output_buffering=off\0"; +"output_buffering=off\n\0"; /* overwriteable ini defaults must be set in phpdbg_ini_defaults() */ #define INI_DEFAULT(name, value) \ + ZVAL_STRINGL(&tmp, value, sizeof(value) - 1); \ Z_SET_REFCOUNT(tmp, 0); \ - Z_UNSET_ISREF(tmp); \ - ZVAL_STRINGL(&tmp, zend_strndup(value, sizeof(value)-1), sizeof(value)-1, 0); \ - zend_hash_update(configuration_hash, name, sizeof(name), &tmp, sizeof(zval), NULL); + zend_hash_str_update(configuration_hash, name, sizeof(name) - 1, &tmp); void phpdbg_ini_defaults(HashTable *configuration_hash) /* {{{ */ { @@ -721,199 +780,173 @@ void phpdbg_ini_defaults(HashTable *configuration_hash) /* {{{ */ INI_DEFAULT("report_zend_debug", "0"); } /* }}} */ -static void phpdbg_welcome(zend_bool cleaning TSRMLS_DC) /* {{{ */ +static void phpdbg_welcome(zend_bool cleaning) /* {{{ */ { /* print blurb */ if (!cleaning) { - phpdbg_notice("Welcome to phpdbg, the interactive PHP debugger, v%s", - PHPDBG_VERSION); - phpdbg_writeln("To get help using phpdbg type \"help\" and press enter"); - phpdbg_notice("Please report bugs to <%s>", PHPDBG_ISSUES); - } else { - phpdbg_notice("Clean Execution Environment"); + phpdbg_xml("<intros>"); + phpdbg_notice("intro", "version=\"%s\"", "Welcome to phpdbg, the interactive PHP debugger, v%s", PHPDBG_VERSION); + phpdbg_writeln("intro", "help=\"help\"", "To get help using phpdbg type \"help\" and press enter"); + phpdbg_notice("intro", "report=\"%s\"", "Please report bugs to <%s>", PHPDBG_ISSUES); + phpdbg_xml("</intros>"); + } else if (phpdbg_startup_run == 0) { + if (!(PHPDBG_G(flags) & PHPDBG_WRITE_XML)) { + phpdbg_notice(NULL, NULL, "Clean Execution Environment"); + } - phpdbg_writeln("Classes\t\t\t%d", zend_hash_num_elements(EG(class_table))); - phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(EG(function_table))); - phpdbg_writeln("Constants\t\t%d", zend_hash_num_elements(EG(zend_constants))); - phpdbg_writeln("Includes\t\t%d", zend_hash_num_elements(&EG(included_files))); + phpdbg_write("cleaninfo", "classes=\"%d\" functions=\"%d\" constants=\"%d\" includes=\"%d\"", + "Classes %d\n" + "Functions %d\n" + "Constants %d\n" + "Includes %d\n", + zend_hash_num_elements(EG(class_table)), + zend_hash_num_elements(EG(function_table)), + zend_hash_num_elements(EG(zend_constants)), + zend_hash_num_elements(&EG(included_files))); } } /* }}} */ static inline void phpdbg_sigint_handler(int signo) /* {{{ */ { - TSRMLS_FETCH(); - if (EG(in_execution)) { - /* set signalled only when not interactive */ - if (!(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) { - PHPDBG_G(flags) |= PHPDBG_IS_SIGNALED; - } - } else { + if (PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE) { /* we quit remote consoles on recv SIGINT */ if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { - PHPDBG_G(flags) |= PHPDBG_IS_QUITTING; + PHPDBG_G(flags) |= PHPDBG_IS_STOPPING; zend_bailout(); } - } -} /* }}} */ - -#ifndef _WIN32 -int phpdbg_open_socket(const char *interface, short port) /* {{{ */ -{ - int fd = socket(AF_INET, SOCK_STREAM, 0); - - switch (fd) { - case -1: - return -1; - - default: { - int reuse = 1; - - switch (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*) &reuse, sizeof(reuse))) { - case -1: - close(fd); - return -2; - - default: { - struct sockaddr_in address; - - memset(&address, 0, sizeof(address)); - - address.sin_port = htons(port); - address.sin_family = AF_INET; - - if ((*interface == '*')) { - address.sin_addr.s_addr = htonl(INADDR_ANY); - } else if (!inet_pton(AF_INET, interface, &address.sin_addr)) { - close(fd); - return -3; - } - - switch (bind(fd, (struct sockaddr *)&address, sizeof(address))) { - case -1: - close(fd); - return -4; - - default: { - listen(fd, 5); - } - } - } + } else { + /* set signalled only when not interactive */ + if (!(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) { + if (PHPDBG_G(flags) & PHPDBG_IS_SIGNALED) { + char mem[PHPDBG_SIGSAFE_MEM_SIZE + 1]; + + phpdbg_set_sigsafe_mem(mem); + zend_try { + phpdbg_force_interruption(); + } zend_end_try() + phpdbg_clear_sigsafe_mem(); + return; } + PHPDBG_G(flags) |= PHPDBG_IS_SIGNALED; } } - - return fd; } /* }}} */ -static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* {{{ */ -{ - if ((*socket)[0] >= 0) { - shutdown( - (*socket)[0], SHUT_RDWR); - close((*socket)[0]); +static void phpdbg_remote_close(int socket, FILE *stream) { + if (socket >= 0) { + phpdbg_close_socket(socket); } - if (streams[0]) { - fclose(streams[0]); + if (stream) { + fclose(stream); } +} - if ((*socket)[1] >= 0) { - shutdown( - (*socket)[1], SHUT_RDWR); - close((*socket)[1]); - } +/* don't inline this, want to debug it easily, will inline when done */ +static int phpdbg_remote_init(const char* address, unsigned short port, int server, int *socket, FILE **stream) { + phpdbg_remote_close(*socket, *stream); - if (streams[1]) { - fclose(streams[1]); + if (server < 0) { + phpdbg_rlog(fileno(stderr), "Initializing connection on %s:%u failed", address, port); + + return FAILURE; } -} /* }}} */ -/* don't inline this, want to debug it easily, will inline when done */ + phpdbg_rlog(fileno(stderr), "accepting connections on %s:%u", address, port); + { + struct sockaddr_storage address; + socklen_t size = sizeof(address); + char buffer[20] = {0}; + /* XXX error checks */ + memset(&address, 0, size); + *socket = accept(server, (struct sockaddr *) &address, &size); + inet_ntop(AF_INET, &(((struct sockaddr_in *)&address)->sin_addr), buffer, sizeof(buffer)); -int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*socket)[2], FILE* streams[2]) /* {{{ */ -{ - if (((*listen)[0]) < 0 && ((*listen)[1]) < 0) { - ((*listen)[0]) = phpdbg_open_socket(address, (short)port[0]); - ((*listen)[1]) = phpdbg_open_socket(address, (short)port[1]); + phpdbg_rlog(fileno(stderr), "connection established from %s", buffer); } - streams[0] = NULL; - streams[1] = NULL; - - if ((*listen)[0] < 0 || (*listen)[1] < 0) { - if ((*listen)[0] < 0) { - phpdbg_rlog(stderr, - "console failed to initialize (stdin) on %s:%d", address, port[0]); - } +#ifndef _WIN32 + dup2(*socket, fileno(stdout)); + dup2(*socket, fileno(stdin)); - if ((*listen)[1] < 0) { - phpdbg_rlog(stderr, - "console failed to initialize (stdout) on %s:%d", address, port[1]); - } + setbuf(stdout, NULL); - if ((*listen)[0] >= 0) { - close((*listen)[0]); - } + *stream = fdopen(*socket, "r+"); - if ((*listen)[1] >= 0) { - close((*listen)[1]); - } + phpdbg_set_async_io(*socket); +#endif + return SUCCESS; +} - return FAILURE; - } +#ifndef _WIN32 +/* This function *strictly* assumes that SIGIO is *only* used on the remote connection stream */ +void phpdbg_sigio_handler(int sig, siginfo_t *info, void *context) /* {{{ */ +{ + int flags; + size_t newlen; + size_t i/*, last_nl*/; - phpdbg_close_sockets(socket, streams); +// if (!(info->si_band & POLLIN)) { +// return; /* Not interested in writeablility etc., just interested in incoming data */ +// } - phpdbg_rlog(stderr, - "accepting connections on %s:%d/%d", address, port[0], port[1]); - { - struct sockaddr_in address; - socklen_t size = sizeof(address); - char buffer[20] = {0}; + /* only non-blocking reading, avoid non-blocking writing */ + flags = fcntl(PHPDBG_G(io)[PHPDBG_STDIN].fd, F_GETFL, 0); + fcntl(PHPDBG_G(io)[PHPDBG_STDIN].fd, F_SETFL, flags | O_NONBLOCK); - { - memset(&address, 0, size); - (*socket)[0] = accept( - (*listen)[0], (struct sockaddr *) &address, &size); - inet_ntop(AF_INET, &address.sin_addr, buffer, sizeof(buffer)); + do { + char mem[PHPDBG_SIGSAFE_MEM_SIZE + 1]; + size_t off = 0; - phpdbg_rlog(stderr, "connection (stdin) from %s", buffer); + if ((newlen = recv(PHPDBG_G(io)[PHPDBG_STDIN].fd, mem, PHPDBG_SIGSAFE_MEM_SIZE, MSG_PEEK)) == (size_t) -1) { + break; } - - { - memset(&address, 0, size); - (*socket)[1] = accept( - (*listen)[1], (struct sockaddr *) &address, &size); - inet_ntop(AF_INET, &address.sin_addr, buffer, sizeof(buffer)); - - phpdbg_rlog(stderr, "connection (stdout) from %s", buffer); + for (i = 0; i < newlen; i++) { + switch (mem[off + i]) { + case '\x03': /* ^C char */ + if (PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE) { + break; /* or quit ??? */ + } + if (PHPDBG_G(flags) & PHPDBG_IS_SIGNALED) { + phpdbg_set_sigsafe_mem(mem); + zend_try { + phpdbg_force_interruption(); + } zend_end_try(); + phpdbg_clear_sigsafe_mem(); + break; + } + if (!(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) { + PHPDBG_G(flags) |= PHPDBG_IS_SIGNALED; + } + break; +/* case '\n': + zend_llist_add_element(PHPDBG_G(stdin), strndup() + last_nl = PHPDBG_G(stdin_buf).len + i; + break; +*/ } } - } + off += i; + } while (0); - dup2((*socket)[0], fileno(stdin)); - dup2((*socket)[1], fileno(stdout)); - setbuf(stdout, NULL); - - streams[0] = fdopen((*socket)[0], "r"); - streams[1] = fdopen((*socket)[1], "w"); - - return SUCCESS; + fcntl(PHPDBG_G(io)[PHPDBG_STDIN].fd, F_SETFL, flags); } /* }}} */ void phpdbg_signal_handler(int sig, siginfo_t *info, void *context) /* {{{ */ { int is_handled = FAILURE; - TSRMLS_FETCH(); switch (sig) { case SIGBUS: case SIGSEGV: - is_handled = phpdbg_watchpoint_segfault_handler(info, context TSRMLS_CC); + if (PHPDBG_G(sigsegv_bailout)) { + LONGJMP(*PHPDBG_G(sigsegv_bailout), FAILURE); + } + is_handled = phpdbg_watchpoint_segfault_handler(info, context); if (is_handled == FAILURE) { #ifdef ZEND_SIGNALS - zend_sigaction(sig, &PHPDBG_G(old_sigsegv_signal), NULL TSRMLS_CC); + zend_sigaction(sig, &PHPDBG_G(old_sigsegv_signal), NULL); #else sigaction(sig, &PHPDBG_G(old_sigsegv_signal), NULL); #endif @@ -928,10 +961,9 @@ static inline zend_mm_heap *phpdbg_mm_get_heap() /* {{{ */ { zend_mm_heap *mm_heap; - TSRMLS_FETCH(); - mm_heap = zend_mm_set_heap(NULL TSRMLS_CC); - zend_mm_set_heap(mm_heap TSRMLS_CC); + mm_heap = zend_mm_set_heap(NULL); + zend_mm_set_heap(mm_heap); return mm_heap; } /* }}} */ @@ -961,8 +993,7 @@ int main(int argc, char **argv) /* {{{ */ zend_ulong zend_extensions_len = 0L; zend_bool ini_ignore; char *ini_override; - char *exec; - size_t exec_len; + char *exec = NULL; char *init_file; size_t init_file_len; zend_bool init_file_default; @@ -971,43 +1002,31 @@ int main(int argc, char **argv) /* {{{ */ zend_ulong flags; char *php_optarg; int php_optind, opt, show_banner = 1; - long cleaning = 0; + long cleaning = -1; zend_bool remote = 0; - int run = 0; int step = 0; - -#ifdef _WIN32 - char *bp_tmp_file = NULL; -#else - char bp_tmp_file[] = "/tmp/phpdbg.XXXXXX"; -#endif - -#ifndef _WIN32 + zend_phpdbg_globals *settings = NULL; + char *bp_tmp = NULL; char *address; - int listen[2]; - int server[2]; - int socket[2]; - FILE* streams[2] = {NULL, NULL}; -#endif + int listen = -1; + int server = -1; + int socket = -1; + FILE* stream = NULL; #ifdef ZTS void ***tsrm_ls; #endif #ifndef _WIN32 + struct sigaction sigio_struct; struct sigaction signal_struct; signal_struct.sa_sigaction = phpdbg_signal_handler; signal_struct.sa_flags = SA_SIGINFO | SA_NODEFER; + sigio_struct.sa_sigaction = phpdbg_sigio_handler; + sigio_struct.sa_flags = SA_SIGINFO; + address = strdup("127.0.0.1"); - socket[0] = -1; - socket[1] = -1; - listen[0] = -1; - listen[1] = -1; - server[0] = -1; - server[1] = -1; - streams[0] = NULL; - streams[1] = NULL; #endif #ifdef PHP_WIN32 @@ -1024,37 +1043,12 @@ int main(int argc, char **argv) /* {{{ */ #endif phpdbg_main: - if (!cleaning) { - -#ifdef _WIN32 - bp_tmp_file = malloc(L_tmpnam); - - if (bp_tmp_file) { - if (!tmpnam(bp_tmp_file)) { - free(bp_tmp_file); - bp_tmp_file = NULL; - } - } - - if (!bp_tmp_file) { - phpdbg_error("Unable to create temporary file"); - return 1; - } -#else - if (!mkstemp(bp_tmp_file)) { - memset(bp_tmp_file, 0, sizeof(bp_tmp_file)); - } -#endif - - } ini_entries = NULL; ini_entries_len = 0; ini_ignore = 0; ini_override = NULL; zend_extensions = NULL; zend_extensions_len = 0L; - exec = NULL; - exec_len = 0; init_file = NULL; init_file_len = 0; init_file_default = 1; @@ -1064,14 +1058,16 @@ phpdbg_main: php_optarg = NULL; php_optind = 1; opt = 0; - run = 0; step = 0; sapi_name = NULL; + if (settings) { + exec = settings->exec; + } while ((opt = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { switch (opt) { case 'r': - run++; + phpdbg_startup_run++; break; case 'n': ini_ignore = 1; @@ -1172,20 +1168,12 @@ phpdbg_main: break; #ifndef _WIN32 - /* if you pass a listen port, we will accept input on listen port */ - /* and write output to listen port * 2 */ - - case 'l': { /* set listen ports */ - if (sscanf(php_optarg, "%d/%d", &listen[0], &listen[1]) != 2) { - if (sscanf(php_optarg, "%d", &listen[0]) != 1) { - /* default to hardcoded ports */ - listen[0] = 4000; - listen[1] = 8000; - } else { - listen[1] = (listen[0] * 2); - } + /* if you pass a listen port, we will read and write on listen port */ + case 'l': /* set listen ports */ + if (sscanf(php_optarg, "%d", &listen) != 1) { + listen = 8000; } - } break; + break; case 'a': { /* set bind address */ free(address); @@ -1195,6 +1183,10 @@ phpdbg_main: } break; #endif + case 'x': + flags |= PHPDBG_WRITE_XML; + break; + case 'V': { sapi_startup(phpdbg); phpdbg->startup(phpdbg); @@ -1206,18 +1198,16 @@ phpdbg_main: PHP_VERSION, get_zend_version() ); - sapi_deactivate(TSRMLS_C); + sapi_deactivate(); sapi_shutdown(); return 0; } break; } } - + /* set exec if present on command line */ - if ((argc > php_optind) && (strcmp(argv[php_optind-1],"--") != SUCCESS)) - { - exec_len = strlen(argv[php_optind]); - if (exec_len) { + if (!exec && (argc > php_optind) && (strcmp(argv[php_optind-1], "--") != SUCCESS)) { + if (strlen(argv[php_optind])) { if (exec) { free(exec); } @@ -1226,19 +1216,6 @@ phpdbg_main: php_optind++; } -#ifndef _WIN32 - /* setup remote server if necessary */ - if (!cleaning && - (listen[0] > 0 && listen[1] > 0)) { - if (phpdbg_open_sockets(address, listen, &server, &socket, streams) == FAILURE) { - remote = 0; - exit(0); - } - /* set remote flag to stop service shutting down upon quit */ - remote = 1; - } -#endif - if (sapi_name) { phpdbg->name = sapi_name; } @@ -1293,60 +1270,102 @@ phpdbg_main: EXCEPTION_POINTERS *xp; __try { #endif - zend_mm_heap *mm_heap = phpdbg_mm_get_heap(); + zend_mm_heap *mm_heap; + void* (*_malloc)(size_t); + void (*_free)(void*); + void* (*_realloc)(void*, size_t); - if (mm_heap->use_zend_alloc) { - mm_heap->_malloc = phpdbg_malloc_wrapper; - mm_heap->_realloc = phpdbg_realloc_wrapper; - mm_heap->_free = phpdbg_free_wrapper; - mm_heap->use_zend_alloc = 0; + /* set flags from command line */ + PHPDBG_G(flags) = flags; + + if (settings) { +#ifdef ZTS + *((zend_phpdbg_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(phpdbg_globals_id)]) = *settings; +#else + phpdbg_globals = *settings; +#endif } - zend_activate(TSRMLS_C); + /* setup remote server if necessary */ + if (cleaning <= 0 && listen > 0) { + server = phpdbg_open_socket(address, listen); + if (-1 > server || phpdbg_remote_init(address, listen, server, &socket, &stream) == FAILURE) { + exit(0); + } - PHPDBG_G(original_free_function) = mm_heap->_free; - mm_heap->_free = phpdbg_watch_efree; +#ifndef _WIN32 + sigaction(SIGIO, &sigio_struct, NULL); +#endif + + /* set remote flag to stop service shutting down upon quit */ + remote = 1; + } + + mm_heap = phpdbg_mm_get_heap(); + zend_mm_get_custom_handlers(mm_heap, &_malloc, &_free, &_realloc); + + if (!_malloc) { + _malloc = phpdbg_malloc_wrapper; + } + if (!_realloc) { + _realloc = phpdbg_realloc_wrapper; + } + if (!_free) { + _free = phpdbg_free_wrapper; + } - phpdbg_setup_watchpoints(TSRMLS_C); + zend_activate(); + + phpdbg_init_list(); + + PHPDBG_G(original_free_function) = _free; + _free = phpdbg_watch_efree; + + zend_mm_set_custom_handlers(mm_heap, _malloc, _free, _realloc); + + phpdbg_setup_watchpoints(); #if defined(ZEND_SIGNALS) && !defined(_WIN32) zend_try { - zend_signal_activate(TSRMLS_C); + zend_signal_activate(); } zend_end_try(); #endif #if defined(ZEND_SIGNALS) && !defined(_WIN32) - zend_try { zend_sigaction(SIGSEGV, &signal_struct, &PHPDBG_G(old_sigsegv_signal) TSRMLS_CC); } zend_end_try(); - zend_try { zend_sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal) TSRMLS_CC); } zend_end_try(); + zend_try { zend_sigaction(SIGSEGV, &signal_struct, &PHPDBG_G(old_sigsegv_signal)); } zend_end_try(); + zend_try { zend_sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal)); } zend_end_try(); #elif !defined(_WIN32) sigaction(SIGSEGV, &signal_struct, &PHPDBG_G(old_sigsegv_signal)); sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal)); #endif - if (php_request_startup(TSRMLS_C) == SUCCESS) { + PHPDBG_G(sapi_name_ptr) = sapi_name; + + php_output_activate(); + php_output_deactivate(); + + php_output_activate(); + + if (php_request_startup() == SUCCESS) { int i; - - SG(request_info).argc = argc - php_optind + 1; + + SG(request_info).argc = argc - php_optind + 1; SG(request_info).argv = emalloc(SG(request_info).argc * sizeof(char *)); for (i = SG(request_info).argc; --i;) { SG(request_info).argv[i] = estrdup(argv[php_optind - 1 + i]); } - SG(request_info).argv[i] = exec ? estrndup(exec, exec_len) : estrdup(""); + SG(request_info).argv[i] = exec ? estrdup(exec) : estrdup(""); - php_hash_environment(TSRMLS_C); + php_hash_environment(); } - /* make sure to turn off buffer for ev command */ - php_output_activate(TSRMLS_C); - php_output_deactivate(TSRMLS_C); - /* do not install sigint handlers for remote consoles */ /* sending SIGINT then provides a decent way of shutting down the server */ #ifndef _WIN32 - if (listen[0] < 0) { + if (listen < 0) { #endif #if defined(ZEND_SIGNALS) && !defined(_WIN32) - zend_try { zend_signal(SIGINT, phpdbg_sigint_handler TSRMLS_CC); } zend_end_try(); + zend_try { zend_signal(SIGINT, phpdbg_sigint_handler); } zend_end_try(); #else signal(SIGINT, phpdbg_sigint_handler); #endif @@ -1356,99 +1375,143 @@ phpdbg_main: PG(modules_activated) = 0; - /* set flags from command line */ - PHPDBG_G(flags) = flags; - #ifndef _WIN32 /* setup io here */ - if (streams[0] && streams[1]) { + if (remote) { PHPDBG_G(flags) |= PHPDBG_IS_REMOTE; signal(SIGPIPE, SIG_IGN); } #endif - PHPDBG_G(io)[PHPDBG_STDIN] = stdin; - PHPDBG_G(io)[PHPDBG_STDOUT] = stdout; - PHPDBG_G(io)[PHPDBG_STDERR] = stderr; +#ifndef _WIN32 + PHPDBG_G(io)[PHPDBG_STDIN].ptr = stdin; + PHPDBG_G(io)[PHPDBG_STDIN].fd = fileno(stdin); + PHPDBG_G(io)[PHPDBG_STDOUT].ptr = stdout; + PHPDBG_G(io)[PHPDBG_STDOUT].fd = fileno(stdout); +#else + /* XXX this is a complete mess here with FILE/fd/SOCKET, + we should let only one to survive probably. Need + a clean separation whether it's a remote or local + prompt. And what is supposed to go as user interaction, + error log, etc. */ + if (remote) { + PHPDBG_G(io)[PHPDBG_STDIN].ptr = stdin; + PHPDBG_G(io)[PHPDBG_STDIN].fd = socket; + PHPDBG_G(io)[PHPDBG_STDOUT].ptr = stdout; + PHPDBG_G(io)[PHPDBG_STDOUT].fd = socket; + } else { + PHPDBG_G(io)[PHPDBG_STDIN].ptr = stdin; + PHPDBG_G(io)[PHPDBG_STDIN].fd = fileno(stdin); + PHPDBG_G(io)[PHPDBG_STDOUT].ptr = stdout; + PHPDBG_G(io)[PHPDBG_STDOUT].fd = fileno(stdout); + } +#endif + PHPDBG_G(io)[PHPDBG_STDERR].ptr = stderr; + PHPDBG_G(io)[PHPDBG_STDERR].fd = fileno(stderr); + +#ifndef _WIN32 + PHPDBG_G(php_stdiop_write) = php_stream_stdio_ops.write; + php_stream_stdio_ops.write = phpdbg_stdiop_write; +#endif if (exec) { /* set execution context */ - PHPDBG_G(exec) = phpdbg_resolve_path(exec TSRMLS_CC); - PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec)); + PHPDBG_G(exec) = phpdbg_resolve_path(exec); + PHPDBG_G(exec_len) = PHPDBG_G(exec) ? strlen(PHPDBG_G(exec)) : 0; free(exec); + exec = NULL; } if (oplog_file) { /* open oplog */ PHPDBG_G(oplog) = fopen(oplog_file, "w+"); if (!PHPDBG_G(oplog)) { - phpdbg_error( - "Failed to open oplog %s", oplog_file); + phpdbg_error("oplog", "path=\"%s\"", "Failed to open oplog %s", oplog_file); } free(oplog_file); } /* set default colors */ - phpdbg_set_color_ex(PHPDBG_COLOR_PROMPT, PHPDBG_STRL("white-bold") TSRMLS_CC); - phpdbg_set_color_ex(PHPDBG_COLOR_ERROR, PHPDBG_STRL("red-bold") TSRMLS_CC); - phpdbg_set_color_ex(PHPDBG_COLOR_NOTICE, PHPDBG_STRL("green") TSRMLS_CC); + phpdbg_set_color_ex(PHPDBG_COLOR_PROMPT, PHPDBG_STRL("white-bold")); + phpdbg_set_color_ex(PHPDBG_COLOR_ERROR, PHPDBG_STRL("red-bold")); + phpdbg_set_color_ex(PHPDBG_COLOR_NOTICE, PHPDBG_STRL("green")); /* set default prompt */ - phpdbg_set_prompt(PROMPT TSRMLS_CC); + phpdbg_set_prompt(PHPDBG_DEFAULT_PROMPT); /* Make stdin, stdout and stderr accessible from PHP scripts */ - phpdbg_register_file_handles(TSRMLS_C); + phpdbg_register_file_handles(); - if (show_banner) { + if (show_banner && cleaning < 2) { /* print blurb */ - phpdbg_welcome((cleaning > 0) TSRMLS_CC); + phpdbg_welcome(cleaning == 1); } - /* auto compile */ - if (PHPDBG_G(exec)) { - phpdbg_compile(TSRMLS_C); - } + cleaning = -1; /* initialize from file */ PHPDBG_G(flags) |= PHPDBG_IS_INITIALIZING; zend_try { - phpdbg_init(init_file, init_file_len, init_file_default TSRMLS_CC); - phpdbg_try_file_init(bp_tmp_file, strlen(bp_tmp_file), 0 TSRMLS_CC); + phpdbg_init(init_file, init_file_len, init_file_default); + if (bp_tmp) { + PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; + phpdbg_string_init(bp_tmp); + free(bp_tmp); + bp_tmp = NULL; + PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; + } } zend_end_try(); PHPDBG_G(flags) &= ~PHPDBG_IS_INITIALIZING; - + /* quit if init says so */ if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { goto phpdbg_out; } + /* auto compile */ + if (PHPDBG_G(exec)) { + if (settings) { + PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; + } + phpdbg_compile(); + PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; + } + /* step from here, not through init */ if (step) { PHPDBG_G(flags) |= PHPDBG_IS_STEPPING; } - if (run) { - /* no need to try{}, run does it ... */ - PHPDBG_COMMAND_HANDLER(run)(NULL TSRMLS_CC); - if (run > 1) { - /* if -r is on the command line more than once just quit */ - goto phpdbg_out; - } - } - /* #ifndef for making compiler shutting up */ #ifndef _WIN32 phpdbg_interact: #endif + /* phpdbg main() */ do { zend_try { - phpdbg_interactive(TSRMLS_C); + if (phpdbg_startup_run) { + zend_bool quit_immediately = phpdbg_startup_run > 1; + phpdbg_startup_run = 0; + PHPDBG_COMMAND_HANDLER(run)(NULL); + if (quit_immediately) { + /* if -r is on the command line more than once just quit */ + EG(bailout) = __orig_bailout; /* reset zend_try */ + break; + } + } + + phpdbg_interactive(1); } zend_catch { if ((PHPDBG_G(flags) & PHPDBG_IS_CLEANING)) { - FILE *bp_tmp_fp = fopen(bp_tmp_file, "w"); - phpdbg_export_breakpoints(bp_tmp_fp TSRMLS_CC); - fclose(bp_tmp_fp); + char *bp_tmp_str; + PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; + phpdbg_export_breakpoints_to_string(&bp_tmp_str); + PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; + if (bp_tmp_str) { + bp_tmp = strdup(bp_tmp_str); + efree(bp_tmp_str); + } cleaning = 1; } else { cleaning = 0; @@ -1458,17 +1521,16 @@ phpdbg_interact: if (!cleaning) { /* remote client disconnected */ if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) { - + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { /* renegociate connections */ - phpdbg_open_sockets( - address, listen, &server, &socket, streams); - + phpdbg_remote_init(address, listen, server, &socket, &stream); + /* set streams */ - if (streams[0] && streams[1]) { + if (stream) { PHPDBG_G(flags) &= ~PHPDBG_IS_QUITTING; } - + /* this must be forced */ CG(unclean_shutdown) = 0; } else { @@ -1479,14 +1541,19 @@ phpdbg_interact: } #endif } zend_end_try(); - } while(!cleaning && !(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)); - + } while (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)); + + + if (PHPDBG_G(exec) && (PHPDBG_G(flags) & PHPDBG_IS_CLEANING)) { + exec = strdup(PHPDBG_G(exec)); /* preserve exec, don't reparse that from cmd */ + } + /* this must be forced */ CG(unclean_shutdown) = 0; - + /* this is just helpful */ PG(report_memleaks) = 0; - + #ifndef _WIN32 phpdbg_out: if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) { @@ -1497,11 +1564,16 @@ phpdbg_out: #ifdef _WIN32 } __except(phpdbg_exception_handler_win32(xp = GetExceptionInformation())) { - phpdbg_error("Access violation (Segmentation fault) encountered\ntrying to abort cleanly..."); + phpdbg_error("segfault", "", "Access violation (Segmentation fault) encountered\ntrying to abort cleanly..."); } phpdbg_out: #endif - + + if (cleaning <= 0) { + PHPDBG_G(flags) &= ~PHPDBG_IS_CLEANING; + cleaning = -1; + } + { int i; /* free argv */ @@ -1511,11 +1583,15 @@ phpdbg_out: efree(SG(request_info).argv); } +#ifndef _WIN32 + /* reset it... else we risk a stack overflow upon next run (when clean'ing) */ + php_stream_stdio_ops.write = PHPDBG_G(php_stdiop_write); +#endif + #ifndef ZTS /* force cleanup of auto and core globals */ zend_hash_clean(CG(auto_globals)); - memset( - &core_globals, 0, sizeof(php_core_globals)); + memset( &core_globals, 0, sizeof(php_core_globals)); #endif if (ini_entries) { free(ini_entries); @@ -1524,27 +1600,47 @@ phpdbg_out: if (ini_override) { free(ini_override); } - + /* this must be forced */ CG(unclean_shutdown) = 0; - + /* this is just helpful */ PG(report_memleaks) = 0; - php_request_shutdown((void*)0); + if ((PHPDBG_G(flags) & (PHPDBG_IS_CLEANING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_CLEANING) { + php_free_shutdown_functions(); + zend_objects_store_mark_destructed(&EG(objects_store)); + } + + /* sapi_module.deactivate is where to backup things, last chance before mm_shutdown... */ zend_try { - php_module_shutdown(TSRMLS_C); + php_request_shutdown(NULL); + } zend_end_try(); + + if ((PHPDBG_G(flags) & (PHPDBG_IS_QUITTING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_RUNNING) { + phpdbg_notice("stop", "type=\"normal\"", "Script ended normally"); + cleaning++; + } + + if ((PHPDBG_G(flags) & PHPDBG_IS_STOPPING) == PHPDBG_IS_CLEANING) { + settings = PHPDBG_G(backup); + } + + php_output_deactivate(); + + zend_try { + php_module_shutdown(); } zend_end_try(); sapi_shutdown(); } - if (cleaning || remote) { + if (cleaning > 0 || remote) { goto phpdbg_main; } - + #ifdef ZTS /* bugggy */ /* tsrm_shutdown(); */ @@ -1556,15 +1652,9 @@ phpdbg_out: } #endif - if (sapi_name) { - free(sapi_name); + if (PHPDBG_G(sapi_name_ptr)) { + free(PHPDBG_G(sapi_name_ptr)); } - -#ifdef _WIN32 - free(bp_tmp_file); -#else - unlink(bp_tmp_file); -#endif return 0; } /* }}} */ diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h index 06cb4b83a9..8a273d4335 100644 --- a/sapi/phpdbg/phpdbg.h +++ b/sapi/phpdbg/phpdbg.h @@ -29,6 +29,12 @@ # define PHPDBG_API #endif +#ifndef PHP_WIN32 +# include <stdint.h> +# include <stddef.h> +#else +# include "win32/php_stdint.h" +#endif #include "php.h" #include "php_globals.h" #include "php_variables.h" @@ -40,20 +46,20 @@ #include "zend_ini_scanner.h" #include "zend_stream.h" #ifndef _WIN32 -# include "zend_signal.h" +# include "zend_signal.h" #endif #include "SAPI.h" #include <fcntl.h> #include <sys/types.h> #if defined(_WIN32) && !defined(__MINGW32__) -# include <windows.h> -# include "config.w32.h" -# undef strcasecmp -# undef strncasecmp -# define strcasecmp _stricmp -# define strncasecmp _strnicmp +# include <windows.h> +# include "config.w32.h" +# undef strcasecmp +# undef strncasecmp +# define strcasecmp _stricmp +# define strncasecmp _strnicmp #else -# include "php_config.h" +# include "php_config.h" #endif #ifndef O_BINARY # define O_BINARY 0 @@ -64,21 +70,51 @@ # include "TSRM.h" #endif -#ifdef LIBREADLINE -# include <readline/readline.h> -# include <readline/history.h> +#undef zend_hash_str_add +#ifdef PHP_WIN32 +#define zend_hash_str_add(...) \ + _zend_hash_str_add(__VA_ARGS__ ZEND_FILE_LINE_CC) +#else +#define zend_hash_str_add_tmp(ht, key, len, pData) \ + _zend_hash_str_add(ht, key, len, pData ZEND_FILE_LINE_CC) +#define zend_hash_str_add(...) zend_hash_str_add_tmp(__VA_ARGS__) +#endif + +#ifdef HAVE_LIBREADLINE +# include <readline/readline.h> +# include <readline/history.h> #endif #ifdef HAVE_LIBEDIT -# include <editline/readline.h> +# include <editline/readline.h> #endif -#include "phpdbg_lexer.h" -#include "phpdbg_cmd.h" -#include "phpdbg_utils.h" -#include "phpdbg_btree.h" -#include "phpdbg_watch.h" +/* {{{ remote console headers */ +#ifndef _WIN32 +# include <sys/socket.h> +# include <sys/un.h> +# include <sys/select.h> +# include <sys/types.h> +# include <netdb.h> +#endif /* }}} */ + +/* {{{ strings */ +#define PHPDBG_NAME "phpdbg" +#define PHPDBG_AUTHORS "Felipe Pena, Joe Watkins and Bob Weinand" /* Ordered by last name */ +#define PHPDBG_URL "http://phpdbg.com" +#define PHPDBG_ISSUES "http://github.com/krakjoe/phpdbg/issues" +#define PHPDBG_VERSION "0.4.0" +#define PHPDBG_INIT_FILENAME ".phpdbginit" +#define PHPDBG_DEFAULT_PROMPT "prompt>" +/* }}} */ + +/* Hey, apple. One shouldn't define *functions* from the standard C library as marcos. */ +#ifdef memcpy +#define memcpy_tmp(...) memcpy(__VA_ARGS__) +#undef memcpy +#define memcpy(...) memcpy_tmp(__VA_ARGS__) +#endif -int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC); +#if !defined(PHPDBG_WEBDATA_TRANSFER_H) && !defined(PHPDBG_WEBHELPER_H) #ifdef ZTS # define PHPDBG_G(v) TSRMG(phpdbg_globals_id, zend_phpdbg_globals *, v) @@ -86,6 +122,20 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC); # define PHPDBG_G(v) (phpdbg_globals.v) #endif +#include "phpdbg_sigsafe.h" +#include "phpdbg_out.h" +#include "phpdbg_lexer.h" +#include "phpdbg_cmd.h" +#include "phpdbg_utils.h" +#include "phpdbg_btree.h" +#include "phpdbg_watch.h" +#include "phpdbg_bp.h" +#ifdef PHP_WIN32 +# include "phpdbg_sigio_win32.h" +#endif + +int phpdbg_do_parse(phpdbg_param_t *stack, char *input); + #define PHPDBG_NEXT 2 #define PHPDBG_UNTIL 3 #define PHPDBG_FINISH 4 @@ -95,84 +145,87 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC); BEGIN: DO NOT CHANGE DO NOT CHANGE DO NOT CHANGE */ -/* {{{ tables */ -#define PHPDBG_BREAK_FILE 0 -#define PHPDBG_BREAK_SYM 1 -#define PHPDBG_BREAK_OPLINE 2 -#define PHPDBG_BREAK_METHOD 3 -#define PHPDBG_BREAK_COND 4 -#define PHPDBG_BREAK_OPCODE 5 -#define PHPDBG_BREAK_FUNCTION_OPLINE 6 -#define PHPDBG_BREAK_METHOD_OPLINE 7 -#define PHPDBG_BREAK_FILE_OPLINE 8 -#define PHPDBG_BREAK_MAP 9 -#define PHPDBG_BREAK_TABLES 10 /* }}} */ - /* {{{ flags */ -#define PHPDBG_HAS_FILE_BP (1<<1) -#define PHPDBG_HAS_SYM_BP (1<<2) -#define PHPDBG_HAS_OPLINE_BP (1<<3) -#define PHPDBG_HAS_METHOD_BP (1<<4) -#define PHPDBG_HAS_COND_BP (1<<5) -#define PHPDBG_HAS_OPCODE_BP (1<<6) -#define PHPDBG_HAS_FUNCTION_OPLINE_BP (1<<7) -#define PHPDBG_HAS_METHOD_OPLINE_BP (1<<8) -#define PHPDBG_HAS_FILE_OPLINE_BP (1<<9) /* }}} */ +#define PHPDBG_HAS_FILE_BP (1ULL<<1) +#define PHPDBG_HAS_PENDING_FILE_BP (1ULL<<2) +#define PHPDBG_HAS_SYM_BP (1ULL<<3) +#define PHPDBG_HAS_OPLINE_BP (1ULL<<4) +#define PHPDBG_HAS_METHOD_BP (1ULL<<5) +#define PHPDBG_HAS_COND_BP (1ULL<<6) +#define PHPDBG_HAS_OPCODE_BP (1ULL<<7) +#define PHPDBG_HAS_FUNCTION_OPLINE_BP (1ULL<<8) +#define PHPDBG_HAS_METHOD_OPLINE_BP (1ULL<<9) +#define PHPDBG_HAS_FILE_OPLINE_BP (1ULL<<10) /* }}} */ /* END: DO NOT CHANGE DO NOT CHANGE DO NOT CHANGE */ -#define PHPDBG_IN_COND_BP (1<<10) -#define PHPDBG_IN_EVAL (1<<11) +#define PHPDBG_IN_COND_BP (1ULL<<11) +#define PHPDBG_IN_EVAL (1ULL<<12) + +#define PHPDBG_IS_STEPPING (1ULL<<13) +#define PHPDBG_STEP_OPCODE (1ULL<<14) +#define PHPDBG_IS_QUIET (1ULL<<15) +#define PHPDBG_IS_QUITTING (1ULL<<16) +#define PHPDBG_IS_COLOURED (1ULL<<17) +#define PHPDBG_IS_CLEANING (1ULL<<18) +#define PHPDBG_IS_RUNNING (1ULL<<19) -#define PHPDBG_IS_STEPPING (1<<12) -#define PHPDBG_STEP_OPCODE (1<<13) -#define PHPDBG_IS_QUIET (1<<14) -#define PHPDBG_IS_QUITTING (1<<15) -#define PHPDBG_IS_COLOURED (1<<16) -#define PHPDBG_IS_CLEANING (1<<17) +#define PHPDBG_IN_UNTIL (1ULL<<20) +#define PHPDBG_IN_FINISH (1ULL<<21) +#define PHPDBG_IN_LEAVE (1ULL<<22) -#define PHPDBG_IN_UNTIL (1<<18) -#define PHPDBG_IN_FINISH (1<<19) -#define PHPDBG_IN_LEAVE (1<<20) +#define PHPDBG_IS_REGISTERED (1ULL<<23) +#define PHPDBG_IS_STEPONEVAL (1ULL<<24) +#define PHPDBG_IS_INITIALIZING (1ULL<<25) +#define PHPDBG_IS_SIGNALED (1ULL<<26) +#define PHPDBG_IS_INTERACTIVE (1ULL<<27) +#define PHPDBG_IS_BP_ENABLED (1ULL<<28) +#define PHPDBG_IS_REMOTE (1ULL<<29) +#define PHPDBG_IS_DISCONNECTED (1ULL<<30) +#define PHPDBG_WRITE_XML (1ULL<<31) -#define PHPDBG_IS_REGISTERED (1<<21) -#define PHPDBG_IS_STEPONEVAL (1<<22) -#define PHPDBG_IS_INITIALIZING (1<<23) -#define PHPDBG_IS_SIGNALED (1<<24) -#define PHPDBG_IS_INTERACTIVE (1<<25) -#define PHPDBG_IS_BP_ENABLED (1<<26) -#define PHPDBG_IS_REMOTE (1<<27) -#define PHPDBG_IS_DISCONNECTED (1<<28) +#define PHPDBG_SHOW_REFCOUNTS (1ULL<<32) -#define PHPDBG_SHOW_REFCOUNTS (1<<29) +#define PHPDBG_IN_SIGNAL_HANDLER (1ULL<<33) -#define PHPDBG_SEEK_MASK (PHPDBG_IN_UNTIL|PHPDBG_IN_FINISH|PHPDBG_IN_LEAVE) -#define PHPDBG_BP_RESOLVE_MASK (PHPDBG_HAS_FUNCTION_OPLINE_BP|PHPDBG_HAS_METHOD_OPLINE_BP|PHPDBG_HAS_FILE_OPLINE_BP) -#define PHPDBG_BP_MASK (PHPDBG_HAS_FILE_BP|PHPDBG_HAS_SYM_BP|PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_OPLINE_BP|PHPDBG_HAS_COND_BP|PHPDBG_HAS_OPCODE_BP|PHPDBG_HAS_FUNCTION_OPLINE_BP|PHPDBG_HAS_METHOD_OPLINE_BP|PHPDBG_HAS_FILE_OPLINE_BP) +#define PHPDBG_DISCARD_OUTPUT (1ULL<<34) + +#define PHPDBG_SEEK_MASK (PHPDBG_IN_UNTIL | PHPDBG_IN_FINISH | PHPDBG_IN_LEAVE) +#define PHPDBG_BP_RESOLVE_MASK (PHPDBG_HAS_FUNCTION_OPLINE_BP | PHPDBG_HAS_METHOD_OPLINE_BP | PHPDBG_HAS_FILE_OPLINE_BP) +#define PHPDBG_BP_MASK (PHPDBG_HAS_FILE_BP | PHPDBG_HAS_SYM_BP | PHPDBG_HAS_METHOD_BP | PHPDBG_HAS_OPLINE_BP | PHPDBG_HAS_COND_BP | PHPDBG_HAS_OPCODE_BP | PHPDBG_HAS_FUNCTION_OPLINE_BP | PHPDBG_HAS_METHOD_OPLINE_BP | PHPDBG_HAS_FILE_OPLINE_BP) +#define PHPDBG_IS_STOPPING (PHPDBG_IS_QUITTING | PHPDBG_IS_CLEANING) + +#define PHPDBG_PRESERVE_FLAGS_MASK (PHPDBG_SHOW_REFCOUNTS | PHPDBG_IS_STEPONEVAL | PHPDBG_IS_BP_ENABLED | PHPDBG_STEP_OPCODE | PHPDBG_IS_QUIET | PHPDBG_IS_COLOURED | PHPDBG_IS_REMOTE | PHPDBG_WRITE_XML | PHPDBG_IS_DISCONNECTED) #ifndef _WIN32 -# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED|PHPDBG_IS_BP_ENABLED) +# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET | PHPDBG_IS_COLOURED | PHPDBG_IS_BP_ENABLED) #else -# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_BP_ENABLED) +# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET | PHPDBG_IS_BP_ENABLED) #endif /* }}} */ -/* {{{ strings */ -#define PHPDBG_NAME "phpdbg" -#define PHPDBG_AUTHORS "Felipe Pena, Joe Watkins and Bob Weinand" /* Ordered by last name */ -#define PHPDBG_URL "http://phpdbg.com" -#define PHPDBG_ISSUES "http://github.com/krakjoe/phpdbg/issues" -#define PHPDBG_VERSION "0.4.0" -#define PHPDBG_INIT_FILENAME ".phpdbginit" -/* }}} */ - /* {{{ output descriptors */ #define PHPDBG_STDIN 0 #define PHPDBG_STDOUT 1 #define PHPDBG_STDERR 2 #define PHPDBG_IO_FDS 3 /* }}} */ +#define phpdbg_try_access \ + { \ + JMP_BUF *__orig_bailout = PHPDBG_G(sigsegv_bailout); \ + JMP_BUF __bailout; \ + \ + PHPDBG_G(sigsegv_bailout) = &__bailout; \ + if (SETJMP(__bailout) == 0) { +#define phpdbg_catch_access \ + } else { \ + PHPDBG_G(sigsegv_bailout) = __orig_bailout; +#define phpdbg_end_try_access() \ + } \ + PHPDBG_G(sigsegv_bailout) = __orig_bailout; \ + } + /* {{{ structs */ ZEND_BEGIN_MODULE_GLOBALS(phpdbg) @@ -180,7 +233,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg) HashTable registered; /* registered */ HashTable seek; /* seek oplines */ phpdbg_frame_t frame; /* frame */ - zend_uint last_line; /* last executed line */ + uint32_t last_line; /* last executed line */ phpdbg_lexer_data lexer; /* lexer data */ phpdbg_param_t *parser_stack; /* param stack during lexer / parser phase */ @@ -191,6 +244,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg) phpdbg_btree watchpoint_tree; /* tree with watchpoints */ phpdbg_btree watch_HashTables; /* tree with original dtors of watchpoints */ HashTable watchpoints; /* watchpoints */ + HashTable watch_collisions; /* collision table to check if multiple watches share the same recursive watchpoint */ zend_llist watchlist_mem; /* triggered watchpoints */ zend_bool watchpoint_hit; /* a watchpoint was hit */ void (*original_free_function)(void *); /* the original AG(mm_heap)->_free function */ @@ -198,33 +252,59 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg) char *exec; /* file to execute */ size_t exec_len; /* size of exec */ zend_op_array *ops; /* op_array */ - zval *retval; /* return value */ + zval retval; /* return value */ int bp_count; /* breakpoint count */ int vmret; /* return from last opcode handler execution */ + zend_bool in_execution; /* in execution? */ + + zend_op_array *(*compile_file)(zend_file_handle *file_handle, int type); + HashTable file_sources; FILE *oplog; /* opline log */ - FILE *io[PHPDBG_IO_FDS]; /* io */ + struct { + FILE *ptr; + int fd; + } io[PHPDBG_IO_FDS]; /* io */ + int eol; /* type of line ending to use */ + size_t (*php_stdiop_write)(php_stream *, const char *, size_t); + int in_script_xml; /* in <stream> output mode */ + struct { + zend_bool active; + int type; + int fd; + char *tag; + char *msg; + int msglen; + char *xml; + int xmllen; + } err_buf; /* error buffer */ + zend_ulong req_id; /* "request id" to keep track of commands */ char *prompt[2]; /* prompt */ const phpdbg_color_t *colors[PHPDBG_COLORS]; /* colors */ char *buffer; /* buffer */ + zend_bool last_was_newline; /* check if we don't need to output a newline upon next phpdbg_error or phpdbg_notice */ + + char input_buffer[PHPDBG_MAX_CMD]; /* stdin input buffer */ + int input_buflen; /* length of stdin input buffer */ + phpdbg_signal_safe_mem sigsafe_mem; /* memory to use in async safe environment (only once!) */ - zend_ulong flags; /* phpdbg flags */ + JMP_BUF *sigsegv_bailout; /* bailout address for accesibility probing */ + + uint64_t flags; /* phpdbg flags */ + + char *socket_path; /* phpdbg.path ini setting */ + char *sapi_name_ptr; /* store sapi name to free it if necessary to not leak memory */ + int socket_fd; /* file descriptor to socket (wait command) (-1 if unused) */ + int socket_server_fd; /* file descriptor to master socket (wait command) (-1 if unused) */ +#ifdef PHP_WIN32 + HANDLE sigio_watcher_thread; /* sigio watcher thread handle */ + struct win32_sigio_watcher_data swd; +#endif + + struct _zend_phpdbg_globals *backup; /* backup of data to store */ ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */ -/* the beginning (= the important part) of the _zend_mm_heap struct defined in Zend/zend_alloc.c - Needed for realizing watchpoints */ -struct _zend_mm_heap { - int use_zend_alloc; - void *(*_malloc)(size_t); - void (*_free)(void *); - void *(*_realloc)(void *, size_t); - size_t free_bitmap; - size_t large_free_bitmap; - size_t block_size; - size_t compact_size; - zend_mm_segment *segments_list; - zend_mm_storage *storage; -}; +#endif #endif /* PHPDBG_H */ diff --git a/sapi/phpdbg/phpdbg_bp.c b/sapi/phpdbg/phpdbg_bp.c index 6df123615a..43a580b365 100644 --- a/sapi/phpdbg/phpdbg_bp.c +++ b/sapi/phpdbg/phpdbg_bp.c @@ -29,25 +29,24 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); /* {{{ private api functions */ -static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array* TSRMLS_DC); -static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_symbol(zend_function* TSRMLS_DC); -static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_method(zend_op_array* TSRMLS_DC); -static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t TSRMLS_DC); -static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opcode(zend_uchar TSRMLS_DC); -static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execute_data *execute_data TSRMLS_DC); /* }}} */ +static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array*); +static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_symbol(zend_function*); +static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_method(zend_op_array*); +static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t); +static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opcode(zend_uchar); +static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execute_data *execute_data); /* }}} */ /* * Note: * A break point must always set the correct id and type * A set breakpoint function must always map new points */ -static inline void _phpdbg_break_mapping(int id, HashTable *table TSRMLS_DC) +static inline void _phpdbg_break_mapping(int id, HashTable *table) { - zend_hash_index_update( - &PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (id), (void**) &table, sizeof(void*), NULL); + zend_hash_index_update_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, table); } -#define PHPDBG_BREAK_MAPPING(id, table) _phpdbg_break_mapping(id, table TSRMLS_CC) +#define PHPDBG_BREAK_MAPPING(id, table) _phpdbg_break_mapping(id, table) #define PHPDBG_BREAK_UNMAPPING(id) \ zend_hash_index_del(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (id)) @@ -58,29 +57,29 @@ static inline void _phpdbg_break_mapping(int id, HashTable *table TSRMLS_DC) b.hits = 0; \ } while(0) -static void phpdbg_file_breaks_dtor(void *data) /* {{{ */ +static void phpdbg_file_breaks_dtor(zval *data) /* {{{ */ { - phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) data; + phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) Z_PTR_P(data); efree((char*)bp->filename); } /* }}} */ -static void phpdbg_class_breaks_dtor(void *data) /* {{{ */ +static void phpdbg_class_breaks_dtor(zval *data) /* {{{ */ { - phpdbg_breakmethod_t *bp = (phpdbg_breakmethod_t*) data; + phpdbg_breakmethod_t *bp = (phpdbg_breakmethod_t *) Z_PTR_P(data); efree((char*)bp->class_name); efree((char*)bp->func_name); } /* }}} */ -static void phpdbg_opline_class_breaks_dtor(void *data) /* {{{ */ +static void phpdbg_opline_class_breaks_dtor(zval *data) /* {{{ */ { - zend_hash_destroy((HashTable *)data); + zend_hash_destroy((HashTable *) Z_PTR_P(data)); } /* }}} */ -static void phpdbg_opline_breaks_dtor(void *data) /* {{{ */ +static void phpdbg_opline_breaks_dtor(zval *data) /* {{{ */ { - phpdbg_breakopline_t *bp = (phpdbg_breakopline_t *) data; + phpdbg_breakopline_t *bp = (phpdbg_breakopline_t *) Z_PTR_P(data); if (bp->class_name) { efree((char*)bp->class_name); @@ -90,94 +89,90 @@ static void phpdbg_opline_breaks_dtor(void *data) /* {{{ */ } } /* }}} */ -PHPDBG_API void phpdbg_reset_breakpoints(TSRMLS_D) /* {{{ */ +PHPDBG_API void phpdbg_reset_breakpoints(void) /* {{{ */ { - if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])) { - HashPosition position[2]; - HashTable **table = NULL; + HashTable *table; - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0]); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (void**)&table, &position[0]) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0])) { - phpdbg_breakbase_t *brake; + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], table) { + phpdbg_breakbase_t *brake; - for (zend_hash_internal_pointer_reset_ex((*table), &position[1]); - zend_hash_get_current_data_ex((*table), (void**)&brake, &position[1]) == SUCCESS; - zend_hash_move_forward_ex((*table), &position[1])) { - brake->hits = 0; - } - } - } + ZEND_HASH_FOREACH_PTR(table, brake) { + brake->hits = 0; + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ -PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_export_breakpoints(FILE *handle) /* {{{ */ { - HashPosition position[2]; - HashTable **table = NULL; + char *string; + phpdbg_export_breakpoints_to_string(&string); + fputs(string, handle); +} + +PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */ +{ + HashTable *table; zend_ulong id = 0L; + *str = ""; + if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])) { - phpdbg_notice( - "Exporting %d breakpoints", - zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])); + phpdbg_notice("exportbreakpoint", "count=\"%d\"", "Exporting %d breakpoints", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])); + /* this only looks like magic, it isn't */ - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0]); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (void**)&table, &position[0]) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0])) { + ZEND_HASH_FOREACH_NUM_KEY_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, table) { phpdbg_breakbase_t *brake; - zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], NULL, NULL, &id, 0, &position[0]); - - for (zend_hash_internal_pointer_reset_ex((*table), &position[1]); - zend_hash_get_current_data_ex((*table), (void**)&brake, &position[1]) == SUCCESS; - zend_hash_move_forward_ex((*table), &position[1])) { + ZEND_HASH_FOREACH_PTR(table, brake) { if (brake->id == id) { + char *new_str = NULL; + switch (brake->type) { case PHPDBG_BREAK_FILE: { - fprintf(handle, - "break %s:%lu\n", + phpdbg_asprintf(&new_str, + "%sbreak %s:%lu\n", *str, ((phpdbg_breakfile_t*)brake)->filename, ((phpdbg_breakfile_t*)brake)->line); } break; case PHPDBG_BREAK_SYM: { - fprintf(handle, - "break %s\n", + phpdbg_asprintf(&new_str, + "%sbreak %s\n", *str, ((phpdbg_breaksymbol_t*)brake)->symbol); } break; case PHPDBG_BREAK_METHOD: { - fprintf(handle, - "break %s::%s\n", + phpdbg_asprintf(&new_str, + "%sbreak %s::%s\n", *str, ((phpdbg_breakmethod_t*)brake)->class_name, ((phpdbg_breakmethod_t*)brake)->func_name); } break; case PHPDBG_BREAK_METHOD_OPLINE: { - fprintf(handle, - "break %s::%s#%ld\n", + phpdbg_asprintf(&new_str, + "%sbreak %s::%s#%llu\n", *str, ((phpdbg_breakopline_t*)brake)->class_name, ((phpdbg_breakopline_t*)brake)->func_name, ((phpdbg_breakopline_t*)brake)->opline_num); } break; case PHPDBG_BREAK_FUNCTION_OPLINE: { - fprintf(handle, - "break %s#%ld\n", + phpdbg_asprintf(&new_str, + "%sbreak %s#%llu\n", *str, ((phpdbg_breakopline_t*)brake)->func_name, ((phpdbg_breakopline_t*)brake)->opline_num); } break; case PHPDBG_BREAK_FILE_OPLINE: { - fprintf(handle, - "break %s:#%ld\n", + phpdbg_asprintf(&new_str, + "%sbreak %s:#%llu\n", *str, ((phpdbg_breakopline_t*)brake)->class_name, ((phpdbg_breakopline_t*)brake)->opline_num); } break; case PHPDBG_BREAK_OPCODE: { - fprintf(handle, - "break %s\n", + phpdbg_asprintf(&new_str, + "%sbreak %s\n", *str, ((phpdbg_breakop_t*)brake)->name); } break; @@ -187,20 +182,20 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ if (conditional->paramed) { switch (conditional->param.type) { case STR_PARAM: - fprintf(handle, - "break at %s if %s\n", conditional->param.str, conditional->code); + phpdbg_asprintf(&new_str, + "%sbreak at %s if %s\n", *str, conditional->param.str, conditional->code); break; case METHOD_PARAM: - fprintf(handle, - "break at %s::%s if %s\n", + phpdbg_asprintf(&new_str, + "%sbreak at %s::%s if %s\n", *str, conditional->param.method.class, conditional->param.method.name, conditional->code); break; case FILE_PARAM: - fprintf(handle, - "break at %s:%lu if %s\n", + phpdbg_asprintf(&new_str, + "%sbreak at %s:%lu if %s\n", *str, conditional->param.file.name, conditional->param.file.line, conditional->code); break; @@ -208,73 +203,166 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ default: { /* do nothing */ } break; } } else { - fprintf( - handle, "break if %s\n", conditional->code); + phpdbg_asprintf(&new_str, "%sbreak if %s\n", str, conditional->code); } } break; } + + if ((*str)[0]) { + efree(*str); + } + *str = new_str; } - } - } + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } + + if (!(*str)[0]) { + *str = NULL; } } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num) /* {{{ */ { php_stream_statbuf ssb; char realpath[MAXPATHLEN]; - - if (php_stream_stat_path(path, &ssb) != FAILURE) { - if (ssb.sb.st_mode & (S_IFREG|S_IFLNK)) { - HashTable *broken; - phpdbg_breakfile_t new_break; - size_t path_len = 0L; - - if (VCWD_REALPATH(path, realpath)) { - path = realpath; + const char *original_path = path; + zend_bool pending = 0; + + HashTable *broken, *file_breaks = &PHPDBG_G(bp)[PHPDBG_BREAK_FILE]; + phpdbg_breakfile_t new_break; + size_t path_len = 0L; + + if (VCWD_REALPATH(path, realpath)) { + path = realpath; + } + path_len = strlen(path); + + phpdbg_debug("file path: %s, resolved path: %s, was compiled: %d\n", original_path, path, zend_hash_exists(&PHPDBG_G(file_sources), path, path_len)); + + if (!zend_hash_str_exists(&PHPDBG_G(file_sources), path, path_len)) { + if (php_stream_stat_path(path, &ssb) == FAILURE) { + if (original_path[0] == '/') { + phpdbg_error("breakpoint", "type=\"nofile\" add=\"fail\" file=\"%s\"", "Cannot stat %s, it does not exist", original_path); + return; } + + file_breaks = &PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING]; + path = original_path; path_len = strlen(path); - - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], - path, path_len, (void**)&broken) == FAILURE) { - HashTable breaks; + pending = 1; + } else if (!(ssb.sb.st_mode & (S_IFREG|S_IFLNK))) { + phpdbg_error("breakpoint", "type=\"notregular\" add=\"fail\" file=\"%s\"", "Cannot set breakpoint in %s, it is not a regular file", path); + return; + } else { + phpdbg_debug("File exists, but not compiled\n"); + } + } - zend_hash_init(&breaks, 8, NULL, phpdbg_file_breaks_dtor, 0); + if (!(broken = zend_hash_str_find_ptr(file_breaks, path, path_len))) { + HashTable breaks; + zend_hash_init(&breaks, 8, NULL, phpdbg_file_breaks_dtor, 0); - zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], - path, path_len, &breaks, sizeof(HashTable), - (void**)&broken); - } + broken = zend_hash_str_add_mem(file_breaks, path, path_len, &breaks, sizeof(HashTable)); + } - if (!zend_hash_index_exists(broken, line_num)) { - PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP; + if (!zend_hash_index_exists(broken, line_num)) { + PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_FILE); + new_break.filename = estrndup(path, path_len); + new_break.line = line_num; - PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_FILE); - new_break.filename = estrndup(path, path_len); - new_break.line = line_num; + zend_hash_index_update_mem(broken, line_num, &new_break, sizeof(phpdbg_breakfile_t)); - zend_hash_index_update( - broken, line_num, (void**)&new_break, sizeof(phpdbg_breakfile_t), NULL); + PHPDBG_BREAK_MAPPING(new_break.id, broken); - phpdbg_notice("Breakpoint #%d added at %s:%ld", - new_break.id, new_break.filename, new_break.line); + if (pending) { + zend_string *file, *path_str = zend_string_init(path, path_len, 0); + ZEND_HASH_FOREACH_STR_KEY(&PHPDBG_G(file_sources), file) { + HashTable *fileht; - PHPDBG_BREAK_MAPPING(new_break.id, broken); - } else { - phpdbg_error("Breakpoint at %s:%ld exists", path, line_num); - } + phpdbg_debug("Compare against loaded %s\n", file); + if (!(pending = ((fileht = phpdbg_resolve_pending_file_break_ex(file->val, file->len, path_str, broken)) == NULL))) { + new_break = *(phpdbg_breakfile_t *) zend_hash_index_find_ptr(broken, line_num); + break; + } + } ZEND_HASH_FOREACH_END(); + zend_string_release(path_str); + } + + if (pending) { + PHPDBG_G(flags) |= PHPDBG_HAS_PENDING_FILE_BP; + + phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" file=\"%s\" line=\"%ld\" pending=\"pending\"", "Pending breakpoint #%d added at %s:%ld", new_break.id, new_break.filename, new_break.line); } else { - phpdbg_error("Cannot set breakpoint in %s, it is not a regular file", path); + PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP; + + phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" file=\"%s\" line=\"%ld\"", "Breakpoint #%d added at %s:%ld", new_break.id, new_break.filename, new_break.line); } } else { - phpdbg_error("Cannot stat %s, it does not exist", path); + phpdbg_error("breakpoint", "type=\"exists\" add=\"fail\" file=\"%s\" line=\"%ld\"", "Breakpoint at %s:%ld exists", path, line_num); } } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_symbol(const char *name, size_t name_len TSRMLS_DC) /* {{{ */ +PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uint filelen, zend_string *cur, HashTable *fileht) /* {{{ */ { - if (!zend_hash_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], name, name_len)) { + phpdbg_debug("file: %s, filelen: %u, cur: %s, curlen %u, pos: %c, memcmp: %d\n", file, filelen, cur, curlen, filelen > curlen ? file[filelen - curlen - 1] : '?', filelen > curlen ? memcmp(file + filelen - curlen, cur, curlen) : 0); + + if (((cur->len < filelen && file[filelen - cur->len - 1] == '/') || filelen == cur->len) && !memcmp(file + filelen - cur->len, cur->val, cur->len)) { + phpdbg_breakfile_t *brake, new_brake; + HashTable *master; + + PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP; + + if (!(master = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen))) { + HashTable new_ht; + zend_hash_init(&new_ht, 8, NULL, phpdbg_file_breaks_dtor, 0); + master = zend_hash_str_add_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen, &new_ht, sizeof(HashTable)); + } + + ZEND_HASH_FOREACH_PTR(fileht, brake) { + new_brake = *brake; + new_brake.filename = estrndup(file, filelen); + PHPDBG_BREAK_UNMAPPING(brake->id); + + if (master) { + zend_hash_index_update_mem(master, brake->line, &new_brake, sizeof(phpdbg_breakfile_t)); + PHPDBG_BREAK_MAPPING(brake->id, master); + } + } ZEND_HASH_FOREACH_END(); + + zend_hash_del(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], cur); + + if (!zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING])) { + PHPDBG_G(flags) &= ~PHPDBG_HAS_PENDING_FILE_BP; + } + + phpdbg_debug("compiled file: %s, cur bp file: %s\n", file, cur); + + return master; + } + + return NULL; +} /* }}} */ + +PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file) /* {{{ */ +{ + HashTable *fileht; + uint filelen = strlen(file); + zend_string *cur; + + phpdbg_debug("was compiled: %s\n", file); + + ZEND_HASH_FOREACH_STR_KEY_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], cur, fileht) { + phpdbg_debug("check bp: %s\n", cur); + + phpdbg_resolve_pending_file_break_ex(file, filelen, cur, fileht); + } ZEND_HASH_FOREACH_END(); +} /* }}} */ + +PHPDBG_API void phpdbg_set_breakpoint_symbol(const char *name, size_t name_len) /* {{{ */ +{ + if (!zend_hash_str_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], name, name_len)) { phpdbg_breaksymbol_t new_break; PHPDBG_G(flags) |= PHPDBG_HAS_SYM_BP; @@ -282,35 +370,29 @@ PHPDBG_API void phpdbg_set_breakpoint_symbol(const char *name, size_t name_len T PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_SYM); new_break.symbol = estrndup(name, name_len); - zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], new_break.symbol, - name_len, &new_break, sizeof(phpdbg_breaksymbol_t), NULL); + zend_hash_str_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], new_break.symbol, name_len, &new_break, sizeof(phpdbg_breaksymbol_t)); - phpdbg_notice("Breakpoint #%d added at %s", - new_break.id, new_break.symbol); + phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" function=\"%s\"", "Breakpoint #%d added at %s", new_break.id, new_break.symbol); PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_SYM]); } else { - phpdbg_notice("Breakpoint exists at %s", name); + phpdbg_error("breakpoint", "type=\"exists\" add=\"fail\" function=\"%s\"", "Breakpoint exists at %s", name); } } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_method(const char *class_name, const char *func_name TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_method(const char *class_name, const char *func_name) /* {{{ */ { HashTable class_breaks, *class_table; size_t class_len = strlen(class_name); size_t func_len = strlen(func_name); char *lcname = zend_str_tolower_dup(func_name, func_len); - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_name, - class_len, (void**)&class_table) != SUCCESS) { + if (!(class_table = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_name, class_len))) { zend_hash_init(&class_breaks, 8, NULL, phpdbg_class_breaks_dtor, 0); - zend_hash_update( - &PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], - class_name, class_len, - (void**)&class_breaks, sizeof(HashTable), (void**)&class_table); + class_table = zend_hash_str_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_name, class_len, &class_breaks, sizeof(HashTable)); } - if (!zend_hash_exists(class_table, lcname, func_len)) { + if (!zend_hash_str_exists(class_table, lcname, func_len)) { phpdbg_breakmethod_t new_break; PHPDBG_G(flags) |= PHPDBG_HAS_METHOD_BP; @@ -321,21 +403,19 @@ PHPDBG_API void phpdbg_set_breakpoint_method(const char *class_name, const char new_break.func_name = estrndup(func_name, func_len); new_break.func_len = func_len; - zend_hash_update(class_table, lcname, func_len, - &new_break, sizeof(phpdbg_breakmethod_t), NULL); + zend_hash_str_update_mem(class_table, lcname, func_len, &new_break, sizeof(phpdbg_breakmethod_t)); - phpdbg_notice("Breakpoint #%d added at %s::%s", - new_break.id, class_name, func_name); + phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" method=\"%s::%s\"", "Breakpoint #%d added at %s::%s", new_break.id, class_name, func_name); PHPDBG_BREAK_MAPPING(new_break.id, class_table); } else { - phpdbg_notice("Breakpoint exists at %s::%s", class_name, func_name); + phpdbg_error("breakpoint", "type=\"exists\" add=\"fail\" method=\"%s::%s\"", "Breakpoint exists at %s::%s", class_name, func_name); } efree(lcname); } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline) /* {{{ */ { if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline)) { phpdbg_breakline_t new_break; @@ -347,27 +427,25 @@ PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{ new_break.opline = opline; new_break.base = NULL; - zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline, - &new_break, sizeof(phpdbg_breakline_t), NULL); + zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline, &new_break, sizeof(phpdbg_breakline_t)); - phpdbg_notice("Breakpoint #%d added at %#lx", - new_break.id, new_break.opline); + phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" opline=\"%#lx\"", "Breakpoint #%d added at %#lx", new_break.id, new_break.opline); PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]); } else { - phpdbg_notice("Breakpoint exists at %#lx", opline); + phpdbg_error("breakpoint", "type=\"exists\" add=\"fail\" opline=\"%#lx\"", "Breakpoint exists at %#lx", opline); } } /* }}} */ -PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array TSRMLS_DC) /* {{{ */ +PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array) /* {{{ */ { phpdbg_breakline_t opline_break; if (op_array->last <= brake->opline_num) { if (brake->class_name == NULL) { - phpdbg_error("There are only %d oplines in function %s (breaking at opline %ld impossible)", op_array->last, brake->func_name, brake->opline_num); + phpdbg_error("breakpoint", "type=\"maxoplines\" add=\"fail\" maxoplinenum=\"%d\" function=\"%s\" usedoplinenum=\"%ld\"", "There are only %d oplines in function %s (breaking at opline %ld impossible)", op_array->last, brake->func_name, brake->opline_num); } else if (brake->func_name == NULL) { - phpdbg_error("There are only %d oplines in file %s (breaking at opline %ld impossible)", op_array->last, brake->class_name, brake->opline_num); + phpdbg_error("breakpoint", "type=\"maxoplines\" add=\"fail\" maxoplinenum=\"%d\" file=\"%s\" usedoplinenum=\"%ld\"", "There are only %d oplines in file %s (breaking at opline %ld impossible)", op_array->last, brake->class_name, brake->opline_num); } else { - phpdbg_error("There are only %d oplines in method %s::%s (breaking at opline %ld impossible)", op_array->last, brake->class_name, brake->func_name, brake->opline_num); + phpdbg_error("breakpoint", "type=\"maxoplines\" add=\"fail\" maxoplinenum=\"%d\" method=\"%s::%s\" usedoplinenum=\"%ld\"", "There are only %d oplines in method %s::%s (breaking at opline %ld impossible)", op_array->last, brake->class_name, brake->func_name, brake->opline_num); } return FAILURE; @@ -389,52 +467,48 @@ PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_o PHPDBG_G(flags) |= PHPDBG_HAS_OPLINE_BP; - zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline_break.opline, &opline_break, sizeof(phpdbg_breakline_t), NULL); + zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline_break.opline, &opline_break, sizeof(phpdbg_breakline_t)); return SUCCESS; } /* }}} */ -PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array) /* {{{ */ { HashTable *func_table = &PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE]; HashTable *oplines_table; - HashPosition position; phpdbg_breakopline_t *brake; - if (op_array->scope != NULL && - zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], op_array->scope->name, op_array->scope->name_length, (void **)&func_table) == FAILURE) { + if (op_array->scope != NULL && !(func_table = zend_hash_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], op_array->scope->name))) { return; } if (op_array->function_name == NULL) { - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], op_array->filename, strlen(op_array->filename), (void **)&oplines_table) == FAILURE) { + if (!(oplines_table = zend_hash_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], op_array->filename))) { return; } - } else if (zend_hash_find(func_table, op_array->function_name?op_array->function_name:"", op_array->function_name?strlen(op_array->function_name):0, (void **)&oplines_table) == FAILURE) { + } else if (!op_array->function_name || !(oplines_table = zend_hash_find_ptr(func_table, op_array->function_name))) { return; } - for (zend_hash_internal_pointer_reset_ex(oplines_table, &position); - zend_hash_get_current_data_ex(oplines_table, (void**) &brake, &position) == SUCCESS; - zend_hash_move_forward_ex(oplines_table, &position)) { - if (phpdbg_resolve_op_array_break(brake, op_array TSRMLS_CC) == SUCCESS) { + ZEND_HASH_FOREACH_PTR(oplines_table, brake) { + if (phpdbg_resolve_op_array_break(brake, op_array) == SUCCESS) { phpdbg_breakline_t *opline_break; zend_hash_internal_pointer_end(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]); - zend_hash_get_current_data(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (void **)&opline_break); + opline_break = zend_hash_get_current_data_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]); - phpdbg_notice("Breakpoint #%d resolved at %s%s%s#%ld (opline %#lx)", + phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" symbol=\"%s\" num=\"%ld\" opline=\"%#lx\"", "Breakpoint #%d resolved at %s%s%s#%ld (opline %#lx)", brake->id, - brake->class_name?brake->class_name:"", - brake->class_name&&brake->func_name?"::":"", - brake->func_name?brake->func_name:"", + brake->class_name ? brake->class_name : "", + brake->class_name && brake->func_name ? "::" : "", + brake->func_name ? brake->func_name : "", brake->opline_num, brake->opline); } - } + } ZEND_HASH_FOREACH_END(); } /* }}} */ -PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRMLS_DC) /* {{{ */ +PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break) /* {{{ */ { HashTable *func_table = EG(function_table); zend_function *func; @@ -442,7 +516,7 @@ PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRML if (new_break->func_name == NULL) { if (EG(current_execute_data) == NULL) { if (PHPDBG_G(ops) != NULL && !memcmp(PHPDBG_G(ops)->filename, new_break->class_name, new_break->class_len)) { - if (phpdbg_resolve_op_array_break(new_break, PHPDBG_G(ops) TSRMLS_CC) == SUCCESS) { + if (phpdbg_resolve_op_array_break(new_break, PHPDBG_G(ops)) == SUCCESS) { return SUCCESS; } else { return 2; @@ -452,8 +526,9 @@ PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRML } else { zend_execute_data *execute_data = EG(current_execute_data); do { - if (execute_data->op_array->function_name == NULL && execute_data->op_array->scope == NULL && !memcmp(execute_data->op_array->filename, new_break->class_name, new_break->class_len)) { - if (phpdbg_resolve_op_array_break(new_break, execute_data->op_array TSRMLS_CC) == SUCCESS) { + zend_op_array *op_array = &execute_data->func->op_array; + if (op_array->function_name == NULL && op_array->scope == NULL && new_break->class_len == op_array->filename->len && !memcmp(op_array->filename->val, new_break->class_name, new_break->class_len)) { + if (phpdbg_resolve_op_array_break(new_break, op_array) == SUCCESS) { return SUCCESS; } else { return 2; @@ -465,16 +540,16 @@ PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRML } if (new_break->class_name != NULL) { - zend_class_entry **ce; - if (zend_hash_find(EG(class_table), zend_str_tolower_dup(new_break->class_name, new_break->class_len), new_break->class_len + 1, (void **)&ce) == FAILURE) { + zend_class_entry *ce; + if (!(ce = zend_hash_str_find_ptr(EG(class_table), zend_str_tolower_dup(new_break->class_name, new_break->class_len), new_break->class_len))) { return FAILURE; } - func_table = &(*ce)->function_table; + func_table = &ce->function_table; } - if (zend_hash_find(func_table, zend_str_tolower_dup(new_break->func_name, new_break->func_len), new_break->func_len + 1, (void **)&func) == FAILURE) { + if (!(func = zend_hash_str_find_ptr(func_table, zend_str_tolower_dup(new_break->func_name, new_break->func_len), new_break->func_len))) { if (new_break->class_name != NULL && new_break->func_name != NULL) { - phpdbg_error("Method %s doesn't exist in class %s", new_break->func_name, new_break->class_name); + phpdbg_error("breakpoint", "type=\"nomethod\" method=\"%s::%s\"", "Method %s doesn't exist in class %s", new_break->func_name, new_break->class_name); return 2; } return FAILURE; @@ -482,21 +557,21 @@ PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRML if (func->type != ZEND_USER_FUNCTION) { if (new_break->class_name == NULL) { - phpdbg_error("%s is not an user defined function, no oplines exist", new_break->func_name); + phpdbg_error("breakpoint", "type=\"internalfunction\" function=\"%s\"", "%s is not an user defined function, no oplines exist", new_break->func_name); } else { - phpdbg_error("%s::%s is not an user defined method, no oplines exist", new_break->class_name, new_break->func_name); + phpdbg_error("breakpoint", "type=\"internalfunction\" method=\"%s::%s\"", "%s::%s is not an user defined method, no oplines exist", new_break->class_name, new_break->func_name); } return 2; } - if (phpdbg_resolve_op_array_break(new_break, &func->op_array TSRMLS_CC) == FAILURE) { + if (phpdbg_resolve_op_array_break(new_break, &func->op_array) == FAILURE) { return 2; } return SUCCESS; } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline) /* {{{ */ { phpdbg_breakopline_t new_break; HashTable class_breaks, *class_table; @@ -510,39 +585,31 @@ PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const cha new_break.opline_num = opline; new_break.opline = 0; - switch (phpdbg_resolve_opline_break(&new_break TSRMLS_CC)) { + switch (phpdbg_resolve_opline_break(&new_break)) { case FAILURE: - phpdbg_notice("Pending breakpoint #%d at %s::%s#%ld", new_break.id, new_break.class_name, new_break.func_name, opline); + phpdbg_notice("breakpoint", "pending=\"pending\" id=\"%d\" method=\"%::%s\" num=\"%ld\"", "Pending breakpoint #%d at %s::%s#%ld", new_break.id, new_break.class_name, new_break.func_name, opline); break; case SUCCESS: - phpdbg_notice("Breakpoint #%d added at %s::%s#%ld", new_break.id, new_break.class_name, new_break.func_name, opline); + phpdbg_notice("breakpoint", "id=\"%d\" method=\"%::%s\" num=\"%ld\"", "Breakpoint #%d added at %s::%s#%ld", new_break.id, new_break.class_name, new_break.func_name, opline); break; case 2: return; } - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], new_break.class_name, new_break.class_len, (void **)&class_table) == FAILURE) { + if (!(class_table = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], new_break.class_name, new_break.class_len))) { zend_hash_init(&class_breaks, 8, NULL, phpdbg_opline_class_breaks_dtor, 0); - zend_hash_update( - &PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], - new_break.class_name, - new_break.class_len, - (void **)&class_breaks, sizeof(HashTable), (void **)&class_table); + class_table = zend_hash_str_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], new_break.class_name, new_break.class_len, &class_breaks, sizeof(HashTable)); } - if (zend_hash_find(class_table, new_break.func_name, new_break.func_len, (void **)&method_table) == FAILURE) { + if (!(method_table = zend_hash_str_find_ptr(class_table, new_break.func_name, new_break.func_len))) { zend_hash_init(&method_breaks, 8, NULL, phpdbg_opline_breaks_dtor, 0); - zend_hash_update( - class_table, - new_break.func_name, - new_break.func_len, - (void **)&method_breaks, sizeof(HashTable), (void **)&method_table); + method_table = zend_hash_str_update_mem(class_table, new_break.func_name, new_break.func_len, &method_breaks, sizeof(HashTable)); } if (zend_hash_index_exists(method_table, opline)) { - phpdbg_notice("Breakpoint already exists for %s::%s#%ld", new_break.class_name, new_break.func_name, opline); + phpdbg_error("breakpoint", "type=\"exists\" method=\"%s\" num=\"%ld\"", "Breakpoint already exists for %s::%s#%ld", new_break.class_name, new_break.func_name, opline); efree((char*)new_break.func_name); efree((char*)new_break.class_name); PHPDBG_G(bp_count)--; @@ -553,10 +620,10 @@ PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const cha PHPDBG_BREAK_MAPPING(new_break.id, method_table); - zend_hash_index_update(method_table, opline, &new_break, sizeof(phpdbg_breakopline_t), NULL); + zend_hash_index_update_mem(method_table, opline, &new_break, sizeof(phpdbg_breakopline_t)); } -PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline) /* {{{ */ { phpdbg_breakopline_t new_break; HashTable func_breaks, *func_table; @@ -569,30 +636,26 @@ PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend new_break.opline_num = opline; new_break.opline = 0; - switch (phpdbg_resolve_opline_break(&new_break TSRMLS_CC)) { + switch (phpdbg_resolve_opline_break(&new_break)) { case FAILURE: - phpdbg_notice("Pending breakpoint #%d at %s#%ld", new_break.id, new_break.func_name, opline); + phpdbg_notice("breakpoint", "pending=\"pending\" id=\"%d\" function=\"%s\" num=\"%ld\"", "Pending breakpoint #%d at %s#%ld", new_break.id, new_break.func_name, opline); break; case SUCCESS: - phpdbg_notice("Breakpoint #%d added at %s#%ld", new_break.id, new_break.func_name, opline); + phpdbg_notice("breakpoint", "id=\"%d\" function=\"%s\" num=\"%ld\"", "Breakpoint #%d added at %s#%ld", new_break.id, new_break.func_name, opline); break; case 2: return; } - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], new_break.func_name, new_break.func_len, (void **)&func_table) == FAILURE) { + if (!(func_table = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], new_break.func_name, new_break.func_len))) { zend_hash_init(&func_breaks, 8, NULL, phpdbg_opline_breaks_dtor, 0); - zend_hash_update( - &PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], - new_break.func_name, - new_break.func_len, - (void **)&func_breaks, sizeof(HashTable), (void **)&func_table); + func_table = zend_hash_str_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], new_break.func_name, new_break.func_len, &func_breaks, sizeof(HashTable)); } if (zend_hash_index_exists(func_table, opline)) { - phpdbg_notice("Breakpoint already exists for %s#%ld", new_break.func_name, opline); + phpdbg_error("breakpoint", "type=\"exists\" function=\"%s\" num=\"%ld\"", "Breakpoint already exists for %s#%ld", new_break.func_name, opline); efree((char*)new_break.func_name); PHPDBG_G(bp_count)--; return; @@ -602,10 +665,10 @@ PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend PHPDBG_G(flags) |= PHPDBG_HAS_FUNCTION_OPLINE_BP; - zend_hash_index_update(func_table, opline, &new_break, sizeof(phpdbg_breakopline_t), NULL); + zend_hash_index_update_mem(func_table, opline, &new_break, sizeof(phpdbg_breakopline_t)); } -PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline) /* {{{ */ { phpdbg_breakopline_t new_break; HashTable file_breaks, *file_table; @@ -618,30 +681,26 @@ PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong o new_break.opline_num = opline; new_break.opline = 0; - switch (phpdbg_resolve_opline_break(&new_break TSRMLS_CC)) { + switch (phpdbg_resolve_opline_break(&new_break)) { case FAILURE: - phpdbg_notice("Pending breakpoint #%d at %s:%ld", new_break.id, new_break.class_name, opline); + phpdbg_notice("breakpoint", "pending=\"pending\" id=\"%d\" file=\"%s\" num=\"%ld\"", "Pending breakpoint #%d at %s:%ld", new_break.id, new_break.class_name, opline); break; case SUCCESS: - phpdbg_notice("Breakpoint #%d added at %s:%ld", new_break.id, new_break.class_name, opline); + phpdbg_notice("breakpoint", "id=\"%d\" file=\"%s\" num=\"%ld\"", "Breakpoint #%d added at %s:%ld", new_break.id, new_break.class_name, opline); break; case 2: return; } - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], new_break.class_name, new_break.class_len, (void **)&file_table) == FAILURE) { + if (!(file_table = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], new_break.class_name, new_break.class_len))) { zend_hash_init(&file_breaks, 8, NULL, phpdbg_opline_breaks_dtor, 0); - zend_hash_update( - &PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], - new_break.class_name, - new_break.class_len, - (void **)&file_breaks, sizeof(HashTable), (void **)&file_table); + file_table = zend_hash_str_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], new_break.class_name, new_break.class_len, &file_breaks, sizeof(HashTable)); } if (zend_hash_index_exists(file_table, opline)) { - phpdbg_notice("Breakpoint already exists for %s:%ld", new_break.class_name, opline); + phpdbg_error("breakpoint", "type=\"exists\" file=\"%s\" num=\"%d\"", "Breakpoint already exists for %s:%ld", new_break.class_name, opline); efree((char*)new_break.class_name); PHPDBG_G(bp_count)--; return; @@ -651,17 +710,16 @@ PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong o PHPDBG_G(flags) |= PHPDBG_HAS_FILE_OPLINE_BP; - zend_hash_index_update(file_table, opline, &new_break, sizeof(phpdbg_breakopline_t), NULL); + zend_hash_index_update_mem(file_table, opline, &new_break, sizeof(phpdbg_breakopline_t)); } -PHPDBG_API void phpdbg_set_breakpoint_opcode(const char *name, size_t name_len TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_opcode(const char *name, size_t name_len) /* {{{ */ { phpdbg_breakop_t new_break; zend_ulong hash = zend_hash_func(name, name_len); if (zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], hash)) { - phpdbg_notice( - "Breakpoint exists for %s", name); + phpdbg_error("breakpoint", "type=\"exists\" opcode=\"%s\"", "Breakpoint exists for %s", name); return; } @@ -669,16 +727,15 @@ PHPDBG_API void phpdbg_set_breakpoint_opcode(const char *name, size_t name_len T new_break.hash = hash; new_break.name = estrndup(name, name_len); - zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], hash, - &new_break, sizeof(phpdbg_breakop_t), NULL); + zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], hash, &new_break, sizeof(phpdbg_breakop_t)); PHPDBG_G(flags) |= PHPDBG_HAS_OPCODE_BP; - phpdbg_notice("Breakpoint #%d added at %s", new_break.id, name); + phpdbg_notice("breakpoint", "id=\"%d\" opcode=\"%s\"", "Breakpoint #%d added at %s", new_break.id, name); PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE]); } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline) /* {{{ */ { if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline)) { phpdbg_breakline_t new_break; @@ -688,19 +745,19 @@ PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRML PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_OPLINE); new_break.opline = (zend_ulong) opline; - zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], - (zend_ulong) opline, &new_break, sizeof(phpdbg_breakline_t), NULL); + zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline, &new_break, sizeof(phpdbg_breakline_t)); - phpdbg_notice("Breakpoint #%d added at %#lx", - new_break.id, new_break.opline); + phpdbg_notice("breakpoint", "id=\"%d\" opline=\"%#lx\"", "Breakpoint #%d added at %#lx", new_break.id, new_break.opline); PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]); + } else { + phpdbg_error("breakpoint", "type=\"exists\" opline=\"%#lx\"", "Breakpoint exists for opline %#lx", (zend_ulong) opline); } } /* }}} */ -static inline void phpdbg_create_conditional_break(phpdbg_breakcond_t *brake, const phpdbg_param_t *param, const char *expr, size_t expr_len, zend_ulong hash TSRMLS_DC) /* {{{ */ +static inline void phpdbg_create_conditional_break(phpdbg_breakcond_t *brake, const phpdbg_param_t *param, const char *expr, size_t expr_len, zend_ulong hash) /* {{{ */ { phpdbg_breakcond_t new_break; - zend_uint cops = CG(compiler_options); + uint32_t cops = CG(compiler_options); zval pv; PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_COND); @@ -709,7 +766,7 @@ static inline void phpdbg_create_conditional_break(phpdbg_breakcond_t *brake, co if (param) { new_break.paramed = 1; phpdbg_copy_param( - param, &new_break.param TSRMLS_CC); + param, &new_break.param); } else { new_break.paramed = 0; } @@ -721,176 +778,164 @@ static inline void phpdbg_create_conditional_break(phpdbg_breakcond_t *brake, co new_break.code = estrndup(expr, expr_len); new_break.code_len = expr_len; - Z_STRLEN(pv) = expr_len + sizeof("return ;") - 1; - Z_STRVAL(pv) = emalloc(Z_STRLEN(pv) + 1); + Z_STR(pv) = zend_string_alloc(expr_len + sizeof("return ;") - 1, 0); memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1); memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, expr, expr_len); Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';'; Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0'; - Z_TYPE(pv) = IS_STRING; + Z_TYPE_INFO(pv) = IS_STRING; - new_break.ops = zend_compile_string( - &pv, "Conditional Breakpoint Code" TSRMLS_CC); + new_break.ops = zend_compile_string(&pv, "Conditional Breakpoint Code"); zval_dtor(&pv); if (new_break.ops) { - zend_hash_index_update( - &PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash, &new_break, - sizeof(phpdbg_breakcond_t), (void**)&brake); + brake = zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash, &new_break, sizeof(phpdbg_breakcond_t)); - phpdbg_notice("Conditional breakpoint #%d added %s/%p", - brake->id, brake->code, brake->ops); + phpdbg_notice("breakpoint", "id=\"%d\" expression=\"%s\" ptr=\"%p\"", "Conditional breakpoint #%d added %s/%p", brake->id, brake->code, brake->ops); PHPDBG_G(flags) |= PHPDBG_HAS_COND_BP; PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_COND]); } else { - phpdbg_error( - "Failed to compile code for expression %s", expr); + phpdbg_error("compile", "expression=\"%s\"", "Failed to compile code for expression %s", expr); efree((char*)new_break.code); PHPDBG_G(bp_count)--; } + CG(compiler_options) = cops; } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_expression(const char *expr, size_t expr_len TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_expression(const char *expr, size_t expr_len) /* {{{ */ { zend_ulong expr_hash = zend_inline_hash_func(expr, expr_len); phpdbg_breakcond_t new_break; if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], expr_hash)) { phpdbg_create_conditional_break( - &new_break, NULL, expr, expr_len, expr_hash TSRMLS_CC); + &new_break, NULL, expr, expr_len, expr_hash); } else { - phpdbg_notice("Conditional break %s exists", expr); + phpdbg_error("breakpoint", "type=\"exists\" expression=\"%s\"", "Conditional break %s exists", expr); } } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param) /* {{{ */ { phpdbg_breakcond_t new_break; phpdbg_param_t *condition; zend_ulong hash = 0L; - + if (param->next) { condition = param->next; hash = zend_inline_hash_func(condition->str, condition->len); - + if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash)) { - phpdbg_create_conditional_break( - &new_break, param, - condition->str, condition->len, hash TSRMLS_CC); + phpdbg_create_conditional_break(&new_break, param, condition->str, condition->len, hash); } else { - phpdbg_notice( - "Conditional break %s exists at the specified location", condition->str); - } + phpdbg_notice("breakpoint", "type=\"exists\" arg=\"%s\"", "Conditional break %s exists at the specified location", condition->str); + } } - + } /* }}} */ -static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */ +static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array *op_array) /* {{{ */ { HashTable *breaks; phpdbg_breakbase_t *brake; - size_t name_len = strlen(op_array->filename); + size_t path_len; + char realpath[MAXPATHLEN]; + const char *path = op_array->filename->val; + + if (VCWD_REALPATH(path, realpath)) { + path = realpath; + } + + path_len = strlen(path); + +#if 0 + phpdbg_debug("Op at: %.*s %d\n", path_len, path, (*EG(opline_ptr))->lineno); +#endif - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], op_array->filename, - name_len, (void**)&breaks) == FAILURE) { + if (!(breaks = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], path, path_len))) { return NULL; } - if (zend_hash_index_find(breaks, (*EG(opline_ptr))->lineno, (void**)&brake) == SUCCESS) { + if (EG(current_execute_data) && (brake = zend_hash_index_find_ptr(breaks, EG(current_execute_data)->opline->lineno))) { return brake; } return NULL; } /* }}} */ -static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */ +static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_symbol(zend_function *fbc) /* {{{ */ { const char *fname; + size_t flen; zend_op_array *ops; - phpdbg_breakbase_t *brake; if (fbc->type != ZEND_USER_FUNCTION) { return NULL; } - ops = (zend_op_array*)fbc; + ops = (zend_op_array *) fbc; if (ops->scope) { /* find method breaks here */ - return phpdbg_find_breakpoint_method(ops TSRMLS_CC); + return phpdbg_find_breakpoint_method(ops); } - fname = ops->function_name; - - if (!fname) { + if (ops->function_name) { + fname = ops->function_name->val; + flen = ops->function_name->len; + } else { fname = "main"; + flen = 4; } - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], fname, strlen(fname), (void**)&brake) == SUCCESS) { - return brake; - } - - return NULL; + return zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], fname, flen); } /* }}} */ -static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_method(zend_op_array *ops TSRMLS_DC) /* {{{ */ +static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_method(zend_op_array *ops) /* {{{ */ { HashTable *class_table; - phpdbg_breakbase_t *brake; + phpdbg_breakbase_t *brake = NULL; - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], ops->scope->name, - ops->scope->name_length, (void**)&class_table) == SUCCESS) { - char *lcname = zend_str_tolower_dup(ops->function_name, strlen(ops->function_name)); - size_t lcname_len = strlen(lcname); - - if (zend_hash_find( - class_table, - lcname, - lcname_len, (void**)&brake) == SUCCESS) { - efree(lcname); - return brake; - } + if ((class_table = zend_hash_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], ops->scope->name))) { + size_t lcname_len = ops->function_name->len; + char *lcname = zend_str_tolower_dup(ops->function_name->val, lcname_len); + + brake = zend_hash_str_find_ptr(class_table, lcname, lcname_len); efree(lcname); } - return NULL; + return brake; } /* }}} */ -static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ */ +static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline) /* {{{ */ { phpdbg_breakline_t *brake; - if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], - (zend_ulong) opline, (void**)&brake) == SUCCESS) { - return (brake->base?(phpdbg_breakbase_t *)brake->base:(phpdbg_breakbase_t *)brake); + if ((brake = zend_hash_index_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline)) && brake->base) { + return (phpdbg_breakbase_t *)brake->base; } - return NULL; + return (phpdbg_breakbase_t *) brake; } /* }}} */ -static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opcode(zend_uchar opcode TSRMLS_DC) /* {{{ */ +static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opcode(zend_uchar opcode) /* {{{ */ { - phpdbg_breakbase_t *brake; const char *opname = phpdbg_decode_opcode(opcode); if (memcmp(opname, PHPDBG_STRL("UNKNOWN")) == 0) { return NULL; } - if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], - zend_hash_func(opname, strlen(opname)), (void**)&brake) == SUCCESS) { - return brake; - } - return NULL; + return zend_hash_index_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], zend_hash_func(opname, strlen(opname))); } /* }}} */ -static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend_execute_data *execute_data TSRMLS_DC) /* {{{ */ +static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend_execute_data *execute_data) /* {{{ */ { - zend_function *function = (zend_function*) execute_data->function_state.function; + zend_function *function = execute_data->func; switch (param->type) { case NUMERIC_FUNCTION_PARAM: @@ -905,8 +950,8 @@ static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend const char *str = NULL; size_t len = 0L; zend_op_array *ops = (zend_op_array*)function; - str = ops->function_name ? ops->function_name : "main"; - len = strlen(str); + str = ops->function_name ? ops->function_name->val : "main"; + len = ops->function_name ? ops->function_name->len : strlen(str); if (len == param->len && memcmp(param->str, str, len) == SUCCESS) { return param->type == STR_PARAM || execute_data->opline - ops->opcodes == param->num; @@ -915,8 +960,8 @@ static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend } break; case FILE_PARAM: { - if (param->file.line == zend_get_executed_lineno(TSRMLS_C)) { - const char *str = zend_get_executed_filename(TSRMLS_C); + if (param->file.line == zend_get_executed_lineno()) { + const char *str = zend_get_executed_filename(); size_t lengths[2] = {strlen(param->file.name), strlen(str)}; if (lengths[0] == lengths[1]) { @@ -936,10 +981,10 @@ static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend zend_op_array *ops = (zend_op_array*) function; if (ops->scope) { - size_t lengths[2] = {strlen(param->method.class), ops->scope->name_length}; + size_t lengths[2] = { strlen(param->method.class), ops->scope->name->len }; if (lengths[0] == lengths[1] && memcmp(param->method.class, ops->scope->name, lengths[0]) == SUCCESS) { lengths[0] = strlen(param->method.name); - lengths[1] = strlen(ops->function_name); + lengths[1] = ops->function_name->len; if (lengths[0] == lengths[1] && memcmp(param->method.name, ops->function_name, lengths[0]) == SUCCESS) { return param->type == METHOD_PARAM || (execute_data->opline - ops->opcodes) == param->num; @@ -960,80 +1005,58 @@ static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend return 0; } /* }}} */ -static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */ +static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execute_data *execute_data) /* {{{ */ { phpdbg_breakcond_t *bp; - HashPosition position; int breakpoint = FAILURE; - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void*)&bp, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) { - zval *retval = NULL; - int orig_interactive = CG(interactive); - zval **orig_retval = EG(return_value_ptr_ptr); - zend_op_array *orig_ops = EG(active_op_array); - zend_op **orig_opline = EG(opline_ptr); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], bp) { + zval retval; + const zend_op *orig_opline = EG(current_execute_data)->opline; + zend_function *orig_func = EG(current_execute_data)->func; + zval *orig_retval = EG(current_execute_data)->return_value; if (((phpdbg_breakbase_t*)bp)->disabled) { continue; } if (bp->paramed) { - if (!phpdbg_find_breakpoint_param(&bp->param, execute_data TSRMLS_CC)) { + if (!phpdbg_find_breakpoint_param(&bp->param, execute_data)) { continue; } } - ALLOC_INIT_ZVAL(retval); - - EG(return_value_ptr_ptr) = &retval; - EG(active_op_array) = bp->ops; EG(no_extensions) = 1; - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); - } - - CG(interactive) = 0; + zend_rebuild_symbol_table(); zend_try { PHPDBG_G(flags) |= PHPDBG_IN_COND_BP; - zend_execute(EG(active_op_array) TSRMLS_CC); + zend_execute(bp->ops, &retval); #if PHP_VERSION_ID >= 50700 - if (zend_is_true(retval TSRMLS_CC)) { + if (zend_is_true(&retval)) { #else - if (zend_is_true(retval)) { + if (zend_is_true(&retval)) { #endif breakpoint = SUCCESS; } - } zend_catch { - CG(interactive) = orig_interactive; - - EG(no_extensions)=1; - EG(return_value_ptr_ptr) = orig_retval; - EG(active_op_array) = orig_ops; - EG(opline_ptr) = orig_opline; - PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP; } zend_end_try(); - CG(interactive) = orig_interactive; - - EG(no_extensions)=1; - EG(return_value_ptr_ptr) = orig_retval; - EG(active_op_array) = orig_ops; - EG(opline_ptr) = orig_opline; + EG(no_extensions) = 1; + EG(current_execute_data)->opline = orig_opline; + EG(current_execute_data)->func = orig_func; + EG(current_execute_data)->return_value = orig_retval; PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP; if (breakpoint == SUCCESS) { break; } - } + } ZEND_HASH_FOREACH_END(); - return (breakpoint == SUCCESS) ? ((phpdbg_breakbase_t*)bp) : NULL; + return (breakpoint == SUCCESS) ? ((phpdbg_breakbase_t *) bp) : NULL; } /* }}} */ -PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakpoint(zend_execute_data* execute_data TSRMLS_DC) /* {{{ */ +PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakpoint(zend_execute_data *execute_data) /* {{{ */ { phpdbg_breakbase_t *base = NULL; @@ -1044,32 +1067,28 @@ PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakpoint(zend_execute_data* execute /* conditions cannot be executed by eval()'d code */ if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL) && (PHPDBG_G(flags) & PHPDBG_HAS_COND_BP) && - (base = phpdbg_find_conditional_breakpoint(execute_data TSRMLS_CC))) { + (base = phpdbg_find_conditional_breakpoint(execute_data))) { goto result; } - if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP) && - (base = phpdbg_find_breakpoint_file(execute_data->op_array TSRMLS_CC))) { + if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP) && (base = phpdbg_find_breakpoint_file(&execute_data->func->op_array))) { goto result; } if (PHPDBG_G(flags) & (PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_SYM_BP)) { /* check we are at the beginning of the stack */ - if (execute_data->opline == EG(active_op_array)->opcodes) { - if ((base = phpdbg_find_breakpoint_symbol( - execute_data->function_state.function TSRMLS_CC))) { + if (execute_data->opline == execute_data->func->op_array.opcodes) { + if ((base = phpdbg_find_breakpoint_symbol(execute_data->func))) { goto result; } } } - if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP) && - (base = phpdbg_find_breakpoint_opline(execute_data->opline TSRMLS_CC))) { + if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP) && (base = phpdbg_find_breakpoint_opline((phpdbg_opline_ptr_t) execute_data->opline))) { goto result; } - if ((PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) && - (base = phpdbg_find_breakpoint_opcode(execute_data->opline->opcode TSRMLS_CC))) { + if ((PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) && (base = phpdbg_find_breakpoint_opcode(execute_data->opline->opcode))) { goto result; } @@ -1084,16 +1103,14 @@ result: return base; } /* }}} */ -PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num) /* {{{ */ { - HashTable **table; - HashPosition position; + HashTable *table; phpdbg_breakbase_t *brake; + zend_string *strkey; + zend_ulong numkey; - if ((brake = phpdbg_find_breakbase_ex(num, &table, &position TSRMLS_CC))) { - char *key; - zend_uint klen; - zend_ulong idx; + if ((brake = phpdbg_find_breakbase_ex(num, &table, &numkey, &strkey))) { int type = brake->type; char *name = NULL; size_t name_len = 0L; @@ -1101,7 +1118,7 @@ PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */ switch (type) { case PHPDBG_BREAK_FILE: case PHPDBG_BREAK_METHOD: - if (zend_hash_num_elements((*table)) == 1) { + if (zend_hash_num_elements(table) == 1) { name = estrdup(brake->name); name_len = strlen(name); if (zend_hash_num_elements(&PHPDBG_G(bp)[type]) == 1) { @@ -1111,7 +1128,7 @@ PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */ break; default: { - if (zend_hash_num_elements((*table)) == 1) { + if (zend_hash_num_elements(table) == 1) { PHPDBG_G(flags) &= ~(1<<(brake->type+1)); } } @@ -1124,40 +1141,36 @@ PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */ if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]) == 1) { PHPDBG_G(flags) &= PHPDBG_HAS_OPLINE_BP; } - zend_hash_index_del(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], ((phpdbg_breakopline_t*)brake)->opline); + zend_hash_index_del(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], ((phpdbg_breakopline_t *) brake)->opline); } - switch (zend_hash_get_current_key_ex( - (*table), &key, &klen, &idx, 0, &position)) { - - case HASH_KEY_IS_STRING: - zend_hash_del((*table), key, klen); - break; - - default: - zend_hash_index_del((*table), idx); + if (strkey) { + zend_hash_del(table, strkey); + } else { + zend_hash_index_del(table, numkey); } switch (type) { case PHPDBG_BREAK_FILE: case PHPDBG_BREAK_METHOD: if (name) { - zend_hash_del(&PHPDBG_G(bp)[type], name, name_len); + zend_hash_str_del(&PHPDBG_G(bp)[type], name, name_len); efree(name); } break; } - phpdbg_notice("Deleted breakpoint #%ld", num); + phpdbg_notice("breakpoint", "deleted=\"success\" id=\"%ld\"", "Deleted breakpoint #%ld", num); PHPDBG_BREAK_UNMAPPING(num); } else { - phpdbg_error("Failed to find breakpoint #%ld", num); + phpdbg_error("breakpoint", "type=\"nobreakpoint\" deleted=\"fail\" id=\"%ld\"", "Failed to find breakpoint #%ld", num); } } /* }}} */ -PHPDBG_API void phpdbg_clear_breakpoints(TSRMLS_D) /* {{{ */ +PHPDBG_API void phpdbg_clear_breakpoints(void) /* {{{ */ { zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]); + zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING]); zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]); zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]); zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE]); @@ -1173,23 +1186,23 @@ PHPDBG_API void phpdbg_clear_breakpoints(TSRMLS_D) /* {{{ */ PHPDBG_G(bp_count) = 0; } /* }}} */ -PHPDBG_API void phpdbg_hit_breakpoint(phpdbg_breakbase_t *brake, zend_bool output TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_hit_breakpoint(phpdbg_breakbase_t *brake, zend_bool output) /* {{{ */ { brake->hits++; if (output) { - phpdbg_print_breakpoint(brake TSRMLS_CC); + phpdbg_print_breakpoint(brake); } } /* }}} */ -PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t *brake TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t *brake) /* {{{ */ { if (!brake) goto unknown; switch (brake->type) { case PHPDBG_BREAK_FILE: { - phpdbg_notice("Breakpoint #%d at %s:%ld, hits: %lu", + phpdbg_notice("breakpoint", "id=\"%d\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d at %s:%ld, hits: %lu", ((phpdbg_breakfile_t*)brake)->id, ((phpdbg_breakfile_t*)brake)->filename, ((phpdbg_breakfile_t*)brake)->line, @@ -1197,91 +1210,90 @@ PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t *brake TSRMLS_DC) /* } break; case PHPDBG_BREAK_SYM: { - phpdbg_notice("Breakpoint #%d in %s() at %s:%u, hits: %lu", + phpdbg_notice("breakpoint", "id=\"%d\" function=\"%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %s() at %s:%u, hits: %lu", ((phpdbg_breaksymbol_t*)brake)->id, ((phpdbg_breaksymbol_t*)brake)->symbol, - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C), + zend_get_executed_filename(), + zend_get_executed_lineno(), ((phpdbg_breakfile_t*)brake)->hits); } break; case PHPDBG_BREAK_OPLINE: { - phpdbg_notice("Breakpoint #%d in %#lx at %s:%u, hits: %lu", + phpdbg_notice("breakpoint", "id=\"%d\" opline=\"%#lx\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %#lx at %s:%u, hits: %lu", ((phpdbg_breakline_t*)brake)->id, ((phpdbg_breakline_t*)brake)->opline, - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C), + zend_get_executed_filename(), + zend_get_executed_lineno(), ((phpdbg_breakline_t*)brake)->hits); } break; case PHPDBG_BREAK_METHOD_OPLINE: { - phpdbg_notice("Breakpoint #%d in %s::%s()#%lu at %s:%u, hits: %lu", + phpdbg_notice("breakpoint", "id=\"%d\" method=\"%s::%s\" num=\"%lu\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %s::%s()#%lu at %s:%u, hits: %lu", ((phpdbg_breakopline_t*)brake)->id, ((phpdbg_breakopline_t*)brake)->class_name, ((phpdbg_breakopline_t*)brake)->func_name, ((phpdbg_breakopline_t*)brake)->opline_num, - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C), + zend_get_executed_filename(), + zend_get_executed_lineno(), ((phpdbg_breakopline_t*)brake)->hits); } break; case PHPDBG_BREAK_FUNCTION_OPLINE: { - phpdbg_notice("Breakpoint #%d in %s()#%lu at %s:%u, hits: %lu", + phpdbg_notice("breakpoint", "id=\"%d\" num=\"%lu\" function=\"%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %s()#%lu at %s:%u, hits: %lu", ((phpdbg_breakopline_t*)brake)->id, ((phpdbg_breakopline_t*)brake)->func_name, ((phpdbg_breakopline_t*)brake)->opline_num, - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C), + zend_get_executed_filename(), + zend_get_executed_lineno(), ((phpdbg_breakopline_t*)brake)->hits); } break; case PHPDBG_BREAK_FILE_OPLINE: { - phpdbg_notice("Breakpoint #%d in %s:%lu at %s:%u, hits: %lu", + phpdbg_notice("breakpoint", "id=\"%d\" num=\"%lu\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in #%lu at %s:%u, hits: %lu", ((phpdbg_breakopline_t*)brake)->id, - ((phpdbg_breakopline_t*)brake)->class_name, ((phpdbg_breakopline_t*)brake)->opline_num, - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C), + zend_get_executed_filename(), + zend_get_executed_lineno(), ((phpdbg_breakopline_t*)brake)->hits); } break; case PHPDBG_BREAK_OPCODE: { - phpdbg_notice("Breakpoint #%d in %s at %s:%u, hits: %lu", + phpdbg_notice("breakpoint", "id=\"%d\" opcode=\"%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %s at %s:%u, hits: %lu", ((phpdbg_breakop_t*)brake)->id, ((phpdbg_breakop_t*)brake)->name, - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C), + zend_get_executed_filename(), + zend_get_executed_lineno(), ((phpdbg_breakop_t*)brake)->hits); } break; case PHPDBG_BREAK_METHOD: { - phpdbg_notice("Breakpoint #%d in %s::%s() at %s:%u, hits: %lu", + phpdbg_notice("breakpoint", "id=\"%d\" method=\"%s::%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %s::%s() at %s:%u, hits: %lu", ((phpdbg_breakmethod_t*)brake)->id, ((phpdbg_breakmethod_t*)brake)->class_name, ((phpdbg_breakmethod_t*)brake)->func_name, - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C), + zend_get_executed_filename(), + zend_get_executed_lineno(), ((phpdbg_breakmethod_t*)brake)->hits); } break; case PHPDBG_BREAK_COND: { if (((phpdbg_breakcond_t*)brake)->paramed) { char *param; - phpdbg_notice("Conditional breakpoint #%d: at %s if %s %s:%u, hits: %lu", + phpdbg_notice("breakpoint", "id=\"%d\" location=\"%s\" eval=\"%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Conditional breakpoint #%d: at %s if %s at %s:%u, hits: %lu", ((phpdbg_breakcond_t*)brake)->id, - phpdbg_param_tostring(&((phpdbg_breakcond_t*)brake)->param, ¶m TSRMLS_CC), + phpdbg_param_tostring(&((phpdbg_breakcond_t*)brake)->param, ¶m), ((phpdbg_breakcond_t*)brake)->code, - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C), + zend_get_executed_filename(), + zend_get_executed_lineno(), ((phpdbg_breakcond_t*)brake)->hits); if (param) free(param); } else { - phpdbg_notice("Conditional breakpoint #%d: on %s == true %s:%u, hits: %lu", + phpdbg_notice("breakpoint", "id=\"%d\" eval=\"%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Conditional breakpoint #%d: on %s == true at %s:%u, hits: %lu", ((phpdbg_breakcond_t*)brake)->id, ((phpdbg_breakcond_t*)brake)->code, - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C), + zend_get_executed_filename(), + zend_get_executed_lineno(), ((phpdbg_breakcond_t*)brake)->hits); } @@ -1289,349 +1301,285 @@ PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t *brake TSRMLS_DC) /* default: { unknown: - phpdbg_notice("Unknown breakpoint at %s:%u", - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C)); + phpdbg_notice("breakpoint", "id=\"\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Unknown breakpoint at %s:%u", + zend_get_executed_filename(), + zend_get_executed_lineno()); } } } /* }}} */ -PHPDBG_API void phpdbg_enable_breakpoint(zend_ulong id TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_enable_breakpoint(zend_ulong id) /* {{{ */ { - phpdbg_breakbase_t *brake = phpdbg_find_breakbase(id TSRMLS_CC); + phpdbg_breakbase_t *brake = phpdbg_find_breakbase(id); if (brake) { brake->disabled = 0; } } /* }}} */ -PHPDBG_API void phpdbg_disable_breakpoint(zend_ulong id TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_disable_breakpoint(zend_ulong id) /* {{{ */ { - phpdbg_breakbase_t *brake = phpdbg_find_breakbase(id TSRMLS_CC); + phpdbg_breakbase_t *brake = phpdbg_find_breakbase(id); if (brake) { brake->disabled = 1; } } /* }}} */ -PHPDBG_API void phpdbg_enable_breakpoints(TSRMLS_D) /* {{{ */ +PHPDBG_API void phpdbg_enable_breakpoints(void) /* {{{ */ { PHPDBG_G(flags) |= PHPDBG_IS_BP_ENABLED; } /* }}} */ -PHPDBG_API void phpdbg_disable_breakpoints(TSRMLS_D) { /* {{{ */ +PHPDBG_API void phpdbg_disable_breakpoints(void) { /* {{{ */ PHPDBG_G(flags) &= ~PHPDBG_IS_BP_ENABLED; } /* }}} */ -PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id TSRMLS_DC) /* {{{ */ +PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id) /* {{{ */ { - HashTable **table; - HashPosition position; + HashTable *table; + zend_string *strkey; + zend_ulong numkey; - return phpdbg_find_breakbase_ex(id, &table, &position TSRMLS_CC); + return phpdbg_find_breakbase_ex(id, &table, &numkey, &strkey); } /* }}} */ -PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable ***table, HashPosition *position TSRMLS_DC) /* {{{ */ +PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable **table, zend_ulong *numkey, zend_string **strkey) /* {{{ */ { - if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, (void**)table) == SUCCESS) { + if ((*table = zend_hash_index_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id))) { phpdbg_breakbase_t *brake; - for (zend_hash_internal_pointer_reset_ex((**table), position); - zend_hash_get_current_data_ex((**table), (void**)&brake, position) == SUCCESS; - zend_hash_move_forward_ex((**table), position)) { - + ZEND_HASH_FOREACH_KEY_PTR(*table, *numkey, *strkey, brake) { if (brake->id == id) { return brake; } - } + } ZEND_HASH_FOREACH_END(); } + return NULL; } /* }}} */ -PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ { + phpdbg_xml("<breakpoints %r>"); + switch (type) { case PHPDBG_BREAK_SYM: if ((PHPDBG_G(flags) & PHPDBG_HAS_SYM_BP)) { - HashPosition position; phpdbg_breaksymbol_t *brake; - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Function Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], (void**) &brake, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position)) { - phpdbg_writeln("#%d\t\t%s%s", + phpdbg_out(SEPARATE "\n"); + phpdbg_out("Function Breakpoints:\n"); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], brake) { + phpdbg_writeln("function", "id=\"%d\" name=\"%s\" disabled=\"%s\"", "#%d\t\t%s%s", brake->id, brake->symbol, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); - } + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); + } ZEND_HASH_FOREACH_END(); } break; case PHPDBG_BREAK_METHOD: if ((PHPDBG_G(flags) & PHPDBG_HAS_METHOD_BP)) { - HashPosition position[2]; HashTable *class_table; - char *class_name = NULL; - zend_uint class_len = 0; - zend_ulong class_idx = 0L; - - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Method Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], &position[0]); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], (void**) &class_table, &position[0]) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], &position[0])) { - - if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], - &class_name, &class_len, &class_idx, 0, &position[0]) == HASH_KEY_IS_STRING) { - phpdbg_breakmethod_t *brake; - - for (zend_hash_internal_pointer_reset_ex(class_table, &position[1]); - zend_hash_get_current_data_ex(class_table, (void**)&brake, &position[1]) == SUCCESS; - zend_hash_move_forward_ex(class_table, &position[1])) { - phpdbg_writeln("#%d\t\t%s::%s%s", - brake->id, brake->class_name, brake->func_name, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); - } - } - } + phpdbg_out(SEPARATE "\n"); + phpdbg_out("Method Breakpoints:\n"); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_table) { + phpdbg_breakmethod_t *brake; + + ZEND_HASH_FOREACH_PTR(class_table, brake) { + phpdbg_writeln("method", "id=\"%d\" name=\"%s::%s\" disabled=\"%s\"", "#%d\t\t%s::%s%s", + brake->id, brake->class_name, brake->func_name, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } break; case PHPDBG_BREAK_FILE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP)) { - HashPosition position[2]; HashTable *points; - phpdbg_writeln(SEPARATE); - phpdbg_writeln("File Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position[0]); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], (void**) &points, &position[0]) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position[0])) { + phpdbg_out(SEPARATE "\n"); + phpdbg_out("File Breakpoints:\n"); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], points) { phpdbg_breakfile_t *brake; - for (zend_hash_internal_pointer_reset_ex(points, &position[1]); - zend_hash_get_current_data_ex(points, (void**)&brake, &position[1]) == SUCCESS; - zend_hash_move_forward_ex(points, &position[1])) { - phpdbg_writeln("#%d\t\t%s:%lu%s", + ZEND_HASH_FOREACH_PTR(points, brake) { + phpdbg_writeln("file", "id=\"%d\" name=\"%s\" line=\"%lu\" disabled=\"%s\"", "#%d\t\t%s:%lu%s", brake->id, brake->filename, brake->line, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); - } - } + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } if ((PHPDBG_G(flags) & PHPDBG_HAS_PENDING_FILE_BP)) { + HashTable *points; + phpdbg_out(SEPARATE "\n"); + phpdbg_out("Pending File Breakpoints:\n"); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], points) { + phpdbg_breakfile_t *brake; + + ZEND_HASH_FOREACH_PTR(points, brake) { + phpdbg_writeln("file", "id=\"%d\" name=\"%s\" line=\"%lu\" disabled=\"%s\" pending=\"pending\"", "#%d\t\t%s:%lu%s", + brake->id, brake->filename, brake->line, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } break; case PHPDBG_BREAK_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP)) { - HashPosition position; phpdbg_breakline_t *brake; - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Opline Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (void**) &brake, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position)) { + phpdbg_out(SEPARATE "\n"); + phpdbg_out("Opline Breakpoints:\n"); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], brake) { + const char *type; switch (brake->type) { case PHPDBG_BREAK_METHOD_OPLINE: + type = "method"; + goto print_opline; case PHPDBG_BREAK_FUNCTION_OPLINE: + type = "function"; + goto print_opline; case PHPDBG_BREAK_FILE_OPLINE: - phpdbg_writeln("#%d\t\t%#lx\t\t(%s breakpoint)%s", brake->id, brake->opline, - brake->type == PHPDBG_BREAK_METHOD_OPLINE?"method": - brake->type == PHPDBG_BREAK_FUNCTION_OPLINE?"function": - brake->type == PHPDBG_BREAK_FILE_OPLINE?"file": - "--- error ---", - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); - break; + type = "method"; + + print_opline: { + if (brake->type == PHPDBG_BREAK_METHOD_OPLINE) { + type = "method"; + } else if (brake->type == PHPDBG_BREAK_FUNCTION_OPLINE) { + type = "function"; + } else if (brake->type == PHPDBG_BREAK_FILE_OPLINE) { + type = "file"; + } + + phpdbg_writeln("opline", "id=\"%d\" num=\"%#lx\" type=\"%s\" disabled=\"%s\"", "#%d\t\t%#lx\t\t(%s breakpoint)%s", + brake->id, brake->opline, type, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); + } break; default: - phpdbg_writeln("#%d\t\t%#lx", brake->id, brake->opline); + phpdbg_writeln("opline", "id=\"%d\" num=\"%#lx\" disabled=\"%s\"", "#%d\t\t%#lx%s", + brake->id, brake->opline, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); break; } - } + } ZEND_HASH_FOREACH_END(); } break; case PHPDBG_BREAK_METHOD_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_METHOD_OPLINE_BP)) { - HashPosition position[3]; HashTable *class_table, *method_table; - char *class_name = NULL, *method_name = NULL; - zend_uint class_len = 0, method_len = 0; - zend_ulong class_idx = 0L, method_idx = 0L; - - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Method opline Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], &position[0]); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], (void**) &class_table, &position[0]) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], &position[0])) { - - if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], - &class_name, &class_len, &class_idx, 0, &position[0]) == HASH_KEY_IS_STRING) { - - for (zend_hash_internal_pointer_reset_ex(class_table, &position[1]); - zend_hash_get_current_data_ex(class_table, (void**) &method_table, &position[1]) == SUCCESS; - zend_hash_move_forward_ex(class_table, &position[1])) { - - if (zend_hash_get_current_key_ex(class_table, - &method_name, &method_len, &method_idx, 0, &position[0]) == HASH_KEY_IS_STRING) { - - phpdbg_breakopline_t *brake; - - for (zend_hash_internal_pointer_reset_ex(method_table, &position[2]); - zend_hash_get_current_data_ex(method_table, (void**)&brake, &position[2]) == SUCCESS; - zend_hash_move_forward_ex(method_table, &position[2])) { - phpdbg_writeln("#%d\t\t%s::%s opline %ld%s", - brake->id, brake->class_name, brake->func_name, brake->opline_num, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); - } - } - } - } - } + phpdbg_out(SEPARATE "\n"); + phpdbg_out("Method opline Breakpoints:\n"); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], class_table) { + ZEND_HASH_FOREACH_PTR(class_table, method_table) { + phpdbg_breakopline_t *brake; + + ZEND_HASH_FOREACH_PTR(method_table, brake) { + phpdbg_writeln("methodopline", "id=\"%d\" name=\"%s::%s\" num=\"%ld\" disabled=\"%s\"", "#%d\t\t%s::%s opline %ld%s", + brake->id, brake->class_name, brake->func_name, brake->opline_num, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } break; case PHPDBG_BREAK_FUNCTION_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FUNCTION_OPLINE_BP)) { - HashPosition position[2]; HashTable *function_table; - char *function_name = NULL; - zend_uint function_len = 0; - zend_ulong function_idx = 0L; - - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Function opline Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], &position[0]); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], (void**) &function_table, &position[0]) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], &position[0])) { - if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], - &function_name, &function_len, &function_idx, 0, &position[0]) == HASH_KEY_IS_STRING) { - - phpdbg_breakopline_t *brake; - - for (zend_hash_internal_pointer_reset_ex(function_table, &position[1]); - zend_hash_get_current_data_ex(function_table, (void**)&brake, &position[1]) == SUCCESS; - zend_hash_move_forward_ex(function_table, &position[1])) { - phpdbg_writeln("#%d\t\t%s opline %ld%s", - brake->id, brake->func_name, brake->opline_num, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); - } - } - - } + phpdbg_out(SEPARATE "\n"); + phpdbg_out("Function opline Breakpoints:\n"); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], function_table) { + phpdbg_breakopline_t *brake; + + ZEND_HASH_FOREACH_PTR(function_table, brake) { + phpdbg_writeln("functionopline", "id=\"%d\" name=\"%s\" num=\"%ld\" disabled=\"%s\"", "#%d\t\t%s opline %ld%s", + brake->id, brake->func_name, brake->opline_num, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } break; case PHPDBG_BREAK_FILE_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_OPLINE_BP)) { - HashPosition position[2]; HashTable *file_table; - char *file_name = NULL; - zend_uint file_len = 0; - zend_ulong file_idx = 0L; - - phpdbg_writeln(SEPARATE); - phpdbg_writeln("File opline Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], &position[0]); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], (void**) &file_table, &position[0]) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], &position[0])) { - - if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], - &file_name, &file_len, &file_idx, 0, &position[0]) == HASH_KEY_IS_STRING) { - phpdbg_breakopline_t *brake; - - for (zend_hash_internal_pointer_reset_ex(file_table, &position[1]); - zend_hash_get_current_data_ex(file_table, (void**)&brake, &position[1]) == SUCCESS; - zend_hash_move_forward_ex(file_table, &position[1])) { - phpdbg_writeln("#%d\t\t%s opline %ld%s", - brake->id, brake->class_name, brake->opline_num, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); - } - } - } + phpdbg_out(SEPARATE "\n"); + phpdbg_out("File opline Breakpoints:\n"); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], file_table) { + phpdbg_breakopline_t *brake; + + ZEND_HASH_FOREACH_PTR(file_table, brake) { + phpdbg_writeln("fileopline", "id=\"%d\" name=\"%s\" num=\"%ld\" disabled=\"%s\"", "#%d\t\t%s opline %ld%s", + brake->id, brake->class_name, brake->opline_num, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } break; case PHPDBG_BREAK_COND: if ((PHPDBG_G(flags) & PHPDBG_HAS_COND_BP)) { - HashPosition position; phpdbg_breakcond_t *brake; - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Conditional Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void**) &brake, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) { + phpdbg_out(SEPARATE "\n"); + phpdbg_out("Conditional Breakpoints:\n"); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], brake) { if (brake->paramed) { switch (brake->param.type) { case STR_PARAM: - phpdbg_writeln("#%d\t\tat %s if %s%s", - brake->id, - brake->param.str, - brake->code, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); + phpdbg_writeln("evalfunction", "id=\"%d\" name=\"%s\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat %s if %s%s", + brake->id, brake->param.str, brake->code, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); break; case NUMERIC_FUNCTION_PARAM: - phpdbg_writeln("#%d\t\tat %s#%ld if %s%s", - brake->id, - brake->param.str, - brake->param.num, - brake->code, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); + phpdbg_writeln("evalfunctionopline", "id=\"%d\" name=\"%s\" num=\"%ld\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat %s#%ld if %s%s", + brake->id, brake->param.str, brake->param.num, brake->code, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); break; case METHOD_PARAM: - phpdbg_writeln("#%d\t\tat %s::%s if %s%s", - brake->id, - brake->param.method.class, - brake->param.method.name, - brake->code, + phpdbg_writeln("evalmethod", "id=\"%d\" name=\"%s::%s\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat %s::%s if %s%s", + brake->id, brake->param.method.class, brake->param.method.name, brake->code, ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); break; case NUMERIC_METHOD_PARAM: - phpdbg_writeln("#%d\t\tat %s::%s#%ld if %s%s", - brake->id, - brake->param.method.class, - brake->param.method.name, - brake->param.num, - brake->code, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); + phpdbg_writeln("evalmethodopline", "id=\"%d\" name=\"%s::%s\" num=\"%d\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat %s::%s#%ld if %s%s", + brake->id, brake->param.method.class, brake->param.method.name, brake->param.num, brake->code, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); break; case FILE_PARAM: - phpdbg_writeln("#%d\t\tat %s:%lu if %s%s", - brake->id, - brake->param.file.name, - brake->param.file.line, - brake->code, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); + phpdbg_writeln("evalfile", "id=\"%d\" name=\"%s\" line=\"%d\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat %s:%lu if %s%s", + brake->id, brake->param.file.name, brake->param.file.line, brake->code, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); break; case ADDR_PARAM: - phpdbg_writeln("#%d\t\tat #%lx if %s%s", - brake->id, - brake->param.addr, - brake->code, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); + phpdbg_writeln("evalopline", "id=\"%d\" opline=\"%#lx\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat #%lx if %s%s", + brake->id, brake->param.addr, brake->code, + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); break; default: - phpdbg_error("Invalid parameter type for conditional breakpoint"); + phpdbg_error("eval", "type=\"invalidparameter\"", "Invalid parameter type for conditional breakpoint"); return; } } else { - phpdbg_writeln("#%d\t\tif %s%s", + phpdbg_writeln("eval", "id=\"%d\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tif %s%s", brake->id, brake->code, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); } - } + } ZEND_HASH_FOREACH_END(); } break; case PHPDBG_BREAK_OPCODE: if (PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) { - HashPosition position; phpdbg_breakop_t *brake; - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Opcode Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], (void**) &brake, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], &position)) { - phpdbg_writeln("#%d\t\t%s%s", + phpdbg_out(SEPARATE "\n"); + phpdbg_out("Opcode Breakpoints:\n"); + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], brake) { + phpdbg_writeln("opcode", "id=\"%d\" name=\"%s\" disabled=\"%s\"", "#%d\t\t%s%s", brake->id, brake->name, - ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : ""); - } + ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); + } ZEND_HASH_FOREACH_END(); } break; } + + phpdbg_xml("</breakpoints>"); } /* }}} */ diff --git a/sapi/phpdbg/phpdbg_bp.h b/sapi/phpdbg/phpdbg_bp.h index 3b75db952e..eaf77d0de7 100644 --- a/sapi/phpdbg/phpdbg_bp.h +++ b/sapi/phpdbg/phpdbg_bp.h @@ -21,6 +21,20 @@ #ifndef PHPDBG_BP_H #define PHPDBG_BP_H +/* {{{ defines */ +#define PHPDBG_BREAK_FILE 0 +#define PHPDBG_BREAK_FILE_PENDING 1 +#define PHPDBG_BREAK_SYM 2 +#define PHPDBG_BREAK_OPLINE 3 +#define PHPDBG_BREAK_METHOD 4 +#define PHPDBG_BREAK_COND 5 +#define PHPDBG_BREAK_OPCODE 6 +#define PHPDBG_BREAK_FUNCTION_OPLINE 7 +#define PHPDBG_BREAK_METHOD_OPLINE 8 +#define PHPDBG_BREAK_FILE_OPLINE 9 +#define PHPDBG_BREAK_MAP 10 +#define PHPDBG_BREAK_TABLES 11 /* }}} */ + /* {{{ */ typedef struct _zend_op *phpdbg_opline_ptr_t; /* }}} */ @@ -103,44 +117,47 @@ typedef struct _phpdbg_breakcond_t { zend_op_array *ops; } phpdbg_breakcond_t; -/* {{{ Opline breaks API */ -PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array TSRMLS_DC); -PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array TSRMLS_DC); -PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRMLS_DC); /* }}} */ +/* {{{ Resolving breaks API */ +PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array); +PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array); +PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break); +PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uint filelen, zend_string *cur, HashTable *fileht); +PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file); /* }}} */ /* {{{ Breakpoint Creation API */ -PHPDBG_API void phpdbg_set_breakpoint_file(const char* filename, long lineno TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_symbol(const char* func_name, size_t func_name_len TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_method(const char* class_name, const char* func_name TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_opcode(const char* opname, size_t opname_len TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_expression(const char* expression, size_t expression_len TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param TSRMLS_DC); /* }}} */ +PHPDBG_API void phpdbg_set_breakpoint_file(const char* filename, long lineno); +PHPDBG_API void phpdbg_set_breakpoint_symbol(const char* func_name, size_t func_name_len); +PHPDBG_API void phpdbg_set_breakpoint_method(const char* class_name, const char* func_name); +PHPDBG_API void phpdbg_set_breakpoint_opcode(const char* opname, size_t opname_len); +PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline); +PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline); +PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline); +PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline); +PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline); +PHPDBG_API void phpdbg_set_breakpoint_expression(const char* expression, size_t expression_len); +PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param); /* }}} */ /* {{{ Breakpoint Detection API */ -PHPDBG_API phpdbg_breakbase_t* phpdbg_find_breakpoint(zend_execute_data* TSRMLS_DC); /* }}} */ +PHPDBG_API phpdbg_breakbase_t* phpdbg_find_breakpoint(zend_execute_data*); /* }}} */ /* {{{ Misc Breakpoint API */ -PHPDBG_API void phpdbg_hit_breakpoint(phpdbg_breakbase_t* brake, zend_bool output TSRMLS_DC); -PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC); -PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t* brake TSRMLS_DC); -PHPDBG_API void phpdbg_reset_breakpoints(TSRMLS_D); -PHPDBG_API void phpdbg_clear_breakpoints(TSRMLS_D); -PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC); -PHPDBG_API void phpdbg_enable_breakpoints(TSRMLS_D); -PHPDBG_API void phpdbg_enable_breakpoint(zend_ulong id TSRMLS_DC); -PHPDBG_API void phpdbg_disable_breakpoint(zend_ulong id TSRMLS_DC); -PHPDBG_API void phpdbg_disable_breakpoints(TSRMLS_D); /* }}} */ +PHPDBG_API void phpdbg_hit_breakpoint(phpdbg_breakbase_t* brake, zend_bool output); +PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type); +PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t* brake); +PHPDBG_API void phpdbg_reset_breakpoints(void); +PHPDBG_API void phpdbg_clear_breakpoints(void); +PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num); +PHPDBG_API void phpdbg_enable_breakpoints(void); +PHPDBG_API void phpdbg_enable_breakpoint(zend_ulong id); +PHPDBG_API void phpdbg_disable_breakpoint(zend_ulong id); +PHPDBG_API void phpdbg_disable_breakpoints(void); /* }}} */ /* {{{ Breakbase API */ -PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id TSRMLS_DC); -PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable ***table, HashPosition *position TSRMLS_DC); /* }}} */ +PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id); +PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable **table, zend_ulong *numkey, zend_string **strkey); /* }}} */ /* {{{ Breakpoint Exportation API */ -PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC); /* }}} */ +PHPDBG_API void phpdbg_export_breakpoints(FILE *handle); +PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str); /* }}} */ #endif /* PHPDBG_BP_H */ diff --git a/sapi/phpdbg/phpdbg_break.c b/sapi/phpdbg/phpdbg_break.c index 470c31b01e..71fc9e16bd 100644 --- a/sapi/phpdbg/phpdbg_break.c +++ b/sapi/phpdbg/phpdbg_break.c @@ -28,28 +28,28 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -#define PHPDBG_BREAK_COMMAND_D(f, h, a, m, l, s) \ - PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[10]) +#define PHPDBG_BREAK_COMMAND_D(f, h, a, m, l, s, flags) \ + PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[10], flags) /** * Commands */ const phpdbg_command_t phpdbg_break_commands[] = { - PHPDBG_BREAK_COMMAND_D(at, "specify breakpoint by location and condition", '@', break_at, NULL, "*c"), - PHPDBG_BREAK_COMMAND_D(del, "delete breakpoint by identifier number", '~', break_del, NULL, "n"), + PHPDBG_BREAK_COMMAND_D(at, "specify breakpoint by location and condition", '@', break_at, NULL, "*c", 0), + PHPDBG_BREAK_COMMAND_D(del, "delete breakpoint by identifier number", '~', break_del, NULL, "n", 0), PHPDBG_END_COMMAND }; PHPDBG_BREAK(at) /* {{{ */ { - phpdbg_set_breakpoint_at(param TSRMLS_CC); + phpdbg_set_breakpoint_at(param); return SUCCESS; } /* }}} */ PHPDBG_BREAK(del) /* {{{ */ { - phpdbg_delete_breakpoint(param->num TSRMLS_CC); + phpdbg_delete_breakpoint(param->num); return SUCCESS; } /* }}} */ diff --git a/sapi/phpdbg/phpdbg_btree.c b/sapi/phpdbg/phpdbg_btree.c index fb42e6a47d..cc42115d83 100644 --- a/sapi/phpdbg/phpdbg_btree.c +++ b/sapi/phpdbg/phpdbg_btree.c @@ -219,3 +219,18 @@ check_branch_existence: return SUCCESS; } + +void phpdbg_btree_branch_dump(phpdbg_btree_branch *branch, zend_ulong depth) { + if (branch) { + if (depth--) { + phpdbg_btree_branch_dump(branch->branches[0], depth); + phpdbg_btree_branch_dump(branch->branches[1], depth); + } else { + fprintf(stderr, "%p: %p\n", (void *) branch->result.idx, branch->result.ptr); + } + } +} + +void phpdbg_btree_dump(phpdbg_btree *tree) { + phpdbg_btree_branch_dump(tree->branch, tree->depth); +} diff --git a/sapi/phpdbg/phpdbg_btree.h b/sapi/phpdbg/phpdbg_btree.h index 3ea1ebd4dc..b194a5fab9 100644 --- a/sapi/phpdbg/phpdbg_btree.h +++ b/sapi/phpdbg/phpdbg_btree.h @@ -62,4 +62,9 @@ int phpdbg_btree_insert_or_update(phpdbg_btree *tree, zend_ulong idx, void *ptr, #define phpdbg_btree_update(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_UPDATE) #define phpdbg_btree_overwrite(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_OWERWRITE) + +/* debugging functions */ +void phpdbg_btree_branch_dump(phpdbg_btree_branch *branch, zend_ulong depth); +void phpdbg_btree_dump(phpdbg_btree *tree); + #endif diff --git a/sapi/phpdbg/phpdbg_cmd.c b/sapi/phpdbg/phpdbg_cmd.c index 27335b0f1b..3e3f932f97 100644 --- a/sapi/phpdbg/phpdbg_cmd.c +++ b/sapi/phpdbg/phpdbg_cmd.c @@ -23,6 +23,7 @@ #include "phpdbg_utils.h" #include "phpdbg_set.h" #include "phpdbg_prompt.h" +#include "phpdbg_io.h" ZEND_EXTERN_MODULE_GLOBALS(phpdbg); @@ -39,11 +40,11 @@ static inline const char *phpdbg_command_name(const phpdbg_command_t *command, c memcpy(&buffer[pos], command->name, command->name_len); pos += command->name_len; buffer[pos] = 0; - + return buffer; } -PHPDBG_API const char *phpdbg_get_param_type(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */ +PHPDBG_API const char *phpdbg_get_param_type(const phpdbg_param_t *param) /* {{{ */ { switch (param->type) { case STACK_PARAM: @@ -69,7 +70,7 @@ PHPDBG_API const char *phpdbg_get_param_type(const phpdbg_param_t *param TSRMLS_ } } -PHPDBG_API void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_clear_param(phpdbg_param_t *param) /* {{{ */ { if (param) { switch (param->type) { @@ -90,80 +91,60 @@ PHPDBG_API void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */ } /* }}} */ -PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer TSRMLS_DC) /* {{{ */ +PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer) /* {{{ */ { switch (param->type) { case STR_PARAM: - asprintf(pointer, - "%s", param->str); + asprintf(pointer, "%s", param->str); break; case ADDR_PARAM: - asprintf(pointer, - "%#lx", param->addr); + asprintf(pointer, "%#llx", param->addr); break; case NUMERIC_PARAM: - asprintf(pointer, - "%li", - param->num); + asprintf(pointer, "%li", param->num); break; case METHOD_PARAM: - asprintf(pointer, - "%s::%s", - param->method.class, - param->method.name); + asprintf(pointer, "%s::%s", param->method.class, param->method.name); break; case FILE_PARAM: if (param->num) { - asprintf(pointer, - "%s:%lu#%lu", - param->file.name, - param->file.line, - param->num); + asprintf(pointer, "%s:%lu#%lu", param->file.name, param->file.line, param->num); } else { - asprintf(pointer, - "%s:%lu", - param->file.name, - param->file.line); + asprintf(pointer, "%s:%lu", param->file.name, param->file.line); } break; case NUMERIC_FUNCTION_PARAM: - asprintf(pointer, - "%s#%lu", param->str, param->num); + asprintf(pointer, "%s#%lu", param->str, param->num); break; case NUMERIC_METHOD_PARAM: - asprintf(pointer, - "%s::%s#%lu", - param->method.class, - param->method.name, - param->num); + asprintf(pointer, "%s::%s#%lu", param->method.class, param->method.name, param->num); break; default: - asprintf(pointer, - "%s", "unknown"); + *pointer = strdup("unknown"); } return *pointer; } /* }}} */ -PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t* src, phpdbg_param_t* dest TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t* src, phpdbg_param_t* dest) /* {{{ */ { switch ((dest->type = src->type)) { case STACK_PARAM: /* nope */ break; - + case STR_PARAM: dest->str = estrndup(src->str, src->len); dest->len = src->len; break; - + case OP_PARAM: dest->str = estrndup(src->str, src->len); dest->len = src->len; @@ -203,14 +184,14 @@ PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t* src, phpdbg_param_t* des break; case EMPTY_PARAM: { /* do nothing */ } break; - + default: { /* not yet */ } } } /* }}} */ -PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */ +PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param) /* {{{ */ { zend_ulong hash = param->type; @@ -218,7 +199,7 @@ PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) / case STACK_PARAM: /* nope */ break; - + case STR_PARAM: hash += zend_inline_hash_func(param->str, param->len); break; @@ -256,7 +237,7 @@ PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) / break; case EMPTY_PARAM: { /* do nothing */ } break; - + default: { /* not yet */ } @@ -265,7 +246,7 @@ PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) / return hash; } /* }}} */ -PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *l, const phpdbg_param_t *r TSRMLS_DC) /* {{{ */ +PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *l, const phpdbg_param_t *r) /* {{{ */ { if (l && r) { if (l->type == r->type) { @@ -274,7 +255,7 @@ PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *l, const phpdbg_pa /* nope, or yep */ return 1; break; - + case NUMERIC_FUNCTION_PARAM: if (l->num != r->num) { break; @@ -329,7 +310,7 @@ PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *l, const phpdbg_pa case EMPTY_PARAM: return 1; - + default: { /* not yet */ } @@ -346,43 +327,43 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg) case STR_PARAM: fprintf(stderr, "%s STR_PARAM(%s=%lu)\n", msg, param->str, param->len); break; - + case ADDR_PARAM: - fprintf(stderr, "%s ADDR_PARAM(%lu)\n", msg, param->addr); + fprintf(stderr, "%s ADDR_PARAM(%llu)\n", msg, param->addr); break; - + case NUMERIC_FILE_PARAM: fprintf(stderr, "%s NUMERIC_FILE_PARAM(%s:#%lu)\n", msg, param->file.name, param->file.line); break; - + case FILE_PARAM: fprintf(stderr, "%s FILE_PARAM(%s:%lu)\n", msg, param->file.name, param->file.line); break; - + case METHOD_PARAM: fprintf(stderr, "%s METHOD_PARAM(%s::%s)\n", msg, param->method.class, param->method.name); break; - + case NUMERIC_METHOD_PARAM: fprintf(stderr, "%s NUMERIC_METHOD_PARAM(%s::%s)\n", msg, param->method.class, param->method.name); break; - + case NUMERIC_FUNCTION_PARAM: fprintf(stderr, "%s NUMERIC_FUNCTION_PARAM(%s::%ld)\n", msg, param->str, param->num); break; - + case NUMERIC_PARAM: fprintf(stderr, "%s NUMERIC_PARAM(%ld)\n", msg, param->num); break; - + case COND_PARAM: fprintf(stderr, "%s COND_PARAM(%s=%lu)\n", msg, param->str, param->len); break; - + case OP_PARAM: fprintf(stderr, "%s OP_PARAM(%s=%lu)\n", msg, param->str, param->len); break; - + default: { /* not yet */ } @@ -394,13 +375,13 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg) PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack) { if (stack && stack->next) { phpdbg_param_t *remove = stack->next; - + while (remove) { phpdbg_param_t *next = NULL; - + if (remove->next) next = remove->next; - + switch (remove->type) { case NUMERIC_METHOD_PARAM: case METHOD_PARAM: @@ -414,29 +395,30 @@ PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack) { case STR_PARAM: case OP_PARAM: if (remove->str) - free(remove->str); + free(remove->str); break; - + case NUMERIC_FILE_PARAM: case FILE_PARAM: if (remove->file.name) free(remove->file.name); break; - + default: { /* nothing */ } } - + free(remove); remove = NULL; - + if (next) - remove = next; + remove = next; else break; } } - + + stack->next = NULL; } /* }}} */ @@ -464,30 +446,29 @@ PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param) stack->len++; } /* }}} */ -PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack, char **why TSRMLS_DC) { +PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack) { if (command) { char buffer[128] = {0,}; const phpdbg_param_t *top = (stack != NULL) ? *stack : NULL; const char *arg = command->args; size_t least = 0L, - received = 0L, - current = 0L; + received = 0L, + current = 0L; zend_bool optional = 0; - + /* check for arg spec */ if (!(arg) || !(*arg)) { if (!top) { return SUCCESS; } - - asprintf(why, - "The command \"%s\" expected no arguments", + + phpdbg_error("command", "type=\"toomanyargs\" command=\"%s\" expected=\"0\"", "The command \"%s\" expected no arguments", phpdbg_command_name(command, buffer)); return FAILURE; } - + least = 0L; - + /* count least amount of arguments */ while (arg && *arg) { if (arg[0] == '|') { @@ -496,38 +477,36 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param least++; arg++; } - + arg = command->args; #define verify_arg(e, a, t) if (!(a)) { \ if (!optional) { \ - asprintf(why, \ - "The command \"%s\" expected %s and got nothing at parameter %lu", \ + phpdbg_error("command", "type=\"noarg\" command=\"%s\" expected=\"%s\" num=\"%lu\"", "The command \"%s\" expected %s and got nothing at parameter %lu", \ phpdbg_command_name(command, buffer), \ (e), \ current); \ return FAILURE;\ } \ } else if ((a)->type != (t)) { \ - asprintf(why, \ - "The command \"%s\" expected %s and got %s at parameter %lu", \ + phpdbg_error("command", "type=\"wrongarg\" command=\"%s\" expected=\"%s\" got=\"%s\" num=\"%lu\"", "The command \"%s\" expected %s and got %s at parameter %lu", \ phpdbg_command_name(command, buffer), \ (e),\ - phpdbg_get_param_type((a) TSRMLS_CC), \ + phpdbg_get_param_type((a)), \ current); \ return FAILURE; \ } while (arg && *arg) { current++; - + switch (*arg) { case '|': { current--; optional = 1; arg++; } continue; - + case 'i': verify_arg("raw input", top, STR_PARAM); break; case 's': verify_arg("string", top, STR_PARAM); break; case 'n': verify_arg("number", top, NUMERIC_PARAM); break; @@ -537,14 +516,14 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param case 'c': verify_arg("condition", top, COND_PARAM); break; case 'o': verify_arg("opcode", top, OP_PARAM); break; case 'b': verify_arg("boolean", top, NUMERIC_PARAM); break; - + case '*': { /* do nothing */ } break; } - + if (top ) { top = top->next; } else break; - + received++; arg++; } @@ -552,28 +531,27 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param #undef verify_arg if ((received < least)) { - asprintf(why, - "The command \"%s\" expected at least %lu arguments (%s) and received %lu", + phpdbg_error("command", "type=\"toofewargs\" command=\"%s\" expected=\"%d\" argtypes=\"%s\" got=\"%d\"", "The command \"%s\" expected at least %lu arguments (%s) and received %lu", phpdbg_command_name(command, buffer), least, - command->args, + command->args, received); return FAILURE; } } - + return SUCCESS; } /* {{{ */ -PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top, char **why) { +PHPDBG_API const phpdbg_command_t *phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top) { const phpdbg_command_t *command = commands; phpdbg_param_t *name = *top; const phpdbg_command_t *matched[3] = {NULL, NULL, NULL}; ulong matches = 0L; - + while (command && command->name && command->handler) { - if ((name->len == 1) || (command->name_len >= name->len)) { + if (name->len == 1 || command->name_len >= name->len) { /* match single letter alias */ if (command->alias && (name->len == 1)) { if (command->alias == (*name->str)) { @@ -581,85 +559,76 @@ PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t * matches++; } } else { - /* match full, case insensitive, command name */ if (strncasecmp(command->name, name->str, name->len) == SUCCESS) { if (matches < 3) { - /* only allow abbreviating commands that can be aliased */ - if (((name->len != command->name_len) && command->alias) || - (name->len == command->name_len)) { + if ((name->len != command->name_len && command->alias) || name->len == command->name_len) { matched[matches] = command; matches++; } - - + /* exact match */ - if (name->len == command->name_len) + if (name->len == command->name_len) { break; - } else break; + } + } else { + break; + } } } } - + command++; } - + switch (matches) { - case 0: { + case 0: if (parent) { - asprintf( - why, - "The command \"%s %s\" could not be found", - parent->name, name->str); - } else asprintf( - why, - "The command \"%s\" could not be found", - name->str); - } return parent; - - case 1: { + phpdbg_error("command", "type=\"notfound\" command=\"%s\" subcommand=\"%s\"", "The command \"%s %s\" could not be found", parent->name, name->str); + } else { + phpdbg_error("command", "type=\"notfound\" command=\"%s\"", "The command \"%s\" could not be found", name->str); + } + return parent; + + case 1: (*top) = (*top)->next; command = matched[0]; - } break; - + break; + default: { char *list = NULL; - zend_uint it = 0; + uint32_t it = 0; size_t pos = 0; - + while (it < matches) { if (!list) { - list = malloc( - matched[it]->name_len + 1 + - ((it+1) < matches ? sizeof(", ")-1 : 0)); + list = emalloc(matched[it]->name_len + 1 + (it + 1 < matches ? sizeof(", ") - 1 : 0)); } else { - list = realloc(list, - (pos + matched[it]->name_len) + 1 + - ((it+1) < matches ? sizeof(", ")-1 : 0)); + list = erealloc(list, (pos + matched[it]->name_len) + 1 + (it + 1 < matches ? sizeof(", ") - 1 : 0)); } memcpy(&list[pos], matched[it]->name, matched[it]->name_len); pos += matched[it]->name_len; - if ((it+1) < matches) { - memcpy(&list[pos], ", ", sizeof(", ")-1); + if ((it + 1) < matches) { + memcpy(&list[pos], ", ", sizeof(", ") - 1); pos += (sizeof(", ") - 1); } - + list[pos] = 0; it++; } - - asprintf( - why, - "The command \"%s\" is ambigious, matching %lu commands (%s)", - name->str, matches, list); - free(list); - } return NULL; + + /* ", " separated matches */ + phpdbg_error("command", "type=\"ambiguous\" command=\"%s\" matches=\"%lu\" matched=\"%s\"", "The command \"%s\" is ambigious, matching %lu commands (%s)", name->str, matches, list); + efree(list); + + return NULL; + } } if (command->subs && (*top) && ((*top)->type == STR_PARAM)) { - return phpdbg_stack_resolve(command->subs, command, top, why); + return phpdbg_stack_resolve(command->subs, command, top); } else { return command; } @@ -668,103 +637,98 @@ PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t * } /* }}} */ /* {{{ */ -PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, char **why TSRMLS_DC) { +PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe) { phpdbg_param_t *top = NULL; const phpdbg_command_t *handler = NULL; - + if (stack->type != STACK_PARAM) { - asprintf( - why, "The passed argument was not a stack !!"); + phpdbg_error("command", "type=\"nostack\"", "The passed argument was not a stack !"); return FAILURE; } - + if (!stack->len) { - asprintf( - why, "The stack contains nothing !!"); + phpdbg_error("command", "type=\"emptystack\"", "The stack contains nothing !"); return FAILURE; } - - top = (phpdbg_param_t*) stack->next; - + + top = (phpdbg_param_t *) stack->next; + switch (top->type) { case EVAL_PARAM: - return PHPDBG_COMMAND_HANDLER(ev)(top TSRMLS_CC); + phpdbg_activate_err_buf(0); + phpdbg_free_err_buf(); + return PHPDBG_COMMAND_HANDLER(ev)(top); case RUN_PARAM: - return PHPDBG_COMMAND_HANDLER(run)(top TSRMLS_CC); - + if (!allow_async_unsafe) { + phpdbg_error("signalsegv", "command=\"run\"", "run command is disallowed during hard interrupt"); + } + phpdbg_activate_err_buf(0); + phpdbg_free_err_buf(); + return PHPDBG_COMMAND_HANDLER(run)(top); + case SHELL_PARAM: - return PHPDBG_COMMAND_HANDLER(sh)(top TSRMLS_CC); - + if (!allow_async_unsafe) { + phpdbg_error("signalsegv", "command=\"sh\"", "sh command is disallowed during hard interrupt"); + return FAILURE; + } + phpdbg_activate_err_buf(0); + phpdbg_free_err_buf(); + return PHPDBG_COMMAND_HANDLER(sh)(top); + case STR_PARAM: { - handler = phpdbg_stack_resolve( - phpdbg_prompt_commands, NULL, &top, why); - + handler = phpdbg_stack_resolve(phpdbg_prompt_commands, NULL, &top); + if (handler) { - if (phpdbg_stack_verify(handler, &top, why TSRMLS_CC) == SUCCESS) { - return handler->handler(top TSRMLS_CC); + if (!allow_async_unsafe && !(handler->flags & PHPDBG_ASYNC_SAFE)) { + phpdbg_error("signalsegv", "command=\"%s\"", "%s command is disallowed during hard interrupt", handler->name); + return FAILURE; + } + + if (phpdbg_stack_verify(handler, &top) == SUCCESS) { + phpdbg_activate_err_buf(0); + phpdbg_free_err_buf(); + return handler->handler(top); } } } return FAILURE; - + default: - asprintf( - why, "The first parameter makes no sense !!"); + phpdbg_error("command", "type=\"invalidcommand\"", "The first parameter makes no sense !"); return FAILURE; } - + return SUCCESS; } /* }}} */ -PHPDBG_API char* phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */ +PHPDBG_API char *phpdbg_read_input(char *buffered) /* {{{ */ { - char *cmd = NULL; -#if !defined(HAVE_LIBREADLINE) && !defined(HAVE_LIBEDIT) char buf[PHPDBG_MAX_CMD]; -#endif + char *cmd = NULL; char *buffer = NULL; - if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { - if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE) && - (buffered == NULL)) { - fflush(PHPDBG_G(io)[PHPDBG_STDOUT]); + if ((PHPDBG_G(flags) & (PHPDBG_IS_STOPPING | PHPDBG_IS_RUNNING)) != PHPDBG_IS_STOPPING) { + if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE) && (buffered == NULL) && !phpdbg_active_sigsafe_mem()) { + fflush(PHPDBG_G(io)[PHPDBG_STDOUT].ptr); } if (buffered == NULL) { -disconnect: - if (0) { - PHPDBG_G(flags) |= (PHPDBG_IS_QUITTING|PHPDBG_IS_DISCONNECTED); - zend_bailout(); - return NULL; - } - -#if !defined(HAVE_LIBREADLINE) && !defined(HAVE_LIBEDIT) - if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) { - if (!phpdbg_write("%s", phpdbg_get_prompt(TSRMLS_C))) { - goto disconnect; - } +#define USE_LIB_STAR (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT)) + /* note: EOF makes readline write prompt again in local console mode - and ignored if compiled without readline */ +#if USE_LIB_STAR +readline: + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) +#endif + { + phpdbg_write("prompt", "", "%s", phpdbg_get_prompt()); + phpdbg_consume_stdin_line(cmd = buf); } - - /* note: EOF is ignored */ -readline: - if (!fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) { - /* the user has gone away */ - if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) { - goto disconnect; - } else goto readline; +#if USE_LIB_STAR + else { + cmd = readline(phpdbg_get_prompt()); + PHPDBG_G(last_was_newline) = 1; } - cmd = buf; -#else - /* note: EOF makes readline write prompt again in local console mode */ -readline: - if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) { - char buf[PHPDBG_MAX_CMD]; - if (fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) { - cmd = buf; - } else goto disconnect; - } else cmd = readline(phpdbg_get_prompt(TSRMLS_C)); - if (!cmd) { goto readline; } @@ -773,13 +737,14 @@ readline: add_history(cmd); } #endif - } else cmd = buffered; - + } else { + cmd = buffered; + } + buffer = estrdup(cmd); -#if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT) - if (!buffered && cmd && - !(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) { +#if USE_LIB_STAR + if (!buffered && cmd && !(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) { free(cmd); } #endif @@ -805,12 +770,32 @@ readline: buffer = estrdup(PHPDBG_G(buffer)); } } - + return buffer; } /* }}} */ -PHPDBG_API void phpdbg_destroy_input(char **input TSRMLS_DC) /*{{{ */ +PHPDBG_API void phpdbg_destroy_input(char **input) /*{{{ */ { efree(*input); } /* }}} */ +PHPDBG_API int phpdbg_ask_user_permission(const char *question) { + if (!(PHPDBG_G(flags) & PHPDBG_WRITE_XML)) { + char buf[PHPDBG_MAX_CMD]; + phpdbg_out("%s", question); + phpdbg_out(" (type y or n): "); + + while (1) { + phpdbg_consume_stdin_line(buf); + if (buf[1] == '\n' && (buf[0] == 'y' || buf[0] == 'n')) { + if (buf[0] == 'y') { + return SUCCESS; + } + return FAILURE; + } + phpdbg_out("Please enter either y (yes) or n (no): "); + } + } + + return SUCCESS; +} diff --git a/sapi/phpdbg/phpdbg_cmd.h b/sapi/phpdbg/phpdbg_cmd.h index d779da548e..a5047be035 100644 --- a/sapi/phpdbg/phpdbg_cmd.h +++ b/sapi/phpdbg/phpdbg_cmd.h @@ -86,7 +86,9 @@ struct _phpdbg_param { #define YYSTYPE phpdbg_param_t #endif -typedef int (*phpdbg_command_handler_t)(const phpdbg_param_t* TSRMLS_DC); +#define PHPDBG_ASYNC_SAFE 1 + +typedef int (*phpdbg_command_handler_t)(const phpdbg_param_t*); typedef struct _phpdbg_command_t phpdbg_command_t; struct _phpdbg_command_t { @@ -97,8 +99,9 @@ struct _phpdbg_command_t { char alias; /* Alias */ phpdbg_command_handler_t handler; /* Command handler */ const phpdbg_command_t *subs; /* Sub Commands */ - char *args; /* Argument Spec */ - const phpdbg_command_t *parent; /* Parent Command */ + char *args; /* Argument Spec */ + const phpdbg_command_t *parent; /* Parent Command */ + zend_bool flags; /* General flags */ }; /* }}} */ @@ -106,7 +109,7 @@ struct _phpdbg_command_t { #define PHPDBG_STRL(s) s, sizeof(s)-1 #define PHPDBG_MAX_CMD 500 #define PHPDBG_FRAME(v) (PHPDBG_G(frame).v) -#define PHPDBG_EX(v) (EG(current_execute_data)->v) +#define PHPDBG_EX(v) (EG(current_execute_data)->v) typedef struct { int num; @@ -126,27 +129,28 @@ typedef struct { /* * Input Management */ -PHPDBG_API char* phpdbg_read_input(char *buffered TSRMLS_DC); -PHPDBG_API void phpdbg_destroy_input(char** TSRMLS_DC); +PHPDBG_API char* phpdbg_read_input(char *buffered); +PHPDBG_API void phpdbg_destroy_input(char**); +PHPDBG_API int phpdbg_ask_user_permission(const char *question); /** * Stack Management */ PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param); -PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top, char **why); -PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack, char **why TSRMLS_DC); -PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, char **why TSRMLS_DC); +PHPDBG_API const phpdbg_command_t *phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top); +PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack); +PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe); PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack); /* * Parameter Management */ -PHPDBG_API void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC); -PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t* TSRMLS_DC); -PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t * TSRMLS_DC); -PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t * TSRMLS_DC); -PHPDBG_API const char* phpdbg_get_param_type(const phpdbg_param_t* TSRMLS_DC); -PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer TSRMLS_DC); +PHPDBG_API void phpdbg_clear_param(phpdbg_param_t*); +PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t*); +PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t *); +PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *); +PHPDBG_API const char* phpdbg_get_param_type(const phpdbg_param_t*); +PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer); PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg); /** @@ -154,27 +158,27 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg) */ #define PHPDBG_COMMAND_HANDLER(name) phpdbg_do_##name -#define PHPDBG_COMMAND_D_EXP(name, tip, alias, handler, children, args, parent) \ - {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, parent} +#define PHPDBG_COMMAND_D_EXP(name, tip, alias, handler, children, args, parent, flags) \ + {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, parent, flags} -#define PHPDBG_COMMAND_D_EX(name, tip, alias, handler, children, args) \ - {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, NULL} +#define PHPDBG_COMMAND_D_EX(name, tip, alias, handler, children, args, flags) \ + {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, NULL, flags} -#define PHPDBG_COMMAND_D(name, tip, alias, children, args) \ - {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##name, children, args, NULL} +#define PHPDBG_COMMAND_D(name, tip, alias, children, args, flags) \ + {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##name, children, args, NULL, flags} -#define PHPDBG_COMMAND(name) int phpdbg_do_##name(const phpdbg_param_t *param TSRMLS_DC) +#define PHPDBG_COMMAND(name) int phpdbg_do_##name(const phpdbg_param_t *param) -#define PHPDBG_COMMAND_ARGS param TSRMLS_CC +#define PHPDBG_COMMAND_ARGS param -#define PHPDBG_END_COMMAND {NULL, 0, NULL, 0, '\0', NULL, NULL, '\0', NULL} +#define PHPDBG_END_COMMAND {NULL, 0, NULL, 0, '\0', NULL, NULL, NULL, NULL, 0} /* * Default Switch Case */ #define phpdbg_default_switch_case() \ default: \ - phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); \ + phpdbg_error("command", "type=\"wrongarg\" got=\"%s\"", "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param)); \ break #endif /* PHPDBG_CMD_H */ diff --git a/sapi/phpdbg/phpdbg_eol.c b/sapi/phpdbg/phpdbg_eol.c new file mode 100644 index 0000000000..000c5f066b --- /dev/null +++ b/sapi/phpdbg/phpdbg_eol.c @@ -0,0 +1,172 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Anatol Belski <ab@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "phpdbg.h" +#include "phpdbg_eol.h" + +ZEND_EXTERN_MODULE_GLOBALS(phpdbg); + +#define EOL_LIST_LEN 4 +struct phpdbg_eol_rep phpdbg_eol_list[EOL_LIST_LEN] = { + {"CRLF", "\r\n", PHPDBG_EOL_CRLF}, +/* {"LFCR", "\n\r", PHPDBG_EOL_LFCR},*/ + {"LF", "\n", PHPDBG_EOL_LF}, + {"CR", "\r", PHPDBG_EOL_CR}, +}; + +int phpdbg_eol_global_update(char *name) +{ + + if (0 == memcmp(name, "CRLF", 4) || 0 == memcmp(name, "crlf", 4) || 0 == memcmp(name, "DOS", 3) || 0 == memcmp(name, "dos", 3)) { + PHPDBG_G(eol) = PHPDBG_EOL_CRLF; + } else if (0 == memcmp(name, "LF", 2) || 0 == memcmp(name, "lf", 2) || 0 == memcmp(name, "UNIX", 4) || 0 == memcmp(name, "unix", 4)) { + PHPDBG_G(eol) = PHPDBG_EOL_LF; + } else if (0 == memcmp(name, "CR", 2) || 0 == memcmp(name, "cr", 2) || 0 == memcmp(name, "MAC", 3) || 0 == memcmp(name, "mac", 3)) { + PHPDBG_G(eol) = PHPDBG_EOL_CR; + } else { + return FAILURE; + } + + return SUCCESS; +} + +char *phpdbg_eol_name(int id) +{ + size_t i = 0; + + while (i < EOL_LIST_LEN) { + + if (id == phpdbg_eol_list[i].id) { + return phpdbg_eol_list[i].name; + } + + i++; + } + + return NULL; +} + +char *phpdbg_eol_rep(int id) +{ + size_t i = 0; + + while (i < EOL_LIST_LEN) { + + if (id == phpdbg_eol_list[i].id) { + return phpdbg_eol_list[i].rep; + } + + i++; + } + + return NULL; +} + + +/* Inspired by https://ccrma.stanford.edu/~craig/utility/flip/flip.cpp */ +void phpdbg_eol_convert(char **str, int *len) +{ + char *in = *str, *out ; + int in_len = *len, out_len, cursor, i; + char last, cur; + + if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE) != PHPDBG_IS_REMOTE) { + return; + } + + out_len = *len; + if (PHPDBG_EOL_CRLF == PHPDBG_G(eol)) { /* XXX add LFCR case if it's gonna be needed */ + /* depending on the source EOL the out str will have all CR/LF duplicated */ + for (i = 0; i < in_len; i++) { + if (0x0a == in[i] || 0x0d == in[i]) { + out_len++; + } + } + out = (char *)emalloc(out_len); + + last = cur = in[0]; + i = cursor = 0; + for (; i < in_len;) { + if (0x0a == cur && last != 0x0d) { + out[cursor] = 0x0d; + cursor++; + out[cursor] = cur; + } else if(0x0d == cur) { + if (i + 1 < in_len && 0x0a != in[i+1]) { + out[cursor] = cur; + cursor++; + out[cursor] = 0x0a; + last = 0x0a; + } else { + out[cursor] = 0x0d; + last = 0x0d; + } + } else { + out[cursor] = cur; + last = cur; + } + + i++; + cursor++; + cur = in[i]; + } + + } else if (PHPDBG_EOL_LF == PHPDBG_G(eol) || PHPDBG_EOL_CR == PHPDBG_G(eol)) { + char want, kick; + + if (PHPDBG_EOL_LF == PHPDBG_G(eol)) { + want = 0x0a; + kick = 0x0d; + } else { + want = 0x0d; + kick = 0x0a; + } + + /* We gonna have a smaller or equally long string, estimation is almost neglecting */ + out = (char *)emalloc(out_len); + + last = cur = in[0]; + i = cursor = 0; + for (; cursor < in_len;) { + if (kick == cur) { + out[cursor] = want; + } else if (want == cur) { + if (kick != last) { + out[cursor] = want; + } + } else { + out[cursor] = cur; + } + + last = cur; + cursor++; + cur = in[cursor]; + } + } else { + return; + } + + efree(*str); + *str = erealloc(out, cursor); + *len = cursor; + in = NULL; +} diff --git a/sapi/phpdbg/phpdbg_eol.h b/sapi/phpdbg/phpdbg_eol.h new file mode 100644 index 0000000000..6f1dd77d81 --- /dev/null +++ b/sapi/phpdbg/phpdbg_eol.h @@ -0,0 +1,46 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Anatol Belski <ab@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifndef PHPDBG_EOL_H +#define PHPDBG_EOL_H + +#include "phpdbg.h" + +struct phpdbg_eol_rep { + char *name; + char *rep; + int id; +}; + +enum { + PHPDBG_EOL_CRLF, /* DOS */ + /*PHPDBG_EOL_LFCR,*/ /* for Risc OS? */ + PHPDBG_EOL_LF, /* UNIX */ + PHPDBG_EOL_CR /* MAC */ +}; + +int phpdbg_eol_global_update(char *name); + +char *phpdbg_eol_name(int id); + +char *phpdbg_eol_rep(int id); + +void phpdbg_eol_convert(char **str, int *len); + +#endif /* PHPDBG_EOL_H */ + diff --git a/sapi/phpdbg/phpdbg_frame.c b/sapi/phpdbg/phpdbg_frame.c index f4d2fcc5dc..a3531f94af 100644 --- a/sapi/phpdbg/phpdbg_frame.c +++ b/sapi/phpdbg/phpdbg_frame.c @@ -26,7 +26,7 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -void phpdbg_restore_frame(TSRMLS_D) /* {{{ */ +void phpdbg_restore_frame(void) /* {{{ */ { if (PHPDBG_FRAME(num) == 0) { return; @@ -37,41 +37,40 @@ void phpdbg_restore_frame(TSRMLS_D) /* {{{ */ /* move things back */ EG(current_execute_data) = PHPDBG_FRAME(execute_data); - EG(opline_ptr) = &PHPDBG_EX(opline); - EG(active_op_array) = PHPDBG_EX(op_array); - EG(return_value_ptr_ptr) = PHPDBG_EX(original_return_value); - EG(active_symbol_table) = PHPDBG_EX(symbol_table); - EG(This) = PHPDBG_EX(current_this); - EG(scope) = PHPDBG_EX(current_scope); - EG(called_scope) = PHPDBG_EX(current_called_scope); + EG(scope) = PHPDBG_EX(func)->op_array.scope; } /* }}} */ -void phpdbg_switch_frame(int frame TSRMLS_DC) /* {{{ */ +void phpdbg_switch_frame(int frame) /* {{{ */ { zend_execute_data *execute_data = PHPDBG_FRAME(num)?PHPDBG_FRAME(execute_data):EG(current_execute_data); int i = 0; if (PHPDBG_FRAME(num) == frame) { - phpdbg_notice("Already in frame #%d", frame); + phpdbg_notice("frame", "id=\"%d\"", "Already in frame #%d", frame); return; } - while (execute_data) { - if (i++ == frame) { - break; - } + phpdbg_try_access { + while (execute_data) { + if (i++ == frame) { + break; + } - do { - execute_data = execute_data->prev_execute_data; - } while (execute_data && execute_data->opline == NULL); - } + do { + execute_data = execute_data->prev_execute_data; + } while (execute_data && execute_data->opline == NULL); + } + } phpdbg_catch_access { + phpdbg_error("signalsegv", "", "Couldn't switch frames, invalid data source"); + return; + } phpdbg_end_try_access(); if (execute_data == NULL) { - phpdbg_error("No frame #%d", frame); + phpdbg_error("frame", "type=\"maxnum\" id=\"%d\"", "No frame #%d", frame); return; } - phpdbg_restore_frame(TSRMLS_C); + phpdbg_restore_frame(); if (frame > 0) { PHPDBG_FRAME(num) = frame; @@ -80,127 +79,149 @@ void phpdbg_switch_frame(int frame TSRMLS_DC) /* {{{ */ PHPDBG_FRAME(execute_data) = EG(current_execute_data); EG(current_execute_data) = execute_data; - EG(opline_ptr) = &PHPDBG_EX(opline); - EG(active_op_array) = PHPDBG_EX(op_array); - PHPDBG_FRAME(execute_data)->original_return_value = EG(return_value_ptr_ptr); - EG(return_value_ptr_ptr) = PHPDBG_EX(original_return_value); - EG(active_symbol_table) = PHPDBG_EX(symbol_table); - EG(This) = PHPDBG_EX(current_this); - EG(scope) = PHPDBG_EX(current_scope); - EG(called_scope) = PHPDBG_EX(current_called_scope); + EG(scope) = PHPDBG_EX(func)->op_array.scope; } - phpdbg_notice("Switched to frame #%d", frame); - phpdbg_list_file( - zend_get_executed_filename(TSRMLS_C), - 3, - zend_get_executed_lineno(TSRMLS_C)-1, - zend_get_executed_lineno(TSRMLS_C) - TSRMLS_CC - ); + phpdbg_notice("frame", "id=\"%d\"", "Switched to frame #%d", frame); + + { + const char *file_chr = zend_get_executed_filename(); + zend_string *file = zend_string_init(file_chr, strlen(file_chr), 0); + phpdbg_list_file(file, 3, zend_get_executed_lineno() - 1, zend_get_executed_lineno()); + efree(file); + } } /* }}} */ -static void phpdbg_dump_prototype(zval **tmp TSRMLS_DC) /* {{{ */ +static void phpdbg_dump_prototype(zval *tmp) /* {{{ */ { - zval **funcname, **class, **type, **args, **argstmp; - char is_class; + zval *funcname, *class, class_zv, *type, *args, *argstmp; - zend_hash_find(Z_ARRVAL_PP(tmp), "function", sizeof("function"), - (void **)&funcname); + funcname = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("function")); - if ((is_class = zend_hash_find(Z_ARRVAL_PP(tmp), - "object", sizeof("object"), (void **)&class)) == FAILURE) { - is_class = zend_hash_find(Z_ARRVAL_PP(tmp), "class", sizeof("class"), - (void **)&class); + if ((class = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("object")))) { + ZVAL_NEW_STR(&class_zv, Z_OBJCE_P(class)->name); + class = &class_zv; } else { - zend_get_object_classname(*class, (const char **)&Z_STRVAL_PP(class), - (zend_uint *)&Z_STRLEN_PP(class) TSRMLS_CC); + class = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("class")); } - if (is_class == SUCCESS) { - zend_hash_find(Z_ARRVAL_PP(tmp), "type", sizeof("type"), (void **)&type); + if (class) { + type = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("type")); } - phpdbg_write("%s%s%s(", - is_class == FAILURE?"":Z_STRVAL_PP(class), - is_class == FAILURE?"":Z_STRVAL_PP(type), - Z_STRVAL_PP(funcname) - ); - - if (zend_hash_find(Z_ARRVAL_PP(tmp), "args", sizeof("args"), - (void **)&args) == SUCCESS) { - HashPosition iterator; - const zend_function *func = phpdbg_get_function( - Z_STRVAL_PP(funcname), is_class == FAILURE ? NULL : Z_STRVAL_PP(class) TSRMLS_CC); - const zend_arg_info *arginfo = func ? func->common.arg_info : NULL; - int j = 0, m = func ? func->common.num_args : 0; + args = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("args")); + + phpdbg_xml(" symbol=\"%s%s%s\"", class ? Z_STRVAL_P(class) : "", class ? Z_STRVAL_P(type) : "", Z_STRVAL_P(funcname)); + + if (args) { + phpdbg_xml(">"); + } else { + phpdbg_xml(" />"); + } + + phpdbg_out("%s%s%s(", class ? Z_STRVAL_P(class) : "", class ? Z_STRVAL_P(type) : "", Z_STRVAL_P(funcname)); + + if (args) { + const zend_function *func = NULL; + const zend_arg_info *arginfo = NULL; zend_bool is_variadic = 0; + int j = 0, m; - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(args), &iterator); - while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(args), - (void **) &argstmp, &iterator) == SUCCESS) { + phpdbg_try_access { + /* assuming no autoloader call is necessary, class should have been loaded if it's in backtrace ... */ + if ((func = phpdbg_get_function(Z_STRVAL_P(funcname), class ? Z_STRVAL_P(class) : NULL))) { + arginfo = func->common.arg_info; + } + } phpdbg_end_try_access(); + + m = func ? func->common.num_args : 0; + + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), argstmp) { if (j) { - phpdbg_write(", "); + phpdbg_out(", "); } + phpdbg_xml("<arg %r"); if (m && j < m) { -#if PHP_VERSION_ID >= 50600 - is_variadic = arginfo[j].is_variadic; -#endif - phpdbg_write("%s=%s", - arginfo[j].name, is_variadic ? "[": ""); + if (!is_variadic) { + is_variadic = arginfo ? arginfo[j].is_variadic : 0; + } + phpdbg_xml(" variadic=\"%s\" name=\"%s\">", is_variadic ? "variadic" : "", arginfo ? arginfo[j].name : ""); + phpdbg_out("%s=%s", arginfo ? arginfo[j].name : "?", is_variadic ? "[": ""); + + } else { + phpdbg_xml(">"); } ++j; - zend_print_flat_zval_r(*argstmp TSRMLS_CC); - zend_hash_move_forward_ex(Z_ARRVAL_PP(args), &iterator); - } + zend_print_flat_zval_r(argstmp); + + phpdbg_xml("</arg>"); + } ZEND_HASH_FOREACH_END(); + if (is_variadic) { - phpdbg_write("]"); + phpdbg_out("]"); } + phpdbg_xml("</frame>"); } - phpdbg_write(")"); + phpdbg_out(")"); } -void phpdbg_dump_backtrace(size_t num TSRMLS_DC) /* {{{ */ +void phpdbg_dump_backtrace(size_t num) /* {{{ */ { - zval zbacktrace; - zval **tmp; - zval **file, **line; HashPosition position; + zval zbacktrace; + zval *tmp; + zval *file, *line; int i = 0, limit = num; - int user_defined; + + PHPDBG_OUTPUT_BACKUP(); if (limit < 0) { - phpdbg_error("Invalid backtrace size %d", limit); + phpdbg_error("backtrace", "type=\"minnum\"", "Invalid backtrace size %d", limit); + + PHPDBG_OUTPUT_BACKUP_RESTORE(); + return; } - zend_fetch_debug_backtrace( - &zbacktrace, 0, 0, limit TSRMLS_CC); + phpdbg_try_access { + zend_fetch_debug_backtrace(&zbacktrace, 0, 0, limit); + } phpdbg_catch_access { + phpdbg_error("signalsegv", "", "Couldn't fetch backtrace, invalid data source"); + return; + } phpdbg_end_try_access(); + + phpdbg_xml("<backtrace %r>"); zend_hash_internal_pointer_reset_ex(Z_ARRVAL(zbacktrace), &position); - zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), (void**)&tmp, &position); + tmp = zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), &position); while (1) { - user_defined = zend_hash_find(Z_ARRVAL_PP(tmp), "file", sizeof("file"), (void **)&file); - zend_hash_find(Z_ARRVAL_PP(tmp), "line", sizeof("line"), (void **)&line); + file = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("file")); + line = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("line")); zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position); - if (zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), - (void**)&tmp, &position) == FAILURE) { - phpdbg_write("frame #%d: {main} at %s:%ld", i, Z_STRVAL_PP(file), Z_LVAL_PP(line)); + if (!(tmp = zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), &position))) { + phpdbg_write("frame", "id=\"%d\" symbol=\"{main}\" file=\"%s\" line=\"%d\"", "frame #%d: {main} at %s:%ld", i, Z_STRVAL_P(file), Z_LVAL_P(line)); break; } - if (user_defined == SUCCESS) { - phpdbg_write("frame #%d: ", i++); - phpdbg_dump_prototype(tmp TSRMLS_CC); - phpdbg_writeln(" at %s:%ld", Z_STRVAL_PP(file), Z_LVAL_PP(line)); + if (file) { /* userland */ + phpdbg_out("frame #%d: ", i); + phpdbg_xml("<frame %r id=\"%d\" file=\"%s\" line=\"%d\"", i, Z_STRVAL_P(file), Z_LVAL_P(line)); + phpdbg_dump_prototype(tmp); + phpdbg_out(" at %s:%ld\n", Z_STRVAL_P(file), Z_LVAL_P(line)); + i++; } else { - phpdbg_write(" => "); - phpdbg_dump_prototype(tmp TSRMLS_CC); - phpdbg_writeln(" (internal function)"); + phpdbg_out(" => "); + phpdbg_xml("<frame %r id=\"%d\" internal=\"internal\"", i); + phpdbg_dump_prototype(tmp); + phpdbg_out(" (internal function)\n"); } } - phpdbg_writeln(EMPTY); + phpdbg_out("\n"); + phpdbg_xml("</backtrace>"); + zval_dtor(&zbacktrace); + + PHPDBG_OUTPUT_BACKUP_RESTORE(); } /* }}} */ diff --git a/sapi/phpdbg/phpdbg_frame.h b/sapi/phpdbg/phpdbg_frame.h index d43d229a31..3576c249ea 100644 --- a/sapi/phpdbg/phpdbg_frame.h +++ b/sapi/phpdbg/phpdbg_frame.h @@ -23,8 +23,8 @@ #include "TSRM.h" -void phpdbg_restore_frame(TSRMLS_D); -void phpdbg_switch_frame(int TSRMLS_DC); -void phpdbg_dump_backtrace(size_t TSRMLS_DC); +void phpdbg_restore_frame(void); +void phpdbg_switch_frame(int); +void phpdbg_dump_backtrace(size_t); #endif /* PHPDBG_FRAME_H */ diff --git a/sapi/phpdbg/phpdbg_help.c b/sapi/phpdbg/phpdbg_help.c index e71b3b5dc3..91cc4519b5 100644 --- a/sapi/phpdbg/phpdbg_help.c +++ b/sapi/phpdbg/phpdbg_help.c @@ -22,6 +22,7 @@ #include "phpdbg.h" #include "phpdbg_help.h" #include "phpdbg_prompt.h" +#include "phpdbg_eol.h" #include "zend.h" ZEND_EXTERN_MODULE_GLOBALS(phpdbg); @@ -40,11 +41,11 @@ const phpdbg_command_t phpdbg_help_commands[] = { }; /* }}} */ /* {{{ pretty_print. Formatting escapes and wrapping text in a string before printing it. */ -void pretty_print(char *text TSRMLS_DC) +void pretty_print(char *text) { char *new, *p, *q; - const char *prompt_escape = phpdbg_get_prompt(TSRMLS_C); + const char *prompt_escape = phpdbg_get_prompt(); unsigned int prompt_escape_len = strlen(prompt_escape); unsigned int prompt_len = strlen(PHPDBG_G(prompt)[0]); @@ -52,7 +53,7 @@ void pretty_print(char *text TSRMLS_DC) const char *bold_off_escape = PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "\033[0m" : ""; unsigned int bold_escape_len = strlen(bold_on_escape); - unsigned int term_width = phpdbg_get_terminal_width(TSRMLS_C); + unsigned int term_width = phpdbg_get_terminal_width(); unsigned int size = 0; int in_bold = 0; @@ -61,6 +62,11 @@ void pretty_print(char *text TSRMLS_DC) unsigned int last_blank_count = 0; /* printable char offset of last blank char */ unsigned int line_count = 0; /* number printable chars on current line */ + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + phpdbg_xml("<help %r msg=\"%s\" />", text); + return; + } + /* First pass calculates a safe size for the pretty print version */ for (p = text; *p; p++) { if (UNEXPECTED(p[0] == '*') && p[1] == '*') { @@ -128,24 +134,24 @@ void pretty_print(char *text TSRMLS_DC) *q++ = '\0'; if ((q-new)>size) { - phpdbg_error("Output overrun of %lu bytes", ((q-new) - size)); + phpdbg_error("help", "overrun=\"%lu\"", "Output overrun of %lu bytes", ((q - new) - size)); } - phpdbg_write("%s\n", new); + phpdbg_out("%s\n", new); efree(new); } /* }}} */ /* {{{ summary_print. Print a summary line giving, the command, its alias and tip */ -void summary_print(phpdbg_command_t const * const cmd TSRMLS_DC) +void summary_print(phpdbg_command_t const * const cmd) { char *summary; spprintf(&summary, 0, "Command: **%s** Alias: **%c** **%s**\n", cmd->name, cmd->alias, cmd->tip); - pretty_print(summary TSRMLS_CC); + pretty_print(summary); efree(summary); } /* {{{ get_help. Retries and formats text from the phpdbg help text table */ -static char *get_help(const char * const key TSRMLS_DC) +static char *get_help(const char * const key) { phpdbg_help_text_t *p; @@ -174,7 +180,7 @@ static int get_command( const char *key, size_t len, /* pointer and length of key */ phpdbg_command_t const **command, /* address of first matching command */ phpdbg_command_t const * commands /* command table to be scanned */ - TSRMLS_DC) + ) { const phpdbg_command_t *c; unsigned int num_matches = 0; @@ -201,7 +207,7 @@ static int get_command( return num_matches; -} /* }}} */ +} /* }}} */ PHPDBG_COMMAND(help) /* {{{ */ { @@ -209,40 +215,40 @@ PHPDBG_COMMAND(help) /* {{{ */ int n; if (!param || param->type == EMPTY_PARAM) { - pretty_print(get_help("overview!" TSRMLS_CC) TSRMLS_CC); + pretty_print(get_help("overview!")); return SUCCESS; } if (param && param->type == STR_PARAM) { - n = get_command(param->str, param->len, &cmd, phpdbg_prompt_commands TSRMLS_CC); + n = get_command(param->str, param->len, &cmd, phpdbg_prompt_commands); if (n==1) { - summary_print(cmd TSRMLS_CC); - pretty_print(get_help(cmd->name TSRMLS_CC) TSRMLS_CC); + summary_print(cmd); + pretty_print(get_help(cmd->name)); return SUCCESS; } else if (n>1) { if (param->len > 1) { for (cmd=phpdbg_prompt_commands; cmd->name; cmd++) { if (!strncmp(cmd->name, param->str, param->len)) { - summary_print(cmd TSRMLS_CC); + summary_print(cmd); } } - pretty_print(get_help("duplicate!" TSRMLS_CC) TSRMLS_CC); + pretty_print(get_help("duplicate!")); return SUCCESS; } else { - phpdbg_error("Internal help error, non-unique alias \"%c\"", param->str[0]); + phpdbg_error("help", "type=\"ambiguousalias\" alias=\"%s\"", "Internal help error, non-unique alias \"%c\"", param->str[0]); return FAILURE; } } else { /* no prompt command found so try help topic */ - n = get_command( param->str, param->len, &cmd, phpdbg_help_commands TSRMLS_CC); + n = get_command( param->str, param->len, &cmd, phpdbg_help_commands); if (n>0) { - if (cmd->alias == 'a') { /* help aliases executes a canned routine */ - return cmd->handler(param TSRMLS_CC); + if (cmd->alias == 'a') { /* help aliases executes a canned routine */ + return cmd->handler(param); } else { - pretty_print(get_help(cmd->name TSRMLS_CC) TSRMLS_CC); + pretty_print(get_help(cmd->name)); return SUCCESS; } } @@ -259,35 +265,42 @@ PHPDBG_HELP(aliases) /* {{{ */ int len; /* Print out aliases for all commands except help as this one comes last */ - phpdbg_writeln("Below are the aliased, short versions of all supported commands"); + phpdbg_writeln("help", "", "Below are the aliased, short versions of all supported commands"); + phpdbg_xml("<helpcommands %r>"); for(c = phpdbg_prompt_commands; c->name; c++) { if (c->alias && c->alias != 'h') { - phpdbg_writeln(" %c %-20s %s", c->alias, c->name, c->tip); + phpdbg_writeln("command", "alias=\"%c\" name=\"%s\" tip=\"%s\"", " %c %-20s %s", c->alias, c->name, c->tip); if (c->subs) { len = 20 - 1 - c->name_len; for(c_sub = c->subs; c_sub->alias; c_sub++) { if (c_sub->alias) { - phpdbg_writeln(" %c %c %s %-*s %s", - c->alias, c_sub->alias, (char *)c->name, len, c_sub->name, c_sub->tip); + phpdbg_writeln("subcommand", "parent_alias=\"%c\" alias=\"%c\" parent=\"%s\" name=\"%-*s\" tip=\"%s\"", " %c %c %s %-*s %s", + c->alias, c_sub->alias, c->name, len, c_sub->name, c_sub->tip); } } } } } + phpdbg_xml("</helpcommands>"); + /* Print out aliases for help as this one comes last, with the added text on how aliases are used */ - get_command("h", 1, &c, phpdbg_prompt_commands TSRMLS_CC); - phpdbg_writeln(" %c %-20s %s\n", c->alias, c->name, c->tip); + get_command("h", 1, &c, phpdbg_prompt_commands); + phpdbg_writeln("aliasinfo", "alias=\"%c\" name=\"%s\" tip=\"%s\"", " %c %-20s %s\n", c->alias, c->name, c->tip); + + phpdbg_xml("<helpaliases>"); len = 20 - 1 - c->name_len; for(c_sub = c->subs; c_sub->alias; c_sub++) { if (c_sub->alias) { - phpdbg_writeln(" %c %c %s %-*s %s", + phpdbg_writeln("alias", "parent_alias=\"%c\" alias=\"%c\" parent=\"%s\" name=\"%-*s\" tip=\"%s\"", " %c %c %s %-*s %s", c->alias, c_sub->alias, c->name, len, c_sub->name, c_sub->tip); } } - pretty_print(get_help("aliases!" TSRMLS_CC) TSRMLS_CC); + phpdbg_xml("</helpaliases>"); + + pretty_print(get_help("aliases!")); return SUCCESS; } /* }}} */ @@ -319,7 +332,7 @@ phpdbg_help_text_t phpdbg_help_text[] = { " **list** list PHP source" CR " **info** displays information on the debug session" CR " **print** show opcodes" CR -" **frame** select a stack frame and print a stack frame summary" CR +" **frame** select a stack frame and print a stack frame summary" CR " **back** shows the current backtrace" CR " **help** provide help on a topic" CR CR @@ -362,7 +375,7 @@ phpdbg_help_text_t phpdbg_help_text[] = { " **-c** **-c**/my/php.ini Set php.ini file to load" CR " **-d** **-d**memory_limit=4G Set a php.ini directive" CR " **-n** Disable default php.ini" CR -" **-q** Supress welcome banner" CR +" **-q** Suppress welcome banner" CR " **-v** Enable oplog output" CR " **-s** Enable stepping" CR " **-b** Disable colour" CR @@ -375,6 +388,7 @@ phpdbg_help_text_t phpdbg_help_text[] = { " **-S** **-S**cli Override SAPI name, careful!" CR " **-l** **-l**4000 Setup remote console ports" CR " **-a** **-a**192.168.0.3 Setup remote console bind address" CR +" **-x** Enable xml output (instead of normal text output)" CR " **-V** Print version number" CR " **--** **--** arg1 arg2 Use to delimit phpdbg arguments and php $argv; append any $argv " "argument after it" CR CR @@ -386,9 +400,7 @@ phpdbg_help_text_t phpdbg_help_text[] = { "bind address using the **-a** option. If **-a** is specied without an argument, then phpdbg " "will bind to all available interfaces. You should be aware of the security implications of " "doing this, so measures should be taken to secure this service if bound to a publicly accessible " -"interface/port." CR CR - -"Specify both stdin and stdout with -lstdin/stdout; by default stdout is stdin * 2." +"interface/port." }, {"phpdbginit", CR @@ -400,10 +412,10 @@ phpdbg_help_text_t phpdbg_help_text[] = { "Debugger scripts can also be executed using the **source** command." CR CR "A script file can contain a sequence of valid debugger commands, comments and embedded PHP " -"code. " CR CR +"code. " CR CR "Comment lines are prefixed by the **#** character. Note that comments are only allowed in script " -"files and not in interactive sessions." CR CR +"files and not in interactive sessions." CR CR "PHP code is delimited by the start and end escape tags **<:** and **:>**. PHP code can be used " "to define application context for a debugging session and also to extend the debugger by defining " @@ -545,7 +557,7 @@ phpdbg_help_text_t phpdbg_help_text[] = { " $P break ZEND_ADD" CR " $P b ZEND_ADD" CR -" Break on any occurence of the opcode ZEND_ADD" CR CR +" Break on any occurrence of the opcode ZEND_ADD" CR CR " $P break del 2" CR " $P b ~ 2" CR @@ -596,7 +608,7 @@ phpdbg_help_text_t phpdbg_help_text[] = { }, {"exec", -"The **exec** command sets the execution context, that is the script to be executed. The " +"The **exec** command sets the execution context, that is the script to be executed. The " "execution context must be defined either by executing the **exec** command or by using the " "**-e** command line option." CR CR @@ -642,14 +654,16 @@ phpdbg_help_text_t phpdbg_help_text[] = { "Specific info commands are show below:" CR CR " **Target** **Alias** **Purpose**" CR -" **break** **b** show current breakpoints" CR -" **files** **F** show included files" CR -" **classes** **c** show loaded classes" CR -" **funcs** **f** show loaded classes" CR -" **error** **e** show last error" CR -" **vars** **v** show active variables" CR -" **literal** **l** show active literal constants" CR -" **memory** **m** show memory manager stats" +" **break** **b** show current breakpoints" CR +" **files** **F** show included files" CR +" **classes** **c** show loaded classes" CR +" **funcs** **f** show loaded functions" CR +" **error** **e** show last error" CR +" **constants** **d** show user-defined constants" CR +" **vars** **v** show active variables" CR +" **globals** **g** show superglobal variables" CR +" **literal** **l** show active literal constants" CR +" **memory** **m** show memory manager stats" }, // ******** same issue about breakpoints in called frames diff --git a/sapi/phpdbg/phpdbg_help.h b/sapi/phpdbg/phpdbg_help.h index d59010e1bd..fea63125f9 100644 --- a/sapi/phpdbg/phpdbg_help.h +++ b/sapi/phpdbg/phpdbg_help.h @@ -35,9 +35,9 @@ PHPDBG_HELP(aliases); extern const phpdbg_command_t phpdbg_help_commands[]; #define phpdbg_help_header() \ - phpdbg_notice("Welcome to phpdbg, the interactive PHP debugger, v%s", PHPDBG_VERSION); + phpdbg_notice("version", "version=\"%s\"", "Welcome to phpdbg, the interactive PHP debugger, v%s", PHPDBG_VERSION); #define phpdbg_help_footer() \ - phpdbg_notice("Please report bugs to <%s>", PHPDBG_ISSUES); + phpdbg_notice("issues", "url=\"%s\"", "Please report bugs to <%s>", PHPDBG_ISSUES); typedef struct _phpdbg_help_text_t { char *key; diff --git a/sapi/phpdbg/phpdbg_info.c b/sapi/phpdbg/phpdbg_info.c index 6c5b9b02d5..0815ac3686 100644 --- a/sapi/phpdbg/phpdbg_info.c +++ b/sapi/phpdbg/phpdbg_info.c @@ -27,50 +27,56 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -#define PHPDBG_INFO_COMMAND_D(f, h, a, m, l, s) \ - PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[14]) +#define PHPDBG_INFO_COMMAND_D(f, h, a, m, l, s, flags) \ + PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[14], flags) const phpdbg_command_t phpdbg_info_commands[] = { - PHPDBG_INFO_COMMAND_D(break, "show breakpoints", 'b', info_break, NULL, 0), - PHPDBG_INFO_COMMAND_D(files, "show included files", 'F', info_files, NULL, 0), - PHPDBG_INFO_COMMAND_D(classes, "show loaded classes", 'c', info_classes, NULL, 0), - PHPDBG_INFO_COMMAND_D(funcs, "show loaded classes", 'f', info_funcs, NULL, 0), - PHPDBG_INFO_COMMAND_D(error, "show last error", 'e', info_error, NULL, 0), - PHPDBG_INFO_COMMAND_D(vars, "show active variables", 'v', info_vars, NULL, 0), - PHPDBG_INFO_COMMAND_D(literal, "show active literal constants", 'l', info_literal, NULL, 0), - PHPDBG_INFO_COMMAND_D(memory, "show memory manager stats", 'm', info_memory, NULL, 0), + PHPDBG_INFO_COMMAND_D(break, "show breakpoints", 'b', info_break, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_INFO_COMMAND_D(files, "show included files", 'F', info_files, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_INFO_COMMAND_D(classes, "show loaded classes", 'c', info_classes, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_INFO_COMMAND_D(funcs, "show loaded classes", 'f', info_funcs, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_INFO_COMMAND_D(error, "show last error", 'e', info_error, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_INFO_COMMAND_D(constants, "show user defined constants", 'd', info_constants, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_INFO_COMMAND_D(vars, "show active variables", 'v', info_vars, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_INFO_COMMAND_D(globals, "show superglobals", 'g', info_globals, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_INFO_COMMAND_D(literal, "show active literal constants", 'l', info_literal, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_INFO_COMMAND_D(memory, "show memory manager stats", 'm', info_memory, NULL, 0, PHPDBG_ASYNC_SAFE), PHPDBG_END_COMMAND }; PHPDBG_INFO(break) /* {{{ */ { - phpdbg_print_breakpoints(PHPDBG_BREAK_FILE TSRMLS_CC); - phpdbg_print_breakpoints(PHPDBG_BREAK_SYM TSRMLS_CC); - phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD TSRMLS_CC); - phpdbg_print_breakpoints(PHPDBG_BREAK_OPLINE TSRMLS_CC); - phpdbg_print_breakpoints(PHPDBG_BREAK_FILE_OPLINE TSRMLS_CC); - phpdbg_print_breakpoints(PHPDBG_BREAK_FUNCTION_OPLINE TSRMLS_CC); - phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD_OPLINE TSRMLS_CC); - phpdbg_print_breakpoints(PHPDBG_BREAK_COND TSRMLS_CC); - phpdbg_print_breakpoints(PHPDBG_BREAK_OPCODE TSRMLS_CC); + phpdbg_print_breakpoints(PHPDBG_BREAK_FILE); + phpdbg_print_breakpoints(PHPDBG_BREAK_SYM); + phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD); + phpdbg_print_breakpoints(PHPDBG_BREAK_OPLINE); + phpdbg_print_breakpoints(PHPDBG_BREAK_FILE_OPLINE); + phpdbg_print_breakpoints(PHPDBG_BREAK_FUNCTION_OPLINE); + phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD_OPLINE); + phpdbg_print_breakpoints(PHPDBG_BREAK_COND); + phpdbg_print_breakpoints(PHPDBG_BREAK_OPCODE); return SUCCESS; } /* }}} */ PHPDBG_INFO(files) /* {{{ */ { - HashPosition pos; - char *fname; + zend_string *fname; - phpdbg_notice("Included files: %d", - zend_hash_num_elements(&EG(included_files))); + phpdbg_try_access { + phpdbg_notice("includedfilecount", "num=\"%d\"", "Included files: %d", zend_hash_num_elements(&EG(included_files))); + } phpdbg_catch_access { + phpdbg_error("signalsegv", "", "Could not fetch included file count, invalid data source"); + return SUCCESS; + } phpdbg_end_try_access(); - zend_hash_internal_pointer_reset_ex(&EG(included_files), &pos); - while (zend_hash_get_current_key_ex(&EG(included_files), &fname, - NULL, NULL, 0, &pos) == HASH_KEY_IS_STRING) { - phpdbg_writeln("File: %s", fname); - zend_hash_move_forward_ex(&EG(included_files), &pos); - } + phpdbg_try_access { + ZEND_HASH_FOREACH_STR_KEY(&EG(included_files), fname) { + phpdbg_writeln("includedfile", "name=\"%s\"", "File: %s", fname); + } ZEND_HASH_FOREACH_END(); + } phpdbg_catch_access { + phpdbg_error("signalsegv", "", "Could not fetch file name, invalid data source, aborting included file listing"); + } phpdbg_end_try_access(); return SUCCESS; } /* }}} */ @@ -78,125 +84,189 @@ PHPDBG_INFO(files) /* {{{ */ PHPDBG_INFO(error) /* {{{ */ { if (PG(last_error_message)) { - phpdbg_writeln("Last error: %s at %s line %d", - PG(last_error_message), PG(last_error_file), PG(last_error_lineno)); + phpdbg_try_access { + phpdbg_writeln("lasterror", "error=\"%s\" file=\"%s\" line=\"%d\"", "Last error: %s at %s line %d", PG(last_error_message), PG(last_error_file), PG(last_error_lineno)); + } phpdbg_catch_access { + phpdbg_notice("lasterror", "error=\"\"", "No error found!"); + } phpdbg_end_try_access(); } else { - phpdbg_notice("No error found!"); + phpdbg_notice("lasterror", "error=\"\"", "No error found!"); } return SUCCESS; } /* }}} */ -PHPDBG_INFO(vars) /* {{{ */ +PHPDBG_INFO(constants) /* {{{ */ { - HashTable vars; - HashPosition pos; - char *var; - zval **data; + HashTable consts; + zend_constant *data; - if (!EG(active_op_array)) { - phpdbg_error("No active op array!"); - return SUCCESS; + zend_hash_init(&consts, 8, NULL, NULL, 0); + + if (EG(zend_constants)) { + phpdbg_try_access { + ZEND_HASH_FOREACH_PTR(EG(zend_constants), data) { + if (data->module_number == PHP_USER_CONSTANT) { + zend_hash_update_ptr(&consts, data->name, data); + } + } ZEND_HASH_FOREACH_END(); + } phpdbg_catch_access { + phpdbg_error("signalsegv", "", "Cannot fetch all the constants, invalid data source"); + } phpdbg_end_try_access(); } - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); + phpdbg_notice("constantinfo", "num=\"%d\"", "User-defined constants (%d)", zend_hash_num_elements(&consts)); + + if (zend_hash_num_elements(&consts)) { + phpdbg_out("Address Refs Type Constant\n"); + ZEND_HASH_FOREACH_PTR(&consts, data) { + +#define VARIABLEINFO(attrs, msg, ...) phpdbg_writeln("constant", "address=\"%p\" refcount=\"%d\" type=\"%s\" name=\"%.*s\" " attrs, "%-18p %-7d %-9s %.*s" msg, &data->value, Z_REFCOUNT(data->value), zend_zval_type_name(&data->value), data->name->len, data->name->val, ##__VA_ARGS__) + + switch (Z_TYPE(data->value)) { + case IS_STRING: + phpdbg_try_access { + VARIABLEINFO("length=\"%d\" value=\"%.*s\"", "\nstring (%d) \"%.*s%s\"", Z_STRLEN(data->value), Z_STRLEN(data->value) < 255 ? Z_STRLEN(data->value) : 255, Z_STRVAL(data->value), Z_STRLEN(data->value) > 255 ? "..." : ""); + } phpdbg_catch_access { + VARIABLEINFO("", ""); + } phpdbg_end_try_access(); + break; + case IS_TRUE: + VARIABLEINFO("value=\"true\"", "\nbool (true)"); + break; + case IS_FALSE: + VARIABLEINFO("value=\"false\"", "\nbool (false)"); + break; + case IS_LONG: + VARIABLEINFO("value=\"%ld\"", "\nint (%ld)", Z_LVAL(data->value)); + break; + case IS_DOUBLE: + VARIABLEINFO("value=\"%lf\"", "\ndouble (%lf)", Z_DVAL(data->value)); + break; + default: + VARIABLEINFO("", ""); + +#undef VARIABLEINFO + } + } ZEND_HASH_FOREACH_END(); + } - if (!EG(active_symbol_table)) { - phpdbg_error("No active symbol table!"); - return SUCCESS; + return SUCCESS; +} /* }}} */ + +static int phpdbg_arm_auto_global(zend_auto_global *auto_global) { + if (auto_global->armed) { + if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) { + phpdbg_notice("variableinfo", "unreachable=\"%.*s\"", "Cannot show information about superglobal variable %.*s", auto_global->name->len, auto_global->name->val); + } else { + auto_global->armed = auto_global->auto_global_callback(auto_global->name); } } - zend_hash_init(&vars, 8, NULL, NULL, 0); + return 0; +} - zend_hash_internal_pointer_reset_ex(EG(active_symbol_table), &pos); - while (zend_hash_get_current_key_ex(EG(active_symbol_table), &var, - NULL, NULL, 0, &pos) == HASH_KEY_IS_STRING) { - zend_hash_get_current_data_ex(EG(active_symbol_table), (void **)&data, &pos); - if (*var != '_') { - zend_hash_update( - &vars, var, strlen(var)+1, (void**)data, sizeof(zval*), NULL); - } - zend_hash_move_forward_ex(EG(active_symbol_table), &pos); +static int phpdbg_print_symbols(zend_bool show_globals) { + HashTable vars; + zend_array *symtable; + zend_string *var; + zval *data; + + if (!EG(current_execute_data) || !EG(current_execute_data)->func) { + phpdbg_error("inactive", "type=\"op_array\"", "No active op array!"); + return SUCCESS; + } + + if (show_globals) { + /* that array should only be manipulated during init, so safe for async access during execution */ + zend_hash_apply(CG(auto_globals), (apply_func_t) phpdbg_arm_auto_global); + symtable = &EG(symbol_table); + } else if (!(symtable = zend_rebuild_symbol_table())) { + phpdbg_error("inactive", "type=\"symbol_table\"", "No active symbol table!"); + return SUCCESS; } - { - zend_op_array *ops = EG(active_op_array); - + zend_hash_init(&vars, 8, NULL, NULL, 0); + + phpdbg_try_access { + ZEND_HASH_FOREACH_STR_KEY_VAL(&symtable->ht, var, data) { + if (zend_is_auto_global(var) ^ !show_globals) { + zend_hash_update(&vars, var, data); + } + } ZEND_HASH_FOREACH_END(); + } phpdbg_catch_access { + phpdbg_error("signalsegv", "", "Cannot fetch all data from the symbol table, invalid data source"); + } phpdbg_end_try_access(); + + if (show_globals) { + phpdbg_notice("variableinfo", "num=\"%d\"", "Superglobal variables (%d)", zend_hash_num_elements(&vars)); + } else { + zend_op_array *ops = &EG(current_execute_data)->func->op_array; + if (ops->function_name) { if (ops->scope) { - phpdbg_notice( - "Variables in %s::%s() (%d)", ops->scope->name, ops->function_name, zend_hash_num_elements(&vars)); + phpdbg_notice("variableinfo", "method=\"%s::%s\" num=\"%d\"", "Variables in %s::%s() (%d)", ops->scope->name, ops->function_name, zend_hash_num_elements(&vars)); } else { - phpdbg_notice( - "Variables in %s() (%d)", ops->function_name, zend_hash_num_elements(&vars)); + phpdbg_notice("variableinfo", "function=\"%s\" num=\"%d\"", "Variables in %s() (%d)", ops->function_name, zend_hash_num_elements(&vars)); } } else { if (ops->filename) { - phpdbg_notice( - "Variables in %s (%d)", ops->filename, zend_hash_num_elements(&vars)); + phpdbg_notice("variableinfo", "file=\"%s\" num=\"%d\"", "Variables in %s (%d)", ops->filename->val, zend_hash_num_elements(&vars)); } else { - phpdbg_notice( - "Variables @ %p (%d)", ops, zend_hash_num_elements(&vars)); + phpdbg_notice("variableinfo", "opline=\"%p\" num=\"%d\"", "Variables @ %p (%d)", ops, zend_hash_num_elements(&vars)); } } } if (zend_hash_num_elements(&vars)) { - phpdbg_writeln("Address\t\tRefs\tType\t\tVariable"); - for (zend_hash_internal_pointer_reset_ex(&vars, &pos); - zend_hash_get_current_data_ex(&vars, (void**) &data, &pos) == SUCCESS; - zend_hash_move_forward_ex(&vars, &pos)) { - char *var; - - zend_hash_get_current_key_ex(&vars, &var, NULL, NULL, 0, &pos); - - if (*data) { - phpdbg_write( - "%p\t%d\t", - *data, - Z_REFCOUNT_PP(data)); - - switch (Z_TYPE_PP(data)) { - case IS_STRING: phpdbg_write("(string)\t"); break; - case IS_LONG: phpdbg_write("(integer)\t"); break; - case IS_DOUBLE: phpdbg_write("(float)\t"); break; - case IS_RESOURCE: phpdbg_write("(resource)\t"); break; - case IS_ARRAY: phpdbg_write("(array)\t"); break; - case IS_OBJECT: phpdbg_write("(object)\t"); break; - case IS_NULL: phpdbg_write("(null)\t"); break; + phpdbg_out("Address Refs Type Variable\n"); + ZEND_HASH_FOREACH_STR_KEY_VAL(&vars, var, data) { + phpdbg_try_access { +#define VARIABLEINFO(attrs, msg, ...) phpdbg_writeln("variable", "address=\"%p\" refcount=\"%d\" type=\"%s\" refstatus=\"%s\" name=\"%.*s\" " attrs, "%-18p %-7d %-9s %s$%.*s" msg, data, Z_REFCOUNT_P(data), zend_zval_type_name(data), Z_ISREF_P(data) ? "&": "", var->len, var->val, ##__VA_ARGS__) + + switch (Z_TYPE_P(data)) { + case IS_RESOURCE: + phpdbg_try_access { + const char *type = zend_rsrc_list_get_rsrc_type(Z_RES_P(data)); + VARIABLEINFO("type=\"%s\"", "\n|-------(typeof)------> (%s)\n", type ? type : "unknown"); + } phpdbg_catch_access { + VARIABLEINFO("type=\"unknown\"", "\n|-------(typeof)------> (unknown)\n"); + } phpdbg_end_try_access(); + break; + case IS_OBJECT: + phpdbg_try_access { + VARIABLEINFO("instanceof=\"%s\"", "\n|-----(instanceof)----> (%s)\n", Z_OBJCE_P(data)->name); + } phpdbg_catch_access { + VARIABLEINFO("instanceof=\"%s\"", "\n|-----(instanceof)----> (unknown)\n"); + } phpdbg_end_try_access(); + break; + case IS_STRING: + phpdbg_try_access { + VARIABLEINFO("length=\"%d\" value=\"%.*s\"", "\nstring (%d) \"%.*s%s\"", Z_STRLEN_P(data), Z_STRLEN_P(data) < 255 ? Z_STRLEN_P(data) : 255, Z_STRVAL_P(data), Z_STRLEN_P(data) > 255 ? "..." : ""); + } phpdbg_catch_access { + VARIABLEINFO("", ""); + } phpdbg_end_try_access(); + break; + case IS_TRUE: + VARIABLEINFO("value=\"true\"", "\nbool (true)"); + break; + case IS_FALSE: + VARIABLEINFO("value=\"false\"", "\nbool (false)"); + break; + case IS_LONG: + VARIABLEINFO("value=\"%ld\"", "\nint (%ld)", Z_LVAL_P(data)); + break; + case IS_DOUBLE: + VARIABLEINFO("value=\"%lf\"", "\ndouble (%lf)", Z_DVAL_P(data)); + break; + default: + VARIABLEINFO("", ""); } - if (Z_TYPE_PP(data) == IS_RESOURCE) { - int type; - - phpdbg_writeln( - "%s$%s", Z_ISREF_PP(data) ? "&": "", var); - if (zend_list_find(Z_RESVAL_PP(data), &type)) { - phpdbg_write( - "|-------(typeof)------> (%s)", - zend_rsrc_list_get_rsrc_type(type TSRMLS_CC)); - } else { - phpdbg_write( - "|-------(typeof)------> (unknown)"); - } - phpdbg_writeln(EMPTY); - } else if (Z_TYPE_PP(data) == IS_OBJECT) { - phpdbg_writeln( - "%s$%s", Z_ISREF_PP(data) ? "&": "", var); - phpdbg_write( - "|-----(instanceof)----> (%s)", Z_OBJCE_PP(data)->name); - phpdbg_writeln(EMPTY); - } else { - phpdbg_write( - "%s$%s", Z_ISREF_PP(data) ? "&": "", var); - } - } else { - phpdbg_write( - "n/a\tn/a\tn/a\t$%s", var); - } - phpdbg_writeln(EMPTY); - } +#undef VARIABLEINFO + } phpdbg_catch_access { + phpdbg_writeln("variable", "address=\"%p\" name=\"%s\"", "%p\tn/a\tn/a\t$%s", data, var); + } phpdbg_end_try_access(); + } ZEND_HASH_FOREACH_END(); } zend_hash_destroy(&vars); @@ -204,42 +274,48 @@ PHPDBG_INFO(vars) /* {{{ */ return SUCCESS; } /* }}} */ +PHPDBG_INFO(vars) /* {{{ */ +{ + return phpdbg_print_symbols(0); +} + +PHPDBG_INFO(globals) /* {{{ */ +{ + return phpdbg_print_symbols(1); +} + PHPDBG_INFO(literal) /* {{{ */ { - if ((EG(in_execution) && EG(active_op_array)) || PHPDBG_G(ops)) { - zend_op_array *ops = EG(active_op_array) ? EG(active_op_array) : PHPDBG_G(ops); + /* literals are assumed to not be manipulated during executing of their op_array and as such async safe */ + zend_bool in_executor = PHPDBG_G(in_execution) && EG(current_execute_data) && EG(current_execute_data)->func; + if (in_executor || PHPDBG_G(ops)) { + zend_op_array *ops = in_executor ? &EG(current_execute_data)->func->op_array : PHPDBG_G(ops); int literal = 0, count = ops->last_literal-1; if (ops->function_name) { if (ops->scope) { - phpdbg_notice( - "Literal Constants in %s::%s() (%d)", ops->scope->name, ops->function_name, count); + phpdbg_notice("literalinfo", "method=\"%s::%s\" num=\"%d\"", "Literal Constants in %s::%s() (%d)", ops->scope->name, ops->function_name, count); } else { - phpdbg_notice( - "Literal Constants in %s() (%d)", ops->function_name, count); + phpdbg_notice("literalinfo", "function=\"%s\" num=\"%d\"", "Literal Constants in %s() (%d)", ops->function_name, count); } } else { if (ops->filename) { - phpdbg_notice( - "Literal Constants in %s (%d)", ops->filename, count); + phpdbg_notice("literalinfo", "file=\"%s\" num=\"%d\"", "Literal Constants in %s (%d)", ops->filename->val, count); } else { - phpdbg_notice( - "Literal Constants @ %p (%d)", ops, count); + phpdbg_notice("literalinfo", "opline=\"%p\" num=\"%d\"", "Literal Constants @ %p (%d)", ops, count); } } while (literal < ops->last_literal) { - if (Z_TYPE(ops->literals[literal].constant) != IS_NULL) { - phpdbg_write("|-------- C%u -------> [", literal); - zend_print_zval( - &ops->literals[literal].constant, 0); - phpdbg_write("]"); - phpdbg_writeln(EMPTY); + if (Z_TYPE(ops->literals[literal]) != IS_NULL) { + phpdbg_write("literal", "id=\"%u\"", "|-------- C%u -------> [", literal); + zend_print_zval(&ops->literals[literal], 0); + phpdbg_out("]\n"); } literal++; } } else { - phpdbg_error("Not executing!"); + phpdbg_error("inactive", "type=\"execution\"", "Not executing!"); } return SUCCESS; @@ -247,85 +323,85 @@ PHPDBG_INFO(literal) /* {{{ */ PHPDBG_INFO(memory) /* {{{ */ { - if (is_zend_mm(TSRMLS_C)) { - phpdbg_notice("Memory Manager Information"); - phpdbg_notice("Current"); - phpdbg_writeln("|-------> Used:\t%.3f kB", - (float) (zend_memory_usage(0 TSRMLS_CC)/1024)); - phpdbg_writeln("|-------> Real:\t%.3f kB", - (float) (zend_memory_usage(1 TSRMLS_CC)/1024)); - phpdbg_notice("Peak"); - phpdbg_writeln("|-------> Used:\t%.3f kB", - (float) (zend_memory_peak_usage(0 TSRMLS_CC)/1024)); - phpdbg_writeln("|-------> Real:\t%.3f kB", - (float) (zend_memory_peak_usage(1 TSRMLS_CC)/1024)); + size_t used, real, peak_used, peak_real; + zend_mm_heap *heap; + zend_bool is_mm; + + if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) { + heap = zend_mm_set_heap(phpdbg_original_heap_sigsafe_mem()); + } + if ((is_mm = is_zend_mm())) { + used = zend_memory_usage(0); + real = zend_memory_usage(1); + peak_used = zend_memory_peak_usage(0); + peak_real = zend_memory_peak_usage(1); + } + if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) { + zend_mm_set_heap(heap); + } + + if (is_mm) { + phpdbg_notice("meminfo", "", "Memory Manager Information"); + phpdbg_notice("current", "", "Current"); + phpdbg_writeln("used", "mem=\"%.3f\"", "|-------> Used:\t%.3f kB", (float) (used / 1024)); + phpdbg_writeln("real", "mem=\"%.3f\"", "|-------> Real:\t%.3f kB", (float) (real / 1024)); + phpdbg_notice("peak", "", "Peak"); + phpdbg_writeln("used", "mem=\"%.3f\"", "|-------> Used:\t%.3f kB", (float) (peak_used / 1024)); + phpdbg_writeln("real", "mem=\"%.3f\"", "|-------> Real:\t%.3f kB", (float) (peak_real / 1024)); } else { - phpdbg_error("Memory Manager Disabled!"); + phpdbg_error("inactive", "type=\"memory_manager\"", "Memory Manager Disabled!"); } return SUCCESS; } /* }}} */ -static inline void phpdbg_print_class_name(zend_class_entry **ce TSRMLS_DC) /* {{{ */ +static inline void phpdbg_print_class_name(zend_class_entry *ce) /* {{{ */ { - phpdbg_write( - "%s %s %s (%d)", - ((*ce)->type == ZEND_USER_CLASS) ? - "User" : "Internal", - ((*ce)->ce_flags & ZEND_ACC_INTERFACE) ? - "Interface" : - ((*ce)->ce_flags & ZEND_ACC_ABSTRACT) ? - "Abstract Class" : - "Class", - (*ce)->name, zend_hash_num_elements(&(*ce)->function_table)); + const char *visibility = ce->type == ZEND_USER_CLASS ? "User" : "Internal"; + const char *type = (ce->ce_flags & ZEND_ACC_INTERFACE) ? "Interface" : (ce->ce_flags & ZEND_ACC_ABSTRACT) ? "Abstract Class" : "Class"; + + phpdbg_writeln("class", "type=\"%s\" flags=\"%s\" name=\"%.*s\" methodcount=\"%d\"", "%s %s %.*s (%d)", visibility, type, ce->name->len, ce->name->val, zend_hash_num_elements(&ce->function_table)); } /* }}} */ PHPDBG_INFO(classes) /* {{{ */ { - HashPosition position; - zend_class_entry **ce; + zend_class_entry *ce; HashTable classes; zend_hash_init(&classes, 8, NULL, NULL, 0); - for (zend_hash_internal_pointer_reset_ex(EG(class_table), &position); - zend_hash_get_current_data_ex(EG(class_table), (void**)&ce, &position) == SUCCESS; - zend_hash_move_forward_ex(EG(class_table), &position)) { - - if ((*ce)->type == ZEND_USER_CLASS) { - zend_hash_next_index_insert( - &classes, ce, sizeof(ce), NULL); - } - } - - phpdbg_notice("User Classes (%d)", - zend_hash_num_elements(&classes)); + phpdbg_try_access { + ZEND_HASH_FOREACH_PTR(EG(class_table), ce) { + if (ce->type == ZEND_USER_CLASS) { + zend_hash_next_index_insert_ptr(&classes, ce); + } + } ZEND_HASH_FOREACH_END(); + } phpdbg_catch_access { + phpdbg_notice("signalsegv", "", "Not all classes could be fetched, possibly invalid data source"); + } phpdbg_end_try_access(); - for (zend_hash_internal_pointer_reset_ex(&classes, &position); - zend_hash_get_current_data_ex(&classes, (void**)&ce, &position) == SUCCESS; - zend_hash_move_forward_ex(&classes, &position)) { + phpdbg_notice("classinfo", "num=\"%d\"", "User Classes (%d)", zend_hash_num_elements(&classes)); - phpdbg_print_class_name(ce TSRMLS_CC); - phpdbg_writeln(EMPTY); + /* once added, assume that classes are stable... until shutdown. */ + ZEND_HASH_FOREACH_PTR(&classes, ce) { + phpdbg_print_class_name(ce); - if ((*ce)->parent) { - zend_class_entry *pce = (*ce)->parent; + if (ce->parent) { + zend_class_entry *pce; + phpdbg_xml("<parents %r>"); + pce = ce->parent; do { - phpdbg_write("|-------- "); - phpdbg_print_class_name(&pce TSRMLS_CC); - phpdbg_writeln(EMPTY); + phpdbg_out("|-------- "); + phpdbg_print_class_name(pce); } while ((pce = pce->parent)); + phpdbg_xml("</parents>"); } - if ((*ce)->info.user.filename) { - phpdbg_writeln( - "|---- in %s on line %u", - (*ce)->info.user.filename, - (*ce)->info.user.line_start); + if (ce->info.user.filename) { + phpdbg_writeln("classsource", "file=\"%s\" line=\"%u\"", "|---- in %s on line %u", ce->info.user.filename->val, ce->info.user.line_start); } else { - phpdbg_writeln("|---- no source code"); + phpdbg_writeln("classsource", "", "|---- no source code"); } - phpdbg_writeln(EMPTY); - } + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&classes); @@ -334,36 +410,34 @@ PHPDBG_INFO(classes) /* {{{ */ PHPDBG_INFO(funcs) /* {{{ */ { - HashPosition position; - zend_function *zf, **pzf; + zend_function *zf; HashTable functions; zend_hash_init(&functions, 8, NULL, NULL, 0); - for (zend_hash_internal_pointer_reset_ex(EG(function_table), &position); - zend_hash_get_current_data_ex(EG(function_table), (void**)&zf, &position) == SUCCESS; - zend_hash_move_forward_ex(EG(function_table), &position)) { + phpdbg_try_access { + ZEND_HASH_FOREACH_PTR(EG(function_table), zf) { + if (zf->type == ZEND_USER_FUNCTION) { + zend_hash_next_index_insert_ptr(&functions, zf); + } + } ZEND_HASH_FOREACH_END(); + } phpdbg_catch_access { + phpdbg_notice("signalsegv", "", "Not all functions could be fetched, possibly invalid data source"); + } phpdbg_end_try_access(); - if (zf->type == ZEND_USER_FUNCTION) { - zend_hash_next_index_insert( - &functions, (void**) &zf, sizeof(zend_function), NULL); - } - } + phpdbg_notice("functioninfo", "num=\"%d\"", "User Functions (%d)", zend_hash_num_elements(&functions)); - phpdbg_notice("User Functions (%d)", - zend_hash_num_elements(&functions)); + ZEND_HASH_FOREACH_PTR(&functions, zf) { + zend_op_array *op_array = &zf->op_array; - for (zend_hash_internal_pointer_reset_ex(&functions, &position); - zend_hash_get_current_data_ex(&functions, (void**)&pzf, &position) == SUCCESS; - zend_hash_move_forward_ex(&functions, &position)) { - zend_op_array *op_array = &((*pzf)->op_array); + phpdbg_write("function", "name=\"%s\"", "|-------- %s", op_array->function_name ? op_array->function_name->val : "{main}"); - phpdbg_writeln( - "|-------- %s in %s on line %d", - op_array->function_name ? op_array->function_name : "{main}", - op_array->filename ? op_array->filename : "(no source code)", - op_array->line_start); - } + if (op_array->filename) { + phpdbg_writeln("functionsource", "file=\"%s\" line=\"%d\"", " in %s on line %d", op_array->filename->val, op_array->line_start); + } else { + phpdbg_writeln("functionsource", "", " (no source code)"); + } + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&functions); diff --git a/sapi/phpdbg/phpdbg_info.h b/sapi/phpdbg/phpdbg_info.h index 36b34738b1..432aaca654 100644 --- a/sapi/phpdbg/phpdbg_info.h +++ b/sapi/phpdbg/phpdbg_info.h @@ -30,7 +30,9 @@ PHPDBG_INFO(break); PHPDBG_INFO(classes); PHPDBG_INFO(funcs); PHPDBG_INFO(error); +PHPDBG_INFO(constants); PHPDBG_INFO(vars); +PHPDBG_INFO(globals); PHPDBG_INFO(literal); PHPDBG_INFO(memory); diff --git a/sapi/phpdbg/phpdbg_io.c b/sapi/phpdbg/phpdbg_io.c new file mode 100644 index 0000000000..7ae5d449e4 --- /dev/null +++ b/sapi/phpdbg/phpdbg_io.c @@ -0,0 +1,321 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Anatol Belski <ab@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "phpdbg_io.h" + +#ifdef PHP_WIN32 +#undef UNICODE +#include "win32/inet.h" +#include <winsock2.h> +#include <windows.h> +#include <Ws2tcpip.h> +#include "win32/sockets.h" + +#else + +#if HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#include <sys/socket.h> +#include <netinet/in.h> +#if HAVE_ARPA_INET_H +#include <arpa/inet.h> +#endif +#include <netdb.h> +#include <fcntl.h> +#include <poll.h> +#endif + +ZEND_EXTERN_MODULE_GLOBALS(phpdbg); + +/* is easy to generalize ... but not needed for now */ +PHPDBG_API int phpdbg_consume_stdin_line(char *buf) { + int bytes = PHPDBG_G(input_buflen), len = 0; + + if (PHPDBG_G(input_buflen)) { + memcpy(buf, PHPDBG_G(input_buffer), bytes); + } + + PHPDBG_G(last_was_newline) = 1; + + do { + int i; + if (bytes <= 0) { + continue; + } + + for (i = len; i < len + bytes; i++) { + if (buf[i] == '\x03') { + if (i != len + bytes - 1) { + memmove(buf + i, buf + i + 1, len + bytes - i - 1); + } + len--; + i--; + continue; + } + if (buf[i] == '\n') { + PHPDBG_G(input_buflen) = len + bytes - 1 - i; + if (PHPDBG_G(input_buflen)) { + memcpy(PHPDBG_G(input_buffer), buf + i + 1, PHPDBG_G(input_buflen)); + } + if (i != PHPDBG_MAX_CMD - 1) { + buf[i + 1] = 0; + } + return i; + } + } + + len += bytes; + } while ((bytes = phpdbg_mixed_read(PHPDBG_G(io)[PHPDBG_STDIN].fd, buf + len, PHPDBG_MAX_CMD - len, -1)) > 0); + + if (bytes <= 0) { + PHPDBG_G(flags) |= PHPDBG_IS_QUITTING | PHPDBG_IS_DISCONNECTED; + zend_bailout(); + return 0; + } + + return bytes; +} + +PHPDBG_API int phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo) { + int got_now, i = len, j; + char *p = ptr; +#ifndef PHP_WIN32 + struct pollfd pfd; + + if (tmo < 0) goto recv_once; + pfd.fd = sock; + pfd.events = POLLIN; + + j = poll(&pfd, 1, tmo); + + if (j == 0) { +#else + struct fd_set readfds; + struct timeval ttmo; + + if (tmo < 0) goto recv_once; + FD_ZERO(&readfds); + FD_SET(sock, &readfds); + + ttmo.tv_sec = 0; + ttmo.tv_usec = tmo*1000; + + j = select(0, &readfds, NULL, NULL, &ttmo); + + if (j <= 0) { +#endif + return -1; + } + +recv_once: + while(i > 0) { + if (tmo < 0) { + /* There's something to read. Read what's available and proceed + disregarding whether len could be exhausted or not.*/ + int can_read = recv(sock, p, i, MSG_PEEK); +#ifndef _WIN32 + if (can_read == -1 && errno == EINTR) { + continue; + } +#endif + i = can_read; + } + +#ifdef _WIN32 + got_now = recv(sock, p, i, 0); +#else + do { + got_now = recv(sock, p, i, 0); + } while (got_now == -1 && errno == EINTR); +#endif + + if (got_now == -1) { + write(PHPDBG_G(io)[PHPDBG_STDERR].fd, ZEND_STRL("Read operation timed out!\n")); + return -1; + } + i -= got_now; + p += got_now; + } + + return p - ptr; +} + +PHPDBG_API int phpdbg_send_bytes(int sock, const char *ptr, int len) { + int sent, i = len; + const char *p = ptr; +/* XXX poll/select needed here? */ + while(i > 0) { + sent = send(sock, p, i, 0); + if (sent == -1) { + return -1; + } + i -= sent; + p += sent; + } + + return len; +} + + +PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo) { + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { + return phpdbg_consume_bytes(sock, ptr, len, tmo); + } + + return read(sock, ptr, len); +} + + +PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len) { + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { + return phpdbg_send_bytes(sock, ptr, len); + } + + return write(sock, ptr, len); +} + + +PHPDBG_API int phpdbg_open_socket(const char *interface, unsigned short port) { + struct addrinfo res; + int fd = phpdbg_create_listenable_socket(interface, port, &res); + + if (fd == -1) { + return -1; + } + + if (bind(fd, res.ai_addr, res.ai_addrlen) == -1) { + phpdbg_close_socket(fd); + return -4; + } + + listen(fd, 5); + + return fd; +} + + +PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, unsigned short port, struct addrinfo *addr_res) { + int sock = -1, rc; + int reuse = 1; + struct in6_addr serveraddr; + struct addrinfo hints, *res = NULL; + char port_buf[8]; + int8_t any_addr = *addr == '*'; + + do { + memset(&hints, 0, sizeof hints); + if (any_addr) { + hints.ai_flags = AI_PASSIVE; + } else { + hints.ai_flags = AI_NUMERICSERV; + } + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + rc = inet_pton(AF_INET, addr, &serveraddr); + if (1 == rc) { + hints.ai_family = AF_INET; + if (!any_addr) { + hints.ai_flags |= AI_NUMERICHOST; + } + } else { + rc = inet_pton(AF_INET6, addr, &serveraddr); + if (1 == rc) { + hints.ai_family = AF_INET6; + if (!any_addr) { + hints.ai_flags |= AI_NUMERICHOST; + } + } else { + /* XXX get host by name ??? */ + } + } + + snprintf(port_buf, 7, "%u", port); + if (!any_addr) { + rc = getaddrinfo(addr, port_buf, &hints, &res); + } else { + rc = getaddrinfo(NULL, port_buf, &hints, &res); + } + + if (0 != rc) { +#ifndef PHP_WIN32 + if (rc == EAI_SYSTEM) { + char buf[128]; + int wrote; + + wrote = snprintf(buf, 128, "Could not translate address '%s'", addr); + buf[wrote] = '\0'; + write(PHPDBG_G(io)[PHPDBG_STDERR].fd, buf, strlen(buf)); + + return sock; + } else { +#endif + char buf[256]; + int wrote; + + wrote = snprintf(buf, 256, "Host '%s' not found. %s", addr, estrdup(gai_strerror(rc))); + buf[wrote] = '\0'; + write(PHPDBG_G(io)[PHPDBG_STDERR].fd, buf, strlen(buf)); + + return sock; +#ifndef PHP_WIN32 + } +#endif + return sock; + } + + if((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) { + char buf[128]; + int wrote; + + wrote = sprintf(buf, "Unable to create socket"); + buf[wrote] = '\0'; + write(PHPDBG_G(io)[PHPDBG_STDERR].fd, buf, strlen(buf)); + + return sock; + } + + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*) &reuse, sizeof(reuse)) == -1) { + phpdbg_close_socket(sock); + return sock; + } + + + } while (0); + + *addr_res = *res; + + return sock; +} + +PHPDBG_API void phpdbg_close_socket(int sock) { + if (socket >= 0) { +#ifdef _WIN32 + closesocket(sock); +#else + shutdown(sock, SHUT_RDWR); + close(sock); +#endif + } +} + diff --git a/sapi/phpdbg/phpdbg_io.h b/sapi/phpdbg/phpdbg_io.h new file mode 100644 index 0000000000..e9482a6a03 --- /dev/null +++ b/sapi/phpdbg/phpdbg_io.h @@ -0,0 +1,36 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Anatol Belski <ab@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifndef PHPDBG_IO_H +#define PHPDBG_IO_H + +#include "phpdbg.h" + +PHPDBG_API int phpdbg_consume_stdin_line(char *buf); + +PHPDBG_API int phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo); +PHPDBG_API int phpdbg_send_bytes(int sock, const char *ptr, int len); +PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo); +PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len); + +PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, unsigned short port, struct addrinfo *res); +PHPDBG_API int phpdbg_open_socket(const char *interface, unsigned short port); +PHPDBG_API void phpdbg_close_socket(int sock); + +#endif /* PHPDBG_IO_H */ + diff --git a/sapi/phpdbg/phpdbg_lexer.c b/sapi/phpdbg/phpdbg_lexer.c index 3092dc396d..d1474dc252 100644 --- a/sapi/phpdbg/phpdbg_lexer.c +++ b/sapi/phpdbg/phpdbg_lexer.c @@ -1,5 +1,5 @@ /* Generated by re2c 0.13.5 */ -#line 1 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 1 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" /* * phpdbg_lexer.l */ @@ -23,12 +23,13 @@ #define YYFILL(n) #define NORMAL 0 -#define RAW 1 -#define INITIAL 2 +#define PRE_RAW 1 +#define RAW 2 +#define INITIAL 3 ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC) { +void phpdbg_init_lexer (phpdbg_param_t *stack, char *input) { PHPDBG_G(parser_stack) = stack; YYSETCONDITION(INITIAL); @@ -38,20 +39,23 @@ void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC) { } int phpdbg_lex (phpdbg_param_t* yylval) { - TSRMLS_FETCH(); /* Slow, but this is not a major problem here. TODO: Use TSRMLS_DC */ restart: LEX(text) = YYCURSOR; -#line 48 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" +#line 49 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" { YYCTYPE yych; unsigned int yyaccept = 0; - if (YYGETCONDITION() < 1) { - goto yyc_NORMAL; + if (YYGETCONDITION() < 2) { + if (YYGETCONDITION() < 1) { + goto yyc_NORMAL; + } else { + goto yyc_PRE_RAW; + } } else { - if (YYGETCONDITION() < 2) { + if (YYGETCONDITION() < 3) { goto yyc_RAW; } else { goto yyc_INITIAL; @@ -61,1083 +65,1454 @@ restart: yyc_INITIAL: { static const unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 128, 128, 0, 0, 128, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 128, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 192, 96, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 192, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, }; YYDEBUG(0, *YYCURSOR); YYFILL(4); yych = *YYCURSOR; - if (yych <= 'D') { - if (yych <= '\n') { - if (yych <= 0x00) goto yy6; - if (yych <= 0x08) goto yy11; - if (yych >= '\n') goto yy4; + if (yybm[0+yych] & 32) { + goto yy4; + } + if (yych <= 'E') { + if (yych <= '\f') { + if (yych <= 0x00) goto yy7; + if (yych != '\t') goto yy12; } else { - if (yych <= '\r') { - if (yych <= '\f') goto yy11; + if (yych <= 0x1F) { + if (yych >= 0x0E) goto yy12; } else { - if (yych != ' ') goto yy11; + if (yych <= ' ') goto yy2; + if (yych <= 'D') goto yy12; + goto yy8; } } } else { if (yych <= 'd') { - if (yych <= 'Q') { - if (yych <= 'E') goto yy7; - goto yy11; - } else { - if (yych <= 'R') goto yy10; - if (yych <= 'S') goto yy8; - goto yy11; - } + if (yych <= 'Q') goto yy12; + if (yych <= 'R') goto yy11; + if (yych <= 'S') goto yy9; + goto yy12; } else { if (yych <= 'q') { - if (yych <= 'e') goto yy7; - goto yy11; + if (yych <= 'e') goto yy8; + goto yy12; } else { - if (yych <= 'r') goto yy9; - if (yych <= 's') goto yy8; - goto yy11; + if (yych <= 'r') goto yy10; + if (yych <= 's') goto yy9; + goto yy12; } } } +yy2: YYDEBUG(2, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '\f') { + if (yych <= 0x00) goto yy29; if (yych <= 0x08) goto yy3; - if (yych <= '\n') goto yy26; + if (yych <= '\n') goto yy29; } else { - if (yych <= '\r') goto yy26; - if (yych == ' ') goto yy26; + if (yych <= '\r') goto yy29; + if (yych == ' ') goto yy29; } yy3: YYDEBUG(3, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 161 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 176 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { YYSETCONDITION(NORMAL); YYCURSOR = LEX(text); goto restart; } -#line 154 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" +#line 161 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" yy4: YYDEBUG(4, *YYCURSOR); ++YYCURSOR; - if ((yych = *YYCURSOR) <= '\f') { - if (yych <= 0x08) goto yy5; - if (yych <= '\n') goto yy26; - } else { - if (yych <= '\r') goto yy26; - if (yych == ' ') goto yy26; - } -yy5: + YYFILL(1); + yych = *YYCURSOR; YYDEBUG(5, *YYCURSOR); + if (yybm[0+yych] & 128) { + goto yy28; + } + if (yych <= 0x00) goto yy27; + if (yych == '\n') goto yy4; +yy6: + YYDEBUG(6, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 68 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 69 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { return 0; } -#line 172 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy6: - YYDEBUG(6, *YYCURSOR); - yych = *++YYCURSOR; - goto yy3; +#line 180 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" yy7: YYDEBUG(7, *YYCURSOR); - yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'V') goto yy22; - if (yych == 'v') goto yy22; + yych = *++YYCURSOR; goto yy3; yy8: YYDEBUG(8, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'H') goto yy18; - if (yych == 'h') goto yy18; + if (yych == 'V') goto yy23; + if (yych == 'v') goto yy23; goto yy3; yy9: YYDEBUG(9, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yybm[0+yych] & 128) { - goto yy15; - } - if (yych == 'U') goto yy12; - if (yych == 'u') goto yy12; + if (yych == 'H') goto yy19; + if (yych == 'h') goto yy19; goto yy3; yy10: YYDEBUG(10, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'U') goto yy12; - if (yych == 'u') goto yy12; + if (yybm[0+yych] & 64) { + goto yy16; + } + if (yych == 'U') goto yy13; + if (yych == 'u') goto yy13; goto yy3; yy11: YYDEBUG(11, *YYCURSOR); - yych = *++YYCURSOR; + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'U') goto yy13; + if (yych == 'u') goto yy13; goto yy3; yy12: YYDEBUG(12, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy14; - if (yych == 'n') goto yy14; + goto yy3; yy13: YYDEBUG(13, *YYCURSOR); - YYCURSOR = YYMARKER; - goto yy3; + yych = *++YYCURSOR; + if (yych == 'N') goto yy15; + if (yych == 'n') goto yy15; yy14: YYDEBUG(14, *YYCURSOR); - yych = *++YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy15; - } - goto yy13; + YYCURSOR = YYMARKER; + goto yy3; yy15: YYDEBUG(15, *YYCURSOR); + yych = *++YYCURSOR; + if (yybm[0+yych] & 64) { + goto yy16; + } + goto yy14; +yy16: + YYDEBUG(16, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(16, *YYCURSOR); - if (yybm[0+yych] & 128) { - goto yy15; - } YYDEBUG(17, *YYCURSOR); + if (yybm[0+yych] & 64) { + goto yy16; + } + YYDEBUG(18, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 155 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 163 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { - YYSETCONDITION(RAW); + YYSETCONDITION(PRE_RAW); phpdbg_init_param(yylval, EMPTY_PARAM); return T_RUN; } -#line 245 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy18: - YYDEBUG(18, *YYCURSOR); +#line 253 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy19: + YYDEBUG(19, *YYCURSOR); yych = *++YYCURSOR; if (yych <= '\f') { - if (yych <= 0x08) goto yy13; - if (yych >= '\v') goto yy13; + if (yych <= 0x08) goto yy14; + if (yych >= '\v') goto yy14; } else { - if (yych <= '\r') goto yy19; - if (yych != ' ') goto yy13; + if (yych <= '\r') goto yy20; + if (yych != ' ') goto yy14; } -yy19: - YYDEBUG(19, *YYCURSOR); +yy20: + YYDEBUG(20, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(20, *YYCURSOR); + YYDEBUG(21, *YYCURSOR); if (yych <= '\f') { - if (yych <= 0x08) goto yy21; - if (yych <= '\n') goto yy19; + if (yych <= 0x08) goto yy22; + if (yych <= '\n') goto yy20; } else { - if (yych <= '\r') goto yy19; - if (yych == ' ') goto yy19; + if (yych <= '\r') goto yy20; + if (yych == ' ') goto yy20; } -yy21: - YYDEBUG(21, *YYCURSOR); +yy22: + YYDEBUG(22, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 150 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 158 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { - YYSETCONDITION(RAW); + YYSETCONDITION(PRE_RAW); phpdbg_init_param(yylval, EMPTY_PARAM); return T_SHELL; } -#line 278 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy22: - YYDEBUG(22, *YYCURSOR); +#line 286 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy23: + YYDEBUG(23, *YYCURSOR); yych = *++YYCURSOR; if (yych <= '\f') { - if (yych <= 0x08) goto yy13; - if (yych >= '\v') goto yy13; + if (yych <= 0x08) goto yy14; + if (yych >= '\v') goto yy14; } else { - if (yych <= '\r') goto yy23; - if (yych != ' ') goto yy13; + if (yych <= '\r') goto yy24; + if (yych != ' ') goto yy14; } -yy23: - YYDEBUG(23, *YYCURSOR); +yy24: + YYDEBUG(24, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(24, *YYCURSOR); + YYDEBUG(25, *YYCURSOR); if (yych <= '\f') { - if (yych <= 0x08) goto yy25; - if (yych <= '\n') goto yy23; + if (yych <= 0x08) goto yy26; + if (yych <= '\n') goto yy24; } else { - if (yych <= '\r') goto yy23; - if (yych == ' ') goto yy23; + if (yych <= '\r') goto yy24; + if (yych == ' ') goto yy24; } -yy25: - YYDEBUG(25, *YYCURSOR); +yy26: + YYDEBUG(26, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 145 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 153 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { - YYSETCONDITION(RAW); + YYSETCONDITION(PRE_RAW); phpdbg_init_param(yylval, EMPTY_PARAM); return T_EVAL; } -#line 311 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy26: - YYDEBUG(26, *YYCURSOR); +#line 319 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy27: + YYDEBUG(27, *YYCURSOR); + yych = *++YYCURSOR; + goto yy6; +yy28: + YYDEBUG(28, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(27, *YYCURSOR); - if (yych <= '\f') { - if (yych <= 0x08) goto yy28; - if (yych <= '\n') goto yy26; - } else { - if (yych <= '\r') goto yy26; - if (yych == ' ') goto yy26; +yy29: + YYDEBUG(29, *YYCURSOR); + if (yybm[0+yych] & 128) { + goto yy28; } -yy28: - YYDEBUG(28, *YYCURSOR); + if (yych <= 0x00) goto yy27; + if (yych == '\n') goto yy4; + YYDEBUG(30, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 139 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 147 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { /* ignore whitespace */ goto restart; } -#line 334 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" +#line 344 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" } /* *********************************** */ yyc_NORMAL: { static const unsigned char yybm[] = { - 0, 16, 16, 16, 16, 16, 16, 16, - 16, 8, 8, 16, 16, 8, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 8, 16, 16, 0, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 48, 16, - 176, 176, 176, 176, 176, 176, 176, 176, - 176, 176, 0, 16, 16, 16, 16, 16, - 16, 208, 208, 208, 208, 208, 208, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 16, 16, 16, 16, 16, - 16, 208, 208, 208, 208, 208, 208, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, + 0, 8, 8, 8, 8, 8, 8, 8, + 8, 66, 68, 8, 8, 66, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 66, 8, 8, 0, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 24, 8, + 152, 152, 152, 152, 152, 152, 152, 152, + 152, 152, 0, 8, 8, 8, 8, 8, + 8, 168, 168, 168, 168, 168, 168, 40, + 40, 40, 40, 40, 40, 40, 40, 40, + 40, 40, 40, 40, 40, 40, 40, 40, + 40, 40, 40, 8, 8, 8, 8, 8, + 8, 168, 168, 168, 168, 168, 168, 40, + 40, 40, 40, 40, 40, 40, 40, 40, + 40, 40, 40, 40, 40, 40, 40, 40, + 40, 40, 40, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, }; - YYDEBUG(29, *YYCURSOR); + YYDEBUG(31, *YYCURSOR); YYFILL(11); yych = *YYCURSOR; - YYDEBUG(-1, yych); - switch (yych) { - case 0x00: goto yy36; - case '\t': - case '\r': - case ' ': goto yy31; - case '\n': goto yy34; - case '#': goto yy55; - case '-': goto yy41; - case '.': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy42; - case '0': goto yy45; - case ':': goto yy57; - case 'D': - case 'd': goto yy46; - case 'E': - case 'e': goto yy47; - case 'F': - case 'f': goto yy48; - case 'I': - case 'i': goto yy37; - case 'N': - case 'n': goto yy49; - case 'O': - case 'o': goto yy50; - case 'T': - case 't': goto yy51; - case 'Y': - case 'y': goto yy52; - case 'Z': goto yy53; - case 'z': goto yy54; - default: goto yy39; + if (yybm[0+yych] & 2) { + goto yy33; } -yy31: - YYDEBUG(31, *YYCURSOR); + if (yych <= 'N') { + if (yych <= '0') { + if (yych <= '#') { + if (yych <= '\t') { + if (yych <= 0x00) goto yy39; + goto yy43; + } else { + if (yych <= '\n') goto yy36; + if (yych <= '"') goto yy43; + goto yy58; + } + } else { + if (yych <= '-') { + if (yych <= ',') goto yy43; + goto yy40; + } else { + if (yych <= '.') goto yy45; + if (yych <= '/') goto yy43; + goto yy48; + } + } + } else { + if (yych <= 'E') { + if (yych <= ':') { + if (yych <= '9') goto yy45; + goto yy60; + } else { + if (yych <= 'C') goto yy43; + if (yych <= 'D') goto yy49; + goto yy50; + } + } else { + if (yych <= 'H') { + if (yych <= 'F') goto yy51; + goto yy43; + } else { + if (yych <= 'I') goto yy42; + if (yych <= 'M') goto yy43; + goto yy52; + } + } + } + } else { + if (yych <= 'f') { + if (yych <= 'Y') { + if (yych <= 'S') { + if (yych <= 'O') goto yy53; + goto yy43; + } else { + if (yych <= 'T') goto yy54; + if (yych <= 'X') goto yy43; + goto yy55; + } + } else { + if (yych <= 'c') { + if (yych <= 'Z') goto yy56; + goto yy43; + } else { + if (yych <= 'd') goto yy49; + if (yych <= 'e') goto yy50; + goto yy51; + } + } + } else { + if (yych <= 'o') { + if (yych <= 'i') { + if (yych <= 'h') goto yy43; + goto yy42; + } else { + if (yych <= 'm') goto yy43; + if (yych <= 'n') goto yy52; + goto yy53; + } + } else { + if (yych <= 'x') { + if (yych == 't') goto yy54; + goto yy43; + } else { + if (yych <= 'y') goto yy55; + if (yych <= 'z') goto yy57; + goto yy43; + } + } + } + } +yy33: + YYDEBUG(33, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(32, *YYCURSOR); - if (yybm[0+yych] & 8) { - goto yy31; + YYDEBUG(34, *YYCURSOR); + if (yybm[0+yych] & 2) { + goto yy33; } - YYDEBUG(33, *YYCURSOR); + if (yych <= 0x00) goto yy39; + if (yych == '\n') goto yy36; + YYDEBUG(35, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 139 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 147 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { /* ignore whitespace */ goto restart; } -#line 434 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy34: - YYDEBUG(34, *YYCURSOR); +#line 493 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy36: + YYDEBUG(36, *YYCURSOR); ++YYCURSOR; - if (yybm[0+(yych = *YYCURSOR)] & 8) { - goto yy31; + YYFILL(1); + yych = *YYCURSOR; + YYDEBUG(37, *YYCURSOR); + if (yybm[0+yych] & 2) { + goto yy33; } -yy35: - YYDEBUG(35, *YYCURSOR); + if (yych <= 0x00) goto yy39; + if (yych == '\n') goto yy36; +yy38: + YYDEBUG(38, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 68 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 69 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { return 0; } -#line 448 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy36: - YYDEBUG(36, *YYCURSOR); +#line 512 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy39: + YYDEBUG(39, *YYCURSOR); yych = *++YYCURSOR; - goto yy35; -yy37: - YYDEBUG(37, *YYCURSOR); + goto yy38; +yy40: + YYDEBUG(40, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'F') goto yy106; - if (yych == 'f') goto yy106; - goto yy40; -yy38: - YYDEBUG(38, *YYCURSOR); + if (yybm[0+yych] & 16) { + goto yy45; + } + if (yych == 'r') goto yy113; + goto yy44; +yy41: + YYDEBUG(41, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 125 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 133 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { phpdbg_init_param(yylval, STR_PARAM); yylval->str = zend_strndup(yytext, yyleng); yylval->len = yyleng; - return T_ID; + return T_ID; } -#line 470 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy39: - YYDEBUG(39, *YYCURSOR); +#line 536 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy42: + YYDEBUG(42, *YYCURSOR); + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'F') goto yy109; + if (yych == 'f') goto yy109; + goto yy44; +yy43: + YYDEBUG(43, *YYCURSOR); yyaccept = 0; YYMARKER = ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; -yy40: - YYDEBUG(40, *YYCURSOR); - if (yybm[0+yych] & 16) { - goto yy39; - } - if (yych <= '9') goto yy38; - goto yy62; -yy41: - YYDEBUG(41, *YYCURSOR); - yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if (yybm[0+yych] & 32) { - goto yy42; +yy44: + YYDEBUG(44, *YYCURSOR); + if (yybm[0+yych] & 8) { + goto yy43; } - goto yy40; -yy42: - YYDEBUG(42, *YYCURSOR); + if (yych <= '9') goto yy41; + goto yy65; +yy45: + YYDEBUG(45, *YYCURSOR); yyaccept = 1; YYMARKER = ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; - YYDEBUG(43, *YYCURSOR); - if (yybm[0+yych] & 32) { - goto yy42; + YYDEBUG(46, *YYCURSOR); + if (yybm[0+yych] & 16) { + goto yy45; } if (yych <= 0x1F) { if (yych <= '\n') { - if (yych <= 0x00) goto yy44; - if (yych <= 0x08) goto yy39; + if (yych <= 0x00) goto yy47; + if (yych <= 0x08) goto yy43; } else { - if (yych != '\r') goto yy39; + if (yych != '\r') goto yy43; } } else { if (yych <= '#') { - if (yych <= ' ') goto yy44; - if (yych <= '"') goto yy39; + if (yych <= ' ') goto yy47; + if (yych <= '"') goto yy43; } else { - if (yych == ':') goto yy62; - goto yy39; + if (yych == ':') goto yy65; + goto yy43; } } -yy44: - YYDEBUG(44, *YYCURSOR); +yy47: + YYDEBUG(47, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 106 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 114 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { phpdbg_init_param(yylval, NUMERIC_PARAM); yylval->num = atoi(yytext); return T_DIGITS; } -#line 527 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy45: - YYDEBUG(45, *YYCURSOR); +#line 592 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy48: + YYDEBUG(48, *YYCURSOR); yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if (yybm[0+yych] & 32) { - goto yy42; + if (yybm[0+yych] & 16) { + goto yy45; } if (yych <= 0x1F) { if (yych <= '\n') { - if (yych <= 0x00) goto yy44; - if (yych <= 0x08) goto yy40; - goto yy44; + if (yych <= 0x00) goto yy47; + if (yych <= 0x08) goto yy44; + goto yy47; } else { - if (yych == '\r') goto yy44; - goto yy40; + if (yych == '\r') goto yy47; + goto yy44; } } else { if (yych <= '#') { - if (yych <= ' ') goto yy44; - if (yych <= '"') goto yy40; - goto yy44; + if (yych <= ' ') goto yy47; + if (yych <= '"') goto yy44; + goto yy47; } else { - if (yych == 'x') goto yy102; - goto yy40; + if (yych == 'x') goto yy105; + goto yy44; } } -yy46: - YYDEBUG(46, *YYCURSOR); - yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'I') goto yy96; - if (yych == 'i') goto yy96; - goto yy40; -yy47: - YYDEBUG(47, *YYCURSOR); - yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'N') goto yy91; - if (yych == 'n') goto yy91; - goto yy40; -yy48: - YYDEBUG(48, *YYCURSOR); - yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'A') goto yy88; - if (yych == 'a') goto yy88; - goto yy40; yy49: YYDEBUG(49, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'O') goto yy84; - if (yych == 'o') goto yy84; - goto yy40; + if (yych == 'I') goto yy99; + if (yych == 'i') goto yy99; + goto yy44; yy50: YYDEBUG(50, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych <= 'N') { - if (yych == 'F') goto yy83; - if (yych <= 'M') goto yy40; - goto yy77; - } else { - if (yych <= 'f') { - if (yych <= 'e') goto yy40; - goto yy83; - } else { - if (yych == 'n') goto yy77; - goto yy40; - } - } + if (yych == 'N') goto yy94; + if (yych == 'n') goto yy94; + goto yy44; yy51: YYDEBUG(51, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'R') goto yy81; - if (yych == 'r') goto yy81; - goto yy40; + if (yych == 'A') goto yy91; + if (yych == 'a') goto yy91; + goto yy44; yy52: YYDEBUG(52, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'E') goto yy76; - if (yych == 'e') goto yy76; - goto yy40; + if (yych == 'O') goto yy87; + if (yych == 'o') goto yy87; + goto yy44; yy53: YYDEBUG(53, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'E') goto yy73; - goto yy40; + if (yych <= 'N') { + if (yych == 'F') goto yy86; + if (yych <= 'M') goto yy44; + goto yy80; + } else { + if (yych <= 'f') { + if (yych <= 'e') goto yy44; + goto yy86; + } else { + if (yych == 'n') goto yy80; + goto yy44; + } + } yy54: YYDEBUG(54, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'e') goto yy61; - goto yy40; + if (yych == 'R') goto yy84; + if (yych == 'r') goto yy84; + goto yy44; yy55: YYDEBUG(55, *YYCURSOR); - ++YYCURSOR; + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'E') goto yy79; + if (yych == 'e') goto yy79; + goto yy44; +yy56: YYDEBUG(56, *YYCURSOR); + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'E') goto yy76; + goto yy44; +yy57: + YYDEBUG(57, *YYCURSOR); + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'e') goto yy64; + goto yy44; +yy58: + YYDEBUG(58, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(59, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 84 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 92 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { return T_POUND; } -#line 634 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy57: - YYDEBUG(57, *YYCURSOR); +#line 699 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy60: + YYDEBUG(60, *YYCURSOR); ++YYCURSOR; - if ((yych = *YYCURSOR) == ':') goto yy59; - YYDEBUG(58, *YYCURSOR); + if ((yych = *YYCURSOR) == ':') goto yy62; + YYDEBUG(61, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 90 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 98 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { return T_COLON; } -#line 645 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy59: - YYDEBUG(59, *YYCURSOR); +#line 710 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy62: + YYDEBUG(62, *YYCURSOR); ++YYCURSOR; - YYDEBUG(60, *YYCURSOR); + YYDEBUG(63, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 87 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 95 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { return T_DCOLON; } -#line 655 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy61: - YYDEBUG(61, *YYCURSOR); +#line 720 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy64: + YYDEBUG(64, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'n') goto yy67; - goto yy40; -yy62: - YYDEBUG(62, *YYCURSOR); + if (yych == 'n') goto yy70; + goto yy44; +yy65: + YYDEBUG(65, *YYCURSOR); yych = *++YYCURSOR; - if (yych == '/') goto yy64; -yy63: - YYDEBUG(63, *YYCURSOR); + if (yych == '/') goto yy67; +yy66: + YYDEBUG(66, *YYCURSOR); YYCURSOR = YYMARKER; - if (yyaccept <= 1) { - if (yyaccept <= 0) { - goto yy38; + if (yyaccept <= 2) { + if (yyaccept <= 1) { + if (yyaccept <= 0) { + goto yy41; + } else { + goto yy47; + } } else { - goto yy44; + goto yy75; } } else { - if (yyaccept <= 2) { - goto yy72; + if (yyaccept <= 3) { + goto yy108; } else { - goto yy105; + goto yy119; } } -yy64: - YYDEBUG(64, *YYCURSOR); +yy67: + YYDEBUG(67, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '/') goto yy63; - YYDEBUG(65, *YYCURSOR); + if (yych != '/') goto yy66; + YYDEBUG(68, *YYCURSOR); ++YYCURSOR; - YYDEBUG(66, *YYCURSOR); + YYDEBUG(69, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 78 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 86 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { phpdbg_init_param(yylval, STR_PARAM); yylval->str = zend_strndup(yytext, yyleng); yylval->len = yyleng; return T_PROTO; } -#line 697 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy67: - YYDEBUG(67, *YYCURSOR); +#line 766 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy70: + YYDEBUG(70, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych != 'd') goto yy40; - YYDEBUG(68, *YYCURSOR); + if (yych != 'd') goto yy44; + YYDEBUG(71, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych != '_') goto yy40; -yy69: - YYDEBUG(69, *YYCURSOR); + if (yych != '_') goto yy44; +yy72: + YYDEBUG(72, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yybm[0+yych] & 64) { - goto yy70; + if (yybm[0+yych] & 32) { + goto yy73; } - goto yy40; -yy70: - YYDEBUG(70, *YYCURSOR); + goto yy44; +yy73: + YYDEBUG(73, *YYCURSOR); yyaccept = 2; YYMARKER = ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; - YYDEBUG(71, *YYCURSOR); - if (yybm[0+yych] & 64) { - goto yy70; + YYDEBUG(74, *YYCURSOR); + if (yybm[0+yych] & 32) { + goto yy73; } if (yych <= 0x1F) { if (yych <= '\n') { - if (yych <= 0x00) goto yy72; - if (yych <= 0x08) goto yy39; + if (yych <= 0x00) goto yy75; + if (yych <= 0x08) goto yy43; } else { - if (yych != '\r') goto yy39; + if (yych != '\r') goto yy43; } } else { if (yych <= '#') { - if (yych <= ' ') goto yy72; - if (yych <= '"') goto yy39; + if (yych <= ' ') goto yy75; + if (yych <= '"') goto yy43; } else { - if (yych == ':') goto yy62; - goto yy39; + if (yych == ':') goto yy65; + goto yy43; } } -yy72: - YYDEBUG(72, *YYCURSOR); +yy75: + YYDEBUG(75, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 118 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 126 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { phpdbg_init_param(yylval, OP_PARAM); yylval->str = zend_strndup(yytext, yyleng); yylval->len = yyleng; return T_OPCODE; } -#line 751 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy73: - YYDEBUG(73, *YYCURSOR); +#line 820 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy76: + YYDEBUG(76, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych != 'N') goto yy40; - YYDEBUG(74, *YYCURSOR); + if (yych != 'N') goto yy44; + YYDEBUG(77, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych != 'D') goto yy40; - YYDEBUG(75, *YYCURSOR); + if (yych != 'D') goto yy44; + YYDEBUG(78, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == '_') goto yy69; - goto yy40; -yy76: - YYDEBUG(76, *YYCURSOR); + if (yych == '_') goto yy72; + goto yy44; +yy79: + YYDEBUG(79, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'S') goto yy77; - if (yych != 's') goto yy40; -yy77: - YYDEBUG(77, *YYCURSOR); + if (yych == 'S') goto yy80; + if (yych != 's') goto yy44; +yy80: + YYDEBUG(80, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych <= '\f') { - if (yych <= 0x08) goto yy40; - if (yych >= '\v') goto yy40; - } else { - if (yych <= '\r') goto yy78; - if (yych != ' ') goto yy40; + if (yybm[0+yych] & 64) { + goto yy81; } -yy78: - YYDEBUG(78, *YYCURSOR); + goto yy44; +yy81: + YYDEBUG(81, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(79, *YYCURSOR); - if (yych <= '\f') { - if (yych <= 0x08) goto yy80; - if (yych <= '\n') goto yy78; - } else { - if (yych <= '\r') goto yy78; - if (yych == ' ') goto yy78; + YYDEBUG(82, *YYCURSOR); + if (yybm[0+yych] & 64) { + goto yy81; } -yy80: - YYDEBUG(80, *YYCURSOR); + YYDEBUG(83, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 94 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 102 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { phpdbg_init_param(yylval, NUMERIC_PARAM); - yylval->num = 1; + yylval->num = 1; return T_TRUTHY; } -#line 805 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy81: - YYDEBUG(81, *YYCURSOR); +#line 866 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy84: + YYDEBUG(84, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'U') goto yy82; - if (yych != 'u') goto yy40; -yy82: - YYDEBUG(82, *YYCURSOR); + if (yych == 'U') goto yy85; + if (yych != 'u') goto yy44; +yy85: + YYDEBUG(85, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'E') goto yy77; - if (yych == 'e') goto yy77; - goto yy40; -yy83: - YYDEBUG(83, *YYCURSOR); + if (yych == 'E') goto yy80; + if (yych == 'e') goto yy80; + goto yy44; +yy86: + YYDEBUG(86, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'F') goto yy84; - if (yych != 'f') goto yy40; -yy84: - YYDEBUG(84, *YYCURSOR); + if (yych == 'F') goto yy87; + if (yych != 'f') goto yy44; +yy87: + YYDEBUG(87, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if (yych <= '\f') { - if (yych <= 0x08) goto yy40; - if (yych >= '\v') goto yy40; + if (yych <= 0x08) goto yy44; + if (yych >= '\v') goto yy44; } else { - if (yych <= '\r') goto yy85; - if (yych != ' ') goto yy40; + if (yych <= '\r') goto yy88; + if (yych != ' ') goto yy44; } -yy85: - YYDEBUG(85, *YYCURSOR); +yy88: + YYDEBUG(88, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(86, *YYCURSOR); + YYDEBUG(89, *YYCURSOR); if (yych <= '\f') { - if (yych <= 0x08) goto yy87; - if (yych <= '\n') goto yy85; + if (yych <= 0x08) goto yy90; + if (yych <= '\n') goto yy88; } else { - if (yych <= '\r') goto yy85; - if (yych == ' ') goto yy85; + if (yych <= '\r') goto yy88; + if (yych == ' ') goto yy88; } -yy87: - YYDEBUG(87, *YYCURSOR); +yy90: + YYDEBUG(90, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 100 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 108 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { phpdbg_init_param(yylval, NUMERIC_PARAM); yylval->num = 0; return T_FALSY; } -#line 858 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy88: - YYDEBUG(88, *YYCURSOR); - yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'L') goto yy89; - if (yych != 'l') goto yy40; -yy89: - YYDEBUG(89, *YYCURSOR); - yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'S') goto yy90; - if (yych != 's') goto yy40; -yy90: - YYDEBUG(90, *YYCURSOR); - yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'E') goto yy84; - if (yych == 'e') goto yy84; - goto yy40; +#line 919 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" yy91: YYDEBUG(91, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'A') goto yy92; - if (yych != 'a') goto yy40; + if (yych == 'L') goto yy92; + if (yych != 'l') goto yy44; yy92: YYDEBUG(92, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'B') goto yy93; - if (yych != 'b') goto yy40; + if (yych == 'S') goto yy93; + if (yych != 's') goto yy44; yy93: YYDEBUG(93, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'L') goto yy94; - if (yych != 'l') goto yy40; + if (yych == 'E') goto yy87; + if (yych == 'e') goto yy87; + goto yy44; yy94: YYDEBUG(94, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'E') goto yy95; - if (yych != 'e') goto yy40; + if (yych == 'A') goto yy95; + if (yych != 'a') goto yy44; yy95: YYDEBUG(95, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'D') goto yy77; - if (yych == 'd') goto yy77; - goto yy40; + if (yych == 'B') goto yy96; + if (yych != 'b') goto yy44; yy96: YYDEBUG(96, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'S') goto yy97; - if (yych != 's') goto yy40; + if (yych == 'L') goto yy97; + if (yych != 'l') goto yy44; yy97: YYDEBUG(97, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'A') goto yy98; - if (yych != 'a') goto yy40; + if (yych == 'E') goto yy98; + if (yych != 'e') goto yy44; yy98: YYDEBUG(98, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'B') goto yy99; - if (yych != 'b') goto yy40; + if (yych == 'D') goto yy80; + if (yych == 'd') goto yy80; + goto yy44; yy99: YYDEBUG(99, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'L') goto yy100; - if (yych != 'l') goto yy40; + if (yych == 'S') goto yy100; + if (yych != 's') goto yy44; yy100: YYDEBUG(100, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'E') goto yy101; - if (yych != 'e') goto yy40; + if (yych == 'A') goto yy101; + if (yych != 'a') goto yy44; yy101: YYDEBUG(101, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'D') goto yy84; - if (yych == 'd') goto yy84; - goto yy40; + if (yych == 'B') goto yy102; + if (yych != 'b') goto yy44; yy102: YYDEBUG(102, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yybm[0+yych] & 128) { - goto yy103; - } - goto yy40; + if (yych == 'L') goto yy103; + if (yych != 'l') goto yy44; yy103: YYDEBUG(103, *YYCURSOR); + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'E') goto yy104; + if (yych != 'e') goto yy44; +yy104: + YYDEBUG(104, *YYCURSOR); + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'D') goto yy87; + if (yych == 'd') goto yy87; + goto yy44; +yy105: + YYDEBUG(105, *YYCURSOR); + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yybm[0+yych] & 128) { + goto yy106; + } + goto yy44; +yy106: + YYDEBUG(106, *YYCURSOR); yyaccept = 3; YYMARKER = ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; - YYDEBUG(104, *YYCURSOR); + YYDEBUG(107, *YYCURSOR); if (yybm[0+yych] & 128) { - goto yy103; + goto yy106; } if (yych <= 0x1F) { if (yych <= '\n') { - if (yych <= 0x00) goto yy105; - if (yych <= 0x08) goto yy39; + if (yych <= 0x00) goto yy108; + if (yych <= 0x08) goto yy43; } else { - if (yych != '\r') goto yy39; + if (yych != '\r') goto yy43; } } else { if (yych <= '#') { - if (yych <= ' ') goto yy105; - if (yych <= '"') goto yy39; + if (yych <= ' ') goto yy108; + if (yych <= '"') goto yy43; } else { - if (yych == ':') goto yy62; - goto yy39; + if (yych == ':') goto yy65; + goto yy43; } } -yy105: - YYDEBUG(105, *YYCURSOR); +yy108: + YYDEBUG(108, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 112 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 120 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { phpdbg_init_param(yylval, ADDR_PARAM); yylval->addr = strtoul(yytext, 0, 16); return T_ADDR; } -#line 989 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy106: - YYDEBUG(106, *YYCURSOR); +#line 1050 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy109: + YYDEBUG(109, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if (yych <= '\f') { - if (yych <= 0x08) goto yy40; - if (yych >= '\v') goto yy40; + if (yych <= 0x08) goto yy44; + if (yych >= '\v') goto yy44; } else { - if (yych <= '\r') goto yy107; - if (yych != ' ') goto yy40; + if (yych <= '\r') goto yy110; + if (yych != ' ') goto yy44; } -yy107: - YYDEBUG(107, *YYCURSOR); +yy110: + YYDEBUG(110, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(108, *YYCURSOR); + YYDEBUG(111, *YYCURSOR); if (yych <= '\f') { - if (yych <= 0x08) goto yy109; - if (yych <= '\n') goto yy107; + if (yych <= 0x08) goto yy112; + if (yych <= '\n') goto yy110; } else { - if (yych <= '\r') goto yy107; - if (yych == ' ') goto yy107; + if (yych <= '\r') goto yy110; + if (yych == ' ') goto yy110; } -yy109: - YYDEBUG(109, *YYCURSOR); +yy112: + YYDEBUG(112, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 72 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 80 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { YYSETCONDITION(RAW); phpdbg_init_param(yylval, EMPTY_PARAM); return T_IF; } -#line 1023 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" +#line 1084 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy113: + YYDEBUG(113, *YYCURSOR); + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yych <= ' ') { + if (yych <= '\f') { + if (yych <= 0x08) goto yy44; + if (yych >= '\v') goto yy44; + } else { + if (yych <= '\r') goto yy114; + if (yych <= 0x1F) goto yy44; + } + } else { + if (yych <= '.') { + if (yych <= ',') goto yy44; + if (yych <= '-') goto yy116; + goto yy117; + } else { + if (yych <= '/') goto yy44; + if (yych <= '9') goto yy117; + goto yy44; + } + } +yy114: + YYDEBUG(114, *YYCURSOR); + ++YYCURSOR; + YYFILL(2); + yych = *YYCURSOR; + YYDEBUG(115, *YYCURSOR); + if (yych <= ' ') { + if (yych <= '\f') { + if (yych <= 0x08) goto yy66; + if (yych <= '\n') goto yy114; + goto yy66; + } else { + if (yych <= '\r') goto yy114; + if (yych <= 0x1F) goto yy66; + goto yy114; + } + } else { + if (yych <= '.') { + if (yych <= ',') goto yy66; + if (yych <= '-') goto yy120; + goto yy121; + } else { + if (yych <= '/') goto yy66; + if (yych <= '9') goto yy121; + goto yy66; + } + } +yy116: + YYDEBUG(116, *YYCURSOR); + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == '.') goto yy117; + if (yych <= '/') goto yy44; + if (yych >= ':') goto yy44; +yy117: + YYDEBUG(117, *YYCURSOR); + yyaccept = 4; + YYMARKER = ++YYCURSOR; + YYFILL(3); + yych = *YYCURSOR; + YYDEBUG(118, *YYCURSOR); + if (yych <= ' ') { + if (yych <= '\n') { + if (yych <= 0x00) goto yy119; + if (yych <= 0x08) goto yy43; + } else { + if (yych == '\r') goto yy119; + if (yych <= 0x1F) goto yy43; + } + } else { + if (yych <= '.') { + if (yych == '#') goto yy119; + if (yych <= '-') goto yy43; + goto yy117; + } else { + if (yych <= '/') goto yy43; + if (yych <= '9') goto yy117; + if (yych <= ':') goto yy65; + goto yy43; + } + } +yy119: + YYDEBUG(119, *YYCURSOR); + yyleng = (size_t) YYCURSOR - (size_t) yytext; +#line 73 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" + { + char *text = yytext + 2; + while (*++text < '0'); + yylval->num = atoi(text); + return T_REQ_ID; +} +#line 1179 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy120: + YYDEBUG(120, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == '.') goto yy121; + if (yych <= '/') goto yy66; + if (yych >= ':') goto yy66; +yy121: + YYDEBUG(121, *YYCURSOR); + ++YYCURSOR; + YYFILL(1); + yych = *YYCURSOR; + YYDEBUG(122, *YYCURSOR); + if (yych == '.') goto yy121; + if (yych <= '/') goto yy119; + if (yych <= '9') goto yy121; + goto yy119; } /* *********************************** */ -yyc_RAW: +yyc_PRE_RAW: { static const unsigned char yybm[] = { - 0, 64, 64, 64, 64, 64, 64, 64, - 64, 224, 128, 64, 64, 224, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 224, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 160, 48, 0, 0, 160, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 160, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 64, 0, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, }; - YYDEBUG(110, *YYCURSOR); + YYDEBUG(123, *YYCURSOR); + YYFILL(2); + yych = *YYCURSOR; + if (yybm[0+yych] & 16) { + goto yy127; + } + if (yych <= '\r') { + if (yych <= 0x08) { + if (yych <= 0x00) goto yy130; + goto yy132; + } else { + if (yych <= '\t') goto yy125; + if (yych <= '\f') goto yy132; + } + } else { + if (yych <= ' ') { + if (yych <= 0x1F) goto yy132; + } else { + if (yych == '-') goto yy131; + goto yy132; + } + } +yy125: + YYDEBUG(125, *YYCURSOR); + ++YYCURSOR; + if ((yych = *YYCURSOR) <= '\f') { + if (yych <= 0x00) goto yy142; + if (yych <= 0x08) goto yy126; + if (yych <= '\n') goto yy142; + } else { + if (yych <= '\r') goto yy142; + if (yych == ' ') goto yy142; + } +yy126: + YYDEBUG(126, *YYCURSOR); + yyleng = (size_t) YYCURSOR - (size_t) yytext; +#line 169 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" + { + YYSETCONDITION(RAW); + + YYCURSOR = LEX(text); + goto restart; +} +#line 1277 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy127: + YYDEBUG(127, *YYCURSOR); + ++YYCURSOR; + YYFILL(1); + yych = *YYCURSOR; + YYDEBUG(128, *YYCURSOR); + if (yybm[0+yych] & 128) { + goto yy141; + } + if (yych <= 0x00) goto yy140; + if (yych == '\n') goto yy127; +yy129: + YYDEBUG(129, *YYCURSOR); + yyleng = (size_t) YYCURSOR - (size_t) yytext; +#line 69 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" + { + return 0; +} +#line 1296 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy130: + YYDEBUG(130, *YYCURSOR); + yych = *++YYCURSOR; + goto yy126; +yy131: + YYDEBUG(131, *YYCURSOR); + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'r') goto yy133; + goto yy126; +yy132: + YYDEBUG(132, *YYCURSOR); + yych = *++YYCURSOR; + goto yy126; +yy133: + YYDEBUG(133, *YYCURSOR); + ++YYCURSOR; YYFILL(2); yych = *YYCURSOR; + YYDEBUG(134, *YYCURSOR); if (yybm[0+yych] & 32) { - goto yy112; + goto yy133; } - if (yych <= 0x00) goto yy117; - if (yych == '\n') goto yy115; - goto yy118; -yy112: - YYDEBUG(112, *YYCURSOR); + if (yych <= '.') { + if (yych <= ',') goto yy135; + if (yych <= '-') goto yy136; + goto yy137; + } else { + if (yych <= '/') goto yy135; + if (yych <= '9') goto yy137; + } +yy135: + YYDEBUG(135, *YYCURSOR); + YYCURSOR = YYMARKER; + goto yy126; +yy136: + YYDEBUG(136, *YYCURSOR); + yych = *++YYCURSOR; + if (yybm[0+yych] & 64) { + goto yy137; + } + goto yy135; +yy137: + YYDEBUG(137, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(113, *YYCURSOR); + YYDEBUG(138, *YYCURSOR); + if (yybm[0+yych] & 64) { + goto yy137; + } + YYDEBUG(139, *YYCURSOR); + yyleng = (size_t) YYCURSOR - (size_t) yytext; +#line 73 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" + { + char *text = yytext + 2; + while (*++text < '0'); + yylval->num = atoi(text); + return T_REQ_ID; +} +#line 1357 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy140: + YYDEBUG(140, *YYCURSOR); + yych = *++YYCURSOR; + goto yy129; +yy141: + YYDEBUG(141, *YYCURSOR); + ++YYCURSOR; + YYFILL(1); + yych = *YYCURSOR; +yy142: + YYDEBUG(142, *YYCURSOR); + if (yybm[0+yych] & 128) { + goto yy141; + } + if (yych <= 0x00) goto yy140; + if (yych == '\n') goto yy127; + YYDEBUG(143, *YYCURSOR); + yyleng = (size_t) YYCURSOR - (size_t) yytext; +#line 147 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" + { + /* ignore whitespace */ + + goto restart; +} +#line 1382 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" + } +/* *********************************** */ +yyc_RAW: + { + static const unsigned char yybm[] = { + 0, 128, 128, 128, 128, 128, 128, 128, + 128, 160, 64, 128, 128, 160, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 160, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + }; + YYDEBUG(144, *YYCURSOR); + YYFILL(1); + yych = *YYCURSOR; if (yybm[0+yych] & 32) { - goto yy112; + goto yy146; } - if (yych <= 0x00) goto yy114; - if (yych == '\n') goto yy120; - goto yy118; -yy114: - YYDEBUG(114, *YYCURSOR); + if (yych <= 0x00) goto yy152; + if (yych == '\n') goto yy149; + goto yy153; +yy146: + YYDEBUG(146, *YYCURSOR); + ++YYCURSOR; + YYFILL(1); + yych = *YYCURSOR; + YYDEBUG(147, *YYCURSOR); + if (yybm[0+yych] & 32) { + goto yy146; + } + if (yych <= 0x00) goto yy152; + if (yych == '\n') goto yy149; + goto yy153; +yy148: + YYDEBUG(148, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 132 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 140 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { phpdbg_init_param(yylval, STR_PARAM); yylval->str = zend_strndup(yytext, yyleng); yylval->len = yyleng; return T_INPUT; } -#line 1093 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy115: - YYDEBUG(115, *YYCURSOR); +#line 1452 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy149: + YYDEBUG(149, *YYCURSOR); ++YYCURSOR; - if (yybm[0+(yych = *YYCURSOR)] & 128) { - goto yy120; + YYFILL(1); + yych = *YYCURSOR; + YYDEBUG(150, *YYCURSOR); + if (yybm[0+yych] & 64) { + goto yy149; } -yy116: - YYDEBUG(116, *YYCURSOR); + if (yych <= '\f') { + if (yych <= 0x00) goto yy152; + if (yych == '\t') goto yy155; + } else { + if (yych <= '\r') goto yy155; + if (yych == ' ') goto yy155; + } +yy151: + YYDEBUG(151, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 68 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 69 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { return 0; } -#line 1107 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" -yy117: - YYDEBUG(117, *YYCURSOR); +#line 1476 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" +yy152: + YYDEBUG(152, *YYCURSOR); yych = *++YYCURSOR; - goto yy116; -yy118: - YYDEBUG(118, *YYCURSOR); + goto yy151; +yy153: + YYDEBUG(153, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(119, *YYCURSOR); - if (yybm[0+yych] & 64) { - goto yy118; + YYDEBUG(154, *YYCURSOR); + if (yybm[0+yych] & 128) { + goto yy153; } - goto yy114; -yy120: - YYDEBUG(120, *YYCURSOR); + goto yy148; +yy155: + YYDEBUG(155, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(121, *YYCURSOR); - if (yybm[0+yych] & 128) { - goto yy120; + YYDEBUG(156, *YYCURSOR); + if (yybm[0+yych] & 64) { + goto yy149; } - YYDEBUG(122, *YYCURSOR); + if (yych <= '\f') { + if (yych <= 0x00) goto yy152; + if (yych == '\t') goto yy155; + } else { + if (yych <= '\r') goto yy155; + if (yych == ' ') goto yy155; + } + YYDEBUG(157, *YYCURSOR); yyleng = (size_t) YYCURSOR - (size_t) yytext; -#line 139 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 147 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" { /* ignore whitespace */ goto restart; } -#line 1139 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c" +#line 1515 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.c" } } -#line 168 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l" +#line 183 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_lexer.l" } diff --git a/sapi/phpdbg/phpdbg_lexer.h b/sapi/phpdbg/phpdbg_lexer.h index d060e08fc3..5c357df7d5 100644 --- a/sapi/phpdbg/phpdbg_lexer.h +++ b/sapi/phpdbg/phpdbg_lexer.h @@ -34,7 +34,7 @@ typedef struct { #define yyparse phpdbg_parse #define yylex phpdbg_lex -void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC); +void phpdbg_init_lexer (phpdbg_param_t *stack, char *input); int phpdbg_lex (phpdbg_param_t* yylval); diff --git a/sapi/phpdbg/phpdbg_lexer.l b/sapi/phpdbg/phpdbg_lexer.l index 7b3ce38c47..b9cdc65d22 100644 --- a/sapi/phpdbg/phpdbg_lexer.l +++ b/sapi/phpdbg/phpdbg_lexer.l @@ -21,12 +21,13 @@ #define YYFILL(n) #define NORMAL 0 -#define RAW 1 -#define INITIAL 2 +#define PRE_RAW 1 +#define RAW 2 +#define INITIAL 3 ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC) { +void phpdbg_init_lexer (phpdbg_param_t *stack, char *input) { PHPDBG_G(parser_stack) = stack; YYSETCONDITION(INITIAL); @@ -36,7 +37,6 @@ void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC) { } int phpdbg_lex (phpdbg_param_t* yylval) { - TSRMLS_FETCH(); /* Slow, but this is not a major problem here. TODO: Use TSRMLS_DC */ restart: LEX(text) = YYCURSOR; @@ -65,10 +65,17 @@ INPUT [^\n\000]+ <!*> := yyleng = (size_t) YYCURSOR - (size_t) yytext; -<*>[\n\000] { +<*>{WS}?[\n\000] { return 0; } +<PRE_RAW, NORMAL>[-][r]{WS}?{DIGITS} { + char *text = yytext + 2; + while (*++text < '0'); + yylval->num = atoi(text); + return T_REQ_ID; +} + <NORMAL>{T_IF}{WS} { YYSETCONDITION(RAW); phpdbg_init_param(yylval, EMPTY_PARAM); @@ -93,7 +100,7 @@ INPUT [^\n\000]+ <NORMAL>({T_YES}|{T_ON}|{T_ENABLED}|{T_TRUE}){WS} { phpdbg_init_param(yylval, NUMERIC_PARAM); - yylval->num = 1; + yylval->num = 1; return T_TRUTHY; } @@ -126,7 +133,7 @@ INPUT [^\n\000]+ phpdbg_init_param(yylval, STR_PARAM); yylval->str = zend_strndup(yytext, yyleng); yylval->len = yyleng; - return T_ID; + return T_ID; } <RAW>{INPUT} { @@ -143,21 +150,28 @@ INPUT [^\n\000]+ } <INITIAL>{T_EVAL}{WS} { - YYSETCONDITION(RAW); + YYSETCONDITION(PRE_RAW); phpdbg_init_param(yylval, EMPTY_PARAM); return T_EVAL; } <INITIAL>{T_SHELL}{WS} { - YYSETCONDITION(RAW); + YYSETCONDITION(PRE_RAW); phpdbg_init_param(yylval, EMPTY_PARAM); return T_SHELL; } <INITIAL>({T_RUN}|{T_RUN_SHORT}){WS} { - YYSETCONDITION(RAW); + YYSETCONDITION(PRE_RAW); phpdbg_init_param(yylval, EMPTY_PARAM); return T_RUN; } +<PRE_RAW>. { + YYSETCONDITION(RAW); + + YYCURSOR = LEX(text); + goto restart; +} + <INITIAL>. { YYSETCONDITION(NORMAL); diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.c index 0709b58ff3..b2a621e561 100644 --- a/sapi/phpdbg/phpdbg_list.c +++ b/sapi/phpdbg/phpdbg_list.c @@ -34,35 +34,37 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -#define PHPDBG_LIST_COMMAND_D(f, h, a, m, l, s) \ - PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[13]) +#define PHPDBG_LIST_COMMAND_D(f, h, a, m, l, s, flags) \ + PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[13], flags) const phpdbg_command_t phpdbg_list_commands[] = { - PHPDBG_LIST_COMMAND_D(lines, "lists the specified lines", 'l', list_lines, NULL, "l"), - PHPDBG_LIST_COMMAND_D(class, "lists the specified class", 'c', list_class, NULL, "s"), - PHPDBG_LIST_COMMAND_D(method, "lists the specified method", 'm', list_method, NULL, "m"), - PHPDBG_LIST_COMMAND_D(func, "lists the specified function", 'f', list_func, NULL, "s"), + PHPDBG_LIST_COMMAND_D(lines, "lists the specified lines", 'l', list_lines, NULL, "l", PHPDBG_ASYNC_SAFE), + PHPDBG_LIST_COMMAND_D(class, "lists the specified class", 'c', list_class, NULL, "s", PHPDBG_ASYNC_SAFE), + PHPDBG_LIST_COMMAND_D(method, "lists the specified method", 'm', list_method, NULL, "m", PHPDBG_ASYNC_SAFE), + PHPDBG_LIST_COMMAND_D(func, "lists the specified function", 'f', list_func, NULL, "s", PHPDBG_ASYNC_SAFE), PHPDBG_END_COMMAND }; PHPDBG_LIST(lines) /* {{{ */ { - if (!PHPDBG_G(exec) && !zend_is_executing(TSRMLS_C)) { - phpdbg_error("Not executing, and execution context not set"); + if (!PHPDBG_G(exec) && !zend_is_executing()) { + phpdbg_error("inactive", "type=\"execution\"", "Not executing, and execution context not set"); return SUCCESS; } switch (param->type) { - case NUMERIC_PARAM: - phpdbg_list_file(phpdbg_current_file(TSRMLS_C), - (param->num < 0 ? 1 - param->num : param->num), - (param->num < 0 ? param->num : 0) + zend_get_executed_lineno(TSRMLS_C), - 0 TSRMLS_CC); - break; - - case FILE_PARAM: - phpdbg_list_file(param->file.name, param->file.line, 0, 0 TSRMLS_CC); - break; + case NUMERIC_PARAM: { + const char *char_file = phpdbg_current_file(); + zend_string *file = zend_string_init(char_file, strlen(char_file), 0); + phpdbg_list_file(file, param->num < 0 ? 1 - param->num : param->num, (param->num < 0 ? param->num : 0) + zend_get_executed_lineno(), 0); + efree(file); + } break; + + case FILE_PARAM: { + zend_string *file = zend_string_init(param->file.name, strlen(param->file.name), 0); + phpdbg_list_file(file, param->file.line, 0, 0); + efree(file); + } break; phpdbg_default_switch_case(); } @@ -72,28 +74,28 @@ PHPDBG_LIST(lines) /* {{{ */ PHPDBG_LIST(func) /* {{{ */ { - phpdbg_list_function_byname(param->str, param->len TSRMLS_CC); + phpdbg_list_function_byname(param->str, param->len); return SUCCESS; } /* }}} */ PHPDBG_LIST(method) /* {{{ */ { - zend_class_entry **ce; + zend_class_entry *ce; - if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) { + if (phpdbg_safe_class_lookup(param->method.class, strlen(param->method.class), &ce) == SUCCESS) { zend_function *function; char *lcname = zend_str_tolower_dup(param->method.name, strlen(param->method.name)); - if (zend_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**) &function) == SUCCESS) { - phpdbg_list_function(function TSRMLS_CC); + if ((function = zend_hash_str_find_ptr(&ce->function_table, lcname, strlen(lcname)))) { + phpdbg_list_function(function); } else { - phpdbg_error("Could not find %s::%s", param->method.class, param->method.name); + phpdbg_error("list", "type=\"notfound\" method=\"%s::%s\"", "Could not find %s::%s", param->method.class, param->method.name); } efree(lcname); } else { - phpdbg_error("Could not find the class %s", param->method.class); + phpdbg_error("list", "type=\"notfound\" class=\"%s\"", "Could not find the class %s", param->method.class); } return SUCCESS; @@ -101,100 +103,94 @@ PHPDBG_LIST(method) /* {{{ */ PHPDBG_LIST(class) /* {{{ */ { - zend_class_entry **ce; - - if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) { - if ((*ce)->type == ZEND_USER_CLASS) { - if ((*ce)->info.user.filename) { - phpdbg_list_file( - (*ce)->info.user.filename, - (*ce)->info.user.line_end - (*ce)->info.user.line_start + 1, - (*ce)->info.user.line_start, 0 TSRMLS_CC - ); + zend_class_entry *ce; + + if (phpdbg_safe_class_lookup(param->str, param->len, &ce) == SUCCESS) { + if (ce->type == ZEND_USER_CLASS) { + if (ce->info.user.filename) { + phpdbg_list_file(ce->info.user.filename, ce->info.user.line_end - ce->info.user.line_start + 1, ce->info.user.line_start, 0); } else { - phpdbg_error("The source of the requested class (%s) cannot be found", (*ce)->name); + phpdbg_error("list", "type=\"nosource\" class=\"%s\"", "The source of the requested class (%s) cannot be found", ce->name); } } else { - phpdbg_error("The class requested (%s) is not user defined", (*ce)->name); + phpdbg_error("list", "type=\"internalclass\" class=\"%s\"", "The class requested (%s) is not user defined", ce->name); } } else { - phpdbg_error("The requested class (%s) could not be found", param->str); + phpdbg_error("list", "type=\"notfound\" class=\"%s\"", "The requested class (%s) could not be found", param->str); } return SUCCESS; } /* }}} */ -void phpdbg_list_file(const char *filename, long count, long offset, int highlight TSRMLS_DC) /* {{{ */ +void phpdbg_list_file(zend_string *filename, uint count, int offset, uint highlight) /* {{{ */ { - struct stat st; - char *opened = NULL; - char buffer[8096] = {0,}; - long line = 0; - - php_stream *stream = NULL; - - if (VCWD_STAT(filename, &st) == FAILURE) { - phpdbg_error("Failed to stat file %s", filename); - return; + uint line, lastline; + phpdbg_file_source *data; + char resolved_path_buf[MAXPATHLEN]; + const char *abspath; + + if (VCWD_REALPATH(filename->val, resolved_path_buf)) { + abspath = resolved_path_buf; + } else { + abspath = filename->val; } - stream = php_stream_open_wrapper(filename, "rb", USE_PATH, &opened); - - if (!stream) { - phpdbg_error("Failed to open file %s to list", filename); + if (!(data = zend_hash_str_find_ptr(&PHPDBG_G(file_sources), abspath, strlen(abspath)))) { + phpdbg_error("list", "type=\"unknownfile\"", "Could not find information about included file..."); return; } - + if (offset < 0) { count += offset; offset = 0; } - - while (php_stream_gets(stream, buffer, sizeof(buffer)) != NULL) { - long linelen = strlen(buffer); - ++line; - - if (offset <= line) { - if (!highlight) { - phpdbg_write("%05ld: %s", line, buffer); - } else { - if (highlight != line) { - phpdbg_write(" %05ld: %s", line, buffer); - } else { - phpdbg_write(">%05ld: %s", line, buffer); - } - } + lastline = offset + count; + + if (lastline > data->lines) { + lastline = data->lines; + } + + phpdbg_xml("<list %r file=\"%s\">", filename); - if (buffer[linelen - 1] != '\n') { - phpdbg_write("\n"); + for (line = offset; line < lastline;) { + uint linestart = data->line[line++]; + uint linelen = data->line[line] - linestart; + char *buffer = data->buf + linestart; + + if (!highlight) { + phpdbg_write("line", "line=\"%u\" code=\"%.*s\"", " %05u: %.*s", line, linelen, buffer); + } else { + if (highlight != line) { + phpdbg_write("line", "line=\"%u\" code=\"%.*s\"", " %05u: %.*s", line, linelen, buffer); + } else { + phpdbg_write("line", "line=\"%u\" code=\"%.*s\" current=\"current\"", ">%05u: %.*s", line, linelen, buffer); } } - if (count > 0 && count + offset - 1 < line) { - break; + if (*(buffer + linelen - 1) != '\n' || !linelen) { + phpdbg_out("\n"); } } - - php_stream_close(stream); + + phpdbg_xml("</list>"); } /* }}} */ -void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */ +void phpdbg_list_function(const zend_function *fbc) /* {{{ */ { const zend_op_array *ops; if (fbc->type != ZEND_USER_FUNCTION) { - phpdbg_error("The function requested (%s) is not user defined", fbc->common.function_name); + phpdbg_error("list", "type=\"internalfunction\" function=\"%s\"", "The function requested (%s) is not user defined", fbc->common.function_name); return; } - ops = (zend_op_array*)fbc; + ops = (zend_op_array *) fbc; - phpdbg_list_file(ops->filename, - ops->line_end - ops->line_start + 1, ops->line_start, 0 TSRMLS_CC); + phpdbg_list_file(ops->filename, ops->line_end - ops->line_start + 1, ops->line_start, 0); } /* }}} */ -void phpdbg_list_function_byname(const char *str, size_t len TSRMLS_DC) /* {{{ */ +void phpdbg_list_function_byname(const char *str, size_t len) /* {{{ */ { HashTable *func_table = EG(function_table); zend_function* fbc; @@ -209,11 +205,11 @@ void phpdbg_list_function_byname(const char *str, size_t len TSRMLS_DC) /* {{{ * func_table = &EG(scope)->function_table; } else { - phpdbg_error("No active class"); + phpdbg_error("inactive", "type=\"noclasses\"", "No active class"); return; } } else if (!EG(function_table)) { - phpdbg_error("No function table loaded"); + phpdbg_error("inactive", "type=\"function_table\"", "No function table loaded"); return; } else { func_table = EG(function_table); @@ -222,12 +218,92 @@ void phpdbg_list_function_byname(const char *str, size_t len TSRMLS_DC) /* {{{ * /* use lowercase names, case insensitive */ func_name = zend_str_tolower_dup(func_name, func_name_len); - if (zend_hash_find(func_table, func_name, func_name_len+1, (void**)&fbc) == SUCCESS) { - phpdbg_list_function(fbc TSRMLS_CC); - } else { - phpdbg_error("Function %s not found", func_name); - } + phpdbg_try_access { + if ((fbc = zend_hash_str_find_ptr(func_table, func_name, func_name_len))) { + phpdbg_list_function(fbc); + } else { + phpdbg_error("list", "type=\"nofunction\" function=\"%s\"", "Function %s not found", func_name); + } + } phpdbg_catch_access { + phpdbg_error("signalsegv", "function=\"%s\"", "Could not list function %s, invalid data source", func_name); + } phpdbg_end_try_access(); efree(func_name); } /* }}} */ +zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) { + phpdbg_file_source data, *dataptr; + zend_file_handle fake = {{0}}; + zend_op_array *ret; + char *filename = (char *)(file->opened_path ? file->opened_path : file->filename); + uint line; + char *bufptr, *endptr; + char resolved_path_buf[MAXPATHLEN]; + + zend_stream_fixup(file, &data.buf, &data.len); + + data.filename = filename; + data.line[0] = 0; + + if (file->handle.stream.mmap.old_closer) { + /* do not unmap */ + file->handle.stream.closer = file->handle.stream.mmap.old_closer; + } + +#if HAVE_MMAP + if (file->handle.stream.mmap.map) { + data.map = file->handle.stream.mmap.map; + } +#endif + + fake.type = ZEND_HANDLE_MAPPED; + fake.handle.stream.mmap.buf = data.buf; + fake.handle.stream.mmap.len = data.len; + fake.free_filename = 0; + fake.opened_path = file->opened_path; + fake.filename = filename; + fake.opened_path = file->opened_path; + + *(dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint) * data.len)) = data; + if (VCWD_REALPATH(filename, resolved_path_buf)) { + filename = resolved_path_buf; + } + + for (line = 0, bufptr = data.buf - 1, endptr = data.buf + data.len; ++bufptr < endptr;) { + if (*bufptr == '\n') { + dataptr->line[++line] = (uint)(bufptr - data.buf) + 1; + } + } + dataptr->lines = ++line; + dataptr->line[line] = endptr - data.buf; + dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line); + + zend_hash_str_add_ptr(&PHPDBG_G(file_sources), filename, strlen(filename), dataptr); + phpdbg_resolve_pending_file_break(filename); + + ret = PHPDBG_G(compile_file)(&fake, type); + + fake.opened_path = NULL; + zend_file_handle_dtor(&fake); + + return ret; +} + +void phpdbg_free_file_source(phpdbg_file_source *data) { +#if HAVE_MMAP + if (data->map) { + munmap(data->map, data->len + ZEND_MMAP_AHEAD); + } else +#endif + if (data->buf) { + efree(data->buf); + } + + efree(data); +} + +void phpdbg_init_list(void) { + PHPDBG_G(compile_file) = zend_compile_file; + zend_hash_init(&PHPDBG_G(file_sources), 1, NULL, (dtor_func_t) phpdbg_free_file_source, 0); + zend_compile_file = phpdbg_compile_file; +} diff --git a/sapi/phpdbg/phpdbg_list.h b/sapi/phpdbg/phpdbg_list.h index 1530a8bbba..46e3395edb 100644 --- a/sapi/phpdbg/phpdbg_list.h +++ b/sapi/phpdbg/phpdbg_list.h @@ -32,10 +32,23 @@ PHPDBG_LIST(class); PHPDBG_LIST(method); PHPDBG_LIST(func); -void phpdbg_list_function_byname(const char *, size_t TSRMLS_DC); -void phpdbg_list_function(const zend_function* TSRMLS_DC); -void phpdbg_list_file(const char*, long, long, int TSRMLS_DC); +void phpdbg_list_function_byname(const char *, size_t); +void phpdbg_list_function(const zend_function *); +void phpdbg_list_file(zend_string *, uint, int, uint); extern const phpdbg_command_t phpdbg_list_commands[]; +void phpdbg_init_list(void); + +typedef struct { + char *filename; + char *buf; + size_t len; +#if HAVE_MMAP + void *map; +#endif + uint lines; + uint line[1]; +} phpdbg_file_source; + #endif /* PHPDBG_LIST_H */ diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c index 1229b7e3a8..a0b20bb9c7 100644 --- a/sapi/phpdbg/phpdbg_opcode.c +++ b/sapi/phpdbg/phpdbg_opcode.c @@ -26,7 +26,7 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -static inline zend_uint phpdbg_decode_literal(zend_op_array *ops, zend_literal *literal TSRMLS_DC) /* {{{ */ +static inline uint32_t phpdbg_decode_literal(zend_op_array *ops, zval *literal) /* {{{ */ { int iter = 0; @@ -40,32 +40,31 @@ static inline zend_uint phpdbg_decode_literal(zend_op_array *ops, zend_literal * return 0; } /* }}} */ -static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, zend_uint type, HashTable *vars TSRMLS_DC) /* {{{ */ +static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, uint32_t type, HashTable *vars) /* {{{ */ { char *decode = NULL; switch (type &~ EXT_TYPE_UNUSED) { case IS_CV: - asprintf(&decode, "$%s", ops->vars[op->var].name); + asprintf(&decode, "$%s", ops->vars[EX_VAR_TO_NUM(op->var)]->val); break; case IS_VAR: case IS_TMP_VAR: { zend_ulong id = 0, *pid = NULL; if (vars != NULL) { - if (zend_hash_index_find(vars, (zend_ulong) ops->vars - op->var, (void**) &pid) != SUCCESS) { + if ((pid = zend_hash_index_find_ptr(vars, (zend_ulong) ops->vars - op->var))) { + id = *pid; + } else { id = zend_hash_num_elements(vars); - zend_hash_index_update( - vars, (zend_ulong) ops->vars - op->var, - (void**) &id, - sizeof(zend_ulong), NULL); - } else id = *pid; + zend_hash_index_update_mem(vars, (zend_ulong) ops->vars - op->var, &id, sizeof(zend_ulong)); + } } - asprintf(&decode, "@%lu", id); + asprintf(&decode, "@%llu", id); } break; case IS_CONST: - asprintf(&decode, "C%u", phpdbg_decode_literal(ops, op->literal TSRMLS_CC)); + asprintf(&decode, "C%u", phpdbg_decode_literal(ops, RT_CONSTANT(ops, *op))); break; case IS_UNUSED: @@ -75,7 +74,7 @@ static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, zend_uint return decode; } /* }}} */ -char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRMLS_DC) /*{{{ */ +char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars) /*{{{ */ { char *decode[4] = {NULL, NULL, NULL, NULL}; @@ -87,13 +86,12 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRM #ifdef ZEND_FAST_CALL case ZEND_FAST_CALL: #endif - asprintf(&decode[1], "J%ld", op->op1.jmp_addr - ops->opcodes); + asprintf(&decode[1], "J%ld", OP_JMP_ADDR(op, op->op1) - ops->opcodes); goto format; case ZEND_JMPZNZ: - decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC); - asprintf( - &decode[2], "J%u or J%lu", op->op2.opline_num, op->extended_value); + decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars); + asprintf(&decode[2], "J%u or J%llu", op->op2.opline_num, op->extended_value); goto result; case ZEND_JMPZ: @@ -104,25 +102,20 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRM #ifdef ZEND_JMP_SET case ZEND_JMP_SET: #endif -#ifdef ZEND_JMP_SET_VAR - case ZEND_JMP_SET_VAR: -#endif - decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC); - asprintf( - &decode[2], "J%ld", op->op2.jmp_addr - ops->opcodes); + decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars); + asprintf(&decode[2], "J%ld", OP_JMP_ADDR(op, op->op2) - ops->opcodes); goto result; case ZEND_RECV_INIT: goto result; default: { - decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC); - decode[2] = phpdbg_decode_op(ops, &op->op2, op->op2_type, vars TSRMLS_CC); + decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars); + decode[2] = phpdbg_decode_op(ops, &op->op2, op->op2_type, vars); result: - decode[3] = phpdbg_decode_op(ops, &op->result, op->result_type, vars TSRMLS_CC); + decode[3] = phpdbg_decode_op(ops, &op->result, op->result_type, vars); format: - asprintf( - &decode[0], + asprintf(&decode[0], "%-20s %-20s %-20s", decode[1] ? decode[1] : "", decode[2] ? decode[2] : "", @@ -140,7 +133,7 @@ format: return decode[0]; } /* }}} */ -void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, zend_bool ignore_flags TSRMLS_DC) /* {{{ */ +void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, zend_bool ignore_flags) /* {{{ */ { /* force out a line while stepping so the user knows what is happening */ if (ignore_flags || @@ -148,26 +141,26 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, ze (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) || (PHPDBG_G(oplog)))) { - zend_op *opline = execute_data->opline; - char *decode = phpdbg_decode_opline(execute_data->op_array, opline, vars TSRMLS_CC); + zend_op *opline = (zend_op *) execute_data->opline; + char *decode = phpdbg_decode_opline(&execute_data->func->op_array, opline, vars); if (ignore_flags || (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) || (PHPDBG_G(flags) & PHPDBG_IS_STEPPING))) { /* output line info */ - phpdbg_notice("L%-5u %16p %-30s %s %s", + phpdbg_notice("opline", "line=\"%u\" opline=\"%p\" opcode=\"%s\" op=\"%s\" file=\"%s\"", "L%-5u %16p %-30s %s %s", opline->lineno, opline, phpdbg_decode_opcode(opline->opcode), decode, - execute_data->op_array->filename ? execute_data->op_array->filename : "unknown"); + execute_data->func->op_array.filename ? execute_data->func->op_array.filename->val : "unknown"); } if (!ignore_flags && PHPDBG_G(oplog)) { - phpdbg_log_ex(PHPDBG_G(oplog), "L%-5u %16p %-30s %s %s", + phpdbg_log_ex(fileno(PHPDBG_G(oplog)), "L%-5u %16p %-30s %s %s", opline->lineno, opline, phpdbg_decode_opcode(opline->opcode), decode, - execute_data->op_array->filename ? execute_data->op_array->filename : "unknown"); + execute_data->func->op_array.filename ? execute_data->func->op_array.filename->val : "unknown"); } if (decode) { @@ -176,193 +169,13 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, ze } } /* }}} */ -void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC) /* {{{ */ +void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags) /* {{{ */ { - phpdbg_print_opline_ex(execute_data, NULL, ignore_flags TSRMLS_CC); + phpdbg_print_opline_ex(execute_data, NULL, ignore_flags); } /* }}} */ const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */ { -#if ZEND_EXTENSION_API_NO <= PHP_5_5_API_NO -#define CASE(s) case s: return #s - switch (opcode) { - CASE(ZEND_NOP); - CASE(ZEND_ADD); - CASE(ZEND_SUB); - CASE(ZEND_MUL); - CASE(ZEND_DIV); - CASE(ZEND_MOD); - CASE(ZEND_SL); - CASE(ZEND_SR); - CASE(ZEND_CONCAT); - CASE(ZEND_BW_OR); - CASE(ZEND_BW_AND); - CASE(ZEND_BW_XOR); - CASE(ZEND_BW_NOT); - CASE(ZEND_BOOL_NOT); - CASE(ZEND_BOOL_XOR); - CASE(ZEND_IS_IDENTICAL); - CASE(ZEND_IS_NOT_IDENTICAL); - CASE(ZEND_IS_EQUAL); - CASE(ZEND_IS_NOT_EQUAL); - CASE(ZEND_IS_SMALLER); - CASE(ZEND_IS_SMALLER_OR_EQUAL); - CASE(ZEND_CAST); - CASE(ZEND_QM_ASSIGN); - CASE(ZEND_ASSIGN_ADD); - CASE(ZEND_ASSIGN_SUB); - CASE(ZEND_ASSIGN_MUL); - CASE(ZEND_ASSIGN_DIV); - CASE(ZEND_ASSIGN_MOD); - CASE(ZEND_ASSIGN_SL); - CASE(ZEND_ASSIGN_SR); - CASE(ZEND_ASSIGN_CONCAT); - CASE(ZEND_ASSIGN_BW_OR); - CASE(ZEND_ASSIGN_BW_AND); - CASE(ZEND_ASSIGN_BW_XOR); - CASE(ZEND_PRE_INC); - CASE(ZEND_PRE_DEC); - CASE(ZEND_POST_INC); - CASE(ZEND_POST_DEC); - CASE(ZEND_ASSIGN); - CASE(ZEND_ASSIGN_REF); - CASE(ZEND_ECHO); - CASE(ZEND_PRINT); - CASE(ZEND_JMP); - CASE(ZEND_JMPZ); - CASE(ZEND_JMPNZ); - CASE(ZEND_JMPZNZ); - CASE(ZEND_JMPZ_EX); - CASE(ZEND_JMPNZ_EX); - CASE(ZEND_CASE); - CASE(ZEND_SWITCH_FREE); - CASE(ZEND_BRK); - CASE(ZEND_CONT); - CASE(ZEND_BOOL); - CASE(ZEND_INIT_STRING); - CASE(ZEND_ADD_CHAR); - CASE(ZEND_ADD_STRING); - CASE(ZEND_ADD_VAR); - CASE(ZEND_BEGIN_SILENCE); - CASE(ZEND_END_SILENCE); - CASE(ZEND_INIT_FCALL_BY_NAME); - CASE(ZEND_DO_FCALL); - CASE(ZEND_DO_FCALL_BY_NAME); - CASE(ZEND_RETURN); - CASE(ZEND_RECV); - CASE(ZEND_RECV_INIT); - CASE(ZEND_SEND_VAL); - CASE(ZEND_SEND_VAR); - CASE(ZEND_SEND_REF); - CASE(ZEND_NEW); - CASE(ZEND_INIT_NS_FCALL_BY_NAME); - CASE(ZEND_FREE); - CASE(ZEND_INIT_ARRAY); - CASE(ZEND_ADD_ARRAY_ELEMENT); - CASE(ZEND_INCLUDE_OR_EVAL); - CASE(ZEND_UNSET_VAR); - CASE(ZEND_UNSET_DIM); - CASE(ZEND_UNSET_OBJ); - CASE(ZEND_FE_RESET); - CASE(ZEND_FE_FETCH); - CASE(ZEND_EXIT); - CASE(ZEND_FETCH_R); - CASE(ZEND_FETCH_DIM_R); - CASE(ZEND_FETCH_OBJ_R); - CASE(ZEND_FETCH_W); - CASE(ZEND_FETCH_DIM_W); - CASE(ZEND_FETCH_OBJ_W); - CASE(ZEND_FETCH_RW); - CASE(ZEND_FETCH_DIM_RW); - CASE(ZEND_FETCH_OBJ_RW); - CASE(ZEND_FETCH_IS); - CASE(ZEND_FETCH_DIM_IS); - CASE(ZEND_FETCH_OBJ_IS); - CASE(ZEND_FETCH_FUNC_ARG); - CASE(ZEND_FETCH_DIM_FUNC_ARG); - CASE(ZEND_FETCH_OBJ_FUNC_ARG); - CASE(ZEND_FETCH_UNSET); - CASE(ZEND_FETCH_DIM_UNSET); - CASE(ZEND_FETCH_OBJ_UNSET); - CASE(ZEND_FETCH_DIM_TMP_VAR); - CASE(ZEND_FETCH_CONSTANT); - CASE(ZEND_GOTO); - CASE(ZEND_EXT_STMT); - CASE(ZEND_EXT_FCALL_BEGIN); - CASE(ZEND_EXT_FCALL_END); - CASE(ZEND_EXT_NOP); - CASE(ZEND_TICKS); - CASE(ZEND_SEND_VAR_NO_REF); - CASE(ZEND_CATCH); - CASE(ZEND_THROW); - CASE(ZEND_FETCH_CLASS); - CASE(ZEND_CLONE); - CASE(ZEND_RETURN_BY_REF); - CASE(ZEND_INIT_METHOD_CALL); - CASE(ZEND_INIT_STATIC_METHOD_CALL); - CASE(ZEND_ISSET_ISEMPTY_VAR); - CASE(ZEND_ISSET_ISEMPTY_DIM_OBJ); - CASE(ZEND_PRE_INC_OBJ); - CASE(ZEND_PRE_DEC_OBJ); - CASE(ZEND_POST_INC_OBJ); - CASE(ZEND_POST_DEC_OBJ); - CASE(ZEND_ASSIGN_OBJ); - CASE(ZEND_INSTANCEOF); - CASE(ZEND_DECLARE_CLASS); - CASE(ZEND_DECLARE_INHERITED_CLASS); - CASE(ZEND_DECLARE_FUNCTION); - CASE(ZEND_RAISE_ABSTRACT_ERROR); - CASE(ZEND_DECLARE_CONST); - CASE(ZEND_ADD_INTERFACE); - CASE(ZEND_DECLARE_INHERITED_CLASS_DELAYED); - CASE(ZEND_VERIFY_ABSTRACT_CLASS); - CASE(ZEND_ASSIGN_DIM); - CASE(ZEND_ISSET_ISEMPTY_PROP_OBJ); - CASE(ZEND_HANDLE_EXCEPTION); - CASE(ZEND_USER_OPCODE); -#ifdef ZEND_JMP_SET - CASE(ZEND_JMP_SET); -#endif - CASE(ZEND_DECLARE_LAMBDA_FUNCTION); -#ifdef ZEND_ADD_TRAIT - CASE(ZEND_ADD_TRAIT); -#endif -#ifdef ZEND_BIND_TRAITS - CASE(ZEND_BIND_TRAITS); -#endif -#ifdef ZEND_SEPARATE - CASE(ZEND_SEPARATE); -#endif -#ifdef ZEND_QM_ASSIGN_VAR - CASE(ZEND_QM_ASSIGN_VAR); -#endif -#ifdef ZEND_JMP_SET_VAR - CASE(ZEND_JMP_SET_VAR); -#endif -#ifdef ZEND_DISCARD_EXCEPTION - CASE(ZEND_DISCARD_EXCEPTION); -#endif -#ifdef ZEND_YIELD - CASE(ZEND_YIELD); -#endif -#ifdef ZEND_GENERATOR_RETURN - CASE(ZEND_GENERATOR_RETURN); -#endif -#ifdef ZEND_FAST_CALL - CASE(ZEND_FAST_CALL); -#endif -#ifdef ZEND_FAST_RET - CASE(ZEND_FAST_RET); -#endif -#ifdef ZEND_RECV_VARIADIC - CASE(ZEND_RECV_VARIADIC); -#endif - CASE(ZEND_OP_DATA); - default: - return "UNKNOWN"; - } -#else const char *ret = zend_get_opcode_name(opcode); return ret?ret:"UNKNOWN"; -#endif } /* }}} */ diff --git a/sapi/phpdbg/phpdbg_opcode.h b/sapi/phpdbg/phpdbg_opcode.h index 6005181b75..d566c9f715 100644 --- a/sapi/phpdbg/phpdbg_opcode.h +++ b/sapi/phpdbg/phpdbg_opcode.h @@ -24,8 +24,8 @@ #include "zend_types.h" const char *phpdbg_decode_opcode(zend_uchar); -char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRMLS_DC); -void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC); -void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, zend_bool ignore_flags TSRMLS_DC); +char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars); +void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags); +void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, zend_bool ignore_flags); #endif /* PHPDBG_OPCODE_H */ diff --git a/sapi/phpdbg/phpdbg_out.c b/sapi/phpdbg/phpdbg_out.c new file mode 100644 index 0000000000..23366e1bf7 --- /dev/null +++ b/sapi/phpdbg/phpdbg_out.c @@ -0,0 +1,1320 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Felipe Pena <felipe@php.net> | + | Authors: Joe Watkins <joe.watkins@live.co.uk> | + | Authors: Bob Weinand <bwoebi@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include "zend.h" +#include "php.h" +#include "spprintf.h" +#include "phpdbg.h" +#include "phpdbg_io.h" +#include "phpdbg_eol.h" +#include "ext/standard/html.h" + +#ifdef _WIN32 +# include "win32/time.h" +#endif + +ZEND_EXTERN_MODULE_GLOBALS(phpdbg); + +/* copied from php-src/main/snprintf.c and slightly modified */ +/* + * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions + * + * XXX: this is a magic number; do not decrease it + * Emax = 1023 + * NDIG = 320 + * NUM_BUF_SIZE >= strlen("-") + Emax + strlrn(".") + NDIG + strlen("E+1023") + 1; + */ +#define NUM_BUF_SIZE 2048 + +/* + * Descriptor for buffer area + */ +struct buf_area { + char *buf_end; + char *nextb; /* pointer to next byte to read/write */ +}; + +typedef struct buf_area buffy; + +/* + * The INS_CHAR macro inserts a character in the buffer and writes + * the buffer back to disk if necessary + * It uses the char pointers sp and bep: + * sp points to the next available character in the buffer + * bep points to the end-of-buffer+1 + * While using this macro, note that the nextb pointer is NOT updated. + * + * NOTE: Evaluation of the c argument should not have any side-effects + */ +#define INS_CHAR(c, sp, bep, cc) \ + { \ + if (sp < bep) \ + { \ + *sp++ = c; \ + } \ + cc++; \ + } + +#define NUM( c ) ( c - '0' ) + +#define STR_TO_DEC( str, num ) \ + num = NUM( *str++ ) ; \ + while ( isdigit((int)*str ) ) \ + { \ + num *= 10 ; \ + num += NUM( *str++ ) ; \ + } + +/* + * This macro does zero padding so that the precision + * requirement is satisfied. The padding is done by + * adding '0's to the left of the string that is going + * to be printed. + */ +#define FIX_PRECISION( adjust, precision, s, s_len ) \ + if ( adjust ) \ + while ( s_len < precision ) \ + { \ + *--s = '0' ; \ + s_len++ ; \ + } + +/* + * Macro that does padding. The padding is done by printing + * the character ch. + */ +#define PAD( width, len, ch ) do \ + { \ + INS_CHAR( ch, sp, bep, cc ) ; \ + width-- ; \ + } \ + while ( width > len ) + +/* + * Prefix the character ch to the string str + * Increase length + * Set the has_prefix flag + */ +#define PREFIX( str, length, ch ) *--str = ch ; length++ ; has_prefix = YES + + +#ifdef HAVE_LOCALE_H +#include <locale.h> +#define LCONV_DECIMAL_POINT (*lconv->decimal_point) +#else +#define LCONV_DECIMAL_POINT '.' +#endif +#define NUL '\0' +#define S_NULL "(null)" +#define S_NULL_LEN 6 +#define FLOAT_DIGITS 6 + +/* + * Do format conversion placing the output in buffer + */ +static int format_converter(register buffy *odp, const char *fmt, zend_bool escape_xml, va_list ap) { + char *sp; + char *bep; + int cc = 0; + int i; + + char *s = NULL, *free_s = NULL; + size_t s_len; + zend_bool free_zcopy; + zval *zvp, zcopy; + + int min_width = 0; + int precision = 0; + enum { + LEFT, RIGHT + } adjust; + char pad_char; + char prefix_char; + + double fp_num; + wide_int i_num = (wide_int) 0; + u_wide_int ui_num; + + char num_buf[NUM_BUF_SIZE]; + char char_buf[2]; /* for printing %% and %<unknown> */ + +#ifdef HAVE_LOCALE_H + struct lconv *lconv = NULL; +#endif + + /* + * Flag variables + */ + length_modifier_e modifier; + boolean_e alternate_form; + boolean_e print_sign; + boolean_e print_blank; + boolean_e adjust_precision; + boolean_e adjust_width; + bool_int is_negative; + + sp = odp->nextb; + bep = odp->buf_end; + + while (*fmt) { + if (*fmt != '%') { + INS_CHAR(*fmt, sp, bep, cc); + } else { + /* + * Default variable settings + */ + adjust = RIGHT; + alternate_form = print_sign = print_blank = NO; + pad_char = ' '; + prefix_char = NUL; + free_zcopy = 0; + + fmt++; + + /* + * Try to avoid checking for flags, width or precision + */ + if (isascii((int)*fmt) && !islower((int)*fmt)) { + /* + * Recognize flags: -, #, BLANK, + + */ + for (;; fmt++) { + if (*fmt == '-') + adjust = LEFT; + else if (*fmt == '+') + print_sign = YES; + else if (*fmt == '#') + alternate_form = YES; + else if (*fmt == ' ') + print_blank = YES; + else if (*fmt == '0') + pad_char = '0'; + else + break; + } + + /* + * Check if a width was specified + */ + if (isdigit((int)*fmt)) { + STR_TO_DEC(fmt, min_width); + adjust_width = YES; + } else if (*fmt == '*') { + min_width = va_arg(ap, int); + fmt++; + adjust_width = YES; + if (min_width < 0) { + adjust = LEFT; + min_width = -min_width; + } + } else + adjust_width = NO; + + /* + * Check if a precision was specified + */ + if (*fmt == '.') { + adjust_precision = YES; + fmt++; + if (isdigit((int)*fmt)) { + STR_TO_DEC(fmt, precision); + } else if (*fmt == '*') { + precision = va_arg(ap, int); + fmt++; + if (precision < 0) + precision = 0; + } else + precision = 0; + + if (precision > FORMAT_CONV_MAX_PRECISION && *fmt != 's' && *fmt != 'v' && *fmt != 'b') { + precision = FORMAT_CONV_MAX_PRECISION; + } + } else + adjust_precision = NO; + } else + adjust_precision = adjust_width = NO; + + /* + * Modifier check + */ + switch (*fmt) { + case 'L': + fmt++; + modifier = LM_LONG_DOUBLE; + break; + case 'I': + fmt++; +#if SIZEOF_LONG_LONG + if (*fmt == '6' && *(fmt+1) == '4') { + fmt += 2; + modifier = LM_LONG_LONG; + } else +#endif + if (*fmt == '3' && *(fmt+1) == '2') { + fmt += 2; + modifier = LM_LONG; + } else { +#ifdef _WIN64 + modifier = LM_LONG_LONG; +#else + modifier = LM_LONG; +#endif + } + break; + case 'l': + fmt++; +#if SIZEOF_LONG_LONG + if (*fmt == 'l') { + fmt++; + modifier = LM_LONG_LONG; + } else +#endif + modifier = LM_LONG; + break; + case 'z': + fmt++; + modifier = LM_SIZE_T; + break; + case 'j': + fmt++; +#if SIZEOF_INTMAX_T + modifier = LM_INTMAX_T; +#else + modifier = LM_SIZE_T; +#endif + break; + case 't': + fmt++; +#if SIZEOF_PTRDIFF_T + modifier = LM_PTRDIFF_T; +#else + modifier = LM_SIZE_T; +#endif + break; + case 'h': + fmt++; + if (*fmt == 'h') { + fmt++; + } + /* these are promoted to int, so no break */ + default: + modifier = LM_STD; + break; + } + + /* + * Argument extraction and printing. + * First we determine the argument type. + * Then, we convert the argument to a string. + * On exit from the switch, s points to the string that + * must be printed, s_len has the length of the string + * The precision requirements, if any, are reflected in s_len. + * + * NOTE: pad_char may be set to '0' because of the 0 flag. + * It is reset to ' ' by non-numeric formats + */ + switch (*fmt) { + case 'Z': + zvp = (zval *) va_arg(ap, zval *); + free_zcopy = zend_make_printable_zval(zvp, &zcopy); + if (free_zcopy) { + zvp = &zcopy; + } + s_len = Z_STRLEN_P(zvp); + s = Z_STRVAL_P(zvp); + if (adjust_precision && precision < s_len) { + s_len = precision; + } + break; + case 'u': + switch(modifier) { + default: + i_num = (wide_int) va_arg(ap, unsigned int); + break; + case LM_LONG_DOUBLE: + goto fmt_error; + case LM_LONG: + i_num = (wide_int) va_arg(ap, unsigned long int); + break; + case LM_SIZE_T: + i_num = (wide_int) va_arg(ap, size_t); + break; +#if SIZEOF_LONG_LONG + case LM_LONG_LONG: + i_num = (wide_int) va_arg(ap, u_wide_int); + break; +#endif +#if SIZEOF_INTMAX_T + case LM_INTMAX_T: + i_num = (wide_int) va_arg(ap, uintmax_t); + break; +#endif +#if SIZEOF_PTRDIFF_T + case LM_PTRDIFF_T: + i_num = (wide_int) va_arg(ap, ptrdiff_t); + break; +#endif + } + /* + * The rest also applies to other integer formats, so fall + * into that case. + */ + case 'd': + case 'i': + /* + * Get the arg if we haven't already. + */ + if ((*fmt) != 'u') { + switch(modifier) { + default: + i_num = (wide_int) va_arg(ap, int); + break; + case LM_LONG_DOUBLE: + goto fmt_error; + case LM_LONG: + i_num = (wide_int) va_arg(ap, long int); + break; + case LM_SIZE_T: +#if SIZEOF_SSIZE_T + i_num = (wide_int) va_arg(ap, ssize_t); +#else + i_num = (wide_int) va_arg(ap, size_t); +#endif + break; +#if SIZEOF_LONG_LONG + case LM_LONG_LONG: + i_num = (wide_int) va_arg(ap, wide_int); + break; +#endif +#if SIZEOF_INTMAX_T + case LM_INTMAX_T: + i_num = (wide_int) va_arg(ap, intmax_t); + break; +#endif +#if SIZEOF_PTRDIFF_T + case LM_PTRDIFF_T: + i_num = (wide_int) va_arg(ap, ptrdiff_t); + break; +#endif + } + } + s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, + &num_buf[NUM_BUF_SIZE], &s_len); + FIX_PRECISION(adjust_precision, precision, s, s_len); + + if (*fmt != 'u') { + if (is_negative) { + prefix_char = '-'; + } else if (print_sign) { + prefix_char = '+'; + } else if (print_blank) { + prefix_char = ' '; + } + } + break; + + + case 'o': + switch(modifier) { + default: + ui_num = (u_wide_int) va_arg(ap, unsigned int); + break; + case LM_LONG_DOUBLE: + goto fmt_error; + case LM_LONG: + ui_num = (u_wide_int) va_arg(ap, unsigned long int); + break; + case LM_SIZE_T: + ui_num = (u_wide_int) va_arg(ap, size_t); + break; +#if SIZEOF_LONG_LONG + case LM_LONG_LONG: + ui_num = (u_wide_int) va_arg(ap, u_wide_int); + break; +#endif +#if SIZEOF_INTMAX_T + case LM_INTMAX_T: + ui_num = (u_wide_int) va_arg(ap, uintmax_t); + break; +#endif +#if SIZEOF_PTRDIFF_T + case LM_PTRDIFF_T: + ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); + break; +#endif + } + s = ap_php_conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); + FIX_PRECISION(adjust_precision, precision, s, s_len); + if (alternate_form && *s != '0') { + *--s = '0'; + s_len++; + } + break; + + + case 'x': + case 'X': + switch(modifier) { + default: + ui_num = (u_wide_int) va_arg(ap, unsigned int); + break; + case LM_LONG_DOUBLE: + goto fmt_error; + case LM_LONG: + ui_num = (u_wide_int) va_arg(ap, unsigned long int); + break; + case LM_SIZE_T: + ui_num = (u_wide_int) va_arg(ap, size_t); + break; +#if SIZEOF_LONG_LONG + case LM_LONG_LONG: + ui_num = (u_wide_int) va_arg(ap, u_wide_int); + break; +#endif +#if SIZEOF_INTMAX_T + case LM_INTMAX_T: + ui_num = (u_wide_int) va_arg(ap, uintmax_t); + break; +#endif +#if SIZEOF_PTRDIFF_T + case LM_PTRDIFF_T: + ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); + break; +#endif + } + s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); + FIX_PRECISION(adjust_precision, precision, s, s_len); + if (alternate_form && i_num != 0) { + *--s = *fmt; /* 'x' or 'X' */ + *--s = '0'; + s_len += 2; + } + break; + + + case 's': + case 'v': + s = va_arg(ap, char *); + if (s != NULL) { + if (adjust_precision) { + s_len = precision; + } else { + s_len = strlen(s); + } + + if (escape_xml) { + /* added: support for xml escaping */ + + int old_slen = s_len, i = 0; + char *old_s = s, *s_ptr; + free_s = s_ptr = s = emalloc(old_slen * 6 + 1); + do { + if (old_s[i] == '&' || old_s[i] == '"' || old_s[i] == '<') { + *s_ptr++ = '&'; + switch (old_s[i]) { + case '"': + s_len += 5; + *s_ptr++ = 'q'; + *s_ptr++ = 'u'; + *s_ptr++ = 'o'; + *s_ptr++ = 't'; + break; + case '<': + s_len += 3; + *s_ptr++ = 'l'; + *s_ptr++ = 't'; + break; + case '&': + s_len += 4; + *s_ptr++ = 'a'; + *s_ptr++ = 'm'; + *s_ptr++ = 'p'; + break; + } + *s_ptr++ = ';'; + } else { + *s_ptr++ = old_s[i]; + } + } while (i++ < old_slen); + } + } else { + s = S_NULL; + s_len = S_NULL_LEN; + } + pad_char = ' '; + break; + + + case 'b': + if (escape_xml) { + s = PHPDBG_G(err_buf).xml; + } else { + s = PHPDBG_G(err_buf).msg; + } + + if (s != NULL) { + if (escape_xml) { + s_len = PHPDBG_G(err_buf).xmllen; + } else { + s_len = PHPDBG_G(err_buf).msglen; + } + + if (adjust_precision && precision != s_len) { + s_len = precision; + } + } else { + s = ""; + s_len = 0; + } + pad_char = ' '; + break; + + + case 'r': + if (PHPDBG_G(req_id)) { + s_len = spprintf(&s, 0, "req=\"%lu\"", PHPDBG_G(req_id)); + free_s = s; + } else { + s = ""; + s_len = 0; + } + break; + + + case 'f': + case 'F': + case 'e': + case 'E': + + switch(modifier) { + case LM_LONG_DOUBLE: + fp_num = (double) va_arg(ap, long double); + break; + case LM_STD: + fp_num = va_arg(ap, double); + break; + default: + goto fmt_error; + } + + if (zend_isnan(fp_num)) { + s = "NAN"; + s_len = 3; + } else if (zend_isinf(fp_num)) { + s = "INF"; + s_len = 3; + } else { +#ifdef HAVE_LOCALE_H + if (!lconv) { + lconv = localeconv(); + } +#endif + s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, + (adjust_precision == NO) ? FLOAT_DIGITS : precision, + (*fmt == 'f')?LCONV_DECIMAL_POINT:'.', + &is_negative, &num_buf[1], &s_len); + if (is_negative) + prefix_char = '-'; + else if (print_sign) + prefix_char = '+'; + else if (print_blank) + prefix_char = ' '; + } + break; + + + case 'g': + case 'k': + case 'G': + case 'H': + switch(modifier) { + case LM_LONG_DOUBLE: + fp_num = (double) va_arg(ap, long double); + break; + case LM_STD: + fp_num = va_arg(ap, double); + break; + default: + goto fmt_error; + } + + if (zend_isnan(fp_num)) { + s = "NAN"; + s_len = 3; + break; + } else if (zend_isinf(fp_num)) { + if (fp_num > 0) { + s = "INF"; + s_len = 3; + } else { + s = "-INF"; + s_len = 4; + } + break; + } + + if (adjust_precision == NO) { + precision = FLOAT_DIGITS; + } else if (precision == 0) { + precision = 1; + } + /* + * * We use &num_buf[ 1 ], so that we have room for the sign + */ +#ifdef HAVE_LOCALE_H + if (!lconv) { + lconv = localeconv(); + } +#endif + s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); + if (*s == '-') { + prefix_char = *s++; + } else if (print_sign) { + prefix_char = '+'; + } else if (print_blank) { + prefix_char = ' '; + } + + s_len = strlen(s); + + if (alternate_form && (strchr(s, '.')) == NULL) { + s[s_len++] = '.'; + } + break; + + + case 'c': + char_buf[0] = (char) (va_arg(ap, int)); + s = &char_buf[0]; + s_len = 1; + pad_char = ' '; + break; + + + case '%': + char_buf[0] = '%'; + s = &char_buf[0]; + s_len = 1; + pad_char = ' '; + break; + + + case 'n': + *(va_arg(ap, int *)) = cc; + goto skip_output; + + /* + * Always extract the argument as a "char *" pointer. We + * should be using "void *" but there are still machines + * that don't understand it. + * If the pointer size is equal to the size of an unsigned + * integer we convert the pointer to a hex number, otherwise + * we print "%p" to indicate that we don't handle "%p". + */ + case 'p': + if (sizeof(char *) <= sizeof(u_wide_int)) { + ui_num = (u_wide_int)((size_t) va_arg(ap, char *)); + s = ap_php_conv_p2(ui_num, 4, 'x', + &num_buf[NUM_BUF_SIZE], &s_len); + if (ui_num != 0) { + *--s = 'x'; + *--s = '0'; + s_len += 2; + } + } else { + s = "%p"; + s_len = 2; + } + pad_char = ' '; + break; + + + case NUL: + /* + * The last character of the format string was %. + * We ignore it. + */ + continue; + + +fmt_error: + php_error(E_ERROR, "Illegal length modifier specified '%c' in s[np]printf call", *fmt); + /* + * The default case is for unrecognized %'s. + * We print %<char> to help the user identify what + * option is not understood. + * This is also useful in case the user wants to pass + * the output of format_converter to another function + * that understands some other %<char> (like syslog). + * Note that we can't point s inside fmt because the + * unknown <char> could be preceded by width etc. + */ + default: + char_buf[0] = '%'; + char_buf[1] = *fmt; + s = char_buf; + s_len = 2; + pad_char = ' '; + break; + } + + if (prefix_char != NUL) { + *--s = prefix_char; + s_len++; + } + if (adjust_width && adjust == RIGHT && min_width > s_len) { + if (pad_char == '0' && prefix_char != NUL) { + INS_CHAR(*s, sp, bep, cc) + s++; + s_len--; + min_width--; + } + PAD(min_width, s_len, pad_char); + } + /* + * Print the string s. + */ + for (i = s_len; i != 0; i--) { + INS_CHAR(*s, sp, bep, cc); + s++; + } + + if (adjust_width && adjust == LEFT && min_width > s_len) + PAD(min_width, s_len, pad_char); + if (free_zcopy) { + zval_dtor(&zcopy); + } + } +skip_output: + if (free_s) { + efree(free_s); + free_s = NULL; + } + + fmt++; + } + odp->nextb = sp; + return (cc); +} + +static void strx_printv(int *ccp, char *buf, size_t len, const char *format, zend_bool escape_xml, va_list ap) { + buffy od; + int cc; + + /* + * First initialize the descriptor + * Notice that if no length is given, we initialize buf_end to the + * highest possible address. + */ + if (len == 0) { + od.buf_end = (char *) ~0; + od.nextb = (char *) ~0; + } else { + od.buf_end = &buf[len-1]; + od.nextb = buf; + } + + /* + * Do the conversion + */ + cc = format_converter(&od, format, escape_xml, ap); + if (len != 0 && od.nextb <= od.buf_end) { + *(od.nextb) = '\0'; + } + if (ccp) { + *ccp = cc; + } +} + +static int phpdbg_xml_vsnprintf(char *buf, size_t len, const char *format, zend_bool escape_xml, va_list ap) { + int cc; + + strx_printv(&cc, buf, len, format, escape_xml, ap); + return (cc); +} + +PHPDBG_API int phpdbg_xml_vasprintf(char **buf, const char *format, zend_bool escape_xml, va_list ap) { + va_list ap2; + int cc; + + va_copy(ap2, ap); + cc = phpdbg_xml_vsnprintf(NULL, 0, format, escape_xml, ap2); + va_end(ap2); + + *buf = NULL; + + if (cc >= 0) { + if ((*buf = emalloc(++cc)) != NULL) { + if ((cc = phpdbg_xml_vsnprintf(*buf, cc, format, escape_xml, ap)) < 0) { + efree(*buf); + *buf = NULL; + } + } + } + + return cc; +} +/* copy end */ + +PHPDBG_API int _phpdbg_xml_asprintf(char **buf, const char *format, zend_bool escape_xml, ...) { + int ret; + va_list va; + + va_start(va, escape_xml); + ret = phpdbg_xml_vasprintf(buf, format, escape_xml, va); + va_end(va); + + return ret; +} + +PHPDBG_API int _phpdbg_asprintf(char **buf, const char *format, ...) { + int ret; + va_list va; + + va_start(va, format); + ret = phpdbg_xml_vasprintf(buf, format, 0, va); + va_end(va); + + return ret; +} + +static int phpdbg_encode_xml(char **buf, char *msg, int msglen, int from, char *to) { + int i; + int tolen = to ? strlen(to) : 5; + char *tmp = *buf = emalloc(msglen * tolen); + for (i = 0; i++ < msglen; msg++) { + if (*msg == '&') { + memcpy(tmp, ZEND_STRL("&")); + tmp += sizeof("&") - 1; + } else if (*msg == '<') { + memcpy(tmp, ZEND_STRL("<")); + tmp += sizeof("<") - 1; + } else if (((int) *msg) == from) { + memcpy(tmp, to, tolen); + tmp += tolen; + } else { + *tmp++ = *msg; + } + } + + { + int len = tmp - *buf; + *buf = erealloc(*buf, len + 1); + return len; + } +} + +static void phpdbg_encode_ctrl_chars(char **buf, int *buflen) { + char *tmp, *tmpptr; + int len; + int i; + + tmp = tmpptr = emalloc(*buflen * 5); + + for (i = 0; i < *buflen; i++) { + if ((*buf)[i] < 0x20) { + *tmpptr++ = '&'; + *tmpptr++ = '#'; + if ((unsigned int) ((*buf)[i]) > 9) { + *tmpptr++ = ((*buf)[i] / 10) + '0'; + } + *tmpptr++ = ((*buf)[i] % 10) + '0'; + *tmpptr++ = ';'; + } else { + *tmpptr++ = (*buf)[i]; + } + } + + len = tmpptr - tmp; + + efree(*buf); + *buf = erealloc(tmp, len + 1); + *buflen = len; +} + +static int phpdbg_process_print(int fd, int type, const char *tag, const char *msg, int msglen, const char *xml, int xmllen) { + char *msgout = NULL, *buf; + int msgoutlen, xmloutlen, buflen; + const char *severity; + + if ((PHPDBG_G(flags) & PHPDBG_WRITE_XML) && PHPDBG_G(in_script_xml) && PHPDBG_G(in_script_xml) != type) { + phpdbg_mixed_write(fd, ZEND_STRL("</stream>")); + PHPDBG_G(in_script_xml) = 0; + } + + switch (type) { + case P_ERROR: + severity = "error"; + if (!PHPDBG_G(last_was_newline)) { + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>\n" "</phpdbg>")); + } else { + phpdbg_mixed_write(fd, ZEND_STRL("\n")); + } + PHPDBG_G(last_was_newline) = 1; + } + if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) { + msgoutlen = phpdbg_asprintf(&msgout, "\033[%sm[%.*s]\033[0m\n", PHPDBG_G(colors)[PHPDBG_COLOR_ERROR]->code, msglen, msg); + } else { + msgoutlen = phpdbg_asprintf(&msgout, "[%.*s]\n", msglen, msg); + } + break; + + case P_NOTICE: + severity = "notice"; + if (!PHPDBG_G(last_was_newline)) { + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>\n" "</phpdbg>")); + } else { + phpdbg_mixed_write(fd, ZEND_STRL("\n")); + } + PHPDBG_G(last_was_newline) = 1; + } + if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) { + msgoutlen = phpdbg_asprintf(&msgout, "\033[%sm[%.*s]\033[0m\n", PHPDBG_G(colors)[PHPDBG_COLOR_NOTICE]->code, msglen, msg); + } else { + msgoutlen = phpdbg_asprintf(&msgout, "[%.*s]\n", msglen, msg); + } + break; + + case P_WRITELN: + severity = "normal"; + if (msg) { + msgoutlen = phpdbg_asprintf(&msgout, "%.*s\n", msglen, msg); + } else { + msgoutlen = 1; + msgout = estrdup("\n"); + } + PHPDBG_G(last_was_newline) = 1; + break; + + case P_WRITE: + severity = "normal"; + if (msg) { + msgout = estrndup(msg, msglen); + msgoutlen = msglen; + PHPDBG_G(last_was_newline) = msg[msglen - 1] == '\n'; + } else { + msgoutlen = 0; + msgout = estrdup(""); + } + break; + + case P_STDOUT: + case P_STDERR: + if (msg) { + PHPDBG_G(last_was_newline) = msg[msglen - 1] == '\n'; + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + zend_string *encoded; + + if (PHPDBG_G(in_script_xml) != type) { + char *stream_buf; + int stream_buflen = phpdbg_asprintf(&stream_buf, "<stream type=\"%s\">", type == P_STDERR ? "stderr" : "stdout"); + phpdbg_mixed_write(fd, stream_buf, stream_buflen); + efree(stream_buf); + PHPDBG_G(in_script_xml) = type; + } + encoded = php_escape_html_entities((unsigned char *) msg, msglen, 0, ENT_NOQUOTES, PG(internal_encoding) && PG(internal_encoding)[0] ? PG(internal_encoding) : (SG(default_charset) ? SG(default_charset) : "UTF-8")); + buflen = encoded->len; + memcpy(buf = emalloc(buflen + 1), encoded->val, buflen); + phpdbg_encode_ctrl_chars(&buf, &buflen); + phpdbg_mixed_write(fd, buf, buflen); + efree(buf); + } else { + phpdbg_mixed_write(fd, msg, msglen); + } + return msglen; + } + break; + + /* no formatting on logging output */ + case P_LOG: + severity = "log"; + if (msg) { + struct timeval tp; + if (gettimeofday(&tp, NULL) == SUCCESS) { + msgoutlen = phpdbg_asprintf(&msgout, "[%ld %.8F]: %.*s\n", tp.tv_sec, tp.tv_usec / 1000000., msglen, msg); + } else { + msgoutlen = FAILURE; + } + } + break; + } + + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + char *xmlout; + + if (PHPDBG_G(req_id)) { + char *xmlbuf = NULL; + xmllen = phpdbg_asprintf(&xmlbuf, "req=\"%lu\" %.*s", PHPDBG_G(req_id), xmllen, xml); + xml = xmlbuf; + } + if (msgout) { + buflen = phpdbg_encode_xml(&buf, msgout, msgoutlen, '"', """); + xmloutlen = phpdbg_asprintf(&xmlout, "<%s severity=\"%s\" %.*s msgout=\"%.*s\" />", tag, severity, xmllen, xml, buflen, buf); + + efree(buf); + } else { + xmloutlen = phpdbg_asprintf(&xmlout, "<%s severity=\"%s\" %.*s msgout=\"\" />", tag, severity, xmllen, xml); + } + + phpdbg_encode_ctrl_chars(&xmlout, &xmloutlen); + phpdbg_eol_convert(&xmlout, &xmloutlen); + phpdbg_mixed_write(fd, xmlout, xmloutlen); + efree(xmlout); + } else if (msgout) { + phpdbg_eol_convert(&msgout, &msgoutlen); + phpdbg_mixed_write(fd, msgout, msgoutlen); + } + + if (PHPDBG_G(req_id) && (PHPDBG_G(flags) & PHPDBG_WRITE_XML)) { + efree((char *) xml); + } + + if (msgout) { + efree(msgout); + } + + return msgout ? msgoutlen : xmloutlen; +} /* }}} */ + +PHPDBG_API int phpdbg_vprint(int type, int fd, const char *tag, const char *xmlfmt, const char *strfmt, va_list args) { + char *msg = NULL, *xml = NULL; + int msglen = 0, xmllen = 0; + int len; + va_list argcpy; + + if (strfmt != NULL && strlen(strfmt) > 0L) { + va_copy(argcpy, args); + msglen = phpdbg_xml_vasprintf(&msg, strfmt, 0, argcpy); + va_end(argcpy); + } + + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + if (xmlfmt != NULL && strlen(xmlfmt) > 0L) { + va_copy(argcpy, args); + xmllen = phpdbg_xml_vasprintf(&xml, xmlfmt, 1, argcpy); + va_end(argcpy); + } else { + xml = estrdup(""); + } + } + + if (PHPDBG_G(err_buf).active && type != P_STDOUT && type != P_STDERR) { + phpdbg_free_err_buf(); + + PHPDBG_G(err_buf).type = type; + PHPDBG_G(err_buf).fd = fd; + PHPDBG_G(err_buf).tag = estrdup(tag); + PHPDBG_G(err_buf).msg = msg; + PHPDBG_G(err_buf).msglen = msglen; + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + PHPDBG_G(err_buf).xml = xml; + PHPDBG_G(err_buf).xmllen = xmllen; + } + + return msglen; + } + + len = phpdbg_process_print(fd, type, tag, msg, msglen, xml, xmllen); + + if (msg) { + efree(msg); + } + + if (xml) { + efree(xml); + } + + return len; +} + +PHPDBG_API void phpdbg_free_err_buf(void) { + if (PHPDBG_G(err_buf).type == 0) { + return; + } + + PHPDBG_G(err_buf).type = 0; + + efree(PHPDBG_G(err_buf).tag); + efree(PHPDBG_G(err_buf).msg); + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + efree(PHPDBG_G(err_buf).xml); + } +} + +PHPDBG_API void phpdbg_activate_err_buf(zend_bool active) { + PHPDBG_G(err_buf).active = active; +} + +PHPDBG_API int phpdbg_output_err_buf(const char *tag, const char *xmlfmt, const char *strfmt, ...) { + int len; + va_list args; + int errbuf_active = PHPDBG_G(err_buf).active; + + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + + PHPDBG_G(err_buf).active = 0; + + va_start(args, strfmt); + len = phpdbg_vprint(PHPDBG_G(err_buf).type, PHPDBG_G(err_buf).fd, tag ? tag : PHPDBG_G(err_buf).tag, xmlfmt, strfmt, args); + va_end(args); + + PHPDBG_G(err_buf).active = errbuf_active; + phpdbg_free_err_buf(); + + return len; +} + +PHPDBG_API int phpdbg_print(int type, int fd, const char *tag, const char *xmlfmt, const char *strfmt, ...) { + va_list args; + int len; + + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + + va_start(args, strfmt); + len = phpdbg_vprint(type, fd, tag, xmlfmt, strfmt, args); + va_end(args); + + return len; +} + +PHPDBG_API int phpdbg_xml_internal(int fd, const char *fmt, ...) { + int len = 0; + + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + va_list args; + char *buffer; + int buflen; + + va_start(args, fmt); + buflen = phpdbg_xml_vasprintf(&buffer, fmt, 1, args); + va_end(args); + + phpdbg_encode_ctrl_chars(&buffer, &buflen); + + if (PHPDBG_G(in_script_xml)) { + phpdbg_mixed_write(fd, ZEND_STRL("</stream>")); + PHPDBG_G(in_script_xml) = 0; + } + + len = phpdbg_mixed_write(fd, buffer, buflen); + efree(buffer); + } + + return len; +} + +PHPDBG_API int phpdbg_log_internal(int fd, const char *fmt, ...) { + va_list args; + char *buffer; + int buflen; + int len = 0; + + va_start(args, fmt); + buflen = phpdbg_xml_vasprintf(&buffer, fmt, 0, args); + va_end(args); + + len = phpdbg_mixed_write(fd, buffer, buflen); + efree(buffer); + + return len; +} + +PHPDBG_API int phpdbg_out_internal(int fd, const char *fmt, ...) { + va_list args; + char *buffer; + int buflen; + int len = 0; + + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + + va_start(args, fmt); + buflen = phpdbg_xml_vasprintf(&buffer, fmt, 0, args); + va_end(args); + + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + char *msg; + int msglen; + + msglen = phpdbg_encode_xml(&msg, buffer, buflen, 256, NULL); + phpdbg_encode_ctrl_chars(&msg, &msglen); + phpdbg_eol_convert(&msg, &msglen); + + if (PHPDBG_G(in_script_xml)) { + phpdbg_mixed_write(fd, ZEND_STRL("</stream>")); + PHPDBG_G(in_script_xml) = 0; + } + + phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>")); + len = phpdbg_mixed_write(fd, msg, msglen); + phpdbg_mixed_write(fd, ZEND_STRL("</phpdbg>")); + } else { + phpdbg_eol_convert(&buffer, &buflen); + len = phpdbg_mixed_write(fd, buffer, buflen); + } + + return len; +} + + +PHPDBG_API int phpdbg_rlog_internal(int fd, const char *fmt, ...) { /* {{{ */ + int rc = 0; + + va_list args; + struct timeval tp; + + va_start(args, fmt); + if (gettimeofday(&tp, NULL) == SUCCESS) { + char friendly[100]; + char *format = NULL, *buffer = NULL, *outbuf = NULL; + const time_t tt = tp.tv_sec; + +#ifdef PHP_WIN32 + strftime(friendly, 100, "%a %b %d %H.%%04d %Y", localtime(&tt)); +#else + strftime(friendly, 100, "%a %b %d %T.%%04d %Y", localtime(&tt)); +#endif + phpdbg_asprintf(&buffer, friendly, tp.tv_usec/1000); + phpdbg_asprintf(&format, "[%s]: %s\n", buffer, fmt); + rc = phpdbg_xml_vasprintf(&outbuf, format, 0, args); + + if (outbuf) { + rc = phpdbg_mixed_write(fd, outbuf, rc); + efree(outbuf); + } + + efree(format); + efree(buffer); + } + va_end(args); + + return rc; +} /* }}} */ diff --git a/sapi/phpdbg/phpdbg_out.h b/sapi/phpdbg/phpdbg_out.h new file mode 100644 index 0000000000..afcdd9cf59 --- /dev/null +++ b/sapi/phpdbg/phpdbg_out.h @@ -0,0 +1,93 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Felipe Pena <felipe@php.net> | + | Authors: Joe Watkins <joe.watkins@live.co.uk> | + | Authors: Bob Weinand <bwoebi@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifndef PHPDBG_OUT_H +#define PHPDBG_OUT_H + +/** + * Error/notice/formatting helpers + */ +enum { + P_ERROR = 1, + P_NOTICE, + P_WRITELN, + P_WRITE, + P_STDOUT, + P_STDERR, + P_LOG +}; + +#ifdef ZTS +PHPDBG_API int phpdbg_print(int severity, int fd, const char *tag, const char *xmlfmt, const char *strfmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 6, 7); +PHPDBG_API int phpdbg_xml_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); +PHPDBG_API int phpdbg_log_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); +PHPDBG_API int phpdbg_out_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); +PHPDBG_API int phpdbg_rlog_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); +#else +PHPDBG_API int phpdbg_print(int severity, int fd, const char *tag, const char *xmlfmt, const char *strfmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 5, 6); +PHPDBG_API int phpdbg_xml_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3); +PHPDBG_API int phpdbg_log_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3); +PHPDBG_API int phpdbg_out_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3); +PHPDBG_API int phpdbg_rlog_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3); +#endif + + +#define phpdbg_error(tag, xmlfmt, strfmt, ...) phpdbg_print(P_ERROR , PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__) +#define phpdbg_notice(tag, xmlfmt, strfmt, ...) phpdbg_print(P_NOTICE , PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__) +#define phpdbg_writeln(tag, xmlfmt, strfmt, ...) phpdbg_print(P_WRITELN, PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__) +#define phpdbg_write(tag, xmlfmt, strfmt, ...) phpdbg_print(P_WRITE , PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__) +#define phpdbg_script(type, fmt, ...) phpdbg_print(type , PHPDBG_G(io)[PHPDBG_STDOUT].fd, NULL, NULL, fmt, ##__VA_ARGS__) +#define phpdbg_log(fmt, ...) phpdbg_log_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__) +#define phpdbg_xml(fmt, ...) phpdbg_xml_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__) +#define phpdbg_out(fmt, ...) phpdbg_out_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__) + +#define phpdbg_error_ex(out, tag, xmlfmt, strfmt, ...) phpdbg_print(P_ERROR , out, tag, xmlfmt, strfmt, ##__VA_ARGS__) +#define phpdbg_notice_ex(out, tag, xmlfmt, strfmt, ...) phpdbg_print(P_NOTICE , out, tag, xmlfmt, strfmt, ##__VA_ARGS__) +#define phpdbg_writeln_ex(out, tag, xmlfmt, strfmt, ...) phpdbg_print(P_WRITELN, out, tag, xmlfmt, strfmt, ##__VA_ARGS__) +#define phpdbg_write_ex(out, tag, xmlfmt, strfmt, ...) phpdbg_print(P_WRITE , out, tag, xmlfmt, strfmt, ##__VA_ARGS__) +#define phpdbg_script_ex(out, type, fmt, ...) phpdbg_print(type , out, NULL, NULL, fmt, ##__VA_ARGS__) +#define phpdbg_log_ex(out, fmt, ...) phpdbg_log_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__) +#define phpdbg_xml_ex(out, fmt, ...) phpdbg_xml_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__) +#define phpdbg_out_ex(out, fmt, ...) phpdbg_out_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__) + +#define phpdbg_rlog(fd, fmt, ...) phpdbg_rlog_internal(fd, fmt, ##__VA_ARGS__) + +#define phpdbg_xml_asprintf(buf, ...) _phpdbg_xml_asprintf(buf, ##__VA_ARGS__) +PHPDBG_API int _phpdbg_xml_asprintf(char **buf, const char *format, zend_bool escape_xml, ...); + +#define phpdbg_asprintf(buf, ...) _phpdbg_asprintf(buf, ##__VA_ARGS__) +PHPDBG_API int _phpdbg_asprintf(char **buf, const char *format, ...); + + +#if PHPDBG_DEBUG +# define phpdbg_debug(fmt, ...) phpdbg_log_ex(PHPDBG_G(io)[PHPDBG_STDERR].fd, fmt, ##__VA_ARGS__) +#else +# define phpdbg_debug(fmt, ...) +#endif + +PHPDBG_API void phpdbg_free_err_buf(void); +PHPDBG_API void phpdbg_activate_err_buf(zend_bool active); +PHPDBG_API int phpdbg_output_err_buf(const char *tag, const char *xmlfmt, const char *strfmt, ...); + + +/* {{{ For separation */ +#define SEPARATE "------------------------------------------------" /* }}} */ + +#endif /* PHPDBG_OUT_H */ diff --git a/sapi/phpdbg/phpdbg_parser.c b/sapi/phpdbg/phpdbg_parser.c index 7d05da659e..ed976f0b3f 100644 --- a/sapi/phpdbg/phpdbg_parser.c +++ b/sapi/phpdbg/phpdbg_parser.c @@ -1,19 +1,21 @@ -/* A Bison parser, made by GNU Bison 2.7.12-4996. */ -/* Bison implementation for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. - +/* A Bison parser, made by GNU Bison 2.4.1. */ + +/* Skeleton implementation for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -26,7 +28,7 @@ special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. - + This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ @@ -44,7 +46,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.7.12-4996" +#define YYBISON_VERSION "2.4.1" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -58,6 +60,8 @@ /* Pull parsers. */ #define YYPULL 1 +/* Using locations. */ +#define YYLSP_NEEDED 0 /* Substitute the variable and function names. */ #define yyparse phpdbg_parse @@ -68,18 +72,20 @@ #define yydebug phpdbg_debug #define yynerrs phpdbg_nerrs + /* Copy the first part of user declarations. */ -/* Line 371 of yacc.c */ -#line 1 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - +/* Line 189 of yacc.c */ +#line 1 "sapi/phpdbg/phpdbg_parser.y" + + /* * phpdbg_parser.y * (from php-src root) * flex sapi/phpdbg/dev/phpdbg_lexer.l * bison sapi/phpdbg/dev/phpdbg_parser.y */ - + #include "phpdbg.h" #include "phpdbg_cmd.h" #include "phpdbg_utils.h" @@ -92,21 +98,19 @@ #include "phpdbg_lexer.h" #undef yyerror -static int yyerror(void ***tsrm_ls, const char *msg); +static int yyerror(const char *msg); ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -/* Line 371 of yacc.c */ -#line 102 "sapi/phpdbg/phpdbg_parser.c" -# ifndef YY_NULL -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULL nullptr -# else -# define YY_NULL 0 -# endif -# endif +/* Line 189 of yacc.c */ +#line 109 "sapi/phpdbg/phpdbg_parser.c" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE @@ -116,20 +120,15 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); # define YYERROR_VERBOSE 1 #endif -/* In a future release of Bison, this section will be replaced - by #include "phpdbg_parser.h". */ -#ifndef YY_PHPDBG_SAPI_PHPDBG_PHPDBG_PARSER_H_INCLUDED -# define YY_PHPDBG_SAPI_PHPDBG_PHPDBG_PARSER_H_INCLUDED -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int phpdbg_debug; +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 #endif + /* "%code requires" blocks. */ -/* Line 387 of yacc.c */ -#line 31 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" + +/* Line 209 of yacc.c */ +#line 31 "sapi/phpdbg/phpdbg_parser.y" #include "phpdbg.h" #ifndef YY_TYPEDEF_YY_SCANNER_T @@ -138,7 +137,8 @@ typedef void* yyscan_t; #endif -/* Line 387 of yacc.c */ + +/* Line 209 of yacc.c */ #line 143 "sapi/phpdbg/phpdbg_parser.c" /* Tokens. */ @@ -164,28 +164,10 @@ typedef void* yyscan_t; T_OPCODE = 272, T_ID = 273, T_INPUT = 274, - T_UNEXPECTED = 275 + T_UNEXPECTED = 275, + T_REQ_ID = 276 }; #endif -/* Tokens. */ -#define T_EVAL 258 -#define T_RUN 259 -#define T_SHELL 260 -#define T_IF 261 -#define T_TRUTHY 262 -#define T_FALSY 263 -#define T_STRING 264 -#define T_COLON 265 -#define T_DCOLON 266 -#define T_POUND 267 -#define T_PROTO 268 -#define T_DIGITS 269 -#define T_LITERAL 270 -#define T_ADDR 271 -#define T_OPCODE 272 -#define T_ID 273 -#define T_INPUT 274 -#define T_UNEXPECTED 275 @@ -197,26 +179,11 @@ typedef int YYSTYPE; #endif -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int phpdbg_parse (void *YYPARSE_PARAM); -#else -int phpdbg_parse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int phpdbg_parse (void *tsrm_ls); -#else -int phpdbg_parse (); -#endif -#endif /* ! YYPARSE_PARAM */ - -#endif /* !YY_PHPDBG_SAPI_PHPDBG_PHPDBG_PARSER_H_INCLUDED */ - /* Copy the second part of user declarations. */ -/* Line 390 of yacc.c */ -#line 220 "sapi/phpdbg/phpdbg_parser.c" + +/* Line 264 of yacc.c */ +#line 187 "sapi/phpdbg/phpdbg_parser.c" #ifdef short # undef short @@ -266,36 +233,27 @@ typedef short int yytype_int16; #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS +# if YYENABLE_NLS # if ENABLE_NLS # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# define YY_(msgid) dgettext ("bison-runtime", msgid) # endif # endif # ifndef YY_ -# define YY_(Msgid) Msgid -# endif -#endif - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if (! defined __GNUC__ || __GNUC__ < 2 \ - || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) -# define __attribute__(Spec) /* empty */ +# define YY_(msgid) msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +# define YYUSE(e) ((void) (e)) #else -# define YYUSE(E) /* empty */ +# define YYUSE(e) /* empty */ #endif - /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint -# define YYID(N) (N) +# define YYID(n) (n) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) @@ -328,12 +286,11 @@ YYID (yyi) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 +# ifndef _STDLIB_H +# define _STDLIB_H 1 # endif # endif # endif @@ -356,24 +313,24 @@ YYID (yyi) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ +# if (defined __cplusplus && ! defined _STDLIB_H \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 +# ifndef _STDLIB_H +# define _STDLIB_H 1 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif @@ -402,7 +359,23 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) -# define YYCOPY_NEEDED 1 +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of @@ -422,43 +395,23 @@ union yyalloc #endif -#if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from SRC to DST. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif -#endif /* !YYCOPY_NEEDED */ - /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 25 +#define YYFINAL 26 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 42 +#define YYLAST 48 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 21 +#define YYNTOKENS 22 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 5 +#define YYNNTS 6 /* YYNRULES -- Number of rules. */ -#define YYNRULES 25 +#define YYNRULES 28 /* YYNRULES -- Number of states. */ -#define YYNSTATES 38 +#define YYNSTATES 43 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 275 +#define YYMAXUTOK 276 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) @@ -493,7 +446,7 @@ static const yytype_uint8 yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20 + 15, 16, 17, 18, 19, 20, 21 }; #if YYDEBUG @@ -501,34 +454,35 @@ static const yytype_uint8 yytranslate[] = YYRHS. */ static const yytype_uint8 yyprhs[] = { - 0, 0, 3, 5, 7, 8, 10, 13, 17, 22, - 27, 33, 37, 43, 47, 50, 52, 54, 56, 58, - 60, 62, 64, 67, 70, 72 + 0, 0, 3, 5, 7, 8, 10, 13, 16, 20, + 25, 30, 36, 40, 46, 50, 53, 55, 57, 59, + 61, 63, 65, 67, 69, 70, 74, 78, 81 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yytype_int8 yyrhs[] = { - 22, 0, -1, 23, -1, 25, -1, -1, 24, -1, - 23, 24, -1, 18, 10, 14, -1, 18, 10, 12, - 14, -1, 13, 18, 10, 14, -1, 13, 18, 10, - 12, 14, -1, 18, 11, 18, -1, 18, 11, 18, - 12, 14, -1, 18, 12, 14, -1, 6, 19, -1, - 17, -1, 16, -1, 15, -1, 7, -1, 8, -1, - 14, -1, 18, -1, 3, 19, -1, 5, 19, -1, - 4, -1, 4, 19, -1 + 23, 0, -1, 24, -1, 27, -1, -1, 25, -1, + 24, 25, -1, 24, 26, -1, 18, 10, 14, -1, + 18, 10, 12, 14, -1, 13, 18, 10, 14, -1, + 13, 18, 10, 12, 14, -1, 18, 11, 18, -1, + 18, 11, 18, 12, 14, -1, 18, 12, 14, -1, + 6, 19, -1, 17, -1, 16, -1, 15, -1, 7, + -1, 8, -1, 14, -1, 18, -1, 21, -1, -1, + 3, 26, 19, -1, 5, 26, 19, -1, 4, 26, + -1, 4, 26, 19, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 66, 66, 67, 68, 72, 73, 77, 82, 87, - 97, 107, 112, 118, 124, 129, 130, 131, 132, 133, - 134, 135, 139, 144, 149, 153 + 0, 65, 65, 66, 67, 71, 72, 73, 77, 82, + 87, 97, 107, 112, 118, 124, 129, 130, 131, 132, + 133, 134, 135, 139, 140, 144, 149, 154, 158 }; #endif -#if YYDEBUG || YYERROR_VERBOSE || 1 +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = @@ -540,8 +494,9 @@ static const char *const yytname[] = "\":: (double colon)\"", "\"# (pound sign)\"", "\"protocol (file://)\"", "\"digits (numbers)\"", "\"literal (string)\"", "\"address\"", "\"opcode\"", "\"identifier (command or function name)\"", - "\"input (input string or data)\"", "\"input\"", "$accept", "input", - "parameters", "parameter", "full_expression", YY_NULL + "\"input (input string or data)\"", "\"input\"", + "\"request id (-r %d)\"", "$accept", "input", "parameters", "parameter", + "req_id", "full_expression", 0 }; #endif @@ -552,86 +507,83 @@ static const yytype_uint16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275 + 275, 276 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint8 yyr1[] = { - 0, 21, 22, 22, 22, 23, 23, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 25, 25, 25, 25 + 0, 22, 23, 23, 23, 24, 24, 24, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 26, 26, 27, 27, 27, 27 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const yytype_uint8 yyr2[] = { - 0, 2, 1, 1, 0, 1, 2, 3, 4, 4, - 5, 3, 5, 3, 2, 1, 1, 1, 1, 1, - 1, 1, 2, 2, 1, 2 + 0, 2, 1, 1, 0, 1, 2, 2, 3, 4, + 4, 5, 3, 5, 3, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 3, 3, 2, 3 }; -/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE doesn't specify something else to do. Zero +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { - 4, 0, 24, 0, 0, 18, 19, 0, 20, 17, - 16, 15, 21, 0, 2, 5, 3, 22, 25, 23, - 14, 0, 0, 0, 0, 1, 6, 0, 0, 7, - 11, 13, 0, 9, 8, 0, 10, 12 + 4, 24, 24, 24, 0, 19, 20, 0, 21, 18, + 17, 16, 22, 0, 2, 5, 3, 23, 0, 27, + 0, 15, 0, 0, 0, 0, 1, 6, 7, 25, + 28, 26, 0, 0, 8, 12, 14, 0, 10, 9, + 0, 11, 13 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int8 yydefgoto[] = { - -1, 13, 14, 15, 16 + -1, 13, 14, 15, 18, 16 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ -#define YYPACT_NINF -11 +#define YYPACT_NINF -16 static const yytype_int8 yypact[] = { - -3, -10, 11, 12, 13, -11, -11, 15, -11, -11, - -11, -11, -4, 29, 10, -11, -11, -11, -11, -11, - -11, 24, 7, 17, 22, -11, -11, 8, 23, -11, - 26, -11, 25, -11, -11, 27, -11, -11 + -3, -15, -15, -15, -10, -16, -16, 3, -16, -16, + -16, -16, 22, 29, 10, -16, -16, -16, 11, 17, + 19, -16, 30, 8, 21, 27, -16, -16, -16, -16, + -16, -16, 23, 28, -16, 31, -16, 32, -16, -16, + 33, -16, -16 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { - -11, -11, -11, 28, -11 + -16, -16, -16, 34, 5, -16 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which - number is the opposite. If YYTABLE_NINF, syntax error. */ + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { - 1, 2, 3, 4, 5, 6, 22, 23, 24, 17, + 1, 2, 3, 4, 5, 6, 17, 19, 20, 21, 7, 8, 9, 10, 11, 12, 4, 5, 6, 28, - 32, 29, 33, 7, 8, 9, 10, 11, 12, 25, - 18, 19, 20, 21, 27, 30, 31, 34, 35, 36, - 0, 37, 26 + 33, 22, 34, 7, 8, 9, 10, 11, 12, 26, + 29, 17, 23, 24, 25, 37, 30, 38, 31, 35, + 32, 36, 39, 40, 0, 0, 41, 42, 27 }; -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-11))) - -#define yytable_value_is_error(Yytable_value) \ - YYID (0) - static const yytype_int8 yycheck[] = { - 3, 4, 5, 6, 7, 8, 10, 11, 12, 19, - 13, 14, 15, 16, 17, 18, 6, 7, 8, 12, - 12, 14, 14, 13, 14, 15, 16, 17, 18, 0, - 19, 19, 19, 18, 10, 18, 14, 14, 12, 14, - -1, 14, 14 + 3, 4, 5, 6, 7, 8, 21, 2, 3, 19, + 13, 14, 15, 16, 17, 18, 6, 7, 8, 14, + 12, 18, 14, 13, 14, 15, 16, 17, 18, 0, + 19, 21, 10, 11, 12, 12, 19, 14, 19, 18, + 10, 14, 14, 12, -1, -1, 14, 14, 14 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing @@ -639,9 +591,10 @@ static const yytype_int8 yycheck[] = static const yytype_uint8 yystos[] = { 0, 3, 4, 5, 6, 7, 8, 13, 14, 15, - 16, 17, 18, 22, 23, 24, 25, 19, 19, 19, - 19, 18, 10, 11, 12, 0, 24, 10, 12, 14, - 18, 14, 12, 14, 14, 12, 14, 14 + 16, 17, 18, 23, 24, 25, 27, 21, 26, 26, + 26, 19, 18, 10, 11, 12, 0, 25, 26, 19, + 19, 19, 10, 12, 14, 18, 14, 12, 14, 14, + 12, 14, 14 }; #define yyerrok (yyerrstatus = 0) @@ -656,50 +609,78 @@ static const yytype_uint8 yystos[] = /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. However, - YYFAIL appears to be in use. Nevertheless, it is formally deprecated - in Bison 2.4.2's NEWS entry, where a plan to phase it out is - discussed. */ + Once GCC version 2 has supplanted version 1, this can go. */ #define YYFAIL goto yyerrlab -#if defined YYFAIL - /* This is here to suppress warnings from the GCC cpp's - -Wunused-macros. Normally we don't worry about that warning, but - some users do, and we want to make it easy for users to remove - YYFAIL uses, which will produce warnings from Bison 2.5. */ -#endif #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (tsrm_ls, YY_("syntax error: cannot back up")); \ +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) -/* Error token number */ + #define YYTERROR 1 #define YYERRCODE 256 -/* This macro is provided for backward compatibility. */ +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) +#endif + + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + #ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# if YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif #endif /* YYLEX -- calling `yylex' with the right arguments. */ + #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, YYLEX_PARAM) #else @@ -726,7 +707,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, tsrm_ls); \ + Type, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (YYID (0)) @@ -740,28 +721,28 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *tsrm_ls) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) #else static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep, tsrm_ls) +yy_symbol_value_print (yyoutput, yytype, yyvaluep) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; - void *tsrm_ls; #endif { - FILE *yyo = yyoutput; - YYUSE (yyo); if (!yyvaluep) return; - YYUSE (tsrm_ls); # ifdef YYPRINT if (yytype < YYNTOKENS) YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); # else YYUSE (yyoutput); # endif - YYUSE (yytype); + switch (yytype) + { + default: + break; + } } @@ -772,14 +753,13 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, tsrm_ls) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *tsrm_ls) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) #else static void -yy_symbol_print (yyoutput, yytype, yyvaluep, tsrm_ls) +yy_symbol_print (yyoutput, yytype, yyvaluep) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; - void *tsrm_ls; #endif { if (yytype < YYNTOKENS) @@ -787,7 +767,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, tsrm_ls) else YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, tsrm_ls); + yy_symbol_value_print (yyoutput, yytype, yyvaluep); YYFPRINTF (yyoutput, ")"); } @@ -830,13 +810,12 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_reduce_print (YYSTYPE *yyvsp, int yyrule, void *tsrm_ls) +yy_reduce_print (YYSTYPE *yyvsp, int yyrule) #else static void -yy_reduce_print (yyvsp, yyrule, tsrm_ls) +yy_reduce_print (yyvsp, yyrule) YYSTYPE *yyvsp; int yyrule; - void *tsrm_ls; #endif { int yynrhs = yyr2[yyrule]; @@ -850,7 +829,7 @@ yy_reduce_print (yyvsp, yyrule, tsrm_ls) YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], &(yyvsp[(yyi + 1) - (yynrhs)]) - , tsrm_ls); + ); YYFPRINTF (stderr, "\n"); } } @@ -858,7 +837,7 @@ yy_reduce_print (yyvsp, yyrule, tsrm_ls) # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyvsp, Rule, tsrm_ls); \ + yy_reduce_print (yyvsp, Rule); \ } while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that @@ -889,6 +868,7 @@ int yydebug; #endif + #if YYERROR_VERBOSE # ifndef yystrlen @@ -990,146 +970,116 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) +/* Copy into YYRESULT an error message about the unexpected token + YYCHAR while in state YYSTATE. Return the number of bytes copied, + including the terminating null byte. If YYRESULT is null, do not + copy anything; just return the number of bytes that would be + copied. As a special case, return 0 if an ordinary "syntax error" + message will do. Return YYSIZE_MAXIMUM if overflow occurs during + size calculation. */ +static YYSIZE_T +yysyntax_error (char *yyresult, int yystate, int yychar) { - YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULL; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; - - /* There are many possibilities here to consider: - - Assume YYFAIL is not used. It's too flawed to consider. See - <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html> - for details. YYERROR is fine as it does not invoke this - function. - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } - } - } + int yyn = yypact[yystate]; - switch (yycount) + if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) + return 0; + else { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } + int yytype = YYTRANSLATE (yychar); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + +# if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +# endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } - { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } + if (yysize_overflow) + return YYSIZE_MAXIMUM; - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - return 0; + if (yyresult) + { + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yyresult; + int yyi = 0; + while ((*yyp = *yyf) != '\0') + { + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } + } + } + return yysize; + } } #endif /* YYERROR_VERBOSE */ + /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ @@ -1138,32 +1088,51 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, void *tsrm_ls) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) #else static void -yydestruct (yymsg, yytype, yyvaluep, tsrm_ls) +yydestruct (yymsg, yytype, yyvaluep) const char *yymsg; int yytype; YYSTYPE *yyvaluep; - void *tsrm_ls; #endif { YYUSE (yyvaluep); - YYUSE (tsrm_ls); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - YYUSE (yytype); + switch (yytype) + { + + default: + break; + } } +/* Prevent warnings from -Wmissing-prototypes. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + -/*----------. -| yyparse. | -`----------*/ + +/*-------------------------. +| yyparse or yypush_parse. | +`-------------------------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ @@ -1179,42 +1148,19 @@ yyparse (YYPARSE_PARAM) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int -yyparse (void *tsrm_ls) +yyparse (void) #else int -yyparse (tsrm_ls) - void *tsrm_ls; +yyparse () + #endif #endif { /* The lookahead symbol. */ int yychar; - -#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ -/* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") -#else -/* Default value used for initialization, for pacifying older GCCs - or non-GCC compilers. */ -static YYSTYPE yyval_default; -# define YY_INITIAL_VALUE(Value) = Value -#endif -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END -#endif -#ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ -#endif - /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); +YYSTYPE yylval; /* Number of syntax errors so far. */ int yynerrs; @@ -1227,7 +1173,7 @@ YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); `yyss': related to states. `yyvs': related to semantic values. - Refer to the stacks through separate pointers, to allow yyoverflow + Refer to the stacks thru separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ @@ -1245,7 +1191,7 @@ YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + int yytoken; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -1263,8 +1209,9 @@ YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); Keep to zero when no symbol should be popped. */ int yylen = 0; - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1273,6 +1220,14 @@ YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + yyssp = yyss; + yyvsp = yyvs; + goto yysetstate; /*------------------------------------------------------------. @@ -1364,7 +1319,7 @@ yybackup: /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) + if (yyn == YYPACT_NINF) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ @@ -1395,8 +1350,8 @@ yybackup: yyn = yytable[yyn]; if (yyn <= 0) { - if (yytable_value_is_error (yyn)) - goto yyerrlab; + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -1413,9 +1368,7 @@ yybackup: yychar = YYEMPTY; yystate = yyn; - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END goto yynewstate; @@ -1452,46 +1405,59 @@ yyreduce: switch (yyn) { case 3: -/* Line 1802 of yacc.c */ -#line 67 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(1) - (1)])); } + +/* Line 1455 of yacc.c */ +#line 66 "sapi/phpdbg/phpdbg_parser.y" + { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(1) - (1)])); ;} break; case 5: -/* Line 1802 of yacc.c */ -#line 72 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(1) - (1)])); } + +/* Line 1455 of yacc.c */ +#line 71 "sapi/phpdbg/phpdbg_parser.y" + { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(1) - (1)])); ;} break; case 6: -/* Line 1802 of yacc.c */ -#line 73 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(2) - (2)])); } + +/* Line 1455 of yacc.c */ +#line 72 "sapi/phpdbg/phpdbg_parser.y" + { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(2) - (2)])); ;} break; case 7: -/* Line 1802 of yacc.c */ -#line 77 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { + +/* Line 1455 of yacc.c */ +#line 73 "sapi/phpdbg/phpdbg_parser.y" + { (yyval) = (yyvsp[(1) - (2)]); ;} + break; + + case 8: + +/* Line 1455 of yacc.c */ +#line 77 "sapi/phpdbg/phpdbg_parser.y" + { (yyval).type = FILE_PARAM; (yyval).file.name = (yyvsp[(2) - (3)]).str; (yyval).file.line = (yyvsp[(3) - (3)]).num; - } + ;} break; - case 8: -/* Line 1802 of yacc.c */ -#line 82 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" + case 9: + +/* Line 1455 of yacc.c */ +#line 82 "sapi/phpdbg/phpdbg_parser.y" { (yyval).type = NUMERIC_FILE_PARAM; (yyval).file.name = (yyvsp[(1) - (4)]).str; (yyval).file.line = (yyvsp[(4) - (4)]).num; - } + ;} break; - case 9: -/* Line 1802 of yacc.c */ -#line 87 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" + case 10: + +/* Line 1455 of yacc.c */ +#line 87 "sapi/phpdbg/phpdbg_parser.y" { (yyval).type = FILE_PARAM; (yyval).file.name = malloc((yyvsp[(1) - (4)]).len + (yyvsp[(2) - (4)]).len + 1); @@ -1501,12 +1467,13 @@ yyreduce: (yyval).file.name[(yyvsp[(1) - (4)]).len + (yyvsp[(2) - (4)]).len] = '\0'; } (yyval).file.line = (yyvsp[(4) - (4)]).num; - } + ;} break; - case 10: -/* Line 1802 of yacc.c */ -#line 97 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" + case 11: + +/* Line 1455 of yacc.c */ +#line 97 "sapi/phpdbg/phpdbg_parser.y" { (yyval).type = NUMERIC_FILE_PARAM; (yyval).file.name = malloc((yyvsp[(1) - (5)]).len + (yyvsp[(2) - (5)]).len + 1); @@ -1516,148 +1483,160 @@ yyreduce: (yyval).file.name[(yyvsp[(1) - (5)]).len + (yyvsp[(2) - (5)]).len] = '\0'; } (yyval).file.line = (yyvsp[(5) - (5)]).num; - } + ;} break; - case 11: -/* Line 1802 of yacc.c */ -#line 107 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { + case 12: + +/* Line 1455 of yacc.c */ +#line 107 "sapi/phpdbg/phpdbg_parser.y" + { (yyval).type = METHOD_PARAM; (yyval).method.class = (yyvsp[(1) - (3)]).str; (yyval).method.name = (yyvsp[(3) - (3)]).str; - } + ;} break; - case 12: -/* Line 1802 of yacc.c */ -#line 112 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { + case 13: + +/* Line 1455 of yacc.c */ +#line 112 "sapi/phpdbg/phpdbg_parser.y" + { (yyval).type = NUMERIC_METHOD_PARAM; (yyval).method.class = (yyvsp[(1) - (5)]).str; (yyval).method.name = (yyvsp[(3) - (5)]).str; - (yyval).num = (yyvsp[(5) - (5)]).num; - } + (yyval).num = (yyvsp[(5) - (5)]).num; + ;} break; - case 13: -/* Line 1802 of yacc.c */ -#line 118 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" + case 14: + +/* Line 1455 of yacc.c */ +#line 118 "sapi/phpdbg/phpdbg_parser.y" { (yyval).type = NUMERIC_FUNCTION_PARAM; (yyval).str = (yyvsp[(1) - (3)]).str; (yyval).len = (yyvsp[(1) - (3)]).len; - (yyval).num = (yyvsp[(3) - (3)]).num; - } + (yyval).num = (yyvsp[(3) - (3)]).num; + ;} break; - case 14: -/* Line 1802 of yacc.c */ -#line 124 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" + case 15: + +/* Line 1455 of yacc.c */ +#line 124 "sapi/phpdbg/phpdbg_parser.y" { - (yyval).type = COND_PARAM; + (yyval).type = COND_PARAM; (yyval).str = (yyvsp[(2) - (2)]).str; (yyval).len = (yyvsp[(2) - (2)]).len; - } - break; - - case 15: -/* Line 1802 of yacc.c */ -#line 129 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { (yyval) = (yyvsp[(1) - (1)]); } + ;} break; case 16: -/* Line 1802 of yacc.c */ -#line 130 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { (yyval) = (yyvsp[(1) - (1)]); } + +/* Line 1455 of yacc.c */ +#line 129 "sapi/phpdbg/phpdbg_parser.y" + { (yyval) = (yyvsp[(1) - (1)]); ;} break; case 17: -/* Line 1802 of yacc.c */ -#line 131 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { (yyval) = (yyvsp[(1) - (1)]); } + +/* Line 1455 of yacc.c */ +#line 130 "sapi/phpdbg/phpdbg_parser.y" + { (yyval) = (yyvsp[(1) - (1)]); ;} break; case 18: -/* Line 1802 of yacc.c */ -#line 132 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { (yyval) = (yyvsp[(1) - (1)]); } + +/* Line 1455 of yacc.c */ +#line 131 "sapi/phpdbg/phpdbg_parser.y" + { (yyval) = (yyvsp[(1) - (1)]); ;} break; case 19: -/* Line 1802 of yacc.c */ -#line 133 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { (yyval) = (yyvsp[(1) - (1)]); } + +/* Line 1455 of yacc.c */ +#line 132 "sapi/phpdbg/phpdbg_parser.y" + { (yyval) = (yyvsp[(1) - (1)]); ;} break; case 20: -/* Line 1802 of yacc.c */ -#line 134 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { (yyval) = (yyvsp[(1) - (1)]); } + +/* Line 1455 of yacc.c */ +#line 133 "sapi/phpdbg/phpdbg_parser.y" + { (yyval) = (yyvsp[(1) - (1)]); ;} break; case 21: -/* Line 1802 of yacc.c */ -#line 135 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { (yyval) = (yyvsp[(1) - (1)]); } + +/* Line 1455 of yacc.c */ +#line 134 "sapi/phpdbg/phpdbg_parser.y" + { (yyval) = (yyvsp[(1) - (1)]); ;} break; case 22: -/* Line 1802 of yacc.c */ -#line 139 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { - (yyval).type = EVAL_PARAM; - (yyval).str = (yyvsp[(2) - (2)]).str; - (yyval).len = (yyvsp[(2) - (2)]).len; - } + +/* Line 1455 of yacc.c */ +#line 135 "sapi/phpdbg/phpdbg_parser.y" + { (yyval) = (yyvsp[(1) - (1)]); ;} break; case 23: -/* Line 1802 of yacc.c */ -#line 144 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { - (yyval).type = SHELL_PARAM; - (yyval).str = (yyvsp[(2) - (2)]).str; - (yyval).len = (yyvsp[(2) - (2)]).len; - } + +/* Line 1455 of yacc.c */ +#line 139 "sapi/phpdbg/phpdbg_parser.y" + { PHPDBG_G(req_id) = (yyvsp[(1) - (1)]).num; ;} break; - case 24: -/* Line 1802 of yacc.c */ -#line 149 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" + case 25: + +/* Line 1455 of yacc.c */ +#line 144 "sapi/phpdbg/phpdbg_parser.y" + { + (yyval).type = EVAL_PARAM; + (yyval).str = (yyvsp[(3) - (3)]).str; + (yyval).len = (yyvsp[(3) - (3)]).len; + ;} + break; + + case 26: + +/* Line 1455 of yacc.c */ +#line 149 "sapi/phpdbg/phpdbg_parser.y" + { + (yyval).type = SHELL_PARAM; + (yyval).str = (yyvsp[(3) - (3)]).str; + (yyval).len = (yyvsp[(3) - (3)]).len; + ;} + break; + + case 27: + +/* Line 1455 of yacc.c */ +#line 154 "sapi/phpdbg/phpdbg_parser.y" { (yyval).type = RUN_PARAM; (yyval).len = 0; - } + ;} break; - case 25: -/* Line 1802 of yacc.c */ -#line 153 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" - { - (yyval).type = RUN_PARAM; - (yyval).str = (yyvsp[(2) - (2)]).str; - (yyval).len = (yyvsp[(2) - (2)]).len; - } + case 28: + +/* Line 1455 of yacc.c */ +#line 158 "sapi/phpdbg/phpdbg_parser.y" + { + (yyval).type = RUN_PARAM; + (yyval).str = (yyvsp[(3) - (3)]).str; + (yyval).len = (yyvsp[(3) - (3)]).len; + ;} break; -/* Line 1802 of yacc.c */ -#line 1648 "sapi/phpdbg/phpdbg_parser.c" + +/* Line 1455 of yacc.c */ +#line 1638 "sapi/phpdbg/phpdbg_parser.c" default: break; } - /* User semantic actions sometimes alter yychar, and that requires - that yytoken be updated with the new translation. We take the - approach of translating immediately before every use of yytoken. - One alternative is translating here after every semantic action, - but that translation would be missed if the semantic action invokes - YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or - if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an - incorrect destructor might then be invoked immediately. In the - case of YYERROR or YYBACKUP, subsequent parser actions might lead - to an incorrect destructor call or verbose syntax error message - before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -1685,47 +1664,44 @@ yyreduce: | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (tsrm_ls, YY_("syntax error")); + yyerror (YY_("syntax error")); #else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (tsrm_ls, yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; + YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); + if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) + { + YYSIZE_T yyalloc = 2 * yysize; + if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) + yyalloc = YYSTACK_ALLOC_MAXIMUM; + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yyalloc); + if (yymsg) + yymsg_alloc = yyalloc; + else + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + } + } + + if (0 < yysize && yysize <= yymsg_alloc) + { + (void) yysyntax_error (yymsg, yystate, yychar); + yyerror (yymsg); + } + else + { + yyerror (YY_("syntax error")); + if (yysize != 0) + goto yyexhaustedlab; + } } -# undef YYSYNTAX_ERROR #endif } @@ -1745,7 +1721,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval, tsrm_ls); + yytoken, &yylval); yychar = YYEMPTY; } } @@ -1784,7 +1760,7 @@ yyerrlab1: for (;;) { yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) + if (yyn != YYPACT_NINF) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) @@ -1801,15 +1777,13 @@ yyerrlab1: yydestruct ("Error: popping", - yystos[yystate], yyvsp, tsrm_ls); + yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ @@ -1833,25 +1807,20 @@ yyabortlab: yyresult = 1; goto yyreturn; -#if !defined yyoverflow || YYERROR_VERBOSE +#if !defined(yyoverflow) || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (tsrm_ls, YY_("memory exhausted")); + yyerror (YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, tsrm_ls); - } + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -1859,7 +1828,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, tsrm_ls); + yystos[*yyssp], yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1875,16 +1844,17 @@ yyreturn: } -/* Line 2050 of yacc.c */ -#line 160 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" + +/* Line 1675 of yacc.c */ +#line 165 "sapi/phpdbg/phpdbg_parser.y" -static int yyerror(void ***tsrm_ls, const char *msg) { - phpdbg_error("Parse Error: %s", msg); +static int yyerror(const char *msg) { + phpdbg_error("command", "type=\"parseerror\" msg=\"%s\"", "Parse Error: %s", msg); { const phpdbg_param_t *top = PHPDBG_G(parser_stack); - + while (top) { phpdbg_param_debug(top, "--> "); top = top->next; @@ -1893,12 +1863,9 @@ static int yyerror(void ***tsrm_ls, const char *msg) { return 0; } -int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC) { - phpdbg_init_lexer(stack, input TSRMLS_CC); +int phpdbg_do_parse(phpdbg_param_t *stack, char *input) { + phpdbg_init_lexer(stack, input); -#ifdef ZTS - return yyparse(TSRMLS_C); -#else - return yyparse(NULL); -#endif + return yyparse(); } + diff --git a/sapi/phpdbg/phpdbg_parser.h b/sapi/phpdbg/phpdbg_parser.h index da5892ac99..0c66b27dc0 100644 --- a/sapi/phpdbg/phpdbg_parser.h +++ b/sapi/phpdbg/phpdbg_parser.h @@ -1,19 +1,21 @@ -/* A Bison parser, made by GNU Bison 2.7.12-4996. */ -/* Bison interface for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. - +/* A Bison parser, made by GNU Bison 2.4.1. */ + +/* Skeleton interface for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -26,22 +28,14 @@ special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. - + This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -#ifndef YY_PHPDBG_SAPI_PHPDBG_PHPDBG_PARSER_H_INCLUDED -# define YY_PHPDBG_SAPI_PHPDBG_PHPDBG_PARSER_H_INCLUDED -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int phpdbg_debug; -#endif /* "%code requires" blocks. */ -/* Line 2060 of yacc.c */ -#line 31 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y" + +/* Line 1676 of yacc.c */ +#line 31 "sapi/phpdbg/phpdbg_parser.y" #include "phpdbg.h" #ifndef YY_TYPEDEF_YY_SCANNER_T @@ -50,8 +44,9 @@ typedef void* yyscan_t; #endif -/* Line 2060 of yacc.c */ -#line 55 "sapi/phpdbg/phpdbg_parser.h" + +/* Line 1676 of yacc.c */ +#line 50 "sapi/phpdbg/phpdbg_parser.h" /* Tokens. */ #ifndef YYTOKENTYPE @@ -76,28 +71,10 @@ typedef void* yyscan_t; T_OPCODE = 272, T_ID = 273, T_INPUT = 274, - T_UNEXPECTED = 275 + T_UNEXPECTED = 275, + T_REQ_ID = 276 }; #endif -/* Tokens. */ -#define T_EVAL 258 -#define T_RUN 259 -#define T_SHELL 260 -#define T_IF 261 -#define T_TRUTHY 262 -#define T_FALSY 263 -#define T_STRING 264 -#define T_COLON 265 -#define T_DCOLON 266 -#define T_POUND 267 -#define T_PROTO 268 -#define T_DIGITS 269 -#define T_LITERAL 270 -#define T_ADDR 271 -#define T_OPCODE 272 -#define T_ID 273 -#define T_INPUT 274 -#define T_UNEXPECTED 275 @@ -109,18 +86,5 @@ typedef int YYSTYPE; #endif -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int phpdbg_parse (void *YYPARSE_PARAM); -#else -int phpdbg_parse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int phpdbg_parse (void *tsrm_ls); -#else -int phpdbg_parse (); -#endif -#endif /* ! YYPARSE_PARAM */ -#endif /* !YY_PHPDBG_SAPI_PHPDBG_PHPDBG_PARSER_H_INCLUDED */ + diff --git a/sapi/phpdbg/phpdbg_parser.y b/sapi/phpdbg/phpdbg_parser.y index 702bf78455..8b3ab27f85 100644 --- a/sapi/phpdbg/phpdbg_parser.y +++ b/sapi/phpdbg/phpdbg_parser.y @@ -1,12 +1,12 @@ %{ - + /* * phpdbg_parser.y * (from php-src root) * flex sapi/phpdbg/dev/phpdbg_lexer.l * bison sapi/phpdbg/dev/phpdbg_parser.y */ - + #include "phpdbg.h" #include "phpdbg_cmd.h" #include "phpdbg_utils.h" @@ -19,7 +19,7 @@ #include "phpdbg_lexer.h" #undef yyerror -static int yyerror(void ***tsrm_ls, const char *msg); +static int yyerror(const char *msg); ZEND_EXTERN_MODULE_GLOBALS(phpdbg); @@ -27,7 +27,7 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); %pure-parser %error-verbose - + %code requires { #include "phpdbg.h" #ifndef YY_TYPEDEF_YY_SCANNER_T @@ -36,8 +36,6 @@ typedef void* yyscan_t; #endif } -%parse-param { void *tsrm_ls } - %output "sapi/phpdbg/phpdbg_parser.c" %defines "sapi/phpdbg/phpdbg_parser.h" @@ -59,6 +57,7 @@ typedef void* yyscan_t; %token T_ID "identifier (command or function name)" %token T_INPUT "input (input string or data)" %token T_UNEXPECTED "input" +%token T_REQ_ID "request id (-r %d)" %% /* Rules */ @@ -71,10 +70,11 @@ input parameters : parameter { phpdbg_stack_push(PHPDBG_G(parser_stack), &$1); } | parameters parameter { phpdbg_stack_push(PHPDBG_G(parser_stack), &$2); } + | parameters req_id { $$ = $1; } ; parameter - : T_ID T_COLON T_DIGITS { + : T_ID T_COLON T_DIGITS { $$.type = FILE_PARAM; $$.file.name = $2.str; $$.file.line = $3.num; @@ -104,25 +104,25 @@ parameter } $$.file.line = $5.num; } - | T_ID T_DCOLON T_ID { + | T_ID T_DCOLON T_ID { $$.type = METHOD_PARAM; $$.method.class = $1.str; $$.method.name = $3.str; } - | T_ID T_DCOLON T_ID T_POUND T_DIGITS { + | T_ID T_DCOLON T_ID T_POUND T_DIGITS { $$.type = NUMERIC_METHOD_PARAM; $$.method.class = $1.str; $$.method.name = $3.str; - $$.num = $5.num; + $$.num = $5.num; } | T_ID T_POUND T_DIGITS { $$.type = NUMERIC_FUNCTION_PARAM; $$.str = $1.str; $$.len = $1.len; - $$.num = $3.num; + $$.num = $3.num; } | T_IF T_INPUT { - $$.type = COND_PARAM; + $$.type = COND_PARAM; $$.str = $2.str; $$.len = $2.len; } @@ -135,36 +135,41 @@ parameter | T_ID { $$ = $1; } ; +req_id + : T_REQ_ID { PHPDBG_G(req_id) = $1.num; } + | /* empty */ +; + full_expression - : T_EVAL T_INPUT { - $$.type = EVAL_PARAM; - $$.str = $2.str; - $$.len = $2.len; + : T_EVAL req_id T_INPUT { + $$.type = EVAL_PARAM; + $$.str = $3.str; + $$.len = $3.len; } - | T_SHELL T_INPUT { - $$.type = SHELL_PARAM; - $$.str = $2.str; - $$.len = $2.len; + | T_SHELL req_id T_INPUT { + $$.type = SHELL_PARAM; + $$.str = $3.str; + $$.len = $3.len; } - | T_RUN { + | T_RUN req_id { $$.type = RUN_PARAM; $$.len = 0; } - | T_RUN T_INPUT { - $$.type = RUN_PARAM; - $$.str = $2.str; - $$.len = $2.len; + | T_RUN req_id T_INPUT { + $$.type = RUN_PARAM; + $$.str = $3.str; + $$.len = $3.len; } ; %% -static int yyerror(void ***tsrm_ls, const char *msg) { - phpdbg_error("Parse Error: %s", msg); +static int yyerror(const char *msg) { + phpdbg_error("command", "type=\"parseerror\" msg=\"%s\"", "Parse Error: %s", msg); { const phpdbg_param_t *top = PHPDBG_G(parser_stack); - + while (top) { phpdbg_param_debug(top, "--> "); top = top->next; @@ -173,12 +178,8 @@ static int yyerror(void ***tsrm_ls, const char *msg) { return 0; } -int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC) { - phpdbg_init_lexer(stack, input TSRMLS_CC); +int phpdbg_do_parse(phpdbg_param_t *stack, char *input) { + phpdbg_init_lexer(stack, input); -#ifdef ZTS - return yyparse(TSRMLS_C); -#else - return yyparse(NULL); -#endif + return yyparse(); } diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c index ddd8725337..116c5451b7 100644 --- a/sapi/phpdbg/phpdbg_print.c +++ b/sapi/phpdbg/phpdbg_print.c @@ -26,68 +26,69 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -#define PHPDBG_PRINT_COMMAND_D(f, h, a, m, l, s) \ - PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[9]) +#define PHPDBG_PRINT_COMMAND_D(f, h, a, m, l, s, flags) \ + PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[9], flags) const phpdbg_command_t phpdbg_print_commands[] = { - PHPDBG_PRINT_COMMAND_D(exec, "print out the instructions in the execution context", 'e', print_exec, NULL, 0), - PHPDBG_PRINT_COMMAND_D(opline, "print out the instruction in the current opline", 'o', print_opline, NULL, 0), - PHPDBG_PRINT_COMMAND_D(class, "print out the instructions in the specified class", 'c', print_class, NULL, "s"), - PHPDBG_PRINT_COMMAND_D(method, "print out the instructions in the specified method", 'm', print_method, NULL, "m"), - PHPDBG_PRINT_COMMAND_D(func, "print out the instructions in the specified function", 'f', print_func, NULL, "s"), - PHPDBG_PRINT_COMMAND_D(stack, "print out the instructions in the current stack", 's', print_stack, NULL, 0), + PHPDBG_PRINT_COMMAND_D(exec, "print out the instructions in the execution context", 'e', print_exec, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_PRINT_COMMAND_D(opline, "print out the instruction in the current opline", 'o', print_opline, NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_PRINT_COMMAND_D(class, "print out the instructions in the specified class", 'c', print_class, NULL, "s", PHPDBG_ASYNC_SAFE), + PHPDBG_PRINT_COMMAND_D(method, "print out the instructions in the specified method", 'm', print_method, NULL, "m", PHPDBG_ASYNC_SAFE), + PHPDBG_PRINT_COMMAND_D(func, "print out the instructions in the specified function", 'f', print_func, NULL, "s", PHPDBG_ASYNC_SAFE), + PHPDBG_PRINT_COMMAND_D(stack, "print out the instructions in the current stack", 's', print_stack, NULL, 0, PHPDBG_ASYNC_SAFE), PHPDBG_END_COMMAND }; PHPDBG_PRINT(opline) /* {{{ */ { - if (EG(in_execution) && EG(current_execute_data)) { - phpdbg_print_opline(EG(current_execute_data), 1 TSRMLS_CC); + if (PHPDBG_G(in_execution) && EG(current_execute_data)) { + phpdbg_print_opline(EG(current_execute_data), 1); } else { - phpdbg_error("Not Executing!"); + phpdbg_error("inactive", "type=\"execution\"", "Not Executing!"); } return SUCCESS; } /* }}} */ -static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC) /* {{{ */ +static inline void phpdbg_print_function_helper(zend_function *method) /* {{{ */ { switch (method->type) { case ZEND_USER_FUNCTION: { zend_op_array* op_array = &(method->op_array); HashTable vars; - + if (op_array) { zend_op *opline = &(op_array->opcodes[0]); - zend_uint opcode = 0, + uint32_t opcode = 0, end = op_array->last-1; if (method->common.scope) { - phpdbg_writeln("\tL%d-%d %s::%s() %s", - op_array->line_start, op_array->line_end, - method->common.scope->name, - method->common.function_name, - op_array->filename ? op_array->filename : "unknown"); + phpdbg_writeln("printoplineinfo", "type=\"User\" startline=\"%d\" endline=\"%d\" method=\"%s::%s\" file=\"%s\"", "\tL%d-%d %s::%s() %s", + op_array->line_start, + op_array->line_end, + method->common.scope->name->val, + method->common.function_name->val, + op_array->filename ? op_array->filename->val : "unknown"); } else { - phpdbg_writeln("\tL%d-%d %s() %s", - method->common.function_name ? op_array->line_start : 0, + phpdbg_writeln("printoplineinfo", "type=\"User\" startline=\"%d\" endline=\"%d\" function=\"%s\" file=\"%s\"", "\tL%d-%d %s() %s", + method->common.function_name ? op_array->line_start : 0, method->common.function_name ? op_array->line_end : 0, - method->common.function_name ? method->common.function_name : "{main}", - op_array->filename ? op_array->filename : "unknown"); + method->common.function_name ? method->common.function_name->val : "{main}", + op_array->filename ? op_array->filename->val : "unknown"); } zend_hash_init(&vars, op_array->last, NULL, NULL, 0); do { - char *decode = phpdbg_decode_opline(op_array, opline, &vars TSRMLS_CC); + char *decode = phpdbg_decode_opline(op_array, opline, &vars); if (decode != NULL) { - phpdbg_writeln("\t\tL%u\t%p %-30s %s", + phpdbg_writeln("print", "line=\"%u\" opline=\"%p\" opcode=\"%s\" op=\"%s\"", "\t\tL%u\t%p %-30s %s", opline->lineno, - opline, + opline, phpdbg_decode_opcode(opline->opcode), decode); free(decode); } else { - phpdbg_error("\tFailed to decode opline %16p", opline); + phpdbg_error("print", "type=\"decodefailure\" opline=\"%16p\"", "\tFailed to decode opline %16p", opline); } opline++; } while (opcode++ < end); @@ -97,9 +98,9 @@ static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC) default: { if (method->common.scope) { - phpdbg_writeln("\tInternal %s::%s()", method->common.scope->name, method->common.function_name); + phpdbg_writeln("printoplineinfo", "type=\"Internal\" method=\"%s::%s\"", "\tInternal %s::%s()", method->common.scope->name->val, method->common.function_name->val); } else { - phpdbg_writeln("\tInternal %s()", method->common.function_name); + phpdbg_writeln("printoplineinfo", "type=\"Internal\" function=\"%s\"", "\tInternal %s()", method->common.function_name->val); } } } @@ -108,17 +109,17 @@ static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC) PHPDBG_PRINT(exec) /* {{{ */ { if (PHPDBG_G(exec)) { - if (!PHPDBG_G(ops)) { - phpdbg_compile(TSRMLS_C); + if (!PHPDBG_G(ops) && !(PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER)) { + phpdbg_compile(); } if (PHPDBG_G(ops)) { - phpdbg_notice("Context %s", PHPDBG_G(exec)); + phpdbg_notice("printinfo", "file=\"%s\" num=\"%d\"", "Context %s (%d ops)", PHPDBG_G(exec), PHPDBG_G(ops)->last); - phpdbg_print_function_helper((zend_function*) PHPDBG_G(ops) TSRMLS_CC); + phpdbg_print_function_helper((zend_function*) PHPDBG_G(ops)); } } else { - phpdbg_error("No execution context set"); + phpdbg_error("inactive", "type=\"nocontext\"", "No execution context set"); } return SUCCESS; @@ -126,25 +127,24 @@ return SUCCESS; PHPDBG_PRINT(stack) /* {{{ */ { - zend_op_array *ops = EG(active_op_array); - - if (EG(in_execution) && ops) { + if (PHPDBG_G(in_execution) && EG(current_execute_data)) { + zend_op_array *ops = &EG(current_execute_data)->func->op_array; if (ops->function_name) { if (ops->scope) { - phpdbg_notice("Stack in %s::%s()", ops->scope->name, ops->function_name); + phpdbg_notice("printinfo", "method=\"%s::%s\" num=\"%d\"", "Stack in %s::%s() (%d ops)", ops->scope->name->val, ops->function_name->val, ops->last); } else { - phpdbg_notice("Stack in %s()", ops->function_name); + phpdbg_notice("printinfo", "function=\"%s\" num=\"%d\"", "Stack in %s() (%d ops)", ops->function_name->val, ops->last); } } else { if (ops->filename) { - phpdbg_notice("Stack in %s", ops->filename); + phpdbg_notice("printinfo", "file=\"%s\" num=\"%d\"", "Stack in %s (%d ops)", ops->filename->val, ops->last); } else { - phpdbg_notice("Stack @ %p", ops); + phpdbg_notice("printinfo", "opline=\"%p\" num=\"%d\"", "Stack @ %p (%d ops)", ops, ops->last); } } - phpdbg_print_function_helper((zend_function*) ops TSRMLS_CC); + phpdbg_print_function_helper((zend_function*) ops); } else { - phpdbg_error("Not Executing!"); + phpdbg_error("inactive", "type=\"execution\"", "Not Executing!"); } return SUCCESS; @@ -152,32 +152,33 @@ PHPDBG_PRINT(stack) /* {{{ */ PHPDBG_PRINT(class) /* {{{ */ { - zend_class_entry **ce; + zend_class_entry *ce; - if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) { - phpdbg_notice("%s %s: %s", - ((*ce)->type == ZEND_USER_CLASS) ? + if (phpdbg_safe_class_lookup(param->str, param->len, &ce) == SUCCESS) { + phpdbg_notice("printinfo", "type=\"%s\" flag=\"%s\" class=\"%s\" num=\"%d\"", "%s %s: %s (%d methods)", + (ce->type == ZEND_USER_CLASS) ? "User" : "Internal", - ((*ce)->ce_flags & ZEND_ACC_INTERFACE) ? + (ce->ce_flags & ZEND_ACC_INTERFACE) ? "Interface" : - ((*ce)->ce_flags & ZEND_ACC_ABSTRACT) ? + (ce->ce_flags & ZEND_ACC_ABSTRACT) ? "Abstract Class" : "Class", - (*ce)->name); + ce->name->val, + zend_hash_num_elements(&ce->function_table)); + + phpdbg_xml("<printmethods %r>"); - phpdbg_writeln("Methods (%d):", zend_hash_num_elements(&(*ce)->function_table)); - if (zend_hash_num_elements(&(*ce)->function_table)) { - HashPosition position; + if (zend_hash_num_elements(&ce->function_table)) { zend_function *method; - for (zend_hash_internal_pointer_reset_ex(&(*ce)->function_table, &position); - zend_hash_get_current_data_ex(&(*ce)->function_table, (void**) &method, &position) == SUCCESS; - zend_hash_move_forward_ex(&(*ce)->function_table, &position)) { - phpdbg_print_function_helper(method TSRMLS_CC); - } + ZEND_HASH_FOREACH_PTR(&ce->function_table, method) { + phpdbg_print_function_helper(method); + } ZEND_HASH_FOREACH_END(); } + + phpdbg_xml("</printmethods>"); } else { - phpdbg_error("The class %s could not be found", param->str); + phpdbg_error("print", "type=\"noclass\" class=\"%s\"", "The class %s could not be found", param->str); } return SUCCESS; @@ -185,25 +186,27 @@ PHPDBG_PRINT(class) /* {{{ */ PHPDBG_PRINT(method) /* {{{ */ { - zend_class_entry **ce; + zend_class_entry *ce; - if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) { + if (phpdbg_safe_class_lookup(param->method.class, strlen(param->method.class), &ce) == SUCCESS) { zend_function *fbc; - char *lcname = zend_str_tolower_dup(param->method.name, strlen(param->method.name)); + zend_string *lcname = zend_string_alloc(strlen(param->method.name), 0); + zend_str_tolower_copy(lcname->val, param->method.name, lcname->len); - if (zend_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**)&fbc) == SUCCESS) { - phpdbg_notice("%s Method %s", + if ((fbc = zend_hash_find_ptr(&ce->function_table, lcname))) { + phpdbg_notice("printinfo", "type=\"%s\" flags=\"Method\" symbol=\"%s\" num=\"%d\"", "%s Method %s (%d ops)", (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal", - fbc->common.function_name); + fbc->common.function_name->val, + (fbc->type == ZEND_USER_FUNCTION) ? fbc->op_array.last : 0); - phpdbg_print_function_helper(fbc TSRMLS_CC); + phpdbg_print_function_helper(fbc); } else { - phpdbg_error("The method %s could not be found", param->method.name); + phpdbg_error("print", "type=\"nomethod\" method=\"%s::%s\"", "The method %s::%s could not be found", param->method.class, param->method.name); } - efree(lcname); + zend_string_release(lcname); } else { - phpdbg_error("The class %s could not be found", param->method.class); + phpdbg_error("print", "type=\"noclass\" class=\"%s\"", "The class %s could not be found", param->method.class); } return SUCCESS; @@ -215,7 +218,7 @@ PHPDBG_PRINT(func) /* {{{ */ zend_function* fbc; const char *func_name = param->str; size_t func_name_len = param->len; - char *lcname; + zend_string *lcname; /* search active scope if begins with period */ if (func_name[0] == '.') { if (EG(scope)) { @@ -224,28 +227,34 @@ PHPDBG_PRINT(func) /* {{{ */ func_table = &EG(scope)->function_table; } else { - phpdbg_error("No active class"); + phpdbg_error("inactive", "type=\"noclasses\"", "No active class"); return SUCCESS; } } else if (!EG(function_table)) { - phpdbg_error("No function table loaded"); + phpdbg_error("inactive", "type=\"function_table\"", "No function table loaded"); return SUCCESS; } else { func_table = EG(function_table); } - lcname = zend_str_tolower_dup(func_name, func_name_len); + lcname = zend_string_alloc(func_name_len, 0); + zend_str_tolower_copy(lcname->val, func_name, lcname->len); - if (zend_hash_find(func_table, lcname, strlen(lcname)+1, (void**)&fbc) == SUCCESS) { - phpdbg_notice("%s %s %s", - (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal", - (fbc->common.scope) ? "Method" : "Function", - fbc->common.function_name); + phpdbg_try_access { + if ((fbc = zend_hash_find_ptr(func_table, lcname))) { + phpdbg_notice("printinfo", "type=\"%s\" flags=\"%s\" symbol=\"%s\" num=\"%d\"", "%s %s %s (%d ops)", + (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal", + (fbc->common.scope) ? "Method" : "Function", + fbc->common.function_name->val, + (fbc->type == ZEND_USER_FUNCTION) ? fbc->op_array.last : 0); - phpdbg_print_function_helper(fbc TSRMLS_CC); - } else { - phpdbg_error("The function %s could not be found", func_name); - } + phpdbg_print_function_helper(fbc); + } else { + phpdbg_error("print", "type=\"nofunction\" function=\"%s\"", "The function %s could not be found", func_name); + } + } phpdbg_catch_access { + phpdbg_error("signalsegv", "function=\"%.*s\"", "Couldn't fetch function %.*s, invalid data source", (int) func_name_len, func_name); + } phpdbg_end_try_access(); efree(lcname); diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 48fabca3f9..cb03b1a287 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -22,12 +22,13 @@ #include <string.h> #include "zend.h" #include "zend_compile.h" +#include "zend_exceptions.h" #include "phpdbg.h" + #include "phpdbg_help.h" #include "phpdbg_print.h" #include "phpdbg_info.h" #include "phpdbg_break.h" -#include "phpdbg_bp.h" #include "phpdbg_opcode.h" #include "phpdbg_list.h" #include "phpdbg_utils.h" @@ -37,253 +38,295 @@ #include "phpdbg_frame.h" #include "phpdbg_lexer.h" #include "phpdbg_parser.h" +#include "phpdbg_wait.h" +#include "phpdbg_eol.h" + +ZEND_EXTERN_MODULE_GLOBALS(phpdbg); +extern int phpdbg_startup_run; + +#ifdef HAVE_LIBDL +#ifdef PHP_WIN32 +#include "win32/param.h" +#include "win32/winutil.h" +#define GET_DL_ERROR() php_win_err() +#elif defined(NETWARE) +#include <sys/param.h> +#define GET_DL_ERROR() dlerror() +#else +#include <sys/param.h> +#define GET_DL_ERROR() DL_ERROR() +#endif +#endif /* {{{ command declarations */ const phpdbg_command_t phpdbg_prompt_commands[] = { - PHPDBG_COMMAND_D(exec, "set execution context", 'e', NULL, "s"), - PHPDBG_COMMAND_D(step, "step through execution", 's', NULL, 0), - PHPDBG_COMMAND_D(continue,"continue execution", 'c', NULL, 0), - PHPDBG_COMMAND_D(run, "attempt execution", 'r', NULL, "|s"), - PHPDBG_COMMAND_D(ev, "evaluate some code", 0, NULL, "i"), - PHPDBG_COMMAND_D(until, "continue past the current line", 'u', NULL, 0), - PHPDBG_COMMAND_D(finish, "continue past the end of the stack", 'F', NULL, 0), - PHPDBG_COMMAND_D(leave, "continue until the end of the stack", 'L', NULL, 0), - PHPDBG_COMMAND_D(print, "print something", 'p', phpdbg_print_commands, 0), - PHPDBG_COMMAND_D(break, "set breakpoint", 'b', phpdbg_break_commands, "|*c"), - PHPDBG_COMMAND_D(back, "show trace", 't', NULL, "|n"), - PHPDBG_COMMAND_D(frame, "switch to a frame", 'f', NULL, "|n"), - PHPDBG_COMMAND_D(list, "lists some code", 'l', phpdbg_list_commands, "*"), - PHPDBG_COMMAND_D(info, "displays some informations", 'i', phpdbg_info_commands, "s"), - PHPDBG_COMMAND_D(clean, "clean the execution environment", 'X', NULL, 0), - PHPDBG_COMMAND_D(clear, "clear breakpoints", 'C', NULL, 0), - PHPDBG_COMMAND_D(help, "show help menu", 'h', phpdbg_help_commands, "|s"), - PHPDBG_COMMAND_D(set, "set phpdbg configuration", 'S', phpdbg_set_commands, "s"), - PHPDBG_COMMAND_D(register,"register a function", 'R', NULL, "s"), - PHPDBG_COMMAND_D(source, "execute a phpdbginit", '<', NULL, "s"), - PHPDBG_COMMAND_D(export, "export breaks to a .phpdbginit script", '>', NULL, "s"), - PHPDBG_COMMAND_D(sh, "shell a command", 0, NULL, "i"), - PHPDBG_COMMAND_D(quit, "exit phpdbg", 'q', NULL, 0), - PHPDBG_COMMAND_D(watch, "set watchpoint", 'w', phpdbg_watch_commands, "|ss"), + PHPDBG_COMMAND_D(exec, "set execution context", 'e', NULL, "s", 0), + PHPDBG_COMMAND_D(step, "step through execution", 's', NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_COMMAND_D(continue,"continue execution", 'c', NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_COMMAND_D(run, "attempt execution", 'r', NULL, "|s", 0), + PHPDBG_COMMAND_D(ev, "evaluate some code", 0 , NULL, "i", PHPDBG_ASYNC_SAFE), /* restricted ASYNC_SAFE */ + PHPDBG_COMMAND_D(until, "continue past the current line", 'u', NULL, 0, 0), + PHPDBG_COMMAND_D(finish, "continue past the end of the stack", 'F', NULL, 0, 0), + PHPDBG_COMMAND_D(leave, "continue until the end of the stack", 'L', NULL, 0, 0), + PHPDBG_COMMAND_D(print, "print something", 'p', phpdbg_print_commands, 0, 0), + PHPDBG_COMMAND_D(break, "set breakpoint", 'b', phpdbg_break_commands, "|*c", 0), + PHPDBG_COMMAND_D(back, "show trace", 't', NULL, "|n", PHPDBG_ASYNC_SAFE), + PHPDBG_COMMAND_D(frame, "switch to a frame", 'f', NULL, "|n", PHPDBG_ASYNC_SAFE), + PHPDBG_COMMAND_D(list, "lists some code", 'l', phpdbg_list_commands, "*", PHPDBG_ASYNC_SAFE), + PHPDBG_COMMAND_D(info, "displays some informations", 'i', phpdbg_info_commands, "s", PHPDBG_ASYNC_SAFE), + PHPDBG_COMMAND_D(clean, "clean the execution environment", 'X', NULL, 0, 0), + PHPDBG_COMMAND_D(clear, "clear breakpoints", 'C', NULL, 0, 0), + PHPDBG_COMMAND_D(help, "show help menu", 'h', phpdbg_help_commands, "|s", PHPDBG_ASYNC_SAFE), + PHPDBG_COMMAND_D(set, "set phpdbg configuration", 'S', phpdbg_set_commands, "s", PHPDBG_ASYNC_SAFE), + PHPDBG_COMMAND_D(register,"register a function", 'R', NULL, "s", 0), + PHPDBG_COMMAND_D(source, "execute a phpdbginit", '<', NULL, "s", 0), + PHPDBG_COMMAND_D(export, "export breaks to a .phpdbginit script", '>', NULL, "s", PHPDBG_ASYNC_SAFE), + PHPDBG_COMMAND_D(sh, "shell a command", 0 , NULL, "i", 0), + PHPDBG_COMMAND_D(quit, "exit phpdbg", 'q', NULL, 0, PHPDBG_ASYNC_SAFE), + PHPDBG_COMMAND_D(wait, "wait for other process", 'W', NULL, 0, 0), + PHPDBG_COMMAND_D(watch, "set watchpoint", 'w', phpdbg_watch_commands, "|ss", 0), + PHPDBG_COMMAND_D(eol, "set EOL", 'E', NULL, "|s", 0), PHPDBG_END_COMMAND }; /* }}} */ -ZEND_EXTERN_MODULE_GLOBALS(phpdbg); - -static inline int phpdbg_call_register(phpdbg_param_t *stack TSRMLS_DC) /* {{{ */ +static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */ { phpdbg_param_t *name = NULL; if (stack->type == STACK_PARAM) { + char *lc_name; + name = stack->next; - + if (!name || name->type != STR_PARAM) { return FAILURE; } - - if (zend_hash_exists( - &PHPDBG_G(registered), name->str, name->len+1)) { - zval fname, *fretval; - zend_fcall_info fci; + lc_name = zend_str_tolower_dup(name->str, name->len); - ZVAL_STRINGL(&fname, name->str, name->len, 1); + if (zend_hash_str_exists(&PHPDBG_G(registered), lc_name, name->len)) { + zval fretval; + zend_fcall_info fci; memset(&fci, 0, sizeof(zend_fcall_info)); + ZVAL_STRINGL(&fci.function_name, lc_name, name->len); fci.size = sizeof(zend_fcall_info); fci.function_table = &PHPDBG_G(registered); - fci.function_name = &fname; - fci.symbol_table = EG(active_symbol_table); - fci.object_ptr = NULL; - fci.retval_ptr_ptr = &fretval; + fci.symbol_table = zend_rebuild_symbol_table(); + fci.object = NULL; + fci.retval = &fretval; fci.no_separation = 1; if (name->next) { zval params; phpdbg_param_t *next = name->next; - + array_init(¶ms); while (next) { char *buffered = NULL; - + switch (next->type) { case OP_PARAM: case COND_PARAM: case STR_PARAM: - add_next_index_stringl( - ¶ms, - next->str, - next->len, 1); + add_next_index_stringl(¶ms, next->str, next->len); break; - + case NUMERIC_PARAM: add_next_index_long(¶ms, next->num); break; - + case METHOD_PARAM: - spprintf(&buffered, 0, "%s::%s", - next->method.class, next->method.name); - add_next_index_string(¶ms, buffered, 0); + spprintf(&buffered, 0, "%s::%s", next->method.class, next->method.name); + add_next_index_string(¶ms, buffered); break; - + case NUMERIC_METHOD_PARAM: - spprintf(&buffered, 0, "%s::%s#%ld", - next->method.class, next->method.name, next->num); - add_next_index_string(¶ms, buffered, 0); + spprintf(&buffered, 0, "%s::%s#%ld", next->method.class, next->method.name, next->num); + add_next_index_string(¶ms, buffered); break; - + case NUMERIC_FUNCTION_PARAM: - spprintf(&buffered, 0, "%s#%ld", - next->str, next->num); - add_next_index_string(¶ms, buffered, 0); + spprintf(&buffered, 0, "%s#%ld", next->str, next->num); + add_next_index_string(¶ms, buffered); break; - + case FILE_PARAM: - spprintf(&buffered, 0, "%s:%ld", - next->file.name, next->file.line); - add_next_index_string(¶ms, buffered, 0); + spprintf(&buffered, 0, "%s:%ld", next->file.name, next->file.line); + add_next_index_string(¶ms, buffered); break; - + case NUMERIC_FILE_PARAM: - spprintf(&buffered, 0, "%s:#%ld", - next->file.name, next->file.line); - add_next_index_string(¶ms, buffered, 0); + spprintf(&buffered, 0, "%s:#%ld", next->file.name, next->file.line); + add_next_index_string(¶ms, buffered); break; - + default: { /* not yet */ } } - - next = next->next; + + next = next->next; } - zend_fcall_info_args(&fci, ¶ms TSRMLS_CC); + zend_fcall_info_args(&fci, ¶ms); } else { fci.params = NULL; fci.param_count = 0; } - phpdbg_debug( - "created %d params from arguments", - fci.param_count); + phpdbg_activate_err_buf(0); + phpdbg_free_err_buf(); - zend_call_function(&fci, NULL TSRMLS_CC); + phpdbg_debug("created %d params from arguments", fci.param_count); - if (fretval) { - zend_print_zval_r( - fretval, 0 TSRMLS_CC); - phpdbg_writeln(EMPTY); + if (zend_call_function(&fci, NULL) == SUCCESS) { + zend_print_zval_r(&fretval, 0); + phpdbg_out("\n"); + zval_ptr_dtor(&fretval); } - zval_dtor(&fname); + zval_dtor(&fci.function_name); + efree(lc_name); return SUCCESS; - } + } + + efree(lc_name); } return FAILURE; } /* }}} */ -void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) /* {{{ */ -{ - struct stat sb; - - if (init_file && VCWD_STAT(init_file, &sb) != -1) { - FILE *fp = fopen(init_file, "r"); - if (fp) { - int line = 1; +struct phpdbg_init_state { + int line; + zend_bool in_code; + char *code; + size_t code_len; + const char *init_file; +}; - char cmd[PHPDBG_MAX_CMD]; - size_t cmd_len = 0L; - char *code = NULL; - size_t code_len = 0L; - zend_bool in_code = 0; +static void phpdbg_line_init(char *cmd, struct phpdbg_init_state *state) { + size_t cmd_len = strlen(cmd); - while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) { - cmd_len = strlen(cmd)-1; - - while (cmd_len > 0L && isspace(cmd[cmd_len-1])) - cmd_len--; - - cmd[cmd_len] = '\0'; - - if (*cmd && cmd_len > 0L && cmd[0] != '#') { - if (cmd_len == 2) { - if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) { - in_code = 1; - goto next_line; - } else { - if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) { - in_code = 0; - code[code_len] = '\0'; - { - zend_eval_stringl( - code, code_len, NULL, "phpdbginit code" TSRMLS_CC); - } - free(code); - code = NULL; - goto next_line; - } - } - } + state->line++; + + while (cmd_len > 0L && isspace(cmd[cmd_len-1])) { + cmd_len--; + } - if (in_code) { - if (code == NULL) { - code = malloc(cmd_len + 1); - } else code = realloc(code, code_len + cmd_len + 1); + cmd[cmd_len] = '\0'; - if (code) { - memcpy( - &code[code_len], cmd, cmd_len); - code_len += cmd_len; - } - goto next_line; - } + if (*cmd && cmd_len > 0L && cmd[0] != '#') { + if (cmd_len == 2) { + if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) { + state->in_code = 1; + return; + } else { + if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) { + state->in_code = 0; + state->code[state->code_len] = '\0'; + zend_eval_stringl(state->code, state->code_len, NULL, "phpdbginit code"); + free(state->code); + state->code = NULL; + return; + } + } + } + + if (state->in_code) { + if (state->code == NULL) { + state->code = malloc(cmd_len + 1); + } else { + state->code = realloc(state->code, state->code_len + cmd_len + 1); + } - { - char *why = NULL; - char *input = phpdbg_read_input(cmd TSRMLS_CC); - phpdbg_param_t stack; - - phpdbg_init_param(&stack, STACK_PARAM); - - if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) { - switch (phpdbg_stack_execute(&stack, &why TSRMLS_CC)) { - case FAILURE: -// if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { - if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { - phpdbg_error( - "Unrecognized command in %s:%d: %s, %s!", - init_file, line, input, why); - } -// } - break; + if (state->code) { + memcpy(&state->code[state->code_len], cmd, cmd_len); + state->code_len += cmd_len; + } + + return; + } + + zend_try { + char *input = phpdbg_read_input(cmd); + phpdbg_param_t stack; + + phpdbg_init_param(&stack, STACK_PARAM); + + phpdbg_activate_err_buf(1); + + if (phpdbg_do_parse(&stack, input) <= 0) { + switch (phpdbg_stack_execute(&stack, 1 /* allow_async_unsafe == 1 */)) { + case FAILURE: + phpdbg_activate_err_buf(0); + if (phpdbg_call_register(&stack) == FAILURE) { + if (state->init_file) { + phpdbg_output_err_buf("initfailure", "%b file=\"%s\" line=\"%d\" input=\"%s\"", "Unrecognized command in %s:%d: %s, %b!", state->init_file, state->line, input); + } else { + phpdbg_output_err_buf("initfailure", "%b line=\"%d\" input=\"%s\"", "Unrecognized command on line %d: %s, %b!", state->line, input); } } + break; + } + } - if (why) { - free(why); - why = NULL; - } + phpdbg_activate_err_buf(0); + phpdbg_free_err_buf(); - phpdbg_stack_free(&stack); - phpdbg_destroy_input(&input TSRMLS_CC); - } - } -next_line: - line++; + phpdbg_stack_free(&stack); + phpdbg_destroy_input(&input); + } zend_catch { + PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING); + if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { + zend_bailout(); + } + } zend_end_try(); + } + +} + +void phpdbg_string_init(char *buffer) { + struct phpdbg_init_state state = {0}; + char *str = strtok(buffer, "\n"); + + while (str) { + phpdbg_line_init(str, &state); + + str = strtok(NULL, "\n"); + } + + if (state.code) { + free(state.code); + } +} + +void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init) /* {{{ */ +{ + zend_stat_t sb; + + if (init_file && VCWD_STAT(init_file, &sb) != -1) { + FILE *fp = fopen(init_file, "r"); + if (fp) { + char cmd[PHPDBG_MAX_CMD]; + struct phpdbg_init_state state = {0}; + + state.init_file = init_file; + + while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) { + phpdbg_line_init(cmd, &state); } - if (code) { - free(code); + if (state.code) { + free(state.code); } fclose(fp); } else { - phpdbg_error( - "Failed to open %s for initialization", init_file); + phpdbg_error("initfailure", "type=\"openfile\" file=\"%s\"", "Failed to open %s for initialization", init_file); } if (free_init) { @@ -292,13 +335,13 @@ next_line: } } /* }}} */ -void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC) /* {{{ */ +void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default) /* {{{ */ { if (!init_file && use_default) { char *scan_dir = getenv("PHP_INI_SCAN_DIR"); int i; - phpdbg_try_file_init(PHPDBG_STRL(PHP_CONFIG_FILE_PATH "/" PHPDBG_INIT_FILENAME), 0 TSRMLS_CC); + phpdbg_try_file_init(PHPDBG_STRL(PHP_CONFIG_FILE_PATH "/" PHPDBG_INIT_FILENAME), 0); if (!scan_dir) { scan_dir = PHP_CONFIG_FILE_SCAN_DIR; @@ -315,93 +358,93 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TS scan_dir[i] = 0; } - asprintf( - &init_file, "%s/%s", scan_dir, PHPDBG_INIT_FILENAME); - phpdbg_try_file_init(init_file, strlen(init_file), 1 TSRMLS_CC); + asprintf(&init_file, "%s/%s", scan_dir, PHPDBG_INIT_FILENAME); + phpdbg_try_file_init(init_file, strlen(init_file), 1); if (i == -1) { break; } scan_dir += i + 1; } - phpdbg_try_file_init(PHPDBG_STRL(PHPDBG_INIT_FILENAME), 0 TSRMLS_CC); + phpdbg_try_file_init(PHPDBG_STRL(PHPDBG_INIT_FILENAME), 0); } else { - phpdbg_try_file_init(init_file, init_file_len, 1 TSRMLS_CC); + phpdbg_try_file_init(init_file, init_file_len, 1); } } PHPDBG_COMMAND(exec) /* {{{ */ { - struct stat sb; + zend_stat_t sb; if (VCWD_STAT(param->str, &sb) != FAILURE) { if (sb.st_mode & (S_IFREG|S_IFLNK)) { - char *res = phpdbg_resolve_path(param->str TSRMLS_CC); + char *res = phpdbg_resolve_path(param->str); size_t res_len = strlen(res); if ((res_len != PHPDBG_G(exec_len)) || (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) { + if (PHPDBG_G(in_execution)) { + if (phpdbg_ask_user_permission("Do you really want to stop execution to set a new execution context?") == FAILURE) { + return FAILURE; + } + } if (PHPDBG_G(exec)) { - phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec)); + phpdbg_notice("exec", "type=\"unset\" context=\"%s\"", "Unsetting old execution context: %s", PHPDBG_G(exec)); efree(PHPDBG_G(exec)); PHPDBG_G(exec) = NULL; PHPDBG_G(exec_len) = 0L; } if (PHPDBG_G(ops)) { - phpdbg_notice("Destroying compiled opcodes"); - phpdbg_clean(0 TSRMLS_CC); + phpdbg_notice("exec", "type=\"unsetops\"", "Destroying compiled opcodes"); + phpdbg_clean(0); } PHPDBG_G(exec) = res; PHPDBG_G(exec_len) = res_len; - + + VCWD_CHDIR_FILE(res); + *SG(request_info).argv = PHPDBG_G(exec); - php_hash_environment(TSRMLS_C); + php_hash_environment(); - phpdbg_notice("Set execution context: %s", PHPDBG_G(exec)); + phpdbg_notice("exec", "type=\"set\" context=\"%s\"", "Set execution context: %s", PHPDBG_G(exec)); - if (phpdbg_compile(TSRMLS_C) == FAILURE) { - phpdbg_error("Failed to compile %s", PHPDBG_G(exec)); + if (PHPDBG_G(in_execution)) { + phpdbg_clean(1); } + + phpdbg_compile(); } else { - phpdbg_notice("Execution context not changed"); + phpdbg_notice("exec", "type=\"unchanged\"", "Execution context not changed"); } } else { - phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str); + phpdbg_error("exec", "type=\"invalid\" context=\"%s\"", "Cannot use %s as execution context, not a valid file or symlink", param->str); } } else { - phpdbg_error("Cannot stat %s, ensure the file exists", param->str); + phpdbg_error("exec", "type=\"notfound\" context=\"%s\"", "Cannot stat %s, ensure the file exists", param->str); } return SUCCESS; } /* }}} */ -int phpdbg_compile(TSRMLS_D) /* {{{ */ +int phpdbg_compile(void) /* {{{ */ { zend_file_handle fh; if (!PHPDBG_G(exec)) { - phpdbg_error("No execution context"); - return SUCCESS; - } - - if (EG(in_execution)) { - phpdbg_error("Cannot compile while in execution"); + phpdbg_error("inactive", "type=\"nocontext\"", "No execution context"); return FAILURE; } - phpdbg_notice("Attempting compilation of %s", PHPDBG_G(exec)); - - if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh, - USE_PATH|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC) == SUCCESS) { + if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh, USE_PATH|STREAM_OPEN_FOR_INCLUDE) == SUCCESS) { + PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE); + zend_destroy_file_handle(&fh); - PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE TSRMLS_CC); - zend_destroy_file_handle(&fh TSRMLS_CC); + phpdbg_notice("compile", "context=\"%s\"", "Successful compilation of %s", PHPDBG_G(exec)); - phpdbg_notice("Success"); return SUCCESS; } else { - phpdbg_error("Could not open file %s", PHPDBG_G(exec)); + phpdbg_error("compile", "type=\"openfailure\" context=\"%s\"", "Could not open file %s", PHPDBG_G(exec)); } return FAILURE; @@ -409,7 +452,7 @@ int phpdbg_compile(TSRMLS_D) /* {{{ */ PHPDBG_COMMAND(step) /* {{{ */ { - if (EG(in_execution)) { + if (PHPDBG_G(in_execution)) { PHPDBG_G(flags) |= PHPDBG_IS_STEPPING; } @@ -423,24 +466,19 @@ PHPDBG_COMMAND(continue) /* {{{ */ PHPDBG_COMMAND(until) /* {{{ */ { - if (!EG(in_execution)) { - phpdbg_error("Not executing"); + if (!PHPDBG_G(in_execution)) { + phpdbg_error("inactive", "type=\"noexec\"", "Not executing"); return SUCCESS; } PHPDBG_G(flags) |= PHPDBG_IN_UNTIL; { - zend_uint next = 0, - self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes); - zend_op *opline = &EG(active_op_array)->opcodes[self]; - - for (next = self; next < EG(active_op_array)->last; next++) { - if (EG(active_op_array)->opcodes[next].lineno != opline->lineno) { - zend_hash_index_update( - &PHPDBG_G(seek), - (zend_ulong) &EG(active_op_array)->opcodes[next], - &EG(active_op_array)->opcodes[next], - sizeof(zend_op), NULL); + const zend_op *opline = EG(current_execute_data)->opline; + const zend_op_array *op_array = &EG(current_execute_data)->func->op_array; + + while (++opline < op_array->opcodes + op_array->last) { + if (opline->lineno != EG(current_execute_data)->opline->lineno) { + zend_hash_index_update_ptr(&PHPDBG_G(seek), (zend_ulong) opline, (void *) opline); break; } } @@ -449,68 +487,46 @@ PHPDBG_COMMAND(until) /* {{{ */ return PHPDBG_UNTIL; } /* }}} */ +static void phpdbg_seek_to_end(void) { + const zend_op *opline = EG(current_execute_data)->opline; + const zend_op_array *op_array = &EG(current_execute_data)->func->op_array - 1; + + while (++opline < op_array->opcodes + op_array->last) { + switch (opline->opcode) { + case ZEND_RETURN: + case ZEND_THROW: + case ZEND_EXIT: +#ifdef ZEND_YIELD + case ZEND_YIELD: +#endif + zend_hash_index_update_ptr(&PHPDBG_G(seek), (zend_ulong) opline, (void *) opline); + return; + } + } +} + PHPDBG_COMMAND(finish) /* {{{ */ { - if (!EG(in_execution)) { - phpdbg_error("Not executing"); + if (!PHPDBG_G(in_execution)) { + phpdbg_error("inactive", "type=\"noexec\"", "Not executing"); return SUCCESS; } PHPDBG_G(flags) |= PHPDBG_IN_FINISH; - { - zend_uint next = 0, - self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes); - - for (next = self; next < EG(active_op_array)->last; next++) { - switch (EG(active_op_array)->opcodes[next].opcode) { - case ZEND_RETURN: - case ZEND_THROW: - case ZEND_EXIT: -#ifdef ZEND_YIELD - case ZEND_YIELD: -#endif - zend_hash_index_update( - &PHPDBG_G(seek), - (zend_ulong) &EG(active_op_array)->opcodes[next], - &EG(active_op_array)->opcodes[next], - sizeof(zend_op), NULL); - break; - } - } - } + phpdbg_seek_to_end(); return PHPDBG_FINISH; } /* }}} */ PHPDBG_COMMAND(leave) /* {{{ */ { - if (!EG(in_execution)) { - phpdbg_error("Not executing"); + if (!PHPDBG_G(in_execution)) { + phpdbg_error("inactive", "type=\"noexec\"", "Not executing"); return SUCCESS; } PHPDBG_G(flags) |= PHPDBG_IN_LEAVE; - { - zend_uint next = 0, - self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes); - - for (next = self; next < EG(active_op_array)->last; next++) { - switch (EG(active_op_array)->opcodes[next].opcode) { - case ZEND_RETURN: - case ZEND_THROW: - case ZEND_EXIT: -#ifdef ZEND_YIELD - case ZEND_YIELD: -#endif - zend_hash_index_update( - &PHPDBG_G(seek), - (zend_ulong) &EG(active_op_array)->opcodes[next], - &EG(active_op_array)->opcodes[next], - sizeof(zend_op), NULL); - break; - } - } - } + phpdbg_seek_to_end(); return PHPDBG_LEAVE; } /* }}} */ @@ -518,108 +534,89 @@ PHPDBG_COMMAND(leave) /* {{{ */ PHPDBG_COMMAND(frame) /* {{{ */ { if (!param) { - phpdbg_notice("Currently in frame #%d", PHPDBG_G(frame).num); - } else phpdbg_switch_frame(param->num TSRMLS_CC); + phpdbg_notice("frame", "id=\"%d\"", "Currently in frame #%d", PHPDBG_G(frame).num); + } else { + phpdbg_switch_frame(param->num); + } return SUCCESS; } /* }}} */ -static inline void phpdbg_handle_exception(TSRMLS_D) /* }}} */ +static inline void phpdbg_handle_exception(void) /* }}} */ { zend_fcall_info fci; - - zval fname, - *trace, - exception; + zval trace; /* get filename and linenumber before unsetting exception */ - const char *filename = zend_get_executed_filename(TSRMLS_C); - zend_uint lineno = zend_get_executed_lineno(TSRMLS_C); - - /* copy exception */ - exception = *EG(exception); - zval_copy_ctor(&exception); - EG(exception) = NULL; - - phpdbg_error( - "Uncaught %s!", - Z_OBJCE(exception)->name); + const char *filename = zend_get_executed_filename(); + uint32_t lineno = zend_get_executed_lineno(); /* call __toString */ - ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring")-1, 1); + ZVAL_STRINGL(&fci.function_name, "__tostring", sizeof("__tostring") - 1); fci.size = sizeof(fci); - fci.function_table = &Z_OBJCE(exception)->function_table; - fci.function_name = &fname; + fci.function_table = &EG(exception)->ce->function_table; fci.symbol_table = NULL; - fci.object_ptr = &exception; - fci.retval_ptr_ptr = &trace; + fci.object = EG(exception); + fci.retval = &trace; fci.param_count = 0; fci.params = NULL; fci.no_separation = 1; - zend_call_function(&fci, NULL TSRMLS_CC); + if (zend_call_function(&fci, NULL) == SUCCESS) { + phpdbg_writeln("exception", "name=\"%s\" trace=\"%.*s\"", "Uncaught %s!\n%.*s", EG(exception)->ce->name->val, Z_STRLEN(trace), Z_STRVAL(trace)); - if (trace) { - phpdbg_writeln( - "Uncaught %s", Z_STRVAL_P(trace)); - /* remember to dtor trace */ zval_ptr_dtor(&trace); + } else { + phpdbg_error("exception", "name=\"%s\"" "Uncaught %s!", EG(exception)->ce->name->val); } /* output useful information about address */ - phpdbg_writeln( - "Stacked entered at %p in %s on line %u", - EG(active_op_array)->opcodes, filename, lineno); + phpdbg_writeln("exception", "opline=\"%p\" file=\"%s\" line=\"%u\"", "Stack entered at %p in %s on line %u", EG(current_execute_data)->func->op_array.opcodes, filename, lineno); - zval_dtor(&fname); - zval_dtor(&exception); + zval_dtor(&fci.function_name); + zend_clear_exception(); } /* }}} */ PHPDBG_COMMAND(run) /* {{{ */ { - if (EG(in_execution)) { - phpdbg_error("Cannot start another execution while one is in progress"); - return SUCCESS; - } - if (PHPDBG_G(ops) || PHPDBG_G(exec)) { - zend_op **orig_opline = EG(opline_ptr); - zend_op_array *orig_op_array = EG(active_op_array); - zval **orig_retval_ptr = EG(return_value_ptr_ptr); - zend_bool restore = 1; zend_execute_data *ex = EG(current_execute_data); - - if (!PHPDBG_G(ops)) { - if (phpdbg_compile(TSRMLS_C) == FAILURE) { - phpdbg_error("Failed to compile %s, cannot run", PHPDBG_G(exec)); - goto out; + zend_bool restore = 1; + + if (PHPDBG_G(in_execution)) { + if (phpdbg_ask_user_permission("Do you really want to restart execution?") == SUCCESS) { + phpdbg_startup_run++; + phpdbg_clean(1); } + return SUCCESS; } - EG(active_op_array) = PHPDBG_G(ops); - EG(return_value_ptr_ptr) = &PHPDBG_G(retval); - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); + if (!PHPDBG_G(ops)) { + if (phpdbg_compile() == FAILURE) { + phpdbg_error("compile", "type=\"compilefailure\" context=\"%s\"", "Failed to compile %s, cannot run", PHPDBG_G(exec)); + goto out; + } } /* clean up from last execution */ if (ex && ex->symbol_table) { - zend_hash_clean(ex->symbol_table); + zend_hash_clean(&ex->symbol_table->ht); + } else { + zend_rebuild_symbol_table(); } /* clean seek state */ PHPDBG_G(flags) &= ~PHPDBG_SEEK_MASK; - zend_hash_clean( - &PHPDBG_G(seek)); + zend_hash_clean(&PHPDBG_G(seek)); /* reset hit counters */ - phpdbg_reset_breakpoints(TSRMLS_C); + phpdbg_reset_breakpoints(); if (param && param->type != EMPTY_PARAM && param->len != 0) { char **argv = emalloc(5 * sizeof(char *)); int argc = 0; int i; char *argv_str = strtok(param->str, " "); - + while (argv_str) { if (argc >= 4 && argc == (argc & -argc)) { argv = erealloc(argv, (argc * 2 + 1) * sizeof(char *)); @@ -635,38 +632,44 @@ PHPDBG_COMMAND(run) /* {{{ */ efree(SG(request_info).argv); SG(request_info).argv = erealloc(argv, ++argc * sizeof(char *)); SG(request_info).argc = argc; - - php_hash_environment(TSRMLS_C); + + php_hash_environment(); } zend_try { - php_output_activate(TSRMLS_C); PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE; - zend_execute(EG(active_op_array) TSRMLS_CC); + PHPDBG_G(flags) |= PHPDBG_IS_RUNNING; + zend_execute(PHPDBG_G(ops), &PHPDBG_G(retval)); PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE; - php_output_deactivate(TSRMLS_C); } zend_catch { - EG(active_op_array) = orig_op_array; - EG(opline_ptr) = orig_opline; - EG(return_value_ptr_ptr) = orig_retval_ptr; + PHPDBG_G(in_execution) = 0; + + if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { + zend_bailout(); + } - if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { - phpdbg_error("Caught exit/error from VM"); + if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { + phpdbg_error("stop", "type=\"bailout\"", "Caught exit/error from VM"); restore = 0; } } zend_end_try(); + if (PHPDBG_G(socket_fd) != -1) { + close(PHPDBG_G(socket_fd)); + PHPDBG_G(socket_fd) = -1; + } + if (restore) { if (EG(exception)) { - phpdbg_handle_exception(TSRMLS_C); + phpdbg_handle_exception(); } - - EG(active_op_array) = orig_op_array; - EG(opline_ptr) = orig_opline; - EG(return_value_ptr_ptr) = orig_retval_ptr; } + + phpdbg_clean(1); + + PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; } else { - phpdbg_error("Nothing to execute!"); + phpdbg_error("inactive", "type=\"nocontext\"", "Nothing to execute!"); } out: @@ -674,50 +677,93 @@ out: return SUCCESS; } /* }}} */ +int phpdbg_output_ev_variable(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv) { + phpdbg_notice("eval", "variable=\"%.*s\"", "Printing variable %.*s", (int) len, name); + phpdbg_xml("<eval %r>"); + zend_print_zval_r(zv, 0); + phpdbg_xml("</eval>"); + phpdbg_out("\n"); + + efree(name); + efree(keyname); + + return SUCCESS; +} + PHPDBG_COMMAND(ev) /* {{{ */ { - zend_bool stepping = ((PHPDBG_G(flags) & PHPDBG_IS_STEPPING)==PHPDBG_IS_STEPPING); + zend_bool stepping = ((PHPDBG_G(flags) & PHPDBG_IS_STEPPING) == PHPDBG_IS_STEPPING); zval retval; + zend_execute_data *original_execute_data = EG(current_execute_data); + zend_class_entry *original_scope = EG(scope); + zend_vm_stack original_stack = EG(vm_stack); + + PHPDBG_OUTPUT_BACKUP(); + + original_stack->top = EG(vm_stack_top); + + if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) { + phpdbg_try_access { + phpdbg_parse_variable(param->str, param->len, &EG(symbol_table).ht, 0, phpdbg_output_ev_variable, 0); + } phpdbg_catch_access { + phpdbg_error("signalsegv", "", "Could not fetch data, invalid data source"); + } phpdbg_end_try_access(); + + PHPDBG_OUTPUT_BACKUP_RESTORE(); + return SUCCESS; + } + if (!(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) { - PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING; + PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING; } /* disable stepping while eval() in progress */ PHPDBG_G(flags) |= PHPDBG_IN_EVAL; zend_try { - if (zend_eval_stringl(param->str, param->len, - &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) { - zend_print_zval_r( - &retval, 0 TSRMLS_CC); - phpdbg_writeln(EMPTY); - zval_dtor(&retval); + if (zend_eval_stringl(param->str, param->len, &retval, "eval()'d code") == SUCCESS) { + phpdbg_xml("<eval %r>"); + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { + zval *zvp = &retval; + phpdbg_xml_var_dump(zvp); + } + zend_print_zval_r(&retval, 0); + phpdbg_xml("</eval>"); + phpdbg_out("\n"); + zval_ptr_dtor(&retval); } + } zend_catch { + EG(current_execute_data) = original_execute_data; + EG(scope) = original_scope; + EG(vm_stack_top) = original_stack->top; + EG(vm_stack_end) = original_stack->end; + EG(vm_stack) = original_stack; } zend_end_try(); PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL; /* switch stepping back on */ - if (stepping && - !(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) { + if (stepping && !(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) { PHPDBG_G(flags) |= PHPDBG_IS_STEPPING; } CG(unclean_shutdown) = 0; + PHPDBG_OUTPUT_BACKUP_RESTORE(); + return SUCCESS; } /* }}} */ PHPDBG_COMMAND(back) /* {{{ */ { - if (!EG(in_execution)) { - phpdbg_error("Not executing!"); + if (!PHPDBG_G(in_execution)) { + phpdbg_error("inactive", "type=\"noexec\"", "Not executing!"); return SUCCESS; } if (!param) { - phpdbg_dump_backtrace(0 TSRMLS_CC); + phpdbg_dump_backtrace(0); } else { - phpdbg_dump_backtrace(param->num TSRMLS_CC); + phpdbg_dump_backtrace(param->num); } return SUCCESS; @@ -725,62 +771,54 @@ PHPDBG_COMMAND(back) /* {{{ */ PHPDBG_COMMAND(print) /* {{{ */ { - phpdbg_writeln(SEPARATE); - phpdbg_notice("Execution Context Information"); + phpdbg_out("Execution Context Information\n\n"); + phpdbg_xml("<printinfo %r>"); #ifdef HAVE_LIBREADLINE - phpdbg_writeln("Readline\tyes"); + phpdbg_writeln("print", "readline=\"yes\"", "Readline yes"); #else - phpdbg_writeln("Readline\tno"); + phpdbg_writeln("print", "readline=\"no\"", "Readline no"); #endif #ifdef HAVE_LIBEDIT - phpdbg_writeln("Libedit\t\tyes"); + phpdbg_writeln("print", "libedit=\"yes\"", "Libedit yes"); #else - phpdbg_writeln("Libedit\t\tno"); + phpdbg_writeln("print", "libedit=\"no\"", "Libedit no"); #endif - phpdbg_writeln("Exec\t\t%s", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none"); - phpdbg_writeln("Compiled\t%s", PHPDBG_G(ops) ? "yes" : "no"); - phpdbg_writeln("Stepping\t%s", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off"); - phpdbg_writeln("Quietness\t%s", (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "on" : "off"); - phpdbg_writeln("Oplog\t\t%s", PHPDBG_G(oplog) ? "on" : "off"); + phpdbg_writeln("print", "context=\"%s\"", "Exec %s", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none"); + phpdbg_writeln("print", "compiled=\"%s\"", "Compiled %s", PHPDBG_G(ops) ? "yes" : "no"); + phpdbg_writeln("print", "stepping=\"%s\"", "Stepping %s", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off"); + phpdbg_writeln("print", "quiet=\"%s\"", "Quietness %s", (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "on" : "off"); + phpdbg_writeln("print", "oplog=\"%s\"", "Oplog %s", PHPDBG_G(oplog) ? "on" : "off"); if (PHPDBG_G(ops)) { - phpdbg_writeln("Opcodes\t\t%d", PHPDBG_G(ops)->last); - - if (PHPDBG_G(ops)->last_var) { - phpdbg_writeln("Variables\t%d", PHPDBG_G(ops)->last_var-1); - } else { - phpdbg_writeln("Variables\tNone"); - } + phpdbg_writeln("print", "ops=\"%d\"", "Opcodes %d", PHPDBG_G(ops)->last); + phpdbg_writeln("print", "vars=\"%d\"", "Variables %d", PHPDBG_G(ops)->last_var ? PHPDBG_G(ops)->last_var - 1 : 0); } - phpdbg_writeln("Executing\t%s", EG(in_execution) ? "yes" : "no"); - if (EG(in_execution)) { - phpdbg_writeln("VM Return\t%d", PHPDBG_G(vmret)); + phpdbg_writeln("print", "executing=\"%d\"", "Executing %s", PHPDBG_G(in_execution) ? "yes" : "no"); + if (PHPDBG_G(in_execution)) { + phpdbg_writeln("print", "vmret=\"%d\"", "VM Return %d", PHPDBG_G(vmret)); } - phpdbg_writeln("Classes\t\t%d", zend_hash_num_elements(EG(class_table))); - phpdbg_writeln("Functions\t%d", zend_hash_num_elements(EG(function_table))); - phpdbg_writeln("Constants\t%d", zend_hash_num_elements(EG(zend_constants))); - phpdbg_writeln("Included\t%d", zend_hash_num_elements(&EG(included_files))); - - phpdbg_writeln(SEPARATE); + phpdbg_writeln("print", "classes=\"%d\"", "Classes %d", zend_hash_num_elements(EG(class_table))); + phpdbg_writeln("print", "functions=\"%d\"", "Functions %d", zend_hash_num_elements(EG(function_table))); + phpdbg_writeln("print", "constants=\"%d\"", "Constants %d", zend_hash_num_elements(EG(zend_constants))); + phpdbg_writeln("print", "includes=\"%d\"", "Included %d", zend_hash_num_elements(&EG(included_files))); + phpdbg_xml("</printinfo>"); return SUCCESS; } /* }}} */ PHPDBG_COMMAND(info) /* {{{ */ { - phpdbg_error( - "No information command selected!"); + phpdbg_error("info", "type=\"toofewargs\" expected=\"1\"", "No information command selected!"); return SUCCESS; } /* }}} */ PHPDBG_COMMAND(set) /* {{{ */ { - phpdbg_error( - "No set command selected!"); + phpdbg_error("set", "type=\"toofewargs\" expected=\"1\"", "No set command selected!"); return SUCCESS; } /* }}} */ @@ -789,42 +827,42 @@ PHPDBG_COMMAND(break) /* {{{ */ { if (!param) { phpdbg_set_breakpoint_file( - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); + zend_get_executed_filename(), + zend_get_executed_lineno()); } else switch (param->type) { case ADDR_PARAM: - phpdbg_set_breakpoint_opline(param->addr TSRMLS_CC); + phpdbg_set_breakpoint_opline(param->addr); break; case NUMERIC_PARAM: if (PHPDBG_G(exec)) { - phpdbg_set_breakpoint_file(phpdbg_current_file(TSRMLS_C), param->num TSRMLS_CC); + phpdbg_set_breakpoint_file(phpdbg_current_file(), param->num); } else { - phpdbg_error("Execution context not set!"); + phpdbg_error("inactive", "type=\"noexec\"", "Execution context not set!"); } break; case METHOD_PARAM: - phpdbg_set_breakpoint_method(param->method.class, param->method.name TSRMLS_CC); + phpdbg_set_breakpoint_method(param->method.class, param->method.name); break; case NUMERIC_METHOD_PARAM: - phpdbg_set_breakpoint_method_opline(param->method.class, param->method.name, param->num TSRMLS_CC); + phpdbg_set_breakpoint_method_opline(param->method.class, param->method.name, param->num); break; case NUMERIC_FUNCTION_PARAM: - phpdbg_set_breakpoint_function_opline(param->str, param->num TSRMLS_CC); + phpdbg_set_breakpoint_function_opline(param->str, param->num); break; case FILE_PARAM: - phpdbg_set_breakpoint_file(param->file.name, param->file.line TSRMLS_CC); + phpdbg_set_breakpoint_file(param->file.name, param->file.line); break; case NUMERIC_FILE_PARAM: - phpdbg_set_breakpoint_file_opline(param->file.name, param->file.line TSRMLS_CC); + phpdbg_set_breakpoint_file_opline(param->file.name, param->file.line); break; case COND_PARAM: - phpdbg_set_breakpoint_expression(param->str, param->len TSRMLS_CC); + phpdbg_set_breakpoint_expression(param->str, param->len); break; case STR_PARAM: - phpdbg_set_breakpoint_symbol(param->str, param->len TSRMLS_CC); + phpdbg_set_breakpoint_symbol(param->str, param->len); break; case OP_PARAM: - phpdbg_set_breakpoint_opcode(param->str, param->len TSRMLS_CC); + phpdbg_set_breakpoint_opcode(param->str, param->len); break; phpdbg_default_switch_case(); @@ -837,42 +875,226 @@ PHPDBG_COMMAND(sh) /* {{{ */ { FILE *fd = NULL; if ((fd=VCWD_POPEN((char*)param->str, "w"))) { - /* do something perhaps ?? do we want input ?? */ - fclose(fd); + /* TODO: do something perhaps ?? do we want input ?? */ + pclose(fd); + } else { + phpdbg_error("sh", "type=\"failure\" smd=\"%s\"", "Failed to execute %s", param->str); + } + + return SUCCESS; +} /* }}} */ + +static int add_module_info(zend_module_entry *module) { + phpdbg_write("module", "name=\"%s\"", "%s\n", module->name); + return 0; +} + +static int add_zendext_info(zend_extension *ext) { + phpdbg_write("extension", "name=\"%s\"", "%s\n", ext->name); + return 0; +} + +PHPDBG_API const char *phpdbg_load_module_or_extension(char **path, char **name) { + DL_HANDLE handle; + char *extension_dir; + + extension_dir = INI_STR("extension_dir"); + + if (strchr(*path, '/') != NULL || strchr(*path, DEFAULT_SLASH) != NULL) { + /* path is fine */ + } else if (extension_dir && extension_dir[0]) { + char *libpath; + int extension_dir_len = strlen(extension_dir); + if (IS_SLASH(extension_dir[extension_dir_len-1])) { + spprintf(&libpath, 0, "%s%s", extension_dir, *path); /* SAFE */ + } else { + spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, *path); /* SAFE */ + } + efree(*path); + *path = libpath; } else { - phpdbg_error( - "Failed to execute %s", param->str); + phpdbg_error("dl", "type=\"relpath\"", "Not a full path given or extension_dir ini setting is not set"); + + return NULL; } - + + handle = DL_LOAD(*path); + + if (!handle) { +#if PHP_WIN32 + char *err = GET_DL_ERROR(); + if (err && *err != "") { + phpdbg_error("dl", "type=\"unknown\"", "%s", err); + LocalFree(err); + } else { + phpdbg_error("dl", "type=\"unknown\"", "Unknown reason"); + } +#else + phpdbg_error("dl", "type=\"unknown\"", "%s", GET_DL_ERROR()); +#endif + return NULL; + } + +#if ZEND_EXTENSIONS_SUPPORT + do { + zend_extension *new_extension; + zend_extension_version_info *extension_version_info; + + extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "extension_version_info"); + if (!extension_version_info) { + extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "_extension_version_info"); + } + new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "zend_extension_entry"); + if (!new_extension) { + new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "_zend_extension_entry"); + } + if (!extension_version_info || !new_extension) { + break; + } + if (extension_version_info->zend_extension_api_no != ZEND_EXTENSION_API_NO &&(!new_extension->api_no_check || new_extension->api_no_check(ZEND_EXTENSION_API_NO) != SUCCESS)) { + phpdbg_error("dl", "type=\"wrongapi\" extension=\"%s\" apineeded=\"%d\" apiinstalled=\"%d\"", "%s requires Zend Engine API version %d, which does not match the installed Zend Engine API version %d", new_extension->name, extension_version_info->zend_extension_api_no, ZEND_EXTENSION_API_NO); + + goto quit; + } else if (strcmp(ZEND_EXTENSION_BUILD_ID, extension_version_info->build_id) && (!new_extension->build_id_check || new_extension->build_id_check(ZEND_EXTENSION_BUILD_ID) != SUCCESS)) { + phpdbg_error("dl", "type=\"wrongbuild\" extension=\"%s\" buildneeded=\"%s\" buildinstalled=\"%s\"", "%s was built with configuration %s, whereas running engine is %s", new_extension->name, extension_version_info->build_id, ZEND_EXTENSION_BUILD_ID); + + goto quit; + } + + *name = new_extension->name; + + zend_register_extension(new_extension, handle); + + if (new_extension->startup) { + if (new_extension->startup(new_extension) != SUCCESS) { + phpdbg_error("dl", "type=\"startupfailure\" extension=\"%s\"", "Unable to startup Zend extension %s", new_extension->name); + + goto quit; + } + zend_append_version_info(new_extension); + } + + return "Zend extension"; + } while (0); +#endif + + do { + zend_module_entry *module_entry; + zend_module_entry *(*get_module)(void); + + get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "get_module"); + if (!get_module) { + get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "_get_module"); + } + + if (!get_module) { + break; + } + + module_entry = get_module(); + *name = (char *) module_entry->name; + + if (strcmp(ZEND_EXTENSION_BUILD_ID, module_entry->build_id)) { + phpdbg_error("dl", "type=\"wrongbuild\" module=\"%s\" buildneeded=\"%s\" buildinstalled=\"%s\"", "%s was built with configuration %s, whereas running engine is %s", module_entry->name, module_entry->build_id, ZEND_EXTENSION_BUILD_ID); + + goto quit; + } + + module_entry->type = MODULE_PERSISTENT; + module_entry->module_number = zend_next_free_module(); + module_entry->handle = handle; + + if ((module_entry = zend_register_module_ex(module_entry)) == NULL) { + phpdbg_error("dl", "type=\"registerfailure\" module=\"%s\"", "Unable to register module %s", module_entry->name); + + goto quit; + } + + if (zend_startup_module_ex(module_entry) == FAILURE) { + phpdbg_error("dl", "type=\"startupfailure\" module=\"%s\"", "Unable to startup module %s", module_entry->name); + + goto quit; + } + + if (module_entry->request_startup_func) { + if (module_entry->request_startup_func(MODULE_PERSISTENT, module_entry->module_number) == FAILURE) { + phpdbg_error("dl", "type=\"initfailure\" module=\"%s\"", "Unable to initialize module %s", module_entry->name); + + goto quit; + } + } + + return "module"; + } while (0); + + phpdbg_error("dl", "type=\"nophpso\"", "This shared object is nor a Zend extension nor a module"); + +quit: + DL_UNLOAD(handle); + return NULL; +} + +PHPDBG_COMMAND(dl) /* {{{ */ +{ + const char *type; + char *name, *path; + + if (!param || param->type == EMPTY_PARAM) { + phpdbg_notice("dl", "extensiontype=\"Zend extension\"", "Zend extensions"); + zend_llist_apply(&zend_extensions, (llist_apply_func_t) add_zendext_info); + phpdbg_out("\n"); + phpdbg_notice("dl", "extensiontype=\"module\"", "Modules"); + zend_hash_apply(&module_registry, (apply_func_t) add_module_info); + } else switch (param->type) { + case STR_PARAM: +#ifdef HAVE_LIBDL + path = estrndup(param->str, param->len); + + phpdbg_activate_err_buf(1); + if ((type = phpdbg_load_module_or_extension(&path, &name)) == NULL) { + phpdbg_error("dl", "path=\"%s\" %b", "Could not load %s, not found or invalid zend extension / module: %b", path); + efree(name); + } else { + phpdbg_notice("dl", "extensiontype=\"%s\" name=\"%s\" path=\"%s\"", "Successfully loaded the %s %s at path %s", type, name, path); + } + phpdbg_activate_err_buf(0); + phpdbg_free_err_buf(); + efree(path); +#else + phpdbg_error("dl", "type=\"unsupported\" path=\"%.*s\"", "Cannot dynamically load %.*s - dynamic modules are not supported", (int) param->len, param->str); +#endif + break; + + phpdbg_default_switch_case(); + } + return SUCCESS; } /* }}} */ PHPDBG_COMMAND(source) /* {{{ */ { - struct stat sb; - + zend_stat_t sb; + if (VCWD_STAT(param->str, &sb) != -1) { - phpdbg_try_file_init(param->str, param->len, 0 TSRMLS_CC); + phpdbg_try_file_init(param->str, param->len, 0); } else { - phpdbg_error( - "Failed to stat %s, file does not exist", param->str); + phpdbg_error("source", "type=\"notfound\" file=\"%s\"", "Failed to stat %s, file does not exist", param->str); } - + return SUCCESS; } /* }}} */ PHPDBG_COMMAND(export) /* {{{ */ { FILE *handle = VCWD_FOPEN(param->str, "w+"); - + if (handle) { - phpdbg_export_breakpoints(handle TSRMLS_CC); + phpdbg_export_breakpoints(handle); fclose(handle); } else { - phpdbg_error( - "Failed to open or create %s, check path and permissions", param->str); + phpdbg_error("export", "type=\"openfailure\" file=\"%s\"", "Failed to open or create %s, check path and permissions", param->str); } - + return SUCCESS; } /* }}} */ @@ -882,20 +1104,17 @@ PHPDBG_COMMAND(register) /* {{{ */ char *lcname = zend_str_tolower_dup(param->str, param->len); size_t lcname_len = strlen(lcname); - if (!zend_hash_exists(&PHPDBG_G(registered), lcname, lcname_len+1)) { - if (zend_hash_find(EG(function_table), lcname, lcname_len+1, (void**) &function) == SUCCESS) { - zend_hash_update( - &PHPDBG_G(registered), lcname, lcname_len+1, (void*)&function, sizeof(zend_function), NULL); + if (!zend_hash_str_exists(&PHPDBG_G(registered), lcname, lcname_len)) { + if ((function = zend_hash_str_find_ptr(EG(function_table), lcname, lcname_len))) { + zend_hash_str_update_ptr(&PHPDBG_G(registered), lcname, lcname_len, function); function_add_ref(function); - phpdbg_notice( - "Registered %s", lcname); + phpdbg_notice("register", "function=\"%s\"", "Registered %s", lcname); } else { - phpdbg_error("The requested function (%s) could not be found", param->str); + phpdbg_error("register", "type=\"notfound\" function=\"%s\"", "The requested function (%s) could not be found", param->str); } } else { - phpdbg_error( - "The requested name (%s) is already in use", lcname); + phpdbg_error("register", "type=\"inuse\" function=\"%s\"", "The requested name (%s) is already in use", lcname); } efree(lcname); @@ -905,8 +1124,9 @@ PHPDBG_COMMAND(register) /* {{{ */ PHPDBG_COMMAND(quit) /* {{{ */ { /* don't allow this to loop, ever ... */ - if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { + if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { PHPDBG_G(flags) |= PHPDBG_IS_QUITTING; + PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING); zend_bailout(); } @@ -915,37 +1135,46 @@ PHPDBG_COMMAND(quit) /* {{{ */ PHPDBG_COMMAND(clean) /* {{{ */ { - if (EG(in_execution)) { - phpdbg_error("Cannot clean environment while executing"); - return SUCCESS; + if (PHPDBG_G(in_execution)) { + if (phpdbg_ask_user_permission("Do you really want to clean your current environment?") == FAILURE) { + return SUCCESS; + } } - phpdbg_notice("Cleaning Execution Environment"); + phpdbg_out("Cleaning Execution Environment\n"); + phpdbg_xml("<cleaninfo %r>"); + + phpdbg_writeln("clean", "classes=\"%d\"", "Classes %d", zend_hash_num_elements(EG(class_table))); + phpdbg_writeln("clean", "functions=\"%d\"", "Functions %d", zend_hash_num_elements(EG(function_table))); + phpdbg_writeln("clean", "constants=\"%d\"", "Constants %d", zend_hash_num_elements(EG(zend_constants))); + phpdbg_writeln("clean", "includes=\"%d\"", "Includes %d", zend_hash_num_elements(&EG(included_files))); - phpdbg_writeln("Classes\t\t\t%d", zend_hash_num_elements(EG(class_table))); - phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(EG(function_table))); - phpdbg_writeln("Constants\t\t%d", zend_hash_num_elements(EG(zend_constants))); - phpdbg_writeln("Includes\t\t%d", zend_hash_num_elements(&EG(included_files))); + PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; - phpdbg_clean(1 TSRMLS_CC); + phpdbg_clean(1); + + phpdbg_xml("</cleaninfo>"); return SUCCESS; } /* }}} */ PHPDBG_COMMAND(clear) /* {{{ */ { - phpdbg_notice("Clearing Breakpoints"); + phpdbg_out("Clearing Breakpoints\n"); + phpdbg_xml("<clearinfo %r>"); + + phpdbg_writeln("clear", "files=\"%d\"", "File %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE])); + phpdbg_writeln("clear", "functions=\"%d\"", "Functions %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM])); + phpdbg_writeln("clear", "methods=\"%d\"", "Methods %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD])); + phpdbg_writeln("clear", "oplines=\"%d\"", "Oplines %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE])); + phpdbg_writeln("clear", "fileoplines=\"%d\"", "File oplines %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE])); + phpdbg_writeln("clear", "functionoplines=\"%d\"", "Function oplines %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE])); + phpdbg_writeln("clear", "methodoplines=\"%d\"", "Method oplines %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE])); + phpdbg_writeln("clear", "eval=\"%d\"", "Conditionals %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_COND])); - phpdbg_writeln("File\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE])); - phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM])); - phpdbg_writeln("Methods\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD])); - phpdbg_writeln("Oplines\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE])); - phpdbg_writeln("File oplines\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE])); - phpdbg_writeln("Function oplines\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE])); - phpdbg_writeln("Method oplines\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE])); - phpdbg_writeln("Conditionals\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_COND])); + phpdbg_clear_breakpoints(); - phpdbg_clear_breakpoints(TSRMLS_C); + phpdbg_xml("</clearinfo>"); return SUCCESS; } /* }}} */ @@ -962,7 +1191,7 @@ PHPDBG_COMMAND(list) /* {{{ */ return PHPDBG_LIST_HANDLER(lines)(PHPDBG_COMMAND_ARGS); case STR_PARAM: - phpdbg_list_function_byname(param->str, param->len TSRMLS_CC); + phpdbg_list_function_byname(param->str, param->len); break; case METHOD_PARAM: @@ -977,11 +1206,11 @@ PHPDBG_COMMAND(list) /* {{{ */ PHPDBG_COMMAND(watch) /* {{{ */ { if (!param || param->type == EMPTY_PARAM) { - phpdbg_list_watchpoints(TSRMLS_C); + phpdbg_list_watchpoints(); } else switch (param->type) { case STR_PARAM: - if (phpdbg_create_var_watchpoint(param->str, param->len TSRMLS_CC) != FAILURE) { - phpdbg_notice("Set watchpoint on %.*s", (int)param->len, param->str); + if (phpdbg_create_var_watchpoint(param->str, param->len) != FAILURE) { + phpdbg_notice("watch", "variable=\"%.*s\"", "Set watchpoint on %.*s", (int) param->len, param->str); } break; @@ -991,87 +1220,95 @@ PHPDBG_COMMAND(watch) /* {{{ */ return SUCCESS; } /* }}} */ -int phpdbg_interactive(TSRMLS_D) /* {{{ */ +int phpdbg_interactive(zend_bool allow_async_unsafe) /* {{{ */ { int ret = SUCCESS; - char *why = NULL; char *input = NULL; phpdbg_param_t stack; PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE; - input = phpdbg_read_input(NULL TSRMLS_CC); + while (ret == SUCCESS || ret == FAILURE) { + if ((PHPDBG_G(flags) & (PHPDBG_IS_STOPPING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_STOPPING) { + zend_bailout(); + } - if (input) { - do { - phpdbg_init_param(&stack, STACK_PARAM); + if (!(input = phpdbg_read_input(NULL))) { + break; + } - if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) { - switch (ret = phpdbg_stack_execute(&stack, &why TSRMLS_CC)) { - case FAILURE: - if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { - if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { - if (why) { - phpdbg_error("%s", why); - } - } - } - if (why) { - free(why); - why = NULL; - } - break; + phpdbg_init_param(&stack, STACK_PARAM); + + if (phpdbg_do_parse(&stack, input) <= 0) { + phpdbg_activate_err_buf(1); - case PHPDBG_LEAVE: - case PHPDBG_FINISH: - case PHPDBG_UNTIL: - case PHPDBG_NEXT: { - if (!EG(in_execution) && !(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { - phpdbg_error("Not running"); +#ifdef PHP_WIN32 +#define PARA ((phpdbg_param_t *)stack.next)->type + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE && (RUN_PARAM == PARA || EVAL_PARAM == PARA)) { + sigio_watcher_start(); + } +#endif + switch (ret = phpdbg_stack_execute(&stack, allow_async_unsafe)) { + case FAILURE: + if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { + if (!allow_async_unsafe || phpdbg_call_register(&stack) == FAILURE) { + phpdbg_output_err_buf(NULL, "%b", "%b"); } - goto out; } + break; + + case PHPDBG_LEAVE: + case PHPDBG_FINISH: + case PHPDBG_UNTIL: + case PHPDBG_NEXT: { + phpdbg_activate_err_buf(0); + phpdbg_free_err_buf(); + if (!PHPDBG_G(in_execution) && !(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) { + phpdbg_error("command", "type=\"noexec\"", "Not running"); + } + break; } } - if (why) { - free(why); - why = NULL; + phpdbg_activate_err_buf(0); + phpdbg_free_err_buf(); +#ifdef PHP_WIN32 + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE && (RUN_PARAM == PARA || EVAL_PARAM == PARA)) { + sigio_watcher_stop(); } +#undef PARA +#endif + } - phpdbg_stack_free(&stack); - phpdbg_destroy_input(&input TSRMLS_CC); - - } while ((input = phpdbg_read_input(NULL TSRMLS_CC))); + phpdbg_stack_free(&stack); + phpdbg_destroy_input(&input); + PHPDBG_G(req_id) = 0; + input = NULL; } -out: if (input) { phpdbg_stack_free(&stack); - phpdbg_destroy_input(&input TSRMLS_CC); - } - - if (why) { - free(why); + phpdbg_destroy_input(&input); + PHPDBG_G(req_id) = 0; } - if (EG(in_execution)) { - phpdbg_restore_frame(TSRMLS_C); + if (PHPDBG_G(in_execution)) { + phpdbg_restore_frame(); } PHPDBG_G(flags) &= ~PHPDBG_IS_INTERACTIVE; - phpdbg_print_changed_zvals(TSRMLS_C); + phpdbg_print_changed_zvals(); return ret; } /* }}} */ -void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */ +void phpdbg_clean(zend_bool full) /* {{{ */ { /* this is implicitly required */ if (PHPDBG_G(ops)) { - destroy_op_array(PHPDBG_G(ops) TSRMLS_CC); + destroy_op_array(PHPDBG_G(ops)); efree(PHPDBG_G(ops)); PHPDBG_G(ops) = NULL; } @@ -1083,138 +1320,49 @@ void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */ } } /* }}} */ -static inline zend_execute_data *phpdbg_create_execute_data(zend_op_array *op_array, zend_bool nested TSRMLS_DC) /* {{{ */ -{ -#if PHP_VERSION_ID >= 50500 - return zend_create_execute_data_from_op_array(op_array, nested TSRMLS_CC); -#else - -#undef EX -#define EX(element) execute_data->element -#undef EX_CV -#define EX_CV(var) EX(CVs)[var] -#undef EX_CVs -#define EX_CVs() EX(CVs) -#undef EX_T -#define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset)) -#undef EX_Ts -#define EX_Ts() EX(Ts) - - zend_execute_data *execute_data = (zend_execute_data *)zend_vm_stack_alloc( - ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) + - ZEND_MM_ALIGNED_SIZE(sizeof(zval**) * op_array->last_var * (EG(active_symbol_table) ? 1 : 2)) + - ZEND_MM_ALIGNED_SIZE(sizeof(temp_variable)) * op_array->T TSRMLS_CC); - - EX(CVs) = (zval***)((char*)execute_data + ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data))); - memset(EX(CVs), 0, sizeof(zval**) * op_array->last_var); - EX(Ts) = (temp_variable *)(((char*)EX(CVs)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval**) * op_array->last_var * (EG(active_symbol_table) ? 1 : 2))); - EX(fbc) = NULL; - EX(called_scope) = NULL; - EX(object) = NULL; - EX(old_error_reporting) = NULL; - EX(op_array) = op_array; - EX(symbol_table) = EG(active_symbol_table); - EX(prev_execute_data) = EG(current_execute_data); - EG(current_execute_data) = execute_data; - EX(nested) = nested; - - if (!op_array->run_time_cache && op_array->last_cache_slot) { - op_array->run_time_cache = ecalloc(op_array->last_cache_slot, sizeof(void*)); - } - - if (op_array->this_var != -1 && EG(This)) { - Z_ADDREF_P(EG(This)); /* For $this pointer */ - if (!EG(active_symbol_table)) { - EX_CV(op_array->this_var) = (zval**)EX_CVs() + (op_array->last_var + op_array->this_var); - *EX_CV(op_array->this_var) = EG(This); - } else { - if (zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), (void**)&EX_CV(op_array->this_var))==FAILURE) { - Z_DELREF_P(EG(This)); - } - } - } - - EX(opline) = UNEXPECTED((op_array->fn_flags & ZEND_ACC_INTERACTIVE) != 0) && EG(start_op) ? EG(start_op) : op_array->opcodes; - EG(opline_ptr) = &EX(opline); - - EX(function_state).function = (zend_function *) op_array; - EX(function_state).arguments = NULL; - - return execute_data; -#endif -} /* }}} */ +#define DO_INTERACTIVE(allow_async_unsafe) do { \ + if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { \ + const char *file_char = zend_get_executed_filename(); \ + zend_string *file = zend_string_init(file_char, strlen(file_char), 0); \ + phpdbg_list_file(file, 3, zend_get_executed_lineno()-1, zend_get_executed_lineno()); \ + efree(file); \ + } \ + \ + switch (phpdbg_interactive(allow_async_unsafe)) { \ + case PHPDBG_LEAVE: \ + case PHPDBG_FINISH: \ + case PHPDBG_UNTIL: \ + case PHPDBG_NEXT:{ \ + goto next; \ + } \ + } \ +} while (0) -#if PHP_VERSION_ID >= 50500 -void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */ -{ -#else -void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC) /* {{{ */ +void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ { - long long flags = 0; - zend_ulong address = 0L; - zend_execute_data *execute_data; - zend_bool nested = 0; -#endif - zend_bool original_in_execution = EG(in_execution); + zend_bool original_in_execution = PHPDBG_G(in_execution); HashTable vars; -#if PHP_VERSION_ID < 50500 - if (EG(exception)) { - return; - } -#endif - - EG(in_execution) = 1; + zend_hash_init(&vars, execute_data->func->op_array.last, NULL, NULL, 0); -#if PHP_VERSION_ID >= 50500 - if (0) { -zend_vm_enter: - execute_data = phpdbg_create_execute_data(EG(active_op_array), 1 TSRMLS_CC); + if ((PHPDBG_G(flags) & PHPDBG_IS_STOPPING) && !(PHPDBG_G(flags) & PHPDBG_IS_RUNNING)) { + zend_bailout(); } - zend_hash_init(&vars, EG(active_op_array)->last, NULL, NULL, 0); -#else -zend_vm_enter: - execute_data = phpdbg_create_execute_data(op_array, nested TSRMLS_CC); - nested = 1; - zend_hash_init(&vars, EG(active_op_array)->last, NULL, NULL, 0); -#endif + + PHPDBG_G(in_execution) = 1; while (1) { - if ((PHPDBG_G(flags) & PHPDBG_BP_RESOLVE_MASK)) { /* resolve nth opline breakpoints */ - phpdbg_resolve_op_array_breaks(EG(active_op_array) TSRMLS_CC); + phpdbg_resolve_op_array_breaks(&execute_data->func->op_array); } - + #ifdef ZEND_WIN32 if (EG(timed_out)) { zend_timeout(0); } #endif -#define DO_INTERACTIVE() do { \ - if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { \ - phpdbg_list_file( \ - zend_get_executed_filename(TSRMLS_C), \ - 3, \ - zend_get_executed_lineno(TSRMLS_C)-1, \ - zend_get_executed_lineno(TSRMLS_C) \ - TSRMLS_CC \ - ); \ - } \ - \ -/* do { */\ - switch (phpdbg_interactive(TSRMLS_C)) { \ - case PHPDBG_LEAVE: \ - case PHPDBG_FINISH: \ - case PHPDBG_UNTIL: \ - case PHPDBG_NEXT:{ \ - goto next; \ - } \ - } \ -/* } while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)); */\ -} while (0) - /* allow conditional breakpoints and initialization to access the vm uninterrupted */ if ((PHPDBG_G(flags) & PHPDBG_IN_COND_BP) || @@ -1232,8 +1380,7 @@ zend_vm_enter: if (PHPDBG_G(flags) & PHPDBG_IN_UNTIL) { if (zend_hash_index_exists(&PHPDBG_G(seek), address)) { PHPDBG_G(flags) &= ~PHPDBG_IN_UNTIL; - zend_hash_clean( - &PHPDBG_G(seek)); + zend_hash_clean(&PHPDBG_G(seek)); } else { /* skip possible breakpoints */ goto next; @@ -1244,8 +1391,7 @@ zend_vm_enter: if (PHPDBG_G(flags) & PHPDBG_IN_FINISH) { if (zend_hash_index_exists(&PHPDBG_G(seek), address)) { PHPDBG_G(flags) &= ~PHPDBG_IN_FINISH; - zend_hash_clean( - &PHPDBG_G(seek)); + zend_hash_clean(&PHPDBG_G(seek)); } /* skip possible breakpoints */ goto next; @@ -1255,14 +1401,12 @@ zend_vm_enter: if (PHPDBG_G(flags) & PHPDBG_IN_LEAVE) { if (zend_hash_index_exists(&PHPDBG_G(seek), address)) { PHPDBG_G(flags) &= ~PHPDBG_IN_LEAVE; - zend_hash_clean( - &PHPDBG_G(seek)); - phpdbg_notice( - "Breaking for leave at %s:%u", - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C) + zend_hash_clean(&PHPDBG_G(seek)); + phpdbg_notice("breakpoint", "id=\"leave\" file=\"%s\" line=\"%u\"", "Breaking for leave at %s:%u", + zend_get_executed_filename(), + zend_get_executed_lineno() ); - DO_INTERACTIVE(); + DO_INTERACTIVE(1); } else { /* skip possible breakpoints */ goto next; @@ -1271,18 +1415,17 @@ zend_vm_enter: } /* not while in conditionals */ - phpdbg_print_opline_ex( - execute_data, &vars, 0 TSRMLS_CC); + phpdbg_print_opline_ex(execute_data, &vars, 0); if (PHPDBG_G(flags) & PHPDBG_IS_STEPPING && (PHPDBG_G(flags) & PHPDBG_STEP_OPCODE || execute_data->opline->lineno != PHPDBG_G(last_line))) { PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING; - DO_INTERACTIVE(); + DO_INTERACTIVE(1); } /* check if some watchpoint was hit */ { - if (phpdbg_print_changed_zvals(TSRMLS_C) == SUCCESS) { - DO_INTERACTIVE(); + if (phpdbg_print_changed_zvals() == SUCCESS) { + DO_INTERACTIVE(1); } } @@ -1291,45 +1434,85 @@ zend_vm_enter: phpdbg_breakbase_t *brake; if ((PHPDBG_G(flags) & PHPDBG_BP_MASK) - && (brake = phpdbg_find_breakpoint(execute_data TSRMLS_CC)) + && (brake = phpdbg_find_breakpoint(execute_data)) && (brake->type != PHPDBG_BREAK_FILE || execute_data->opline->lineno != PHPDBG_G(last_line))) { - phpdbg_hit_breakpoint(brake, 1 TSRMLS_CC); - DO_INTERACTIVE(); + phpdbg_hit_breakpoint(brake, 1); + DO_INTERACTIVE(1); } } -next: if (PHPDBG_G(flags) & PHPDBG_IS_SIGNALED) { - phpdbg_writeln(EMPTY); - phpdbg_notice("Program received signal SIGINT"); PHPDBG_G(flags) &= ~PHPDBG_IS_SIGNALED; - DO_INTERACTIVE(); + + phpdbg_out("\n"); + phpdbg_notice("signal", "type=\"SIGINT\"", "Program received signal SIGINT"); + DO_INTERACTIVE(1); } - PHPDBG_G(last_line) = execute_data->opline->lineno; +next: - PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC); + PHPDBG_G(last_line) = execute_data->opline->lineno; - if (PHPDBG_G(vmret) > 0) { - switch (PHPDBG_G(vmret)) { - case 1: - EG(in_execution) = original_in_execution; - zend_hash_destroy(&vars); - return; - case 2: -#if PHP_VERSION_ID < 50500 - op_array = EG(active_op_array); -#endif - zend_hash_destroy(&vars); - goto zend_vm_enter; - break; - case 3: - execute_data = EG(current_execute_data); - break; - default: - break; + /* stupid hack to make zend_do_fcall_common_helper return ZEND_VM_ENTER() instead of recursively calling zend_execute() and eventually segfaulting */ + if (execute_data->opline->opcode == ZEND_DO_FCALL && execute_data->func->type == ZEND_USER_FUNCTION) { + zend_execute_ex = execute_ex; + } + PHPDBG_G(vmret) = execute_data->opline->handler(execute_data); + zend_execute_ex = phpdbg_execute_ex; + + if (PHPDBG_G(vmret) != 0) { + if (PHPDBG_G(vmret) < 0) { + zend_hash_destroy(&vars); + PHPDBG_G(in_execution) = original_in_execution; + return; + } else { + execute_data = EG(current_execute_data); } } } zend_error_noreturn(E_ERROR, "Arrived at end of main loop which shouldn't happen"); } /* }}} */ + +/* only if *not* interactive and while executing */ +void phpdbg_force_interruption(void) { + zend_execute_data *data = EG(current_execute_data); /* should be always readable if not NULL */ + + PHPDBG_G(flags) |= PHPDBG_IN_SIGNAL_HANDLER; + + if (data) { + if (data->func) { + phpdbg_notice("hardinterrupt", "opline=\"%p\" num=\"%lu\" file=\"%s\" line=\"%u\"", "Current opline: %p (op #%lu) in %s:%u", data->opline, (data->opline - data->func->op_array.opcodes) / sizeof(data->opline), data->func->op_array.filename, data->opline->lineno); + } else { + phpdbg_notice("hardinterrupt", "opline=\"%p\"", "Current opline: %p (op_array information unavailable)", data->opline); + } + } else { + phpdbg_notice("hardinterrupt", "", "No information available about executing context"); + } + + DO_INTERACTIVE(0); + +next: + PHPDBG_G(flags) &= ~PHPDBG_IN_SIGNAL_HANDLER; + + if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) { + zend_bailout(); + } +} + +PHPDBG_COMMAND(eol) /* {{{ */ +{ + if (!param || param->type == EMPTY_PARAM) { + phpdbg_notice("eol", "argument required", "argument required"); + } else switch (param->type) { + case STR_PARAM: + if (FAILURE == phpdbg_eol_global_update(param->str)) { + phpdbg_notice("eol", "unknown EOL name '%s', give crlf, lf, cr", "unknown EOL name '%s', give crlf, lf, cr", param->str); + } + break; + + phpdbg_default_switch_case(); + } + + return SUCCESS; +} /* }}} */ + diff --git a/sapi/phpdbg/phpdbg_prompt.h b/sapi/phpdbg/phpdbg_prompt.h index 5a0ea4bad3..5fb1e3a654 100644 --- a/sapi/phpdbg/phpdbg_prompt.h +++ b/sapi/phpdbg/phpdbg_prompt.h @@ -22,11 +22,14 @@ #define PHPDBG_PROMPT_H /* {{{ */ -void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC); -void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC); -int phpdbg_interactive(TSRMLS_D); -int phpdbg_compile(TSRMLS_D); -void phpdbg_clean(zend_bool full TSRMLS_DC); /* }}} */ +void phpdbg_string_init(char *buffer); +void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default); +void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init); +int phpdbg_interactive(zend_bool allow_async_unsafe); +int phpdbg_compile(void); +void phpdbg_clean(zend_bool full); +void phpdbg_force_interruption(void); +/* }}} */ /* {{{ phpdbg command handlers */ PHPDBG_COMMAND(exec); @@ -47,21 +50,24 @@ PHPDBG_COMMAND(clean); PHPDBG_COMMAND(clear); PHPDBG_COMMAND(help); PHPDBG_COMMAND(sh); +PHPDBG_COMMAND(dl); PHPDBG_COMMAND(set); PHPDBG_COMMAND(source); PHPDBG_COMMAND(export); PHPDBG_COMMAND(register); PHPDBG_COMMAND(quit); -PHPDBG_COMMAND(watch); /* }}} */ +PHPDBG_COMMAND(watch); +PHPDBG_COMMAND(eol); +PHPDBG_COMMAND(wait); /* }}} */ /* {{{ prompt commands */ extern const phpdbg_command_t phpdbg_prompt_commands[]; /* }}} */ /* {{{ */ #if PHP_VERSION_ID >= 50500 -void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC); +void phpdbg_execute_ex(zend_execute_data *execute_data); #else -void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC); +void phpdbg_execute_ex(zend_op_array *op_array); #endif /* }}} */ #endif /* PHPDBG_PROMPT_H */ diff --git a/sapi/phpdbg/phpdbg_rinit_hook.c b/sapi/phpdbg/phpdbg_rinit_hook.c new file mode 100644 index 0000000000..57f9ae2c7e --- /dev/null +++ b/sapi/phpdbg/phpdbg_rinit_hook.c @@ -0,0 +1,105 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Bob Weinand <bwoebi@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include "phpdbg_rinit_hook.h" +#include "php_ini.h" +#include <errno.h> + +ZEND_DECLARE_MODULE_GLOBALS(phpdbg_webhelper); + +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY("phpdbg.auth", "", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdateString, auth, zend_phpdbg_webhelper_globals, phpdbg_webhelper_globals) + STD_PHP_INI_ENTRY("phpdbg.path", "", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdateString, path, zend_phpdbg_webhelper_globals, phpdbg_webhelper_globals) +PHP_INI_END() + +static inline void php_phpdbg_webhelper_globals_ctor(zend_phpdbg_webhelper_globals *pg) /* {{{ */ +{ +} /* }}} */ + +static PHP_MINIT_FUNCTION(phpdbg_webhelper) /* {{{ */ +{ + if (!strcmp(sapi_module.name, PHPDBG_NAME)) { + return SUCCESS; + } + + ZEND_INIT_MODULE_GLOBALS(phpdbg_webhelper, php_phpdbg_webhelper_globals_ctor, NULL); + REGISTER_INI_ENTRIES(); + + return SUCCESS; +} /* }}} */ + +static PHP_RINIT_FUNCTION(phpdbg_webhelper) /* {{{ */ +{ + zval cookies = PG(http_globals)[TRACK_VARS_COOKIE]; + zval *auth; + + if (Z_TYPE(cookies) == IS_ARRAY || (auth = zend_hash_str_find(Z_ARRVAL(cookies), PHPDBG_NAME "_AUTH_COOKIE", sizeof(PHPDBG_NAME "_AUTH_COOKIE"))) || Z_STRLEN_P(auth) != strlen(PHPDBG_WG(auth)) || strcmp(Z_STRVAL_P(auth), PHPDBG_WG(auth))) { + return SUCCESS; + } + +#ifndef _WIN32 + { + struct sockaddr_un sock; + int s = socket(AF_UNIX, SOCK_STREAM, 0); + int len = strlen(PHPDBG_WG(path)) + sizeof(sock.sun_family); + char buf[(1 << 8) + 1]; + int buflen; + sock.sun_family = AF_UNIX; + strcpy(sock.sun_path, PHPDBG_WG(path)); + + if (connect(s, (struct sockaddr *)&sock, len) == -1) { + zend_error(E_ERROR, "Unable to connect to UNIX domain socket at %s defined by phpdbg.path ini setting. Reason: %s", PHPDBG_WG(path), strerror(errno)); + } + + char *msg = NULL; + char msglen[5] = {0}; + phpdbg_webdata_compress(&msg, (int *)msglen); + + send(s, msglen, 4, 0); + send(s, msg, *(int *) msglen, 0); + + while ((buflen = recv(s, buf, sizeof(buf) - 1, 0)) > 0) { + php_write(buf, buflen); + } + + close(s); + + php_output_flush_all(); + zend_bailout(); + } +#endif + + return SUCCESS; +} /* }}} */ + +zend_module_entry phpdbg_webhelper_module_entry = { + STANDARD_MODULE_HEADER, + "phpdbg_webhelper", + NULL, + PHP_MINIT(phpdbg_webhelper), + NULL, + PHP_RINIT(phpdbg_webhelper), + NULL, + NULL, + PHPDBG_VERSION, + STANDARD_MODULE_PROPERTIES +}; + +#ifdef COMPILE_DL_PHPDBG_WEBHELPER +ZEND_GET_MODULE(phpdbg_webhelper) +#endif diff --git a/sapi/phpdbg/phpdbg_rinit_hook.h b/sapi/phpdbg/phpdbg_rinit_hook.h new file mode 100644 index 0000000000..7ad0e46aca --- /dev/null +++ b/sapi/phpdbg/phpdbg_rinit_hook.h @@ -0,0 +1,41 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Felipe Pena <felipe@php.net> | + | Authors: Joe Watkins <joe.watkins@live.co.uk> | + | Authors: Bob Weinand <bwoebi@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifndef PHPDBG_WEBHELPER_H +#define PHPDBG_WEBHELPER_H + +#include "phpdbg_webdata_transfer.h" + +extern zend_module_entry phpdbg_webhelper_module_entry; +#define phpext_phpdbg_webhelper_ptr &phpdbg_webhelper_module_entry + +#ifdef ZTS +# define PHPDBG_WG(v) TSRMG(phpdbg_webhelper_globals_id, zend_phpdbg_webhelper_globals *, v) +#else +# define PHPDBG_WG(v) (phpdbg_webhelper_globals.v) +#endif + +/* {{{ structs */ +ZEND_BEGIN_MODULE_GLOBALS(phpdbg_webhelper) + char *auth; + char *path; +ZEND_END_MODULE_GLOBALS(phpdbg_webhelper) /* }}} */ + +#endif /* PHPDBG_WEBHELPER_H */ diff --git a/sapi/phpdbg/phpdbg_set.c b/sapi/phpdbg/phpdbg_set.c index b9ff097751..2062d25e77 100644 --- a/sapi/phpdbg/phpdbg_set.c +++ b/sapi/phpdbg/phpdbg_set.c @@ -27,30 +27,32 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -#define PHPDBG_SET_COMMAND_D(f, h, a, m, l, s) \ - PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[18]) +#define PHPDBG_SET_COMMAND_D(f, h, a, m, l, s, flags) \ + PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[18], flags) const phpdbg_command_t phpdbg_set_commands[] = { - PHPDBG_SET_COMMAND_D(prompt, "usage: set prompt [<string>]", 'p', set_prompt, NULL, "|s"), + PHPDBG_SET_COMMAND_D(prompt, "usage: set prompt [<string>]", 'p', set_prompt, NULL, "|s", 0), #ifndef _WIN32 - PHPDBG_SET_COMMAND_D(color, "usage: set color <element> <color>", 'c', set_color, NULL, "ss"), - PHPDBG_SET_COMMAND_D(colors, "usage: set colors [<on|off>]", 'C', set_colors, NULL, "|b"), + PHPDBG_SET_COMMAND_D(color, "usage: set color <element> <color>", 'c', set_color, NULL, "ss", PHPDBG_ASYNC_SAFE), + PHPDBG_SET_COMMAND_D(colors, "usage: set colors [<on|off>]", 'C', set_colors, NULL, "|b", PHPDBG_ASYNC_SAFE), #endif - PHPDBG_SET_COMMAND_D(oplog, "usage: set oplog [<output>]", 'O', set_oplog, NULL, "|s"), - PHPDBG_SET_COMMAND_D(break, "usage: set break id [<on|off>]", 'b', set_break, NULL, "l|b"), - PHPDBG_SET_COMMAND_D(breaks, "usage: set breaks [<on|off>]", 'B', set_breaks, NULL, "|b"), - PHPDBG_SET_COMMAND_D(quiet, "usage: set quiet [<on|off>]", 'q', set_quiet, NULL, "|b"), - PHPDBG_SET_COMMAND_D(stepping, "usage: set stepping [<line|op>]", 's', set_stepping, NULL, "|s"), - PHPDBG_SET_COMMAND_D(refcount, "usage: set refcount [<on|off>]", 'r', set_refcount, NULL, "|b"), + PHPDBG_SET_COMMAND_D(oplog, "usage: set oplog [<output>]", 'O', set_oplog, NULL, "|s", 0), + PHPDBG_SET_COMMAND_D(break, "usage: set break id [<on|off>]", 'b', set_break, NULL, "l|b", PHPDBG_ASYNC_SAFE), + PHPDBG_SET_COMMAND_D(breaks, "usage: set breaks [<on|off>]", 'B', set_breaks, NULL, "|b", PHPDBG_ASYNC_SAFE), + PHPDBG_SET_COMMAND_D(quiet, "usage: set quiet [<on|off>]", 'q', set_quiet, NULL, "|b", PHPDBG_ASYNC_SAFE), + PHPDBG_SET_COMMAND_D(stepping, "usage: set stepping [<line|op>]", 's', set_stepping, NULL, "|s", PHPDBG_ASYNC_SAFE), + PHPDBG_SET_COMMAND_D(refcount, "usage: set refcount [<on|off>]", 'r', set_refcount, NULL, "|b", PHPDBG_ASYNC_SAFE), PHPDBG_END_COMMAND }; PHPDBG_SET(prompt) /* {{{ */ { if (!param || param->type == EMPTY_PARAM) { - phpdbg_writeln("%s", phpdbg_get_prompt(TSRMLS_C)); - } else phpdbg_set_prompt(param->str TSRMLS_CC); - + phpdbg_writeln("setprompt", "str=\"%s\"", "Current prompt: %s", phpdbg_get_prompt()); + } else { + phpdbg_set_prompt(param->str); + } + return SUCCESS; } /* }}} */ @@ -60,22 +62,22 @@ PHPDBG_SET(break) /* {{{ */ case NUMERIC_PARAM: { if (param->next) { if (param->next->num) { - phpdbg_enable_breakpoint(param->num TSRMLS_CC); - } else phpdbg_disable_breakpoint(param->num TSRMLS_CC); + phpdbg_enable_breakpoint(param->num); + } else { + phpdbg_disable_breakpoint(param->num); + } } else { - phpdbg_breakbase_t *brake = phpdbg_find_breakbase(param->num TSRMLS_CC); + phpdbg_breakbase_t *brake = phpdbg_find_breakbase(param->num); if (brake) { - phpdbg_writeln( - "%s", brake->disabled ? "off" : "on"); + phpdbg_writeln("setbreak", "id=\"%ld\" active=\"%s\"", "Breakpoint #%ld %s", param->num, brake->disabled ? "off" : "on"); } else { - phpdbg_error("Failed to find breakpoint #%ld", param->num); + phpdbg_error("setbreak", "type=\"nobreak\" id=\"%ld\"", "Failed to find breakpoint #%ld", param->num); } } } break; default: - phpdbg_error( - "set break used incorrectly: set break [id] <on|off>"); + phpdbg_error("setbreak", "type=\"wrongargs\"", "set break used incorrectly: set break [id] <on|off>"); } return SUCCESS; @@ -84,18 +86,18 @@ PHPDBG_SET(break) /* {{{ */ PHPDBG_SET(breaks) /* {{{ */ { if (!param || param->type == EMPTY_PARAM) { - phpdbg_writeln("%s", - PHPDBG_G(flags) & PHPDBG_IS_BP_ENABLED ? "on" : "off"); - } else switch (param->type) { + phpdbg_writeln("setbreaks", "active=\"%s\"", "Breakpoints %s",PHPDBG_G(flags) & PHPDBG_IS_BP_ENABLED ? "on" : "off"); + } else switch (param->type) { case NUMERIC_PARAM: { if (param->num) { - phpdbg_enable_breakpoints(TSRMLS_C); - } else phpdbg_disable_breakpoints(TSRMLS_C); + phpdbg_enable_breakpoints(); + } else { + phpdbg_disable_breakpoints(); + } } break; default: - phpdbg_error( - "set break used incorrectly: set break [id] <on|off>"); + phpdbg_error("setbreaks", "type=\"wrongargs\"", "set breaks used incorrectly: set breaks <on|off>"); } return SUCCESS; @@ -104,41 +106,35 @@ PHPDBG_SET(breaks) /* {{{ */ #ifndef _WIN32 PHPDBG_SET(color) /* {{{ */ { - const phpdbg_color_t *color = phpdbg_get_color( - param->next->str, param->next->len TSRMLS_CC); - + const phpdbg_color_t *color = phpdbg_get_color(param->next->str, param->next->len); + if (!color) { - phpdbg_error( - "Failed to find the requested color (%s)", param->next->str); + phpdbg_error("setcolor", "type=\"nocolor\"", "Failed to find the requested color (%s)", param->next->str); return SUCCESS; } - - switch (phpdbg_get_element(param->str, param->len TSRMLS_CC)) { + + switch (phpdbg_get_element(param->str, param->len)) { case PHPDBG_COLOR_PROMPT: - phpdbg_notice( - "setting prompt color to %s (%s)", color->name, color->code); + phpdbg_notice("setcolor", "type=\"prompt\" color=\"%s\" code=\"%s\"", "setting prompt color to %s (%s)", color->name, color->code); if (PHPDBG_G(prompt)[1]) { free(PHPDBG_G(prompt)[1]); PHPDBG_G(prompt)[1]=NULL; } - phpdbg_set_color(PHPDBG_COLOR_PROMPT, color TSRMLS_CC); + phpdbg_set_color(PHPDBG_COLOR_PROMPT, color); break; - + case PHPDBG_COLOR_ERROR: - phpdbg_notice( - "setting error color to %s (%s)", color->name, color->code); - phpdbg_set_color(PHPDBG_COLOR_ERROR, color TSRMLS_CC); + phpdbg_notice("setcolor", "type=\"error\" color=\"%s\" code=\"%s\"", "setting error color to %s (%s)", color->name, color->code); + phpdbg_set_color(PHPDBG_COLOR_ERROR, color); break; - + case PHPDBG_COLOR_NOTICE: - phpdbg_notice( - "setting notice color to %s (%s)", color->name, color->code); - phpdbg_set_color(PHPDBG_COLOR_NOTICE, color TSRMLS_CC); + phpdbg_notice("setcolor", "type=\"notice\" color=\"%s\" code=\"%s\"", "setting notice color to %s (%s)", color->name, color->code); + phpdbg_set_color(PHPDBG_COLOR_NOTICE, color); break; - + default: - phpdbg_error( - "Failed to find the requested element (%s)", param->str); + phpdbg_error("setcolor", "type=\"invalidtype\"", "Failed to find the requested element (%s)", param->str); } return SUCCESS; @@ -147,7 +143,7 @@ PHPDBG_SET(color) /* {{{ */ PHPDBG_SET(colors) /* {{{ */ { if (!param || param->type == EMPTY_PARAM) { - phpdbg_writeln("%s", PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "on" : "off"); + phpdbg_writeln("setcolors", "active=\"%s\"", "Colors %s", PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "on" : "off"); } else switch (param->type) { case NUMERIC_PARAM: { if (param->num) { @@ -156,10 +152,9 @@ PHPDBG_SET(colors) /* {{{ */ PHPDBG_G(flags) &= ~PHPDBG_IS_COLOURED; } } break; - + default: - phpdbg_error( - "set colors used incorrectly: set colors <on|off>"); + phpdbg_error("setcolors", "type=\"wrongargs\"", "set colors used incorrectly: set colors <on|off>"); } return SUCCESS; @@ -169,7 +164,7 @@ PHPDBG_SET(colors) /* {{{ */ PHPDBG_SET(oplog) /* {{{ */ { if (!param || param->type == EMPTY_PARAM) { - phpdbg_notice("Oplog %s", PHPDBG_G(oplog) ? "enabled" : "disabled"); + phpdbg_notice("setoplog", "active=\"%s\"", "Oplog %s", PHPDBG_G(oplog) ? "on" : "off"); } else switch (param->type) { case STR_PARAM: { /* open oplog */ @@ -177,14 +172,15 @@ PHPDBG_SET(oplog) /* {{{ */ PHPDBG_G(oplog) = fopen(param->str, "w+"); if (!PHPDBG_G(oplog)) { - phpdbg_error("Failed to open %s for oplog", param->str); + phpdbg_error("setoplog", "type=\"openfailure\" file=\"%s\"", "Failed to open %s for oplog", param->str); PHPDBG_G(oplog) = old; } else { if (old) { - phpdbg_notice("Closing previously open oplog"); + phpdbg_notice("setoplog", "type=\"closingold\"", "Closing previously open oplog"); fclose(old); } - phpdbg_notice("Successfully opened oplog %s", param->str); + + phpdbg_notice("setoplog", "file=\"%s\"", "Successfully opened oplog %s", param->str); } } break; @@ -197,8 +193,7 @@ PHPDBG_SET(oplog) /* {{{ */ PHPDBG_SET(quiet) /* {{{ */ { if (!param || param->type == EMPTY_PARAM) { - phpdbg_writeln("Quietness %s", - PHPDBG_G(flags) & PHPDBG_IS_QUIET ? "on" : "off"); + phpdbg_writeln("setquiet", "active=\"%s\"", "Quietness %s", PHPDBG_G(flags) & PHPDBG_IS_QUIET ? "on" : "off"); } else switch (param->type) { case NUMERIC_PARAM: { if (param->num) { @@ -217,18 +212,15 @@ PHPDBG_SET(quiet) /* {{{ */ PHPDBG_SET(stepping) /* {{{ */ { if (!param || param->type == EMPTY_PARAM) { - phpdbg_writeln("Stepping %s", - PHPDBG_G(flags) & PHPDBG_STEP_OPCODE ? "opcode" : "line"); + phpdbg_writeln("setstepping", "type=\"%s\"", "Stepping %s", PHPDBG_G(flags) & PHPDBG_STEP_OPCODE ? "opcode" : "line"); } else switch (param->type) { - case STR_PARAM: { - if ((param->len == sizeof("opcode")-1) && - (memcmp(param->str, "opcode", sizeof("opcode")) == SUCCESS)) { + case STR_PARAM: { + if (param->len == sizeof("opcode") - 1 && !memcmp(param->str, "opcode", sizeof("opcode"))) { PHPDBG_G(flags) |= PHPDBG_STEP_OPCODE; - } else if ((param->len == sizeof("line")-1) && - (memcmp(param->str, "line", sizeof("line")) == SUCCESS)) { + } else if (param->len == sizeof("line") - 1 && !memcmp(param->str, "line", sizeof("line"))) { PHPDBG_G(flags) &= ~PHPDBG_STEP_OPCODE; } else { - phpdbg_error("usage set stepping [<opcode|line>]"); + phpdbg_error("setstepping", "type=\"wrongargs\"", "usage set stepping [<opcode|line>]"); } } break; @@ -241,7 +233,7 @@ PHPDBG_SET(stepping) /* {{{ */ PHPDBG_SET(refcount) /* {{{ */ { if (!param || param->type == EMPTY_PARAM) { - phpdbg_writeln("Refcount %s", PHPDBG_G(flags) & PHPDBG_IS_QUIET ? "on" : "off"); + phpdbg_writeln("setrefcount", "active=\"%s\"", "Showing refcounts %s", PHPDBG_G(flags) & PHPDBG_IS_QUIET ? "on" : "off"); } else switch (param->type) { case NUMERIC_PARAM: { if (param->num) { diff --git a/sapi/phpdbg/phpdbg_sigio_win32.c b/sapi/phpdbg/phpdbg_sigio_win32.c new file mode 100644 index 0000000000..7b99a66478 --- /dev/null +++ b/sapi/phpdbg/phpdbg_sigio_win32.c @@ -0,0 +1,112 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 7-4 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Anatol Belski <ab@php.net> | + +----------------------------------------------------------------------+ +*/ + + +#include <signal.h> + +#include "phpdbg.h" +#include "phpdbg_sigio_win32.h" + + +ZEND_EXTERN_MODULE_GLOBALS(phpdbg); + + +VOID +SigIoWatcherThread(VOID *p) +{ + zend_uchar sig; + struct win32_sigio_watcher_data *swd = (struct win32_sigio_watcher_data *)p; + +top: + (void)phpdbg_consume_bytes(swd->fd, &sig, 1, -1); + + + if (3 == sig) { + /* XXX completely not sure it is done right here */ + if (*swd->flags & PHPDBG_IS_INTERACTIVE) { + if (raise(sig)) { + goto top; + } + } + if (*swd->flags & PHPDBG_IS_SIGNALED) { + phpdbg_set_sigsafe_mem(&sig); + zend_try { + phpdbg_force_interruption(); + } zend_end_try(); + phpdbg_clear_sigsafe_mem(); + goto end; + } + if (!(*swd->flags & PHPDBG_IS_INTERACTIVE)) { + *swd->flags |= PHPDBG_IS_SIGNALED; + } +end: + /* XXX set signaled flag to the caller thread, question is - whether it's needed */ + ExitThread(sig); + } else { + goto top; + } +} + + +/* Start this only for the time of the run or eval command, +for so long that the main thread is busy serving some debug +session. */ +void +sigio_watcher_start(void) +{ + + PHPDBG_G(swd).fd = PHPDBG_G(io)[PHPDBG_STDIN].fd; +#ifdef ZTS + PHPDBG_G(swd).flags = &PHPDBG_G(flags); +#endif + + PHPDBG_G(sigio_watcher_thread) = CreateThread( + NULL, + 0, + (LPTHREAD_START_ROUTINE)SigIoWatcherThread, + &PHPDBG_G(swd), + 0, + NULL); +} + +void +sigio_watcher_stop(void) +{ + DWORD waited; + + if (INVALID_HANDLE_VALUE == PHPDBG_G(sigio_watcher_thread)) { + /* it probably did bail out already */ + return; + } + + waited = WaitForSingleObject(PHPDBG_G(sigio_watcher_thread), 300); + + if (WAIT_OBJECT_0 != waited) { + if (!CancelSynchronousIo(PHPDBG_G(sigio_watcher_thread))) { + /* error out */ + } + + if (!TerminateThread(PHPDBG_G(sigio_watcher_thread), 0)) { + /* error out */ + } + } + + PHPDBG_G(swd).fd = -1; + PHPDBG_G(sigio_watcher_thread) = INVALID_HANDLE_VALUE; +} + diff --git a/sapi/phpdbg/phpdbg_sigio_win32.h b/sapi/phpdbg/phpdbg_sigio_win32.h new file mode 100644 index 0000000000..beb27f979f --- /dev/null +++ b/sapi/phpdbg/phpdbg_sigio_win32.h @@ -0,0 +1,38 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 7-4 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Anatol Belski <ab@php.net> | + +----------------------------------------------------------------------+ +*/ + + +#ifndef PHPDBG_SIGIO_WIN32_H +#define PHPDBG_SIGIO_WIN32_H + +#include "phpdbg.h" +#include "phpdbg_prompt.h" +#include "phpdbg_io.h" + +struct win32_sigio_watcher_data { + uint64_t *flags; + int fd; +}; + +void +sigio_watcher_start(void); + +void +sigio_watcher_stop(void); + +#endif /* PHPDBG_SIGIO_WIN32_H */ diff --git a/sapi/phpdbg/phpdbg_sigsafe.c b/sapi/phpdbg/phpdbg_sigsafe.c new file mode 100644 index 0000000000..ce321595b1 --- /dev/null +++ b/sapi/phpdbg/phpdbg_sigsafe.c @@ -0,0 +1,55 @@ +#include "phpdbg_sigsafe.h" +#include "phpdbg.h" + +ZEND_EXTERN_MODULE_GLOBALS(phpdbg); + +#define STR(x) #x +#define EXP_STR(x) STR(x) + +static void* zend_mm_mem_alloc(zend_mm_storage *storage, size_t size, size_t alignment) { + + if (EXPECTED(size == PHPDBG_SIGSAFE_MEM_SIZE && !PHPDBG_G(sigsafe_mem).allocated)) { + PHPDBG_G(sigsafe_mem).allocated = 1; + return PHPDBG_G(sigsafe_mem).mem; + } + + write(PHPDBG_G(io)[PHPDBG_STDERR].fd, ZEND_STRL("Tried to allocate more than " EXP_STR(PHPDBG_SIGSAFE_MEM_SIZE) " bytes from stack memory in signal handler ... bailing out of signal handler\n")); + + if (*EG(bailout)) { + LONGJMP(*EG(bailout), FAILURE); + } + + write(PHPDBG_G(io)[PHPDBG_STDERR].fd, ZEND_STRL("Bailed out without a bailout address in signal handler!\n")); + + return NULL; +} + +static void zend_mm_mem_free(zend_mm_storage *storage, void *ptr, size_t size) { +} + +void phpdbg_set_sigsafe_mem(char *buffer) { + phpdbg_signal_safe_mem *mem = &PHPDBG_G(sigsafe_mem); + mem->mem = buffer; + mem->allocated = 0; + + mem->storage.chunk_alloc = zend_mm_mem_alloc; + mem->storage.chunk_free = zend_mm_mem_free; + + mem->heap = zend_mm_startup_ex(&mem->storage); + + mem->old_heap = zend_mm_set_heap(mem->heap); +} + +zend_mm_heap *phpdbg_original_heap_sigsafe_mem(void) { + return PHPDBG_G(sigsafe_mem).old_heap; +} + +void phpdbg_clear_sigsafe_mem(void) { + zend_mm_set_heap(phpdbg_original_heap_sigsafe_mem()); + PHPDBG_G(sigsafe_mem).mem = NULL; +} + +zend_bool phpdbg_active_sigsafe_mem(void) { + return !!PHPDBG_G(sigsafe_mem).mem; +} + diff --git a/sapi/phpdbg/phpdbg_sigsafe.h b/sapi/phpdbg/phpdbg_sigsafe.h new file mode 100644 index 0000000000..d8a195f266 --- /dev/null +++ b/sapi/phpdbg/phpdbg_sigsafe.h @@ -0,0 +1,28 @@ +#ifndef PHPDBG_SIGSAFE_H +#define PHPDBG_SIGSAFE_H + +//#include "zend_mm_structs.h" + +#define PHPDBG_SIGSAFE_MEM_SIZE ZEND_MM_CHUNK_SIZE +//(1 << 20) + +#include "zend.h" + +typedef struct { + char *mem; + zend_bool allocated; + zend_mm_heap *heap; + zend_mm_heap *old_heap; + zend_mm_storage storage; +} phpdbg_signal_safe_mem; + +#include "phpdbg.h" + +zend_bool phpdbg_active_sigsafe_mem(void); + +void phpdbg_set_sigsafe_mem(char *mem); +void phpdbg_clear_sigsafe_mem(void); + +zend_mm_heap *phpdbg_original_heap_sigsafe_mem(void); + +#endif diff --git a/sapi/phpdbg/phpdbg_utils.c b/sapi/phpdbg/phpdbg_utils.c index 7c7307a58b..357905fa06 100644 --- a/sapi/phpdbg/phpdbg_utils.c +++ b/sapi/phpdbg/phpdbg_utils.c @@ -18,19 +18,14 @@ +----------------------------------------------------------------------+ */ -#include <stdio.h> -#include <ctype.h> -#include <string.h> #include "zend.h" + #include "php.h" -#include "spprintf.h" #include "phpdbg.h" #include "phpdbg_opcode.h" #include "phpdbg_utils.h" -#ifdef _WIN32 -# include "win32/time.h" -#elif defined(HAVE_SYS_IOCTL_H) +#if defined(HAVE_SYS_IOCTL_H) # include "sys/ioctl.h" # ifndef GWINSZ_IN_SYS_IOCTL # include <termios.h> @@ -128,12 +123,12 @@ PHPDBG_API int phpdbg_is_class_method(const char *str, size_t len, char **class, } if (class != NULL) { - + if (str[0] == '\\') { str++; len--; } - + *class = estrndup(str, sep - str); (*class)[sep - str] = 0; } @@ -145,20 +140,20 @@ PHPDBG_API int phpdbg_is_class_method(const char *str, size_t len, char **class, return 1; } /* }}} */ -PHPDBG_API char *phpdbg_resolve_path(const char *path TSRMLS_DC) /* {{{ */ +PHPDBG_API char *phpdbg_resolve_path(const char *path) /* {{{ */ { char resolved_name[MAXPATHLEN]; - if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) { + if (expand_filepath(path, resolved_name) == NULL) { return NULL; } return estrdup(resolved_name); } /* }}} */ -PHPDBG_API const char *phpdbg_current_file(TSRMLS_D) /* {{{ */ +PHPDBG_API const char *phpdbg_current_file(void) /* {{{ */ { - const char *file = zend_get_executed_filename(TSRMLS_C); + const char *file = zend_get_executed_filename(); if (memcmp(file, "[no active file]", sizeof("[no active file]")) == 0) { return PHPDBG_G(exec); @@ -167,30 +162,28 @@ PHPDBG_API const char *phpdbg_current_file(TSRMLS_D) /* {{{ */ return file; } /* }}} */ -PHPDBG_API const zend_function *phpdbg_get_function(const char *fname, const char *cname TSRMLS_DC) /* {{{ */ +PHPDBG_API const zend_function *phpdbg_get_function(const char *fname, const char *cname) /* {{{ */ { zend_function *func = NULL; - size_t fname_len = strlen(fname); - char *lcname = zend_str_tolower_dup(fname, fname_len); + zend_string *lfname = zend_string_alloc(strlen(fname), 0); + memcpy(lfname->val, zend_str_tolower_dup(fname, lfname->len), lfname->len + 1); if (cname) { - zend_class_entry **ce; - size_t cname_len = strlen(cname); - char *lc_cname = zend_str_tolower_dup(cname, cname_len); - int ret = zend_lookup_class(lc_cname, cname_len, &ce TSRMLS_CC); + zend_class_entry *ce; + zend_string *lcname = zend_string_alloc(strlen(cname), 0); + memcpy(lcname->val, zend_str_tolower_dup(cname, lcname->len), lcname->len + 1); + ce = zend_lookup_class(lcname); - efree(lc_cname); + efree(lcname); - if (ret == SUCCESS) { - zend_hash_find(&(*ce)->function_table, lcname, fname_len+1, - (void**)&func); + if (ce) { + func = zend_hash_find_ptr(&ce->function_table, lfname); } } else { - zend_hash_find(EG(function_table), lcname, fname_len+1, - (void**)&func); + func = zend_hash_find_ptr(EG(function_table), lfname); } - efree(lcname); + efree(lfname); return func; } /* }}} */ @@ -224,145 +217,46 @@ PHPDBG_API char *phpdbg_trim(const char *str, size_t len, size_t *new_len) /* {{ } /* }}} */ -PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ...) /* {{{ */ -{ - int rc = 0; - char *buffer = NULL; - va_list args; - - if (format != NULL && strlen(format) > 0L) { - va_start(args, format); - vspprintf(&buffer, 0, format, args); - va_end(args); - } - - /* TODO(anyone) colours */ - - switch (type) { - case P_ERROR: - if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) { - rc = fprintf(fp, - "\033[%sm[%s]\033[0m\n", - PHPDBG_G(colors)[PHPDBG_COLOR_ERROR]->code, buffer); - } else { - rc = fprintf(fp, "[%s]\n", buffer); - } - break; - - case P_NOTICE: - if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) { - rc = fprintf(fp, - "\033[%sm[%s]\033[0m\n", - PHPDBG_G(colors)[PHPDBG_COLOR_NOTICE]->code, buffer); - } else { - rc = fprintf(fp, "[%s]\n", buffer); - } - break; - - case P_WRITELN: { - if (buffer) { - rc = fprintf(fp, "%s\n", buffer); - } else { - rc = fprintf(fp, "\n"); - } - } break; - - case P_WRITE: - if (buffer) { - rc = fprintf(fp, "%s", buffer); - } - break; - - /* no formatting on logging output */ - case P_LOG: - if (buffer) { - struct timeval tp; - if (gettimeofday(&tp, NULL) == SUCCESS) { - rc = fprintf(fp, "[%ld %.8F]: %s\n", tp.tv_sec, tp.tv_usec / 1000000.00, buffer); - } else { - rc = FAILURE; - } - } - break; - } - - if (buffer) { - efree(buffer); - } - - return rc; -} /* }}} */ - -PHPDBG_API int phpdbg_rlog(FILE *fp, const char *fmt, ...) { /* {{{ */ - int rc = 0; - - va_list args; - struct timeval tp; - - va_start(args, fmt); - if (gettimeofday(&tp, NULL) == SUCCESS) { - char friendly[100]; - char *format = NULL, *buffer = NULL; - const time_t tt = tp.tv_sec; - - strftime(friendly, 100, "%a %b %d %T.%%04d %Y", localtime(&tt)); - asprintf( - &buffer, friendly, tp.tv_usec/1000); - asprintf( - &format, "[%s]: %s\n", buffer, fmt); - rc = vfprintf( - fp, format, args); - - free(format); - free(buffer); - } - va_end(args); - - return rc; -} /* }}} */ - -PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC) /* {{{ */ +PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length) /* {{{ */ { const phpdbg_color_t *color = colors; while (color && color->name) { if (name_length == color->name_length && memcmp(name, color->name, name_length) == SUCCESS) { - phpdbg_debug( - "phpdbg_get_color(%s, %lu): %s", name, name_length, color->code); + phpdbg_debug("phpdbg_get_color(%s, %lu): %s", name, name_length, color->code); return color; } ++color; } - phpdbg_debug( - "phpdbg_get_color(%s, %lu): failed", name, name_length); + phpdbg_debug("phpdbg_get_color(%s, %lu): failed", name, name_length); return NULL; } /* }}} */ -PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color) /* {{{ */ { PHPDBG_G(colors)[element] = color; } /* }}} */ -PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length) /* {{{ */ { - const phpdbg_color_t *color = phpdbg_get_color(name, name_length TSRMLS_CC); + const phpdbg_color_t *color = phpdbg_get_color(name, name_length); if (color) { - phpdbg_set_color(element, color TSRMLS_CC); + phpdbg_set_color(element, color); } else PHPDBG_G(colors)[element] = colors; } /* }}} */ -PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D) /* {{{ */ +PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(void) /* {{{ */ { return colors; } /* }}} */ -PHPDBG_API int phpdbg_get_element(const char *name, size_t len TSRMLS_DC) { +PHPDBG_API int phpdbg_get_element(const char *name, size_t len) { const phpdbg_element_t *element = elements; - + while (element && element->name) { if (len == element->name_length) { if (strncasecmp(name, element->name, len) == SUCCESS) { @@ -371,11 +265,11 @@ PHPDBG_API int phpdbg_get_element(const char *name, size_t len TSRMLS_DC) { } element++; } - + return PHPDBG_COLOR_INVALID; } -PHPDBG_API void phpdbg_set_prompt(const char *prompt TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_prompt(const char *prompt) /* {{{ */ { /* free formatted prompt */ if (PHPDBG_G(prompt)[1]) { @@ -392,7 +286,7 @@ PHPDBG_API void phpdbg_set_prompt(const char *prompt TSRMLS_DC) /* {{{ */ PHPDBG_G(prompt)[0] = strdup(prompt); } /* }}} */ -PHPDBG_API const char *phpdbg_get_prompt(TSRMLS_D) /* {{{ */ +PHPDBG_API const char *phpdbg_get_prompt(void) /* {{{ */ { /* find cached prompt */ if (PHPDBG_G(prompt)[1]) { @@ -418,33 +312,29 @@ PHPDBG_API const char *phpdbg_get_prompt(TSRMLS_D) /* {{{ */ return PHPDBG_G(prompt)[1]; } /* }}} */ -int phpdbg_rebuild_symtable(TSRMLS_D) { - if (!EG(active_op_array)) { - phpdbg_error("No active op array!"); +int phpdbg_rebuild_symtable(void) { + if (!EG(current_execute_data) || !EG(current_execute_data)->func) { + phpdbg_error("inactive", "type=\"op_array\"", "No active op array!"); return FAILURE; } - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); - - if (!EG(active_symbol_table)) { - phpdbg_error("No active symbol table!"); - return FAILURE; - } + if (!zend_rebuild_symbol_table()) { + phpdbg_error("inactive", "type=\"symbol_table\"", "No active symbol table!"); + return FAILURE; } return SUCCESS; } -PHPDBG_API int phpdbg_get_terminal_width(TSRMLS_D) /* {{{ */ +PHPDBG_API int phpdbg_get_terminal_width(void) /* {{{ */ { - int columns; + int columns; #ifdef _WIN32 CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; -#elif defined(HAVE_SYS_IOCTL_H) && defined (TIOCGWINSZ) +#elif defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) struct winsize w; columns = ioctl(fileno(stdout), TIOCGWINSZ, &w) == 0 ? w.ws_col : 80; @@ -453,3 +343,328 @@ PHPDBG_API int phpdbg_get_terminal_width(TSRMLS_D) /* {{{ */ #endif return columns; } /* }}} */ + +PHPDBG_API void phpdbg_set_async_io(int fd) { +#ifndef _WIN32 + int flags; + fcntl(STDIN_FILENO, F_SETOWN, getpid()); + flags = fcntl(STDIN_FILENO, F_GETFL); + fcntl(STDIN_FILENO, F_SETFL, flags | FASYNC); +#endif +} + +int phpdbg_safe_class_lookup(const char *name, int name_length, zend_class_entry **ce) { + if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) { + char *lc_name, *lc_free; + int lc_length; + + if (name == NULL || !name_length) { + return FAILURE; + } + + lc_free = lc_name = emalloc(name_length + 1); + zend_str_tolower_copy(lc_name, name, name_length); + lc_length = name_length + 1; + + if (lc_name[0] == '\\') { + lc_name += 1; + lc_length -= 1; + } + + phpdbg_try_access { + *ce = zend_hash_str_find_ptr(EG(class_table), lc_name, lc_length); + } phpdbg_catch_access { + phpdbg_error("signalsegv", "class=\"%.*s\"", "Could not fetch class %.*s, invalid data source", name_length, name); + } phpdbg_end_try_access(); + + efree(lc_free); + } else { + zend_string *str_name = zend_string_init(name, name_length, 0); + *ce = zend_lookup_class(str_name); + efree(str_name); + } + + return ce ? SUCCESS : FAILURE; +} + +char *phpdbg_get_property_key(char *key) { + if (*key != 0) { + return key; + } + return strchr(key + 1, 0) + 1; +} + +static int phpdbg_parse_variable_arg_wrapper(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv, phpdbg_parse_var_func callback) { + return callback(name, len, keyname, keylen, parent, zv); +} + +PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, zend_bool silent) { + return phpdbg_parse_variable_with_arg(input, len, parent, i, (phpdbg_parse_var_with_arg_func) phpdbg_parse_variable_arg_wrapper, silent, callback); +} + +PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, zend_bool silent, void *arg) { + int ret = FAILURE; + zend_bool new_index = 1; + char *last_index; + size_t index_len = 0; + zval *zv; + + if (len < 2 || *input != '$') { + goto error; + } + + while (i++ < len) { + if (i == len) { + new_index = 1; + } else { + switch (input[i]) { + case '[': + new_index = 1; + break; + case ']': + break; + case '>': + if (last_index[index_len - 1] == '-') { + new_index = 1; + index_len--; + } + break; + + default: + if (new_index) { + last_index = input + i; + new_index = 0; + } + if (input[i - 1] == ']') { + goto error; + } + index_len++; + } + } + + if (new_index && index_len == 0) { + zend_ulong numkey; + zend_string *strkey; + ZEND_HASH_FOREACH_KEY_PTR(parent, numkey, strkey, zv) { + while (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + + if (i == len || (i == len - 1 && input[len - 1] == ']')) { + char *key, *propkey; + size_t namelen, keylen; + char *name; + char *keyname = estrndup(last_index, index_len); + if (strkey) { + key = strkey->val; + keylen = strkey->len; + } else { + keylen = spprintf(&key, 0, "%llu", numkey); + } + propkey = phpdbg_get_property_key(key); + name = emalloc(i + keylen + 2); + namelen = sprintf(name, "%.*s%.*s%s", (int) i, input, keylen - (propkey - key), propkey, input[len - 1] == ']'?"]":""); + if (!strkey) { + efree(key); + } + + ret = callback(name, namelen, keyname, index_len, parent, zv, arg) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE; + } else if (Z_TYPE_P(zv) == IS_OBJECT) { + phpdbg_parse_variable_with_arg(input, len, Z_OBJPROP_P(zv), i, callback, silent, arg); + } else if (Z_TYPE_P(zv) == IS_ARRAY) { + phpdbg_parse_variable_with_arg(input, len, Z_ARRVAL_P(zv), i, callback, silent, arg); + } else { + /* Ignore silently */ + } + } ZEND_HASH_FOREACH_END(); + return ret; + } else if (new_index) { + char last_chr = last_index[index_len]; + last_index[index_len] = 0; + if (!(zv = zend_symtable_str_find(parent, last_index, index_len))) { + if (!silent) { + phpdbg_error("variable", "type=\"undefined\" variable=\"%.*s\"", "%.*s is undefined", (int) i, input); + } + return FAILURE; + } + while (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + + last_index[index_len] = last_chr; + if (i == len) { + char *name = estrndup(input, len); + char *keyname = estrndup(last_index, index_len); + + ret = callback(name, len, keyname, index_len, parent, zv, arg) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE; + } else if (Z_TYPE_P(zv) == IS_OBJECT) { + parent = Z_OBJPROP_P(zv); + } else if (Z_TYPE_P(zv) == IS_ARRAY) { + parent = Z_ARRVAL_P(zv); + } else { + phpdbg_error("variable", "type=\"notiterable\" variable=\"%.*s\"", "%.*s is nor an array nor an object", (int) i, input); + return FAILURE; + } + index_len = 0; + } + } + + return ret; + error: + phpdbg_error("variable", "type=\"invalidinput\"", "Malformed input"); + return FAILURE; +} + +int phpdbg_is_auto_global(char *name, int len) { + int ret; + zend_string *str = zend_string_init(name, len, 0); + ret = zend_is_auto_global(str); + efree(str); + return ret; +} + +static int phpdbg_xml_array_element_dump(zval *zv, zend_string *key, zend_ulong num) { + phpdbg_xml("<element"); + + phpdbg_try_access { + if (key) { /* string key */ + phpdbg_xml(" name=\"%.*s\"", key->len, key->val); + } else { /* numeric key */ + phpdbg_xml(" name=\"%ld\"", num); + } + } phpdbg_catch_access { + phpdbg_xml(" severity=\"error\" ></element>"); + return 0; + } phpdbg_end_try_access(); + + phpdbg_xml(">"); + + phpdbg_xml_var_dump(zv); + + phpdbg_xml("</element>"); + + return 0; +} + +static int phpdbg_xml_object_property_dump(zval *zv, zend_string *key, zend_ulong num) { + phpdbg_xml("<property"); + + phpdbg_try_access { + if (key) { /* string key */ + const char *prop_name, *class_name; + int unmangle = zend_unmangle_property_name(key, &class_name, &prop_name); + + if (class_name && unmangle == SUCCESS) { + phpdbg_xml(" name=\"%s\"", prop_name); + if (class_name[0] == '*') { + phpdbg_xml(" protection=\"protected\""); + } else { + phpdbg_xml(" class=\"%s\" protection=\"private\"", class_name); + } + } else { + phpdbg_xml(" name=\"%.*s\" protection=\"public\"", key->len, key->val); + } + } else { /* numeric key */ + phpdbg_xml(" name=\"%ld\" protection=\"public\"", num); + } + } phpdbg_catch_access { + phpdbg_xml(" severity=\"error\" ></property>"); + return 0; + } phpdbg_end_try_access(); + + phpdbg_xml(">"); + + phpdbg_xml_var_dump(zv); + + phpdbg_xml("</property>"); + + return 0; +} + +#define COMMON (is_ref ? "&" : "") + +PHPDBG_API void phpdbg_xml_var_dump(zval *zv) { + HashTable *myht; + zend_string *class_name, *key; + zend_ulong num; + zval *val; + int (*element_dump_func)(zval *zv, zend_string *key, zend_ulong num); + zend_bool is_ref = 0; + + int is_temp; + + phpdbg_try_access { + is_ref = Z_ISREF_P(zv) && GC_REFCOUNT(Z_COUNTED_P(zv)) > 1; + ZVAL_DEREF(zv); + + switch (Z_TYPE_P(zv)) { + case IS_TRUE: + phpdbg_xml("<bool refstatus=\"%s\" value=\"true\" />", COMMON); + break; + case IS_FALSE: + phpdbg_xml("<bool refstatus=\"%s\" value=\"false\" />", COMMON); + break; + case IS_NULL: + phpdbg_xml("<null refstatus=\"%s\" />", COMMON); + break; + case IS_LONG: + phpdbg_xml("<int refstatus=\"%s\" value=\"" ZEND_LONG_FMT "\" />", COMMON, Z_LVAL_P(zv)); + break; + case IS_DOUBLE: + phpdbg_xml("<float refstatus=\"%s\" value=\"%.*G\" />", COMMON, (int) EG(precision), Z_DVAL_P(zv)); + break; + case IS_STRING: + phpdbg_xml("<string refstatus=\"%s\" length=\"%d\" value=\"%.*s\" />", COMMON, Z_STRLEN_P(zv), Z_STRLEN_P(zv), Z_STRVAL_P(zv)); + break; + case IS_ARRAY: + myht = Z_ARRVAL_P(zv); + if (ZEND_HASH_APPLY_PROTECTION(myht) && ++myht->u.v.nApplyCount > 1) { + phpdbg_xml("<recursion />"); + --myht->u.v.nApplyCount; + break; + } + phpdbg_xml("<array refstatus=\"%s\" num=\"%d\">", COMMON, zend_hash_num_elements(myht)); + element_dump_func = phpdbg_xml_array_element_dump; + is_temp = 0; + goto head_done; + case IS_OBJECT: + myht = Z_OBJDEBUG_P(zv, is_temp); + if (myht && ++myht->u.v.nApplyCount > 1) { + phpdbg_xml("<recursion />"); + --myht->u.v.nApplyCount; + break; + } + + class_name = Z_OBJ_HANDLER_P(zv, get_class_name)(Z_OBJ_P(zv)); + phpdbg_xml("<object refstatus=\"%s\" class=\"%.*s\" id=\"%d\" num=\"%d\">", COMMON, class_name->len, class_name->val, Z_OBJ_HANDLE_P(zv), myht ? zend_hash_num_elements(myht) : 0); + zend_string_release(class_name); + + element_dump_func = phpdbg_xml_object_property_dump; +head_done: + if (myht) { + ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { + element_dump_func(val, key, num); + } ZEND_HASH_FOREACH_END(); + zend_hash_apply_with_arguments(myht, (apply_func_args_t) element_dump_func, 0); + --myht->u.v.nApplyCount; + if (is_temp) { + zend_hash_destroy(myht); + efree(myht); + } + } + if (Z_TYPE_P(zv) == IS_ARRAY) { + phpdbg_xml("</array>"); + } else { + phpdbg_xml("</object>"); + } + break; + case IS_RESOURCE: { + const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(zv)); + phpdbg_xml("<resource refstatus=\"%s\" id=\"%pd\" type=\"%ld\" />", COMMON, Z_RES_P(zv)->handle, type_name ? type_name : "unknown"); + break; + } + default: + break; + } + } phpdbg_end_try_access(); +} diff --git a/sapi/phpdbg/phpdbg_utils.h b/sapi/phpdbg/phpdbg_utils.h index 8f974a9bbf..ca78c63ff9 100644 --- a/sapi/phpdbg/phpdbg_utils.h +++ b/sapi/phpdbg/phpdbg_utils.h @@ -28,56 +28,10 @@ PHPDBG_API int phpdbg_is_numeric(const char*); PHPDBG_API int phpdbg_is_empty(const char*); PHPDBG_API int phpdbg_is_addr(const char*); PHPDBG_API int phpdbg_is_class_method(const char*, size_t, char**, char**); -PHPDBG_API const char *phpdbg_current_file(TSRMLS_D); -PHPDBG_API char *phpdbg_resolve_path(const char* TSRMLS_DC); +PHPDBG_API const char *phpdbg_current_file(void); +PHPDBG_API char *phpdbg_resolve_path(const char*); PHPDBG_API char *phpdbg_trim(const char*, size_t, size_t*); -PHPDBG_API const zend_function *phpdbg_get_function(const char*, const char* TSRMLS_DC); - -/** - * Error/notice/formatting helpers - */ -enum { - P_ERROR = 1, - P_NOTICE, - P_WRITELN, - P_WRITE, - P_LOG -}; - -#ifdef ZTS -PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 4, 5); -#else -PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); -#endif - -PHPDBG_API int phpdbg_rlog(FILE *stream, const char *fmt, ...); - -#define phpdbg_error(fmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__) -#define phpdbg_notice(fmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__) -#define phpdbg_writeln(fmt, ...) phpdbg_print(P_WRITELN TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__) -#define phpdbg_write(fmt, ...) phpdbg_print(P_WRITE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__) -#define phpdbg_log(fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__) - -#define phpdbg_error_ex(out, fmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, out, fmt, ##__VA_ARGS__) -#define phpdbg_notice_ex(out, fmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, out, fmt, ##__VA_ARGS__) -#define phpdbg_writeln_ex(out, fmt, ...) phpdbg_print(P_WRITELN TSRMLS_CC, out, fmt, ##__VA_ARGS__) -#define phpdbg_write_ex(out, fmt, ...) phpdbg_print(P_WRITE TSRMLS_CC, out, fmt, ##__VA_ARGS__) -#define phpdbg_log_ex(out, fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, out, fmt, ##__VA_ARGS__) - -#if PHPDBG_DEBUG -# define phpdbg_debug(fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDERR], fmt, ##__VA_ARGS__) -#else -# define phpdbg_debug(fmt, ...) -#endif - -/* {{{ For writing blank lines */ -#define EMPTY NULL /* }}} */ - -/* {{{ For prompt lines */ -#define PROMPT "phpdbg>" /* }}} */ - -/* {{{ For separation */ -#define SEPARATE "------------------------------------------------" /* }}} */ +PHPDBG_API const zend_function *phpdbg_get_function(const char*, const char*); /* {{{ Color Management */ #define PHPDBG_COLOR_LEN 12 @@ -109,39 +63,60 @@ typedef struct _phpdbg_element_t { int id; } phpdbg_element_t; -PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC); -PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color TSRMLS_DC); -PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length TSRMLS_DC); -PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D); -PHPDBG_API int phpdbg_get_element(const char *name, size_t len TSRMLS_DC); /* }}} */ +PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length); +PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color); +PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length); +PHPDBG_API const phpdbg_color_t *phpdbg_get_colors(void); +PHPDBG_API int phpdbg_get_element(const char *name, size_t len); /* }}} */ /* {{{ Prompt Management */ -PHPDBG_API void phpdbg_set_prompt(const char* TSRMLS_DC); -PHPDBG_API const char *phpdbg_get_prompt(TSRMLS_D); /* }}} */ +PHPDBG_API void phpdbg_set_prompt(const char*); +PHPDBG_API const char *phpdbg_get_prompt(void); /* }}} */ /* {{{ Console Width */ -PHPDBG_API int phpdbg_get_terminal_width(TSRMLS_D); /* }}} */ - -int phpdbg_rebuild_symtable(TSRMLS_D); - -#if PHP_VERSION_ID < 50500 -/* copy from zend_hash.c PHP 5.5 for 5.4 compatibility */ -static void zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos) { - Bucket *p; - - p = pos ? (*pos) : ht->pInternalPointer; - - if (!p) { - Z_TYPE_P(key) = IS_NULL; - } else if (p->nKeyLength) { - Z_TYPE_P(key) = IS_STRING; - Z_STRVAL_P(key) = IS_INTERNED(p->arKey) ? (char*)p->arKey : estrndup(p->arKey, p->nKeyLength - 1); - Z_STRLEN_P(key) = p->nKeyLength - 1; - } else { - Z_TYPE_P(key) = IS_LONG; - Z_LVAL_P(key) = p->h; - } -} +PHPDBG_API int phpdbg_get_terminal_width(void); /* }}} */ + +PHPDBG_API void phpdbg_set_async_io(int fd); + +int phpdbg_rebuild_symtable(void); + +int phpdbg_safe_class_lookup(const char *name, int name_length, zend_class_entry **ce); + +char *phpdbg_get_property_key(char *key); + +typedef int (*phpdbg_parse_var_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv); +typedef int (*phpdbg_parse_var_with_arg_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv, void *arg); + +PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, zend_bool silent); +PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, zend_bool silent, void *arg); + +int phpdbg_is_auto_global(char *name, int len); + +PHPDBG_API void phpdbg_xml_var_dump(zval *zv); + +#ifdef ZTS +#define PHPDBG_OUTPUT_BACKUP_DEFINES() \ + zend_output_globals *output_globals_ptr; \ + zend_output_globals original_output_globals; \ + output_globals_ptr = (zend_output_globals *) (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(output_globals_id)]; +#else +#define PHPDBG_OUTPUT_BACKUP_DEFINES() \ + zend_output_globals *output_globals_ptr; \ + zend_output_globals original_output_globals; \ + output_globals_ptr = &output_globals; #endif +#define PHPDBG_OUTPUT_BACKUP_SWAP() \ + original_output_globals = *output_globals_ptr; \ + memset(output_globals_ptr, 0, sizeof(zend_output_globals)); \ + php_output_activate(); + +#define PHPDBG_OUTPUT_BACKUP() \ + PHPDBG_OUTPUT_BACKUP_DEFINES() \ + PHPDBG_OUTPUT_BACKUP_SWAP() + +#define PHPDBG_OUTPUT_BACKUP_RESTORE() \ + php_output_deactivate(); \ + *output_globals_ptr = original_output_globals; + #endif /* PHPDBG_UTILS_H */ diff --git a/sapi/phpdbg/phpdbg_wait.c b/sapi/phpdbg/phpdbg_wait.c new file mode 100644 index 0000000000..821b848443 --- /dev/null +++ b/sapi/phpdbg/phpdbg_wait.c @@ -0,0 +1,400 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Bob Weinand <bwoebi@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include "phpdbg_wait.h" +#include "phpdbg_prompt.h" +#include "ext/standard/php_var.h" +#include "ext/standard/basic_functions.h" + +ZEND_EXTERN_MODULE_GLOBALS(phpdbg); + +static void phpdbg_rebuild_http_globals_array(int type, const char *name) { + zval *zvp; + if (Z_TYPE(PG(http_globals)[type]) != IS_UNDEF) { + zval_dtor(&PG(http_globals)[type]); + } + if ((zvp = zend_hash_str_find(&EG(symbol_table).ht, name, strlen(name)))) { + Z_ADDREF_P(zvp); + PG(http_globals)[type] = *zvp; + } +} + + +static int phpdbg_dearm_autoglobals(zend_auto_global *auto_global) { + if (auto_global->name->len != sizeof("GLOBALS") - 1 || memcmp(auto_global->name->val, "GLOBALS", sizeof("GLOBALS") - 1)) { + auto_global->armed = 0; + } + + return ZEND_HASH_APPLY_KEEP; +} + +typedef struct { + HashTable *ht[2]; + HashPosition pos[2]; +} phpdbg_intersect_ptr; + +static int phpdbg_array_data_compare(const void *a, const void *b) { + Bucket *f, *s; + zval result; + zval *first, *second; + + f = *((Bucket **) a); + s = *((Bucket **) b); + + first = &f->val; + second = &s->val; + + if (string_compare_function(&result, first, second) == FAILURE) { + return 0; + } + + if (Z_LVAL(result) < 0) { + return -1; + } else if (Z_LVAL(result) > 0) { + return 1; + } + + return 0; +} + +static void phpdbg_array_intersect_init(phpdbg_intersect_ptr *info, HashTable *ht1, HashTable *ht2) { + info->ht[0] = ht1; + info->ht[1] = ht2; + + zend_hash_sort(info->ht[0], (compare_func_t) phpdbg_array_data_compare, 0); + zend_hash_sort(info->ht[1], (compare_func_t) phpdbg_array_data_compare, 0); + + zend_hash_internal_pointer_reset_ex(info->ht[0], &info->pos[0]); + zend_hash_internal_pointer_reset_ex(info->ht[1], &info->pos[1]); +} + +/* -1 => first array, 0 => both arrays equal, 1 => second array */ +static int phpdbg_array_intersect(phpdbg_intersect_ptr *info, zval **ptr) { + int ret; + zval *zvp[2]; + int invalid = !info->ht[0] + !info->ht[1]; + + if (invalid > 0) { + invalid = !info->ht[0]; + + if (!(*ptr = zend_hash_get_current_data_ex(info->ht[invalid], &info->pos[invalid]))) { + return 0; + } + + zend_hash_move_forward_ex(info->ht[invalid], &info->pos[invalid]); + + return invalid ? 1 : -1; + } + + if (!(zvp[0] = zend_hash_get_current_data_ex(info->ht[0], &info->pos[0]))) { + info->ht[0] = NULL; + return phpdbg_array_intersect(info, ptr); + } + if (!(zvp[1] = zend_hash_get_current_data_ex(info->ht[1], &info->pos[1]))) { + info->ht[1] = NULL; + return phpdbg_array_intersect(info, ptr); + } + + ret = zend_binary_zval_strcmp(zvp[0], zvp[1]); + + if (ret <= 0) { + *ptr = zvp[0]; + zend_hash_move_forward_ex(info->ht[0], &info->pos[0]); + } + if (ret >= 0) { + *ptr = zvp[1]; + zend_hash_move_forward_ex(info->ht[1], &info->pos[1]); + } + + return ret; +} + +void phpdbg_webdata_decompress(char *msg, int len) { + zval *free_zv = NULL; + zval zv, *zvp; + HashTable *ht; + php_unserialize_data_t var_hash; + + PHP_VAR_UNSERIALIZE_INIT(var_hash); + if (!php_var_unserialize(&zv, (const unsigned char **) &msg, (unsigned char *) msg + len, &var_hash)) { + PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + phpdbg_error("wait", "type=\"invaliddata\" import=\"fail\"", "Malformed serialized was sent to this socket, arborting"); + return; + } + PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + + ht = Z_ARRVAL(zv); + + /* Reapply symbol table */ + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("GLOBALS"))) && Z_TYPE_P(zvp) == IS_ARRAY) { + { + zval *srv; + if ((srv = zend_hash_str_find(Z_ARRVAL_P(zvp), ZEND_STRL("_SERVER"))) && Z_TYPE_P(srv) == IS_ARRAY) { + zval *script; + if ((script = zend_hash_str_find(Z_ARRVAL_P(srv), ZEND_STRL("SCRIPT_FILENAME"))) && Z_TYPE_P(script) == IS_STRING) { + phpdbg_param_t param; + param.str = Z_STRVAL_P(script); + PHPDBG_COMMAND_HANDLER(exec)(¶m); + } + } + } + + PG(auto_globals_jit) = 0; + zend_hash_apply(CG(auto_globals), (apply_func_t) phpdbg_dearm_autoglobals); + + zend_hash_clean(&EG(symbol_table).ht); + EG(symbol_table) = *Z_ARR_P(zvp); + + /* Rebuild cookies, env vars etc. from GLOBALS (PG(http_globals)) */ + phpdbg_rebuild_http_globals_array(TRACK_VARS_POST, "_POST"); + phpdbg_rebuild_http_globals_array(TRACK_VARS_GET, "_GET"); + phpdbg_rebuild_http_globals_array(TRACK_VARS_COOKIE, "_COOKIE"); + phpdbg_rebuild_http_globals_array(TRACK_VARS_SERVER, "_SERVER"); + phpdbg_rebuild_http_globals_array(TRACK_VARS_ENV, "_ENV"); + phpdbg_rebuild_http_globals_array(TRACK_VARS_FILES, "_FILES"); + + Z_ADDREF_P(zvp); + free_zv = zvp; + } + + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("input"))) && Z_TYPE_P(zvp) == IS_STRING) { + if (SG(request_info).request_body) { + php_stream_close(SG(request_info).request_body); + } + SG(request_info).request_body = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir)); + php_stream_truncate_set_size(SG(request_info).request_body, 0); + php_stream_write(SG(request_info).request_body, Z_STRVAL_P(zvp), Z_STRLEN_P(zvp)); + } + + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("cwd"))) && Z_TYPE_P(zvp) == IS_STRING) { + if (VCWD_CHDIR(Z_STRVAL_P(zvp)) == SUCCESS) { + if (BG(CurrentStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentStatFile), strlen(BG(CurrentStatFile)))) { + efree(BG(CurrentStatFile)); + BG(CurrentStatFile) = NULL; + } + if (BG(CurrentLStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentLStatFile), strlen(BG(CurrentLStatFile)))) { + efree(BG(CurrentLStatFile)); + BG(CurrentLStatFile) = NULL; + } + } + } + + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("sapi_name"))) && (Z_TYPE_P(zvp) == IS_STRING || Z_TYPE_P(zvp) == IS_NULL)) { + if (PHPDBG_G(sapi_name_ptr)) { + free(PHPDBG_G(sapi_name_ptr)); + } + if (Z_TYPE_P(zvp) == IS_STRING) { + PHPDBG_G(sapi_name_ptr) = sapi_module.name = strdup(Z_STRVAL_P(zvp)); + } else { + PHPDBG_G(sapi_name_ptr) = sapi_module.name = NULL; + } + } + + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("modules"))) && Z_TYPE_P(zvp) == IS_ARRAY) { + phpdbg_intersect_ptr pos; + zval *module; + zend_module_entry *mod; + HashTable zv_registry; + + /* intersect modules, unregister modules loaded "too much", announce not yet registered modules (phpdbg_notice) */ + + zend_hash_init(&zv_registry, zend_hash_num_elements(&module_registry), 0, ZVAL_PTR_DTOR, 0); + ZEND_HASH_FOREACH_PTR(&module_registry, mod) { + if (mod->name) { + zval value; + ZVAL_NEW_STR(&value, zend_string_init(mod->name, strlen(mod->name), 0)); + zend_hash_next_index_insert(&zv_registry, &value); + } + } ZEND_HASH_FOREACH_END(); + + phpdbg_array_intersect_init(&pos, &zv_registry, Z_ARRVAL_P(zvp)); + do { + int mode = phpdbg_array_intersect(&pos, &module); + if (mode < 0) { + // loaded module, but not needed + if (strcmp(PHPDBG_NAME, Z_STRVAL_P(module))) { + zend_hash_del(&module_registry, Z_STR_P(module)); + } + } else if (mode > 0) { + // not loaded module + if (!sapi_module.name || strcmp(sapi_module.name, Z_STRVAL_P(module))) { + phpdbg_notice("wait", "missingmodule=\"%.*s\"", "The module %.*s isn't present in " PHPDBG_NAME ", you still can load via dl /path/to/module/%.*s.so", Z_STRLEN_P(module), Z_STRVAL_P(module), Z_STRLEN_P(module), Z_STRVAL_P(module)); + } + } + } while (module); + + zend_hash_clean(&zv_registry); + } + + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("extensions"))) && Z_TYPE_P(zvp) == IS_ARRAY) { + zend_extension *extension; + zend_llist_position pos; + zval *name = NULL; + zend_string *strkey; + + extension = (zend_extension *) zend_llist_get_first_ex(&zend_extensions, &pos); + while (extension) { + extension = (zend_extension *) zend_llist_get_next_ex(&zend_extensions, &pos); + + /* php_serach_array() body should be in some ZEND_API function... */ + ZEND_HASH_FOREACH_STR_KEY_PTR(Z_ARRVAL_P(zvp), strkey, name) { + if (Z_TYPE_P(name) == IS_STRING && !zend_binary_strcmp(extension->name, strlen(extension->name), Z_STRVAL_P(name), Z_STRLEN_P(name))) { + break; + } + name = NULL; + } ZEND_HASH_FOREACH_END(); + + if (name) { + /* sigh, breaking the encapsulation, there aren't any functions manipulating the llist at the place of the zend_llist_position */ + zend_llist_element *elm = pos; + if (elm->prev) { + elm->prev->next = elm->next; + } else { + zend_extensions.head = elm->next; + } + if (elm->next) { + elm->next->prev = elm->prev; + } else { + zend_extensions.tail = elm->prev; + } +#if ZEND_EXTENSIONS_SUPPORT + if (extension->shutdown) { + extension->shutdown(extension); + } +#endif + if (zend_extensions.dtor) { + zend_extensions.dtor(elm->data); + } + pefree(elm, zend_extensions.persistent); + zend_extensions.count--; + } else { +/* zend_hash_get_current_key_zval_ex(Z_ARRVAL_PP(zvpp), &key, &hpos); + if (Z_TYPE(key) == IS_LONG) { + zend_hash_index_del(Z_ARRVAL_PP(zvpp), Z_LVAL(key)); + } +*/ + zend_hash_del(Z_ARRVAL_P(zvp), strkey); + } + } + + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zvp), name) { + if (Z_TYPE_P(name) == IS_STRING) { + phpdbg_notice("wait", "missingextension=\"%.*s\"", "The Zend extension %.*s isn't present in " PHPDBG_NAME ", you still can load via dl /path/to/extension.so", Z_STRLEN_P(name), Z_STRVAL_P(name)); + } + } ZEND_HASH_FOREACH_END(); + } + + zend_ini_deactivate(); + + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("systemini"))) && Z_TYPE_P(zvp) == IS_ARRAY) { + zval *ini_entry; + zend_ini_entry *original_ini; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zvp), key, ini_entry) { + if (key && Z_TYPE_P(ini_entry) == IS_STRING) { + if ((original_ini = zend_hash_find_ptr(EG(ini_directives), key))) { + if (!original_ini->on_modify || original_ini->on_modify(original_ini, Z_STR_P(ini_entry), original_ini->mh_arg1, original_ini->mh_arg2, original_ini->mh_arg3, ZEND_INI_STAGE_ACTIVATE) == SUCCESS) { + if (original_ini->modified && original_ini->orig_value != original_ini->value) { + efree(original_ini->value); + } + original_ini->value = Z_STR_P(ini_entry); + Z_ADDREF_P(ini_entry); /* don't free the string */ + } + } + } + } ZEND_HASH_FOREACH_END(); + } + + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("userini"))) && Z_TYPE_P(zvp) == IS_ARRAY) { + zval *ini_entry; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zvp), key, ini_entry) { + if (key && Z_TYPE_P(ini_entry) == IS_STRING) { + zend_alter_ini_entry_ex(key, Z_STR_P(ini_entry), ZEND_INI_PERDIR, ZEND_INI_STAGE_HTACCESS, 1); + } + } ZEND_HASH_FOREACH_END(); + } + + zval_dtor(&zv); + if (free_zv) { + /* separate freeing to not dtor the symtable too, just the container zval... */ + efree(free_zv); + } + + /* Reapply raw input */ + /* ??? */ +} + +PHPDBG_COMMAND(wait) /* {{{ */ +{ +#ifndef PHP_WIN32 + struct sockaddr_un local, remote; + int rlen, sr, sl; + unlink(PHPDBG_G(socket_path)); + if (PHPDBG_G(socket_server_fd) == -1) { + int len; + PHPDBG_G(socket_server_fd) = sl = socket(AF_UNIX, SOCK_STREAM, 0); + + local.sun_family = AF_UNIX; + strcpy(local.sun_path, PHPDBG_G(socket_path)); + len = strlen(local.sun_path) + sizeof(local.sun_family); + if (bind(sl, (struct sockaddr *)&local, len) == -1) { + phpdbg_error("wait", "type=\"nosocket\" import=\"fail\"", "Unable to connect to UNIX domain socket at %s defined by phpdbg.path ini setting", PHPDBG_G(socket_path)); + return FAILURE; + } + + chmod(PHPDBG_G(socket_path), 0666); + + listen(sl, 2); + } else { + sl = PHPDBG_G(socket_server_fd); + } + + rlen = sizeof(remote); + sr = accept(sl, (struct sockaddr *) &remote, (socklen_t *) &rlen); + + char msglen[5]; + int recvd = 4; + + do { + recvd -= recv(sr, &(msglen[4 - recvd]), recvd, 0); + } while (recvd > 0); + + recvd = *(size_t *) msglen; + char *data = emalloc(recvd); + + do { + recvd -= recv(sr, &(data[(*(int *) msglen) - recvd]), recvd, 0); + } while (recvd > 0); + + phpdbg_webdata_decompress(data, *(int *) msglen); + + if (PHPDBG_G(socket_fd) != -1) { + close(PHPDBG_G(socket_fd)); + } + PHPDBG_G(socket_fd) = sr; + + efree(data); + + phpdbg_notice("wait", "import=\"success\"", "Successfully imported request data, stopped before executing"); +#endif + + return SUCCESS; +} /* }}} */ diff --git a/sapi/phpdbg/phpdbg_wait.h b/sapi/phpdbg/phpdbg_wait.h new file mode 100644 index 0000000000..d8d314c742 --- /dev/null +++ b/sapi/phpdbg/phpdbg_wait.h @@ -0,0 +1,29 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Bob Weinand <bwoebi@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifndef PHPDBG_WAIT_H +#define PHPDBG_WAIT_H + +#include "zend.h" +#include "phpdbg.h" + +PHPDBG_COMMAND(wait); + +void phpdbg_webdata_decompress(char *msg, int len); + +#endif /* PHPDBG_WAIT_H */ diff --git a/sapi/phpdbg/phpdbg_watch.c b/sapi/phpdbg/phpdbg_watch.c index 422cf92b72..373b4481b3 100644 --- a/sapi/phpdbg/phpdbg_watch.c +++ b/sapi/phpdbg/phpdbg_watch.c @@ -30,6 +30,15 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); +const phpdbg_command_t phpdbg_watch_commands[] = { + PHPDBG_COMMAND_D_EX(array, "create watchpoint on an array", 'a', watch_array, NULL, "s", 0), + PHPDBG_COMMAND_D_EX(delete, "delete watchpoint", 'd', watch_delete, NULL, "s", 0), + PHPDBG_COMMAND_D_EX(recursive, "create recursive watchpoints", 'r', watch_recursive, NULL, "s", 0), + PHPDBG_END_COMMAND +}; + +//#define HT_FROM_WATCH(watch) (watch->type == WATCH_ON_OBJECT ? watch->addr.obj->handlers->get_properties(watch->parent_container.zv) : watch->type == WATCH_ON_ARRAY ? &watch->addr.arr->ht : NULL) +#define HT_FROM_ZVP(zvp) (Z_TYPE_P(zvp) == IS_OBJECT ? Z_OBJPROP_P(zvp) : Z_TYPE_P(zvp) == IS_ARRAY ? Z_ARRVAL_P(zvp) : NULL) typedef struct { void *page; @@ -42,7 +51,7 @@ typedef struct { #define MEMDUMP_SIZE(size) (sizeof(phpdbg_watch_memdump) - sizeof(void *) + (size)) -static phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *addr TSRMLS_DC) { +static phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *addr) { phpdbg_watchpoint_t *watch; phpdbg_btree_result *result = phpdbg_btree_find_closest(&PHPDBG_G(watchpoint_tree), (zend_ulong)phpdbg_get_page_boundary(addr) + phpdbg_pagesize - 1); @@ -53,7 +62,7 @@ static phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *addr TSRMLS_DC) { watch = result->ptr; /* check if that addr is in a mprotect()'ed memory area */ - if ((char *)phpdbg_get_page_boundary(watch->addr.ptr) > (char *)addr || (char *)phpdbg_get_page_boundary(watch->addr.ptr) + phpdbg_get_total_page_size(watch->addr.ptr, watch->size) < (char *)addr) { + if ((char *) phpdbg_get_page_boundary(watch->addr.ptr) > (char *) addr || (char *) phpdbg_get_page_boundary(watch->addr.ptr) + phpdbg_get_total_page_size(watch->addr.ptr, watch->size) < (char *) addr) { /* failure */ return NULL; } @@ -61,27 +70,25 @@ static phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *addr TSRMLS_DC) { return watch; } -static void phpdbg_change_watchpoint_access(phpdbg_watchpoint_t *watch, int access TSRMLS_DC) { - int m; - +static void phpdbg_change_watchpoint_access(phpdbg_watchpoint_t *watch, int access) { /* pagesize is assumed to be in the range of 2^x */ - m = mprotect(phpdbg_get_page_boundary(watch->addr.ptr), phpdbg_get_total_page_size(watch->addr.ptr, watch->size), access); + mprotect(phpdbg_get_page_boundary(watch->addr.ptr), phpdbg_get_total_page_size(watch->addr.ptr, watch->size), access); } -static inline void phpdbg_activate_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) { - phpdbg_change_watchpoint_access(watch, PROT_READ TSRMLS_CC); +static inline void phpdbg_activate_watchpoint(phpdbg_watchpoint_t *watch) { + phpdbg_change_watchpoint_access(watch, PROT_READ); } -static inline void phpdbg_deactivate_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) { - phpdbg_change_watchpoint_access(watch, PROT_READ | PROT_WRITE TSRMLS_CC); +static inline void phpdbg_deactivate_watchpoint(phpdbg_watchpoint_t *watch) { + phpdbg_change_watchpoint_access(watch, PROT_READ | PROT_WRITE); } -static inline void phpdbg_store_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) { - phpdbg_btree_insert(&PHPDBG_G(watchpoint_tree), (zend_ulong)watch->addr.ptr, watch); +static inline void phpdbg_store_watchpoint(phpdbg_watchpoint_t *watch) { + phpdbg_btree_insert(&PHPDBG_G(watchpoint_tree), (zend_ulong) watch->addr.ptr, watch); } -static inline void phpdbg_remove_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) { - phpdbg_btree_delete(&PHPDBG_G(watchpoint_tree), (zend_ulong)watch->addr.ptr); +static inline void phpdbg_remove_watchpoint(phpdbg_watchpoint_t *watch) { + phpdbg_btree_delete(&PHPDBG_G(watchpoint_tree), (zend_ulong) watch->addr.ptr); } void phpdbg_create_addr_watchpoint(void *addr, size_t size, phpdbg_watchpoint_t *watch) { @@ -99,81 +106,151 @@ void phpdbg_create_ht_watchpoint(HashTable *ht, phpdbg_watchpoint_t *watch) { watch->type = WATCH_ON_HASHTABLE; } -void phpdbg_watch_HashTable_dtor(zval **ptr); +void phpdbg_watch_HashTable_dtor(zval *ptr); + +static int phpdbg_delete_watchpoint(phpdbg_watchpoint_t *tmp_watch); +static void phpdbg_delete_ht_watchpoints_recursive(phpdbg_watchpoint_t *watch); +static void phpdbg_delete_zval_watchpoints_recursive(phpdbg_watchpoint_t *watch); +static void phpdbg_delete_watchpoints_recursive(phpdbg_watchpoint_t *watch); + +/* TODO: Store all the possible watches the refcounted may refer to (for displaying & deleting by identifier) */ + +static phpdbg_watchpoint_t *phpdbg_create_refcounted_watchpoint(phpdbg_watchpoint_t *parent, zend_refcounted *ref) { + phpdbg_watchpoint_t *watch = emalloc(sizeof(phpdbg_watchpoint_t)); + watch->flags = parent->flags; + watch->parent = parent; + phpdbg_create_addr_watchpoint(&ref->refcount, sizeof(uint32_t), watch); + watch->type = WATCH_ON_REFCOUNTED; + + return watch; +} + +static void phpdbg_add_watch_collision(phpdbg_watchpoint_t *watch) { + phpdbg_watch_collision *cur; + if ((cur = zend_hash_index_find_ptr(&PHPDBG_G(watch_collisions), (zend_ulong) watch->addr.ref))) { + cur->num++; + if (watch->flags == PHPDBG_WATCH_RECURSIVE) { + cur->refs++; + } + } else { + phpdbg_watch_collision coll; + coll.num = 1; + coll.refs = watch->flags == PHPDBG_WATCH_RECURSIVE; + coll.watch = *watch; + zend_hash_init(&coll.watches, 8, NULL, NULL, 0); + cur = zend_hash_index_add_mem(&PHPDBG_G(watch_collisions), (zend_ulong) watch->addr.ref, &coll, sizeof(phpdbg_watch_collision)); + phpdbg_store_watchpoint(&cur->watch); + phpdbg_activate_watchpoint(&cur->watch); + } + + zend_hash_str_add_ptr(&cur->watches, watch->parent->str, watch->parent->str_len, watch->parent); +} + +static void phpdbg_remove_watch_collision(zend_refcounted *ref) { + phpdbg_watch_collision *cur; + if ((cur = zend_hash_index_find_ptr(&PHPDBG_G(watch_collisions), (zend_ulong) ref))) { + phpdbg_watchpoint_t *watch = cur->watch.parent; + + if (watch->flags == PHPDBG_WATCH_RECURSIVE && !--cur->refs) { + phpdbg_delete_watchpoints_recursive(watch); + } + + zend_hash_str_del(&cur->watches, watch->str, watch->str_len); + + if (!--cur->num) { + phpdbg_deactivate_watchpoint(&cur->watch); + phpdbg_remove_watchpoint(&cur->watch); -static int phpdbg_create_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) { + phpdbg_delete_watchpoint(watch); + + zend_hash_index_del(&PHPDBG_G(watch_collisions), (zend_ulong) ref); + } + } +} + +static int phpdbg_create_watchpoint(phpdbg_watchpoint_t *watch) { watch->flags |= PHPDBG_WATCH_SIMPLE; - phpdbg_store_watchpoint(watch TSRMLS_CC); - zend_hash_add(&PHPDBG_G(watchpoints), watch->str, watch->str_len, &watch, sizeof(phpdbg_watchpoint_t *), NULL); + phpdbg_store_watchpoint(watch); + zend_hash_str_add_ptr(&PHPDBG_G(watchpoints), watch->str, watch->str_len, watch); + + if (watch->parent && watch->parent->type == WATCH_ON_ZVAL && Z_REFCOUNTED_P(watch->parent->addr.zv)) { + phpdbg_add_watch_collision(phpdbg_create_refcounted_watchpoint(watch, Z_COUNTED_P(watch->parent->addr.zv))); + } if (watch->type == WATCH_ON_ZVAL) { - phpdbg_btree_insert(&PHPDBG_G(watch_HashTables), (zend_ulong)watch->parent_container, watch->parent_container->pDestructor); - watch->parent_container->pDestructor = (dtor_func_t)phpdbg_watch_HashTable_dtor; + if (watch->parent_container) { + phpdbg_btree_insert(&PHPDBG_G(watch_HashTables), (zend_ulong) watch->parent_container, watch->parent_container->pDestructor); + watch->parent_container->pDestructor = (dtor_func_t) phpdbg_watch_HashTable_dtor; + } + + if (Z_ISREF_P(watch->addr.zv)) { + phpdbg_watchpoint_t *ref = emalloc(sizeof(phpdbg_watchpoint_t)); + ref->flags = watch->flags; + ref->str = watch->str; + ref->str_len = watch->str_len; + ref->parent = watch; + ref->parent_container = NULL; + phpdbg_create_zval_watchpoint(Z_REFVAL_P(watch->addr.zv), ref); + + phpdbg_create_watchpoint(ref); + } } - phpdbg_activate_watchpoint(watch TSRMLS_CC); + phpdbg_activate_watchpoint(watch); return SUCCESS; } -static int phpdbg_create_array_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) { - HashTable *ht; +static int phpdbg_create_array_watchpoint(phpdbg_watchpoint_t *zv_watch) { + zval *zv = zv_watch->addr.zv; + phpdbg_watchpoint_t *watch = emalloc(sizeof(phpdbg_watchpoint_t)); + HashTable *ht = HT_FROM_ZVP(zv); - switch (Z_TYPE_P(watch->addr.zv)) { - case IS_ARRAY: - ht = Z_ARRVAL_P(watch->addr.zv); - break; - case IS_OBJECT: - ht = Z_OBJPROP_P(watch->addr.zv); - break; - default: - return FAILURE; + watch->parent = zv_watch; + + if (!ht) { + return FAILURE; } phpdbg_create_ht_watchpoint(ht, watch); - phpdbg_create_watchpoint(watch TSRMLS_CC); - - return SUCCESS; -} + phpdbg_create_watchpoint(watch); -static char *phpdbg_get_property_key(char *key) { - if (*key != 0) { - return key; + if (Z_TYPE_P(zv) == IS_ARRAY) { + watch->flags |= PHPDBG_WATCH_ARRAY; + } else { + watch->flags |= PHPDBG_WATCH_OBJECT; } - return strchr(key + 1, 0) + 1; + + phpdbg_add_watch_collision(phpdbg_create_refcounted_watchpoint(watch, Z_COUNTED_P(zv))); + + return SUCCESS; } -static int phpdbg_create_recursive_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) { +static int phpdbg_create_recursive_watchpoint(phpdbg_watchpoint_t *watch) { HashTable *ht; + zval *zvp = watch->addr.zv; if (watch->type != WATCH_ON_ZVAL) { return FAILURE; } watch->flags |= PHPDBG_WATCH_RECURSIVE; - phpdbg_create_watchpoint(watch TSRMLS_CC); + phpdbg_create_watchpoint(watch); - switch (Z_TYPE_P(watch->addr.zv)) { - case IS_ARRAY: - ht = Z_ARRVAL_P(watch->addr.zv); - break; - case IS_OBJECT: - ht = Z_OBJPROP_P(watch->addr.zv); - break; - default: - return SUCCESS; + ZVAL_DEREF(zvp); + + if (!(ht = HT_FROM_ZVP(zvp))) { + return SUCCESS; } { HashPosition position; - zval **zv; + zval *zv; zval key; - for (zend_hash_internal_pointer_reset_ex(ht, &position); - zend_hash_get_current_data_ex(ht, (void **)&zv, &position) == SUCCESS; - zend_hash_move_forward_ex(ht, &position)) { + ZEND_HASH_FOREACH_VAL(ht, zv) { phpdbg_watchpoint_t *new_watch = emalloc(sizeof(phpdbg_watchpoint_t)); new_watch->flags = PHPDBG_WATCH_RECURSIVE; @@ -182,19 +259,21 @@ static int phpdbg_create_recursive_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_ zend_hash_get_current_key_zval_ex(ht, &key, &position); if (Z_TYPE(key) == IS_STRING) { - new_watch->name_in_parent = zend_strndup(Z_STRVAL(key), Z_STRLEN(key)); + new_watch->name_in_parent = estrndup(Z_STRVAL(key), Z_STRLEN(key)); new_watch->name_in_parent_len = Z_STRLEN(key); } else { - new_watch->name_in_parent = NULL; - new_watch->name_in_parent_len = asprintf(&new_watch->name_in_parent, "%ld", Z_LVAL(key)); + new_watch->name_in_parent_len = spprintf(&new_watch->name_in_parent, 0, "%lld", Z_LVAL(key)); } - new_watch->str = NULL; - new_watch->str_len = asprintf(&new_watch->str, "%.*s%s%s%s", (int)watch->str_len, watch->str, Z_TYPE_P(watch->addr.zv) == IS_ARRAY?"[":"->", phpdbg_get_property_key(new_watch->name_in_parent), Z_TYPE_P(watch->addr.zv) == IS_ARRAY?"]":""); + new_watch->str_len = spprintf(&new_watch->str, 0, "%.*s%s%s%s", (int) watch->str_len, watch->str, Z_TYPE_P(zvp) == IS_ARRAY ? "[" : "->", phpdbg_get_property_key(new_watch->name_in_parent), Z_TYPE_P(zvp) == IS_ARRAY ? "]" : ""); - phpdbg_create_zval_watchpoint(*zv, new_watch); - phpdbg_create_recursive_watchpoint(new_watch TSRMLS_CC); - } + while (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + + phpdbg_create_zval_watchpoint(zv, new_watch); + phpdbg_create_recursive_watchpoint(new_watch); + } ZEND_HASH_FOREACH_END(); } { @@ -202,219 +281,150 @@ static int phpdbg_create_recursive_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_ new_watch->parent = watch; new_watch->parent_container = watch->parent_container; - new_watch->name_in_parent = zend_strndup(watch->name_in_parent, watch->name_in_parent_len); + new_watch->name_in_parent = estrndup(watch->name_in_parent, watch->name_in_parent_len); new_watch->name_in_parent_len = watch->name_in_parent_len; new_watch->str = NULL; - new_watch->str_len = asprintf(&new_watch->str, "%.*s[]", (int)watch->str_len, watch->str); + new_watch->str_len = spprintf(&new_watch->str, 0, "%.*s[]", (int) watch->str_len, watch->str); new_watch->flags = PHPDBG_WATCH_RECURSIVE; + if (Z_TYPE_P(zvp) == IS_ARRAY) { + new_watch->flags |= PHPDBG_WATCH_ARRAY; + } else { + new_watch->flags |= PHPDBG_WATCH_OBJECT; + } + phpdbg_create_ht_watchpoint(ht, new_watch); - phpdbg_create_watchpoint(new_watch TSRMLS_CC); + phpdbg_create_watchpoint(new_watch); } return SUCCESS; } -static int phpdbg_delete_watchpoint_recursive(phpdbg_watchpoint_t *watch, zend_bool user_request TSRMLS_DC) { - if (watch->type == WATCH_ON_HASHTABLE || (watch->type == WATCH_ON_ZVAL && (Z_TYPE_P(watch->addr.zv) == IS_ARRAY || Z_TYPE_P(watch->addr.zv) == IS_OBJECT))) { +static int phpdbg_delete_watchpoint_recursive(phpdbg_watchpoint_t *watch, zend_bool user_request) { + if (watch->type == WATCH_ON_HASHTABLE) { HashTable *ht; phpdbg_btree_result *result; if (watch->type == WATCH_ON_HASHTABLE && user_request) { - HashPosition position; - zval **zv; - zval key; - char *str; - int str_len; - phpdbg_watchpoint_t **watchpoint; - - ht = watch->addr.ht; - - for (zend_hash_internal_pointer_reset_ex(ht, &position); - zend_hash_get_current_data_ex(ht, (void **)&zv, &position) == SUCCESS; - zend_hash_move_forward_ex(ht, &position)) { - zend_hash_get_current_key_zval_ex(ht, &key, &position); - str = NULL; - if (Z_TYPE(key) == IS_STRING) { - str_len = asprintf(&str, "%.*s%s%s%s", (int)watch->parent->str_len, watch->parent->str, Z_TYPE_P(watch->parent->addr.zv) == IS_ARRAY?"[":"->", phpdbg_get_property_key(Z_STRVAL(key)), Z_TYPE_P(watch->parent->addr.zv) == IS_ARRAY?"]":""); - } else { - str_len = asprintf(&str, "%.*s%s%li%s", (int)watch->parent->str_len, watch->parent->str, Z_TYPE_P(watch->parent->addr.zv) == IS_ARRAY?"[":"->", Z_LVAL(key), Z_TYPE_P(watch->parent->addr.zv) == IS_ARRAY?"]":""); - } - - if (zend_hash_find(&PHPDBG_G(watchpoints), str, str_len, (void **) &watchpoint) == SUCCESS) { - phpdbg_delete_watchpoint_recursive(*watchpoint, 1 TSRMLS_CC); - } - } + phpdbg_delete_ht_watchpoints_recursive(watch); } else { - switch (Z_TYPE_P(watch->addr.zv)) { - case IS_ARRAY: - ht = Z_ARRVAL_P(watch->addr.zv); - break; - case IS_OBJECT: - ht = Z_OBJPROP_P(watch->addr.zv); - break; - } + ht = HT_FROM_ZVP(watch->addr.zv); if ((result = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong) ht))) { - phpdbg_delete_watchpoint_recursive((phpdbg_watchpoint_t *) result->ptr, user_request TSRMLS_CC); + phpdbg_delete_watchpoint_recursive((phpdbg_watchpoint_t *) result->ptr, user_request); } } + } else if (watch->type == WATCH_ON_ZVAL) { + phpdbg_delete_zval_watchpoints_recursive(watch); + } + + return zend_hash_str_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); +} + +static void phpdbg_delete_ht_watchpoints_recursive(phpdbg_watchpoint_t *watch) { + zend_string *strkey; + zend_long numkey; + char *str; + int str_len; + phpdbg_watchpoint_t *watchpoint; + + ZEND_HASH_FOREACH_KEY(watch->addr.ht, numkey, strkey) { + if (strkey) { + str_len = asprintf(&str, "%.*s%s%s%s", (int) watch->str_len, watch->str, (watch->flags & PHPDBG_WATCH_ARRAY) ? "[" : "->", phpdbg_get_property_key(strkey->val), (watch->flags & PHPDBG_WATCH_ARRAY) ? "]" : ""); + } else { + str_len = asprintf(&str, "%.*s%s%lli%s", (int) watch->str_len, watch->str, (watch->flags & PHPDBG_WATCH_ARRAY) ? "[" : "->", numkey, (watch->flags & PHPDBG_WATCH_ARRAY) ? "]" : ""); + } + + if ((watchpoint = zend_hash_str_find_ptr(&PHPDBG_G(watchpoints), str, str_len))) { + phpdbg_delete_watchpoint_recursive(watchpoint, 1); + } + } ZEND_HASH_FOREACH_END(); +} + +static void phpdbg_delete_zval_watchpoints_recursive(phpdbg_watchpoint_t *watch) { + if (Z_REFCOUNTED_P(watch->addr.zv)) { + phpdbg_remove_watch_collision(Z_COUNTED_P(watch->addr.zv)); } +} - return zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); +static void phpdbg_delete_watchpoints_recursive(phpdbg_watchpoint_t *watch) { + if (watch->type == WATCH_ON_ZVAL) { + phpdbg_delete_zval_watchpoints_recursive(watch); + } else if (watch->type == WATCH_ON_HASHTABLE) { + phpdbg_delete_ht_watchpoints_recursive(watch); + } } -static int phpdbg_delete_watchpoint(phpdbg_watchpoint_t *tmp_watch TSRMLS_DC) { +static int phpdbg_delete_watchpoint(phpdbg_watchpoint_t *tmp_watch) { int ret; phpdbg_watchpoint_t *watch; phpdbg_btree_result *result; - if ((result = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong)tmp_watch->addr.ptr)) == NULL) { + if ((result = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong) tmp_watch->addr.ptr)) == NULL) { return FAILURE; } watch = result->ptr; if (watch->flags & PHPDBG_WATCH_RECURSIVE) { - ret = phpdbg_delete_watchpoint_recursive(watch, 1 TSRMLS_CC); + ret = phpdbg_delete_watchpoint_recursive(watch, 1); } else { - ret = zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); + ret = zend_hash_str_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); } - free(tmp_watch->str); + efree(tmp_watch->str); + efree(tmp_watch->name_in_parent); efree(tmp_watch); return ret; } -static int phpdbg_watchpoint_parse_input(char *input, size_t len, HashTable *parent, size_t i, int (*callback)(phpdbg_watchpoint_t * TSRMLS_DC), zend_bool silent TSRMLS_DC) { - int ret = FAILURE; - zend_bool new_index = 1; - char *last_index; - int index_len = 0; - zval **zv; - - if (len < 2 || *input != '$') { - goto error; - } - - while (i++ < len) { - if (i == len) { - new_index = 1; - } else { - switch (input[i]) { - case '[': - new_index = 1; - break; - case ']': - break; - case '>': - if (last_index[index_len - 1] == '-') { - new_index = 1; - index_len--; - } - break; - - default: - if (new_index) { - last_index = input + i; - new_index = 0; - } - if (input[i - 1] == ']') { - goto error; - } - index_len++; - } - } - - if (new_index && index_len == 0) { - HashPosition position; - for (zend_hash_internal_pointer_reset_ex(parent, &position); - zend_hash_get_current_data_ex(parent, (void **)&zv, &position) == SUCCESS; - zend_hash_move_forward_ex(parent, &position)) { - if (i == len || (i == len - 1 && input[len - 1] == ']')) { - zval *key = emalloc(sizeof(zval)); - phpdbg_watchpoint_t *watch = emalloc(sizeof(phpdbg_watchpoint_t)); - watch->flags = 0; - zend_hash_get_current_key_zval_ex(parent, key, &position); - convert_to_string(key); - watch->str = malloc(i + Z_STRLEN_P(key) + 2); - watch->str_len = sprintf(watch->str, "%.*s%s%s", (int)i, input, phpdbg_get_property_key(Z_STRVAL_P(key)), input[len - 1] == ']'?"]":""); - efree(key); - watch->name_in_parent = zend_strndup(last_index, index_len); - watch->name_in_parent_len = index_len; - watch->parent_container = parent; - phpdbg_create_zval_watchpoint(*zv, watch); - - ret = callback(watch TSRMLS_CC) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE; - } else if (Z_TYPE_PP(zv) == IS_OBJECT) { - phpdbg_watchpoint_parse_input(input, len, Z_OBJPROP_PP(zv), i, callback, silent TSRMLS_CC); - } else if (Z_TYPE_PP(zv) == IS_ARRAY) { - phpdbg_watchpoint_parse_input(input, len, Z_ARRVAL_PP(zv), i, callback, silent TSRMLS_CC); - } else { - /* Ignore silently */ - } - } - return ret; - } else if (new_index) { - char last_chr = last_index[index_len]; - last_index[index_len] = 0; - if (zend_symtable_find(parent, last_index, index_len + 1, (void **)&zv) == FAILURE) { - if (!silent) { - phpdbg_error("%.*s is undefined", (int)i, input); - } - return FAILURE; - } - last_index[index_len] = last_chr; - if (i == len) { - phpdbg_watchpoint_t *watch = emalloc(sizeof(phpdbg_watchpoint_t)); - watch->flags = 0; - watch->str = zend_strndup(input, len); - watch->str_len = len; - watch->name_in_parent = zend_strndup(last_index, index_len); - watch->name_in_parent_len = index_len; - watch->parent_container = parent; - phpdbg_create_zval_watchpoint(*zv, watch); - - ret = callback(watch TSRMLS_CC) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE; - } else if (Z_TYPE_PP(zv) == IS_OBJECT) { - parent = Z_OBJPROP_PP(zv); - } else if (Z_TYPE_PP(zv) == IS_ARRAY) { - parent = Z_ARRVAL_PP(zv); - } else { - phpdbg_error("%.*s is nor an array nor an object", (int)i, input); - return FAILURE; - } - index_len = 0; - } +static int phpdbg_watchpoint_parse_wrapper(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv, int (*callback)(phpdbg_watchpoint_t *)) { + int ret; + phpdbg_watchpoint_t *watch = emalloc(sizeof(phpdbg_watchpoint_t)); + watch->flags = 0; + watch->str = name; + watch->str_len = len; + watch->name_in_parent = keyname; + watch->name_in_parent_len = keylen; + watch->parent_container = parent; + phpdbg_create_zval_watchpoint(zv, watch); + + ret = callback(watch); + + if (ret != SUCCESS) { + efree(watch); + efree(name); + efree(keyname); } return ret; - error: - phpdbg_error("Malformed input"); - return FAILURE; } -static int phpdbg_watchpoint_parse_symtables(char *input, size_t len, int (*callback)(phpdbg_watchpoint_t * TSRMLS_DC) TSRMLS_DC) { - if (EG(This) && len >= 5 && !memcmp("$this", input, 5)) { - zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), NULL); +PHPDBG_API int phpdbg_watchpoint_parse_input(char *input, size_t len, HashTable *parent, size_t i, int (*callback)(phpdbg_watchpoint_t *), zend_bool silent) { + return phpdbg_parse_variable_with_arg(input, len, parent, i, (phpdbg_parse_var_with_arg_func) phpdbg_watchpoint_parse_wrapper, 0, callback); +} + +static int phpdbg_watchpoint_parse_symtables(char *input, size_t len, int (*callback)(phpdbg_watchpoint_t *)) { + if (EG(scope) && len >= 5 && !memcmp("$this", input, 5)) { + zend_hash_str_add(&EG(current_execute_data)->symbol_table->ht, ZEND_STRL("this"), &EG(current_execute_data)->This); } - if (zend_is_auto_global(input, len TSRMLS_CC) && phpdbg_watchpoint_parse_input(input, len, &EG(symbol_table), 0, callback, 1 TSRMLS_CC) != FAILURE) { + if (phpdbg_is_auto_global(input, len) && phpdbg_watchpoint_parse_input(input, len, &EG(symbol_table).ht, 0, callback, 1) != FAILURE) { return SUCCESS; } - return phpdbg_watchpoint_parse_input(input, len, EG(active_symbol_table), 0, callback, 0 TSRMLS_CC); + return phpdbg_watchpoint_parse_input(input, len, &EG(current_execute_data)->symbol_table->ht, 0, callback, 0); } PHPDBG_WATCH(delete) /* {{{ */ { switch (param->type) { case STR_PARAM: - if (phpdbg_delete_var_watchpoint(param->str, param->len TSRMLS_CC) == FAILURE) { - phpdbg_error("Nothing was deleted, no corresponding watchpoint found"); + if (phpdbg_delete_var_watchpoint(param->str, param->len) == FAILURE) { + phpdbg_error("watchdelete", "type=\"nowatch\"", "Nothing was deleted, no corresponding watchpoint found"); } else { - phpdbg_notice("Removed watchpoint %.*s", (int)param->len, param->str); + phpdbg_notice("watchdelete", "variable=\"%.*s\"", "Removed watchpoint %.*s", (int) param->len, param->str); } break; @@ -426,14 +436,14 @@ PHPDBG_WATCH(delete) /* {{{ */ PHPDBG_WATCH(recursive) /* {{{ */ { - if (phpdbg_rebuild_symtable(TSRMLS_C) == FAILURE) { + if (phpdbg_rebuild_symtable() == FAILURE) { return SUCCESS; } switch (param->type) { case STR_PARAM: - if (phpdbg_watchpoint_parse_symtables(param->str, param->len, phpdbg_create_recursive_watchpoint TSRMLS_CC) != FAILURE) { - phpdbg_notice("Set recursive watchpoint on %.*s", (int)param->len, param->str); + if (phpdbg_watchpoint_parse_symtables(param->str, param->len, phpdbg_create_recursive_watchpoint) != FAILURE) { + phpdbg_notice("watchrecursive", "variable=\"%.*s\"", "Set recursive watchpoint on %.*s", (int)param->len, param->str); } break; @@ -445,14 +455,14 @@ PHPDBG_WATCH(recursive) /* {{{ */ PHPDBG_WATCH(array) /* {{{ */ { - if (phpdbg_rebuild_symtable(TSRMLS_C) == FAILURE) { + if (phpdbg_rebuild_symtable() == FAILURE) { return SUCCESS; } switch (param->type) { case STR_PARAM: - if (phpdbg_watchpoint_parse_symtables(param->str, param->len, phpdbg_create_array_watchpoint TSRMLS_CC) != FAILURE) { - phpdbg_notice("Set array watchpoint on %.*s", (int)param->len, param->str); + if (phpdbg_watchpoint_parse_symtables(param->str, param->len, phpdbg_create_array_watchpoint) != FAILURE) { + phpdbg_notice("watcharray", "variable=\"%.*s\"", "Set array watchpoint on %.*s", (int)param->len, param->str); } break; @@ -462,48 +472,47 @@ PHPDBG_WATCH(array) /* {{{ */ return SUCCESS; } /* }}} */ -void phpdbg_watch_HashTable_dtor(zval **zv) { +void phpdbg_watch_HashTable_dtor(zval *zv) { phpdbg_btree_result *result; - TSRMLS_FETCH(); zval_ptr_dtor_wrapper(zv); - if ((result = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong)*zv))) { + if ((result = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong) zv))) { phpdbg_watchpoint_t *watch = result->ptr; PHPDBG_G(watchpoint_hit) = 1; - phpdbg_notice("%.*s was removed, removing watchpoint%s", (int)watch->str_len, watch->str, (watch->flags & PHPDBG_WATCH_RECURSIVE)?" recursively":""); + phpdbg_notice("watchdelete", "variable=\"%.*s\" recursive=\"%s\"", "%.*s was removed, removing watchpoint%s", (int) watch->str_len, watch->str, (watch->flags & PHPDBG_WATCH_RECURSIVE) ? " recursively" : ""); if (watch->flags & PHPDBG_WATCH_RECURSIVE) { - phpdbg_delete_watchpoint_recursive(watch, 0 TSRMLS_CC); + phpdbg_delete_watchpoint_recursive(watch, 0); } else { - zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); + zend_hash_str_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); } } } -int phpdbg_create_var_watchpoint(char *input, size_t len TSRMLS_DC) { - if (phpdbg_rebuild_symtable(TSRMLS_C) == FAILURE) { +int phpdbg_create_var_watchpoint(char *input, size_t len) { + if (phpdbg_rebuild_symtable() == FAILURE) { return FAILURE; } - return phpdbg_watchpoint_parse_symtables(input, len, phpdbg_create_watchpoint TSRMLS_CC); + return phpdbg_watchpoint_parse_symtables(input, len, phpdbg_create_watchpoint); } -int phpdbg_delete_var_watchpoint(char *input, size_t len TSRMLS_DC) { - if (phpdbg_rebuild_symtable(TSRMLS_C) == FAILURE) { +int phpdbg_delete_var_watchpoint(char *input, size_t len) { + if (phpdbg_rebuild_symtable() == FAILURE) { return FAILURE; } - return phpdbg_watchpoint_parse_symtables(input, len, phpdbg_delete_watchpoint TSRMLS_CC); + return phpdbg_watchpoint_parse_symtables(input, len, phpdbg_delete_watchpoint); } #ifdef _WIN32 -int phpdbg_watchpoint_segfault_handler(void *addr TSRMLS_DC) { +int phpdbg_watchpoint_segfault_handler(void *addr) { #else -int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC) { +int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context) { #endif void *page; phpdbg_watch_memdump *dump; @@ -516,7 +525,7 @@ int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC) #else info->si_addr #endif - TSRMLS_CC); + ); if (watch == NULL) { return FAILURE; @@ -539,34 +548,32 @@ int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC) return SUCCESS; } -void phpdbg_watchpoints_clean(TSRMLS_D) { +void phpdbg_watchpoints_clean(void) { zend_hash_clean(&PHPDBG_G(watchpoints)); } -static void phpdbg_watch_dtor(void *pDest) { - phpdbg_watchpoint_t *watch = *(phpdbg_watchpoint_t **)pDest; - TSRMLS_FETCH(); +static void phpdbg_watch_dtor(zval *pDest) { + phpdbg_watchpoint_t *watch = (phpdbg_watchpoint_t *) Z_PTR_P(pDest); - phpdbg_deactivate_watchpoint(watch TSRMLS_CC); - phpdbg_remove_watchpoint(watch TSRMLS_CC); + phpdbg_deactivate_watchpoint(watch); + phpdbg_remove_watchpoint(watch); - free(watch->str); - free(watch->name_in_parent); - efree(watch); + efree(watch->str); + efree(watch->name_in_parent); } static void phpdbg_watch_mem_dtor(void *llist_data) { - phpdbg_watch_memdump *dump = *(phpdbg_watch_memdump **)llist_data; + phpdbg_watch_memdump *dump = *(phpdbg_watch_memdump **) llist_data; /* Disble writing again */ if (dump->reenable_writing) { mprotect(dump->page, dump->size, PROT_READ); } - free(*(void **)llist_data); + free(*(void **) llist_data); } -void phpdbg_setup_watchpoints(TSRMLS_D) { +void phpdbg_setup_watchpoints(void) { #if _SC_PAGE_SIZE phpdbg_pagesize = sysconf(_SC_PAGE_SIZE); #elif _SC_PAGESIZE @@ -580,131 +587,145 @@ void phpdbg_setup_watchpoints(TSRMLS_D) { zend_llist_init(&PHPDBG_G(watchlist_mem), sizeof(void *), phpdbg_watch_mem_dtor, 1); phpdbg_btree_init(&PHPDBG_G(watchpoint_tree), sizeof(void *) * 8); phpdbg_btree_init(&PHPDBG_G(watch_HashTables), sizeof(void *) * 8); - zend_hash_init(&PHPDBG_G(watchpoints), 8, NULL, phpdbg_watch_dtor, 0 ZEND_FILE_LINE_CC); + zend_hash_init(&PHPDBG_G(watchpoints), 8, NULL, phpdbg_watch_dtor, 0); + zend_hash_init(&PHPDBG_G(watch_collisions), 8, NULL, NULL, 0); } -static void phpdbg_print_changed_zval(phpdbg_watch_memdump *dump TSRMLS_DC) { +static void phpdbg_print_changed_zval(phpdbg_watch_memdump *dump) { /* fetch all changes between dump->page and dump->page + dump->size */ - phpdbg_btree_position pos = phpdbg_btree_find_between(&PHPDBG_G(watchpoint_tree), (zend_ulong)dump->page, (zend_ulong)dump->page + dump->size); - phpdbg_btree_result *result, *htresult; + phpdbg_btree_position pos = phpdbg_btree_find_between(&PHPDBG_G(watchpoint_tree), (zend_ulong) dump->page, (zend_ulong) dump->page + dump->size); + phpdbg_btree_result *result; int elementDiff; void *curTest; dump->reenable_writing = 0; while ((result = phpdbg_btree_next(&pos))) { - phpdbg_watchpoint_t *watch = result->ptr, *htwatch; - void *oldPtr = (char *)&dump->data + ((size_t)watch->addr.ptr - (size_t)dump->page); + phpdbg_watchpoint_t *watch = result->ptr; + void *oldPtr = (char *) &dump->data + ((size_t) watch->addr.ptr - (size_t) dump->page); char reenable = 1; + int removed = 0; - if ((size_t)watch->addr.ptr < (size_t)dump->page || (size_t)watch->addr.ptr + watch->size > (size_t)dump->page + dump->size) { + if ((size_t) watch->addr.ptr < (size_t) dump->page || (size_t) watch->addr.ptr + watch->size > (size_t) dump->page + dump->size) { continue; } /* Test if the zval was separated and if necessary move the watchpoint */ - if (zend_hash_find(watch->parent_container, watch->name_in_parent, watch->name_in_parent_len + 1, &curTest) == SUCCESS) { - if (watch->type == WATCH_ON_HASHTABLE) { - switch (Z_TYPE_PP((zval **)curTest)) { - case IS_ARRAY: - curTest = (void *)Z_ARRVAL_PP((zval **)curTest); - break; - case IS_OBJECT: - curTest = (void *)Z_OBJPROP_PP((zval **)curTest); - break; + if ((watch->type == WATCH_ON_HASHTABLE || watch->type == WATCH_ON_ZVAL) && watch->parent_container) { + if ((curTest = zend_hash_str_find(watch->parent_container, watch->name_in_parent, watch->name_in_parent_len))) { + while (Z_TYPE_P((zval *) curTest) == IS_INDIRECT) { + curTest = Z_INDIRECT_P((zval *) curTest); + } + + if (watch->type == WATCH_ON_HASHTABLE) { + switch (Z_TYPE_P((zval *) curTest)) { + case IS_ARRAY: + curTest = (void *) Z_ARRVAL_P((zval *) curTest); + break; + case IS_OBJECT: + curTest = (void *) Z_OBJPROP_P((zval *) curTest); + break; + } } - } else { - curTest = *(void **)curTest; - } - if (curTest != watch->addr.ptr) { - phpdbg_deactivate_watchpoint(watch TSRMLS_CC); - phpdbg_remove_watchpoint(watch TSRMLS_CC); - watch->addr.ptr = curTest; - phpdbg_store_watchpoint(watch TSRMLS_CC); - phpdbg_activate_watchpoint(watch TSRMLS_CC); + if (curTest != watch->addr.ptr) { + phpdbg_deactivate_watchpoint(watch); + phpdbg_remove_watchpoint(watch); + watch->addr.ptr = curTest; + phpdbg_store_watchpoint(watch); + phpdbg_activate_watchpoint(watch); - reenable = 0; + reenable = 0; + } + } else { + removed = 1; } } /* Show to the user what changed and delete watchpoint upon removal */ if (memcmp(oldPtr, watch->addr.ptr, watch->size) != SUCCESS) { - if (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS || (watch->type == WATCH_ON_ZVAL && memcmp(oldPtr, watch->addr.zv, sizeof(zvalue_value))) || (watch->type == WATCH_ON_HASHTABLE -#if ZEND_DEBUG - && !watch->addr.ht->inconsistent -#endif - && zend_hash_num_elements((HashTable *)oldPtr) != zend_hash_num_elements(watch->addr.ht))) { + zend_bool do_break = 0; + + switch (watch->type) { + case WATCH_ON_ZVAL: + do_break = memcmp(oldPtr, watch->addr.zv, sizeof(zend_value) + sizeof(uint32_t) /* value + typeinfo */); + break; + case WATCH_ON_HASHTABLE: + do_break = zend_hash_num_elements((HashTable *) oldPtr) != zend_hash_num_elements(watch->addr.ht); + break; + case WATCH_ON_REFCOUNTED: + if (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS) { + do_break = memcmp(oldPtr, watch->addr.ref, sizeof(uint32_t) /* no zend_refcounted metadata info */); + } + break; + } + + + if (do_break) { PHPDBG_G(watchpoint_hit) = 1; - phpdbg_notice("Breaking on watchpoint %s", watch->str); + phpdbg_notice("watchhit", "variable=\"%s\"", "Breaking on watchpoint %.*s", (int) watch->str_len, watch->str); + phpdbg_xml("<watchdata %r>"); } switch (watch->type) { case WATCH_ON_ZVAL: { - int removed = ((zval *)oldPtr)->refcount__gc != watch->addr.zv->refcount__gc && !zend_symtable_exists(watch->parent_container, watch->name_in_parent, watch->name_in_parent_len + 1); - int show_value = memcmp(oldPtr, watch->addr.zv, sizeof(zvalue_value)); - int show_ref = ((zval *)oldPtr)->refcount__gc != watch->addr.zv->refcount__gc || ((zval *)oldPtr)->is_ref__gc != watch->addr.zv->is_ref__gc; + int show_value = memcmp(oldPtr, watch->addr.zv, sizeof(zval) - sizeof(uint32_t) /* no metadata info */); if (removed || show_value) { - phpdbg_write("Old value: "); - if ((Z_TYPE_P((zval *)oldPtr) == IS_ARRAY || Z_TYPE_P((zval *)oldPtr) == IS_OBJECT) && removed) { - phpdbg_writeln("Value inaccessible, HashTable already destroyed"); + if (removed && (Z_TYPE_P((zval *) oldPtr) == IS_ARRAY || Z_TYPE_P((zval *) oldPtr) == IS_OBJECT)) { + phpdbg_writeln("watchvalue", "type=\"old\" inaccessible=\"inaccessible\"", "Old value inaccessible, array or object (HashTable) already destroyed"); } else { - zend_print_flat_zval_r((zval *)oldPtr TSRMLS_CC); - phpdbg_writeln(""); + phpdbg_out("Old value: "); + phpdbg_xml("<watchvalue %r type=\"old\">"); + zend_print_flat_zval_r((zval *) oldPtr); + phpdbg_xml("</watchvalue>"); + phpdbg_out("\n"); } } - if (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS && (removed || show_ref)) { - phpdbg_writeln("Old refcount: %d; Old is_ref: %d", ((zval *)oldPtr)->refcount__gc, ((zval *)oldPtr)->is_ref__gc); - } /* check if zval was removed */ if (removed) { - phpdbg_notice("Watchpoint %s was unset, removing watchpoint", watch->str); - zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); + phpdbg_notice("watchdelete", "variable=\"%.*s\"", "Watchpoint %.*s was unset, removing watchpoint", (int) watch->str_len, watch->str); + zend_hash_str_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); reenable = 0; - if (Z_TYPE_P((zval *)oldPtr) == IS_ARRAY || Z_TYPE_P((zval *)oldPtr) == IS_OBJECT) { - goto remove_ht_watch; + if (Z_REFCOUNTED_P((zval *) oldPtr)) { + phpdbg_remove_watch_collision(Z_COUNTED_P((zval *) oldPtr)); } - break; } if (show_value) { - phpdbg_write("New value: "); - zend_print_flat_zval_r(watch->addr.zv TSRMLS_CC); - phpdbg_writeln(""); - } - if (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS && show_ref) { - phpdbg_writeln("New refcount: %d; New is_ref: %d", watch->addr.zv->refcount__gc, watch->addr.zv->is_ref__gc); + phpdbg_out("New value: "); + phpdbg_xml("<watchvalue %r type=\"new\">"); + zend_print_flat_zval_r(watch->addr.zv); + phpdbg_xml("</watchvalue>"); + phpdbg_out("\n"); } - if ((Z_TYPE_P(watch->addr.zv) == IS_ARRAY && Z_ARRVAL_P(watch->addr.zv) != Z_ARRVAL_P((zval *)oldPtr)) || (Z_TYPE_P(watch->addr.zv) != IS_OBJECT && Z_OBJ_HANDLE_P(watch->addr.zv) == Z_OBJ_HANDLE_P((zval *)oldPtr))) { - /* add new watchpoints if necessary */ - if (watch->flags & PHPDBG_WATCH_RECURSIVE) { - phpdbg_create_recursive_watchpoint(watch TSRMLS_CC); + /* add new watchpoints if necessary */ + if (Z_PTR_P(watch->addr.zv) != Z_PTR_P((zval *) oldPtr)) { + if (Z_REFCOUNTED_P((zval *) oldPtr)) { + phpdbg_remove_watch_collision(Z_COUNTED_P((zval *) oldPtr)); + } + if (Z_REFCOUNTED_P(watch->addr.zv)) { + if (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS) { + phpdbg_writeln("watchrefcount", "type=\"new\" refcount=\"%d\"", "New refcount: %d", Z_COUNTED_P(watch->addr.zv)->refcount); + } + if (watch->flags & PHPDBG_WATCH_RECURSIVE) { + phpdbg_create_recursive_watchpoint(watch); + } } - } - - if ((Z_TYPE_P((zval *)oldPtr) != IS_ARRAY || Z_ARRVAL_P(watch->addr.zv) == Z_ARRVAL_P((zval *)oldPtr)) && (Z_TYPE_P((zval *)oldPtr) != IS_OBJECT || Z_OBJ_HANDLE_P(watch->addr.zv) == Z_OBJ_HANDLE_P((zval *)oldPtr))) { - break; - } - -remove_ht_watch: - if ((htresult = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong)Z_ARRVAL_P((zval *)oldPtr)))) { - htwatch = htresult->ptr; - zend_hash_del(&PHPDBG_G(watchpoints), htwatch->str, htwatch->str_len); } break; } case WATCH_ON_HASHTABLE: - -#if ZEND_DEBUG - if (watch->addr.ht->inconsistent) { - phpdbg_notice("Watchpoint %s was unset, removing watchpoint", watch->str); +#if 0 && ZEND_DEBUG + if (watch->addr.arr->ht->inconsistent) { + phpdbg_notice("watchdelete", "variable=\"%.*s\"", "Watchpoint %.*s was unset, removing watchpoint", (int) watch->str_len, watch->str); zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); reenable = 0; @@ -712,24 +733,38 @@ remove_ht_watch: break; } #endif - - elementDiff = zend_hash_num_elements((HashTable *)oldPtr) - zend_hash_num_elements(watch->addr.ht); + elementDiff = zend_hash_num_elements((HashTable *) oldPtr) - zend_hash_num_elements(watch->addr.ht); if (elementDiff) { if (elementDiff > 0) { - phpdbg_writeln("%d elements were removed from the array", elementDiff); + phpdbg_writeln("watchsize", "removed=\"%d\"", "%d elements were removed from the array", elementDiff); } else { - phpdbg_writeln("%d elements were added to the array", -elementDiff); + phpdbg_writeln("watchsize", "added=\"%d\"", "%d elements were added to the array", -elementDiff); /* add new watchpoints if necessary */ if (watch->flags & PHPDBG_WATCH_RECURSIVE) { - phpdbg_create_recursive_watchpoint(watch TSRMLS_CC); + phpdbg_create_recursive_watchpoint(watch); } } } - if (((HashTable *)oldPtr)->pInternalPointer != watch->addr.ht->pInternalPointer) { - phpdbg_writeln("Internal pointer of array was changed"); + if (watch->addr.ht->nInternalPointer != ((HashTable *) oldPtr)->nInternalPointer) { + phpdbg_writeln("watcharrayptr", "", "Internal pointer of array was changed"); + } + break; + case WATCH_ON_REFCOUNTED: { + if (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS) { + phpdbg_writeln("watchrefcount", "type=\"old\" refcount=\"%d\"", "Old refcount: %d", ((zend_refcounted *) oldPtr)->refcount); + + if (!removed) { + phpdbg_writeln("watchrefcount", "type=\"old\" refcount=\"%d\"", "Old refcount: %d", ((zend_refcounted *) oldPtr)->refcount); + } } + break; + } + } + + if (do_break) { + phpdbg_xml("</watchdata>"); } } @@ -737,7 +772,7 @@ remove_ht_watch: } } -int phpdbg_print_changed_zvals(TSRMLS_D) { +int phpdbg_print_changed_zvals(void) { zend_llist_position pos; phpdbg_watch_memdump **dump; int ret; @@ -746,42 +781,45 @@ int phpdbg_print_changed_zvals(TSRMLS_D) { return FAILURE; } - dump = (phpdbg_watch_memdump **)zend_llist_get_last_ex(&PHPDBG_G(watchlist_mem), &pos); + dump = (phpdbg_watch_memdump **) zend_llist_get_last_ex(&PHPDBG_G(watchlist_mem), &pos); do { - phpdbg_print_changed_zval(*dump TSRMLS_CC); - } while ((dump = (phpdbg_watch_memdump **)zend_llist_get_prev_ex(&PHPDBG_G(watchlist_mem), &pos))); + phpdbg_print_changed_zval(*dump); + } while ((dump = (phpdbg_watch_memdump **) zend_llist_get_prev_ex(&PHPDBG_G(watchlist_mem), &pos))); zend_llist_clean(&PHPDBG_G(watchlist_mem)); - ret = PHPDBG_G(watchpoint_hit)?SUCCESS:FAILURE; + ret = PHPDBG_G(watchpoint_hit) ? SUCCESS : FAILURE; PHPDBG_G(watchpoint_hit) = 0; return ret; } -void phpdbg_list_watchpoints(TSRMLS_D) { - HashPosition position; - phpdbg_watchpoint_t **watch; +void phpdbg_list_watchpoints(void) { + phpdbg_watchpoint_t *watch; - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(watchpoints), &position); - zend_hash_get_current_data_ex(&PHPDBG_G(watchpoints), (void**) &watch, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(watchpoints), &position)) { - phpdbg_writeln("%.*s", (int)(*watch)->str_len, (*watch)->str); - } + phpdbg_xml("<watchlist %r>"); + + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(watchpoints), watch) { + phpdbg_writeln("watchvariable", "variable=\"%.*s\" on=\"%s\" type=\"%s\"", "%.*s (%s, %s)", (int) watch->str_len, watch->str, watch->type == WATCH_ON_HASHTABLE ? "array" : watch->type == WATCH_ON_REFCOUNTED ? "refcount" : "variable", watch->flags == PHPDBG_WATCH_RECURSIVE ? "recursive" : "simple"); + } ZEND_HASH_FOREACH_END(); + + phpdbg_xml("</watchlist>"); } void phpdbg_watch_efree(void *ptr) { phpdbg_btree_result *result; - TSRMLS_FETCH(); - result = phpdbg_btree_find_closest(&PHPDBG_G(watchpoint_tree), (zend_ulong)ptr); + result = phpdbg_btree_find_closest(&PHPDBG_G(watchpoint_tree), (zend_ulong) ptr); if (result) { phpdbg_watchpoint_t *watch = result->ptr; - if ((size_t)watch->addr.ptr + watch->size > (size_t)ptr) { - zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); + if ((size_t) watch->addr.ptr + watch->size > (size_t) ptr) { + if (watch->type == WATCH_ON_ZVAL) { + phpdbg_remove_watch_collision(Z_COUNTED_P(watch->addr.zv)); + } + zend_hash_str_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len); } } diff --git a/sapi/phpdbg/phpdbg_watch.h b/sapi/phpdbg/phpdbg_watch.h index 0240a47265..a838d6d81a 100644 --- a/sapi/phpdbg/phpdbg_watch.h +++ b/sapi/phpdbg/phpdbg_watch.h @@ -25,7 +25,7 @@ #include "phpdbg_cmd.h" #ifdef _WIN32 -# include "phpdbg_win.h" +# include "phpdbg_win.h" #endif #define PHPDBG_WATCH(name) PHPDBG_COMMAND(watch_##name) @@ -37,64 +37,66 @@ PHPDBG_WATCH(array); PHPDBG_WATCH(delete); PHPDBG_WATCH(recursive); -/** - * Commands - */ - -static const phpdbg_command_t phpdbg_watch_commands[] = { - PHPDBG_COMMAND_D_EX(array, "create watchpoint on an array", 'a', watch_array, NULL, "s"), - PHPDBG_COMMAND_D_EX(delete, "delete watchpoint", 'd', watch_delete, NULL, "s"), - PHPDBG_COMMAND_D_EX(recursive, "create recursive watchpoints", 'r', watch_recursive, NULL, "s"), - PHPDBG_END_COMMAND -}; +extern const phpdbg_command_t phpdbg_watch_commands[]; /* Watchpoint functions/typedefs */ typedef enum { WATCH_ON_ZVAL, WATCH_ON_HASHTABLE, + WATCH_ON_REFCOUNTED, } phpdbg_watchtype; -#define PHPDBG_WATCH_SIMPLE 0x0 -#define PHPDBG_WATCH_RECURSIVE 0x1 +#define PHPDBG_WATCH_SIMPLE 0x0 +#define PHPDBG_WATCH_RECURSIVE 0x1 +#define PHPDBG_WATCH_ARRAY 0x2 +#define PHPDBG_WATCH_OBJECT 0x4 typedef struct _phpdbg_watchpoint_t phpdbg_watchpoint_t; struct _phpdbg_watchpoint_t { - phpdbg_watchpoint_t *parent; - HashTable *parent_container; - char *name_in_parent; - size_t name_in_parent_len; - char *str; - size_t str_len; union { zval *zv; HashTable *ht; + zend_refcounted *ref; void *ptr; } addr; size_t size; phpdbg_watchtype type; char flags; + phpdbg_watchpoint_t *parent; + HashTable *parent_container; + char *name_in_parent; + size_t name_in_parent_len; + char *str; + size_t str_len; }; -void phpdbg_setup_watchpoints(TSRMLS_D); +typedef struct { + phpdbg_watchpoint_t watch; + unsigned int num; + unsigned int refs; + HashTable watches; +} phpdbg_watch_collision; + +void phpdbg_setup_watchpoints(void); #ifndef _WIN32 -int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC); +int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context); #else -int phpdbg_watchpoint_segfault_handler(void *addr TSRMLS_DC); +int phpdbg_watchpoint_segfault_handler(void *addr); #endif void phpdbg_create_addr_watchpoint(void *addr, size_t size, phpdbg_watchpoint_t *watch); void phpdbg_create_zval_watchpoint(zval *zv, phpdbg_watchpoint_t *watch); -int phpdbg_delete_var_watchpoint(char *input, size_t len TSRMLS_DC); -int phpdbg_create_var_watchpoint(char *input, size_t len TSRMLS_DC); +int phpdbg_delete_var_watchpoint(char *input, size_t len); +int phpdbg_create_var_watchpoint(char *input, size_t len); -int phpdbg_print_changed_zvals(TSRMLS_D); +int phpdbg_print_changed_zvals(void); -void phpdbg_list_watchpoints(TSRMLS_D); +void phpdbg_list_watchpoints(void); void phpdbg_watch_efree(void *ptr); @@ -102,11 +104,11 @@ void phpdbg_watch_efree(void *ptr); static long phpdbg_pagesize; static zend_always_inline void *phpdbg_get_page_boundary(void *addr) { - return (void *)((size_t)addr & ~(phpdbg_pagesize - 1)); + return (void *) ((size_t) addr & ~(phpdbg_pagesize - 1)); } static zend_always_inline size_t phpdbg_get_total_page_size(void *addr, size_t size) { - return (size_t)phpdbg_get_page_boundary((void *)((size_t)addr + size - 1)) - (size_t)phpdbg_get_page_boundary(addr) + phpdbg_pagesize; + return (size_t) phpdbg_get_page_boundary((void *) ((size_t) addr + size - 1)) - (size_t) phpdbg_get_page_boundary(addr) + phpdbg_pagesize; } #endif diff --git a/sapi/phpdbg/phpdbg_webdata_transfer.c b/sapi/phpdbg/phpdbg_webdata_transfer.c new file mode 100644 index 0000000000..10432c9fda --- /dev/null +++ b/sapi/phpdbg/phpdbg_webdata_transfer.c @@ -0,0 +1,175 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Bob Weinand <bwoebi@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include "phpdbg_webdata_transfer.h" +#include "ext/standard/php_var.h" + +static int phpdbg_is_auto_global(char *name, int len) { + int ret; + zend_string *str = zend_string_init(name, len, 0); + ret = zend_is_auto_global(str); + efree(str); + return ret; +} + +PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len) { + zval array; + HashTable *ht; + zval zv[9] = {{{0}}}; + + array_init(&array); + ht = Z_ARRVAL(array); + + /* fetch superglobals */ + { + phpdbg_is_auto_global(ZEND_STRL("GLOBALS")); + /* might be JIT */ + phpdbg_is_auto_global(ZEND_STRL("_ENV")); + phpdbg_is_auto_global(ZEND_STRL("_SERVER")); + phpdbg_is_auto_global(ZEND_STRL("_REQUEST")); + array_init(&zv[1]); + zend_hash_copy(Z_ARRVAL(zv[1]), &EG(symbol_table).ht, NULL); + Z_ARRVAL(zv[1])->pDestructor = NULL; /* we're operating on a copy! Don't double free zvals */ + zend_hash_str_del(Z_ARRVAL(zv[1]), ZEND_STRL("GLOBALS")); /* do not use the reference to itself in json */ + zend_hash_str_add(ht, ZEND_STRL("GLOBALS"), &zv[1]); + } + + /* save php://input */ + { + php_stream *stream; + zend_string *str; + + stream = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir)); + if ((str = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0))) { + ZVAL_STR(&zv[2], str); + } else { + ZVAL_EMPTY_STRING(&zv[2]); + } + Z_SET_REFCOUNT(zv[2], 1); + zend_hash_str_add(ht, ZEND_STRL("input"), &zv[2]); + } + + /* change sapi name */ + { + if (sapi_module.name) { + ZVAL_STRING(&zv[6], sapi_module.name); + } else { + Z_TYPE_INFO(zv[6]) = IS_NULL; + } + zend_hash_str_add(ht, ZEND_STRL("sapi_name"), &zv[6]); + Z_SET_REFCOUNT(zv[6], 1); + } + + /* handle modules / extensions */ + { + zend_module_entry *module; + zend_extension *extension; + zend_llist_position pos; + + array_init(&zv[7]); + ZEND_HASH_FOREACH_PTR(&module_registry, module) { + zval *value = ecalloc(sizeof(zval), 1); + ZVAL_STRING(value, module->name); + zend_hash_next_index_insert(Z_ARRVAL(zv[7]), value); + } ZEND_HASH_FOREACH_END(); + zend_hash_str_add(ht, ZEND_STRL("modules"), &zv[7]); + + array_init(&zv[8]); + extension = (zend_extension *) zend_llist_get_first_ex(&zend_extensions, &pos); + while (extension) { + zval *value = ecalloc(sizeof(zval), 1); + ZVAL_STRING(value, extension->name); + zend_hash_next_index_insert(Z_ARRVAL(zv[8]), value); + extension = (zend_extension *) zend_llist_get_next_ex(&zend_extensions, &pos); + } + zend_hash_str_add(ht, ZEND_STRL("extensions"), &zv[8]); + } + + /* switch cwd */ + if (SG(options) & SAPI_OPTION_NO_CHDIR) { + char *ret = NULL; + char path[MAXPATHLEN]; + +#if HAVE_GETCWD + ret = VCWD_GETCWD(path, MAXPATHLEN); +#elif HAVE_GETWD + ret = VCWD_GETWD(path); +#endif + if (ret) { + ZVAL_STRING(&zv[5], path); + Z_SET_REFCOUNT(zv[5], 1); + zend_hash_str_add(ht, ZEND_STRL("cwd"), &zv[5]); + } + } + + /* get system ini entries */ + { + zend_ini_entry *ini_entry; + + array_init(&zv[3]); + ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) { + zval *value = ecalloc(sizeof(zval), 1); + if (ini_entry->modified) { + if (!ini_entry->orig_value) { + efree(value); + continue; + } + ZVAL_STR(value, ini_entry->orig_value); + } else { + if (!ini_entry->value) { + efree(value); + continue; + } + ZVAL_STR(value, ini_entry->value); + } + zend_hash_add(Z_ARRVAL(zv[3]), ini_entry->name, value); + } ZEND_HASH_FOREACH_END(); + zend_hash_str_add(ht, ZEND_STRL("systemini"), &zv[3]); + } + + /* get perdir ini entries */ + if (EG(modified_ini_directives)) { + zend_ini_entry *ini_entry; + + array_init(&zv[4]); + ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) { + zval *value = ecalloc(sizeof(zval), 1); + if (!ini_entry->value) { + efree(value); + continue; + } + ZVAL_STR(value, ini_entry->value); + zend_hash_add(Z_ARRVAL(zv[4]), ini_entry->name, value); + } ZEND_HASH_FOREACH_END(); + zend_hash_str_add(ht, ZEND_STRL("userini"), &zv[4]); + } + + /* encode data */ + { + php_serialize_data_t var_hash; + smart_str buf = {0}; + + PHP_VAR_SERIALIZE_INIT(var_hash); + php_var_serialize(&buf, &array, &var_hash); + PHP_VAR_SERIALIZE_DESTROY(var_hash); + *msg = buf.s->val; + *len = buf.s->len; + } + + zval_dtor(&array); +} diff --git a/sapi/phpdbg/phpdbg_webdata_transfer.h b/sapi/phpdbg/phpdbg_webdata_transfer.h new file mode 100644 index 0000000000..ce15a7b639 --- /dev/null +++ b/sapi/phpdbg/phpdbg_webdata_transfer.h @@ -0,0 +1,27 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2015 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Bob Weinand <bwoebi@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifndef PHPDBG_WEBDATA_TRANSFER_H +#define PHPDBG_WEBDATA_TRANSFER_H + +#include "zend.h" +#include "phpdbg.h" + +PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len); + +#endif /* PHPDBG_WEBDATA_TRANSFER_H */ diff --git a/sapi/phpdbg/phpdbg_win.c b/sapi/phpdbg/phpdbg_win.c index a10baba800..42e9d95bdd 100644 --- a/sapi/phpdbg/phpdbg_win.c +++ b/sapi/phpdbg/phpdbg_win.c @@ -31,9 +31,8 @@ int phpdbg_exception_handler_win32(EXCEPTION_POINTERS *xp) { CONTEXT *xc = xp->ContextRecord; if(xr->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { - TSRMLS_FETCH(); - if (phpdbg_watchpoint_segfault_handler((void *)xr->ExceptionInformation[1] TSRMLS_CC) == SUCCESS) { + if (phpdbg_watchpoint_segfault_handler((void *)xr->ExceptionInformation[1]) == SUCCESS) { return EXCEPTION_CONTINUE_EXECUTION; } } diff --git a/sapi/phpdbg/phpdbg_win.h b/sapi/phpdbg/phpdbg_win.h index bc51c3f247..9a6ba6faa7 100644 --- a/sapi/phpdbg/phpdbg_win.h +++ b/sapi/phpdbg/phpdbg_win.h @@ -34,4 +34,4 @@ void phpdbg_win_set_mm_heap(zend_mm_heap *heap); int phpdbg_exception_handler_win32(EXCEPTION_POINTERS *xp); -#endif
\ No newline at end of file +#endif diff --git a/sapi/phpdbg/tests/commands/0002_set.test b/sapi/phpdbg/tests/commands/0002_set.test index 468ac6d9ea..6a14a15adc 100644 --- a/sapi/phpdbg/tests/commands/0002_set.test +++ b/sapi/phpdbg/tests/commands/0002_set.test @@ -8,7 +8,7 @@ # setting error color # setting notice color # Failed to find breakpoint #0 -# oplog disabled +# [Oplog off] # opened oplog test.log # nothing ################################################# diff --git a/sapi/phpdbg/tests/commands/0102_print.test b/sapi/phpdbg/tests/commands/0102_print.test index de4acb7651..c174564e07 100644 --- a/sapi/phpdbg/tests/commands/0102_print.test +++ b/sapi/phpdbg/tests/commands/0102_print.test @@ -4,15 +4,14 @@ # expect: TEST::FORMAT # options: -rr ################################################# -#[User Class: test] -#Methods (3): +#[User Class: test (3 methods)] #L%d-%d test::testMethod() %s # L%d %s ZEND_RETURN C%d <unused> <unused> # L%d-%d test::testPrivateMethod() %s # L%d %s ZEND_RETURN C%d <unused> <unused> # L%d-%d test::testProtectedMethod() %s # L%d %s ZEND_RETURN C%d <unused> <unused> -#[User Method testMethod] +#[User Method testMethod (1 ops)] # L%d-%d test::testMethod() %s # L%d %s ZEND_RETURN C%d <unused> <unused> ################################################# diff --git a/sapi/phpdbg/tests/commands/0104_clean.test b/sapi/phpdbg/tests/commands/0104_clean.test index c7a579be17..2c7660ad60 100644 --- a/sapi/phpdbg/tests/commands/0104_clean.test +++ b/sapi/phpdbg/tests/commands/0104_clean.test @@ -4,12 +4,11 @@ # expect: TEST::FORMAT # options: -rr ################################################# -#[Cleaning Execution Environment] -#Classes %d -#Functions %d -#Constants %d -#Includes %d -#[Nothing to execute!] +#Cleaning Execution Environment +#Classes %d +#Functions %d +#Constants %d +#Includes %d ################################################# clean quit diff --git a/sapi/phpdbg/tests/commands/0105_clear.test b/sapi/phpdbg/tests/commands/0105_clear.test index b547b0d6ba..8ce1002491 100644 --- a/sapi/phpdbg/tests/commands/0105_clear.test +++ b/sapi/phpdbg/tests/commands/0105_clear.test @@ -4,7 +4,7 @@ # expect: TEST::FORMAT # options: -rr ################################################# -#[Clearing Breakpoints] +#Clearing Breakpoints #File%w%d #Functions%w%d #Methods%w%d diff --git a/sapi/phpdbg/tests/commands/0106_compile.test b/sapi/phpdbg/tests/commands/0106_compile.test index 7193600ea3..b4d801670b 100644 --- a/sapi/phpdbg/tests/commands/0106_compile.test +++ b/sapi/phpdbg/tests/commands/0106_compile.test @@ -4,9 +4,9 @@ # expect: TEST::FORMAT # options: -rr ################################################# -#[Attempting compilation of %s] -#[Success] +#[Successful compilation of %s] #Hello World +#[Script ended normally] ################################################# <: define('OUT', diff --git a/sapi/phpdbg/tests/run-tests.php b/sapi/phpdbg/tests/run-tests.php index 1cc31d815e..4afb64561c 100644 --- a/sapi/phpdbg/tests/run-tests.php +++ b/sapi/phpdbg/tests/run-tests.php @@ -389,7 +389,7 @@ namespace phpdbg\testing { } break; default: { - $this->$chunks[0] = $chunks[1]; + $this->{$chunks[0]} = $chunks[1]; } } } else switch(substr($trim, 1, 1)) { diff --git a/sapi/phpdbg/xml.md b/sapi/phpdbg/xml.md new file mode 100644 index 0000000000..56dcaaa1f7 --- /dev/null +++ b/sapi/phpdbg/xml.md @@ -0,0 +1,651 @@ +phpdbg XML format +================= + +Common attributes +================= + +severity +-------- + +- indicates the genre of phpdbg system output +- usually one of these values: + - normal + - notice + - error + +msgout +------ + +- text message output related to the xml data (e.g. <intro severity="normal" help="help" msgout="To get help using phpdbg type &quot;help&quot; and press enter" />) + +req +--- + +- the request id, if one was passed to the last command (via -r %d, where %d is the id) (and the output is related to that message) + +file +---- + +- refers to a filename + +method +------ + +- format classname::methodname +- refers to a method + +function +-------- + +- refers to a function + +symbol +------ + +- either function or method (is method if "::" are present) + +opline +------ + +- in hexadecimal format +- refers to a specific pointer to a (zend_)op + +opcode +------ + +- refers to an opcode (ZEND_*) + +type +---- + +- general attribute for most errors, describes the genre of the error + +General tags +============ + +intro +----- + +- appears on startup if -q flag wasn't provided as command line arg +- before any input possibility +- attributes may be spread over multiple tags +- wrapped in <intros> tag + +### attributes ### + +- version: current phpdbg version (as string) +- help: command name for help +- report: URL for bug reporting + + +phpdbg +------ + +- general text message output from phpdbg system + +stream +------ + +- any output by PHP itself (e.g. <stream type="stdout">test</stream>) + +### attributes ### + +- type: stderr or stdout + +php +--- + +- php error output + +### attributes ### + +- msg: the error message + + +General error tags +================== + +command +------- + +- general errors about commands + +### possible attributes ### + +- type + - toomanyargs: more arguments than allowed + - noarg: argument missing + - wrongarg: wrong type of argument (e.g. letters instead of integer) + - toofewargs: not enough arguments + - notfound: command (or subcommand) doesn't exist + - ambiguous: command was ambiguous + - invalidcommand: command input is totally invalid + - (nostack: should not happen: is an internal error) + - (emptystack: should not happen: is an internal error) +- command: passed command +- subcommand: passed subcommand (present if the error is related to the subcommand) +- expected: count of expected arguments +- got: type of argument for type "wrongarg" +- num: if possible, information about which parameter had a wrong argument + +inactive +-------- + +- by type + - op_array: nothing was yet compiled (probably because no execution context set) + - symbol_table: no symbol table present (not yet initiailized or already destructed) + - noexec: not in execution + - memory_manager: using the native memory manager (malloc, free, realloc) instead of e.g. the Zend MM + - notfound: file not found + - nocontext: execution context was not set (or compilation had failed) + - isrunning: command requires no running script + + +Commands +======== + +export +------ + +- tag: <exportbreakpoint /> +- usually triggered by successful export command +- may appear when cleaning to temporary store breakpoints +- errors by type + - openfailure: could not create file + +### attributes ### + +- count: number of exported breakpoints + +break / info break +------------------ + +- General tag for breakpoint creation, deletion and hits is "<breakpoint />" + +### possible attributes ### + +- id: the breakpoint id (if the leave command was executed, the id has the value "leave") +- num: the nth opline of a function/method/file +- add: has value "success"/"fail": a brekpoint was successfully/not added +- pending: the breakpoint is waiting for resolving (e.g. a file opline on a not yet loaded file) +- deleted: has value "success"/"fail": a breakpoint was successfully/not deleted +- eval: the condition on conditional breakpoints +- file +- opline +- opcode +- symbol +- function +- method +- line + + +- listing breakpoints always in a container element "<breakpoints>" + - Child nodes: + - function + - method + - file + - opline + - methodopline + - functionopline + - fileopline + - evalfunction + - evalfunctionopline + - evalmethod + - evalmethodopline + - evalfile + - evalopline + - eval + - opcode + - attributes: + - name: name of the symbol (function/method/file/opcode) + - disabled: empty value if enabled, non-empty if enabled + +- errors (by type) + - exists: the breakpoint already exists + - maxoplines: tries to break at an opline (usedoplinenum) higher than the number of present oplines (in maxoplinenum) + - nomethod: method doesn't exist + - internalfunction: one cannot break on an opline of an internal function + - notregular: tries to set a breakpoint in not a regular file + - (invalidparameter: should not happen: is an internal error) + +frame +----- + +- General tag for frames is "<frame>" +- always has id attribute; if it only has id attribute, it just indicates current frame number, no other elements follow +- may contain other elements (of type <arg>) when contained in <backtrace> tag +- <arg> always contains a <stream> element, the value of the variable + +### possible attributes ### + +- id: the frame id, current frame has id 0 (frames with internal function calls have the same id than their called frame) +- symbol ("{main}" is root frame) +- file +- line +- internal: has value "internal" when being an internal function call (one cannot inspect that frame) + +- being an error: (by type) + - maxnum: tried to access a frame with a number higher than existing (or < 0) + +### attributes on <arg> ### + +- variadic: has a non-empty value if the argument is variadic +- name: variable name of parameter + +info (subcommands) +------------------ + +### break ### + +- See above ("break / info break") + +###Â files ### + +- lists included files +- <includedfileinfo num="" /> with num having an integer value, indicating the number of included files +- <includedfile name=""/>: one per file, with name being the file path of the included file + +### error ### + +- gets last error +- <lasterror error="" (file="" line="") /> +- error attribute contains the last error as a string, is empty if there's no last error + +### vars / globals ### + +- <variableinfo num="" /> with num having an integer value, indicating the number of (local or superglobal) variables +- if info vars was used it'll have also one of these attributes: + - method + - function + - file + - opline +- for each variable there is a <variable> followed by a <variabledetails> element +- <variable address="" refcount="" type="" name="" /> + - address: pointer to zval (hexadecimal) + - refcount: refcount of zval + - type: the variable type (long, string, ...). If the value is "unknown", the other attributes are meaningless + - name: the name of the variable + - refstatus: empty if the zval is not a reference + - class: the class the object in the zval is an instance of + - resource: the type of the resource in the zval + +### literal ### + +- <literalinfo num="" /> with num having an integer value, indicating the number of literals, optional arguments are: + - method + - function + - file + - opline +- for each literal there is a <literal> followed by a <stream type="stdout"> which prints the value of the literal +- <literal id="" />: where id is the internal identifier of the literal + +### memory ### + +- Format: + + <meminfo /> + <current /> + <used mem="" /> + <real mem="" /> + <peak /> + <used mem="" /> + <real mem="" /> + +- mem is an attribute whose value is a float. The memory is given in kilobytes (1 kB == 1024 bytes) + +### classes ### + +- <classinfo num="" /> with num having an integer value, indicating the number of loaded user-defined classes +- Each class is enumerated with first a <class>, then an optional <parents> container and then a <classsource> element +- The <parents> container contains the <class> elements of the parent of the last <class> element. +- <class type="" flags="" name="" methodcount="" /> + - type: either "User" or "Internal" + - flags: either "Interface", "Class" or "Abstract Class" +- <classsource /> where the class was defined, if there are no attributes, location is unknown, usually defined by + - file + - line + +### funcs ### + +- <functioninfo num="" /> with num having an integer value, indicating the number of loaded user-defined functions +- Each class is enumerated with first a <function> and then a <functionsource> element +- <function name="" /> +- <functionsource /> where the function was defined, if there are no attributes, location is unknown, usually defined by + - file + - line + +list +---- + +- consists of <line> elements wrapped in a <list> container +- <list file=""> is the container element with file being the filename +- <line line="" code="" /> with value of code being the whole line of code in the line specified in the line attribute + - current: this attribute is set to "current" if that line is the line where the executor currently is + +print +----- + +### without a subcommand ### + +- <print> elements are wrapped in a <printinfo> element +- there may be a variable number of <print> elements with a variable count of args inside the <printinfo> element +- possible args are: + - readline: yes/no - readline enabled or disabled + - libedit: yes/no - libedit enabled or disabled + - context: current executing context + - compiled: yes/no - are there actual compiled ops? + - stepping: @@ TODO (meaningless for now) @@ + - quiet: on/off - should it always print the opline being currently executed? + - oplog: on/off - are oplines logged in a file? + - ops: number of opcodes in current executing context + - vars: number of compiled variables (CV) + - executing: yes/no - in executor? + - vmret: the return value of the last executed opcode + - default: continue + - 1: return from vm + - 2: enter stack frame + - 3: leave stack frame + - classes: number of classes + - functions: number of functions + - constants: number of constants + - includes: number of included files + +### with a subcommand ### + +- introduced by <printinfo num="" /> (except for print opline) with num being the number of opcodes and one of these args: + - file + - method + - function + - class (then also type and flags attributes, see info classes command for their meanings) + - symbol (also type and flags attributes; here the value of flags is either "Method" or "Function") +- if there is a class method, the methods are all wrapped in a <printmethods> container +- then comes a <printoplineinfo type="" /> where type is either "User" or "Internal" +- the <printoplineinfo> has either a method or a function attribute +- if the type is "Internal" + - there are no oplines, it's an internal method or function +- if the type is "User" + - it has these attributes + - startline: the first line of code where the method or function is defined + - endline: the lastt line of code where the method or function is defined + - file: the file of code where the method or function is defined + - is followed by the oplines of that method or function (<print> elements) +- <print line="%u" opline="%p" opcode="%s" op="%s" /> +- in case of print opline it emits a single <opline line="" opline="" opcode="" op="" file="" /> + +exec +---- + +- command executing and compiling a given file + - <exec type="unset" context="" />: indicates unsetting of the old context + - <exec type="unsetops" />: indicates unsetting of the old compiled opcodes + - <exec type="unchanged" />: same execution context chosen again + - <exec type="set" context="" />: indicates setting of the new context +- errors by tag + - <compile> + - openfailure: couldn't open file + - compilefailure: The file indicated in context couldn't be compiled + - <exec> + - invalid: given context (attribute) is not matching a valid file or symlink + - notfound: given context (attribute) does not exist + +run / <stop> tag +------------------- + +- runs the script (set via exec command) +- <stop type="end" />: script execution ended normally +- (error) <stop type="bailout" /> the VM bailed out (usually because there was some error) +- compile failures see under exec, errors, <compile> + +step +---- + +- steps by one line or opcode (as defined via set stepping) default is one line +- returns back to the executor + +continue +-------- + +- returns back to the executor + +until +----- + +- temporarily disables all the breakpoints on that line until that line was left once +- returns back to the executor + +finish +------ + +- temporarily disables all the breakpoints until the end of the current frame +- returns back to the executor + +leave +------ + +- temporarily disables all the breakpoints past the end of the current frame and then stops +- returns back to the executor + +back +---- + +- prints backtrace +- see frame command + +ev +-- + +- eval()uates some code +- output wrapped in <eval> tags + +sh +-- + +- executes shell command +- still pipes to stdout ... without wrapping <stream> !!! (@@ TODO @@) + +source +------ + +- executes a file in .phpdbginit format +- errors by type + - notfound: file not found + +register +-------- + +- registers a function to be used like a command +- <register function="" />: successfully registered function +- errors by type + - notfound: no such function + - inuse: function already registered + +quit +---- + +- quits phpdbg +- if successful connection will be closed... + +clean +----- + +- cleans environment (basically a shutdown + new startup) +- <clean> tags wrapped in a <cleaninfo> container +- possible attributes of <clean> tag + - classes: number of classes + - functions: number of functions + - constants: number of constants + - includes: number of included files + +clear +----- + +- removes all breakpoints +- <clear> tags wrapped in a <clearinfo> container +- possible attributes of <clear> tag (value is always the number of defined breakpoints of that type) + - files + - functions + - methods + - oplines + - fileoplines + - functionoplines + - methodoplines + - eval + +watch +----- + +- watchpoints generally are identified by a variable (one may need to switch frames first...) +- <watch variable="" />, <watchrecursive variable="" /> and <watcharray variable="" /> (normal, array, recursive) +- <watch> if error, by type: + - undefined: tried to set a watchpoint on a not (yet) defined variable + - notiterable: element which is tried to be accessed as an object or array is nor array nor object + - invalidinput: generally malformed input +- <watchdelete variable="" />: when "watch delete" was used on a watchpoint +- (error) <watchdelete type="nowatch" />: that watchpoint doesn't exist, so couldn't be deleted +- for hit watchpoints etc., see Other tags, <watch*> +- when using watch list, <watchvariable> elements are wrapped in a <watchlist> container + - <watchvariable variable="" on="" type="" /> + - variable: watched variable (may be a variable of another scope!) + - on: values are array or variable, depending on what is watched + - type: values are recursive or simple, depending on whether the watchpoint is checked recursively or not + +set +--- + +- a general error is type="wrongargs" where a wrong argument was passed to a subcommand; tag is then <set*> + +### prompt ### + +- without other args, a <setpromt str="" /> tag is emitted where the value of the str attribue is the value of the prompt +- when there is another arg, the prompt is changed to that arg, no further xml answer + +### break ### + +- enables / disables a given breakpoint silently with no further xml answer +- if the boolean switch is omitted, it emits current state in a <setbreak id="" active="" /> where active is on or off +- error with type="nobreak", when no breakpoint with the given id exists + +### breaks ### + +- generally enables / disables breakpoint functionality silently with no further xml answer +- if the boolean switch is omitted, it emits current state in a <setbreaks active="" /> where active is on or off + +### color ### + +- sets the color on prompt, error or notices +- <setcolor type="" color="" code="" />: code is the color code of color, type is either: + - prompt + - error + - notice +- errors by type: + - nocolor: color doesn't exist + - invalidtype: type wasn't one of the three allowed types + +### colors ### + +- generally enables / disables colors silently with no further xml answer +- if the boolean switch is omitted, it emits current state in a <setcolors active="" /> where active is on or off + +### oplog ### + +- sets oplog +- (error) <setoplog type="openfailure" file="" /> when it couldn't open the passed file path +- <setoplog type="closingold" /> is emitted when there was a previous open oplog (and a file is passed) +- if no further argument is passed, it emits current state in a <setoplog active="" /> where active is on or off + +### quiet ### + +- generally enables / disables quietness silently with no further xml answer +- if the boolean switch is omitted, it emits current state in a <setquiet active="" /> where active is on or off + +### setpping ### + +- sets stepping to either opcode or line (so a step command will either advance one op or one line) +- if no further argument is passed, it emits current state in a <setoplog type="" /> where active is opcode or line + +### refcount ### + +- generally enables / disables showing of refcount in watchpoint breaks silently with no further xml answer +- if the boolean switch is omitted, it emits current state in a <setrefcount active="" /> where active is on or off + +wait +---- + +- internally executes exec, so exec will output first (if binding to socket worked) + +### attributes ### + +- import: has value "success"/"fail" +- missingmodule/missingextension: modules/extensions loaded in the target SAPI, but not in phpdbg + +### errors (by type) ### + +- nosocket: couldn't establish socket +- invaliddata: invalid JSON passed to socket + +dl +-- + +- loads a module or Zend extension at a given path +- if a relative path is passed, it's relative to the extension_dir ini setting + +### attributes ### + +- extensiontype: "Zend extension" or "module" +- name: the extension name +- path: the path where it was loaded + +### errors (by type) ### + +- unsupported: dynamic extension loading is unsupported +- relpath: relative path given, but no extension_dir defined +- unknown: general error with internal DL_LOAD() (for message see msg attribute) +- wrongapi: wrong Zend engine version (apineeded / apiinstalled attributes give information about the API versions) +- wrongbuild: unmatched build versions (buildneeded / buildinstalled attributes give information about the build versions) +- registerfailure: registering module failed +- startupfailure: couldn't startup Zend extension / module +- initfailure: couldn't initialize module +- nophpso: passed shared object is not a valid Zend extension nor module + +- errors may have the module or extension attribute when their name is already known at the point of failure + +Other tags +========== + +<signal> +----------- + +- received caught signal + +### attributes ### + +- type: type of signal (e.g. SIGINT) + +### by type ### + +- SIGINT: interactive mode is entered... + +<watch*> +----------- + +- generally emitted on hit watchpoint +- <watchdelete variable="" />: when a variable was unset, the watchpoint is removed too +- <watchhit variable="" />: when ever a watched variable is changed, followed by a <watchdata> container +- <watchdata> may contain + - for watchpoints on variables: + - each of these <watch*> tags conatins a type attribute whose value is either "old" or "new") + - <watchvalue type="" inaccessible="inaccessible" />: old value is inaccessible + - <watchvalue type=""> may contain a <stream> element which indicates the old/new (type attribute) value of the variable + - <watchrefcount type="" refcount="" isref="" />: old/new (type attribute) refcount and isref, both numbers + - isref: if the value is 0, it's not a reference, else it is one + - for watchpoints on arrays: + - <watchsize> inspects size variations of an array (the sum): + - removed: number of elements removed + - added: number of elements added + - <watcharrayptr>: if this tag appears, the internal pointer of the array way changed + +<signalsegv> +--------------- + +- generally emitted when data couldn't be fetched (e.g. by accessing inconsistent data); only used in hard interrupt mode +- it might mean that data couldn't be fetched at all, or that only incomplete data was fetched (e.g. when a fixed number of following attributes are fetched, this tag will mark a stop of fetching if none or not all tags were printed) diff --git a/sapi/phpdbg/zend_mm_structs.h b/sapi/phpdbg/zend_mm_structs.h new file mode 100644 index 0000000000..ca64069e0f --- /dev/null +++ b/sapi/phpdbg/zend_mm_structs.h @@ -0,0 +1,102 @@ +#ifndef ZEND_MM_STRUCTS_H +#define ZEND_MM_STRUCTS_H + +/* structs and macros defined in Zend/zend_alloc.c + Needed for realizing watchpoints and sigsafe memory */ + +#include "zend.h" + +#ifndef ZEND_MM_COOKIES +# define ZEND_MM_COOKIES ZEND_DEBUG +#endif + +#define ZEND_MM_CACHE 1 +#ifndef ZEND_MM_CACHE_STAT +# define ZEND_MM_CACHE_STAT 0 +#endif + +typedef struct _zend_mm_block_info { +#if ZEND_MM_COOKIES + size_t _cookie; +#endif + size_t _size; + size_t _prev; +} zend_mm_block_info; + +typedef struct _zend_mm_small_free_block { + zend_mm_block_info info; +#if ZEND_DEBUG + unsigned int magic; +#ifdef ZTS + THREAD_T thread_id; +#endif +#endif + struct _zend_mm_free_block *prev_free_block; + struct _zend_mm_free_block *next_free_block; +} zend_mm_small_free_block; + +typedef struct _zend_mm_free_block { + zend_mm_block_info info; +#if ZEND_DEBUG + unsigned int magic; +#ifdef ZTS + THREAD_T thread_id; +#endif +#endif + struct _zend_mm_free_block *prev_free_block; + struct _zend_mm_free_block *next_free_block; + + struct _zend_mm_free_block **parent; + struct _zend_mm_free_block *child[2]; +} zend_mm_free_block; + +#define ZEND_MM_SMALL_FREE_BUCKET(heap, index) \ + (zend_mm_free_block *) ((char *)&heap->free_buckets[index * 2] + \ + sizeof(zend_mm_free_block *) * 2 - \ + sizeof(zend_mm_small_free_block)) + +#define ZEND_MM_REST_BUCKET(heap) \ + (zend_mm_free_block *)((char *)&heap->rest_buckets[0] + \ + sizeof(zend_mm_free_block *) * 2 - \ + sizeof(zend_mm_small_free_block)) + +#define ZEND_MM_NUM_BUCKETS (sizeof(size_t) << 3) +struct _zend_mm_heap { + int use_zend_alloc; + void *(*_malloc)(size_t); + void (*_free)(void *); + void *(*_realloc)(void *, size_t); + size_t free_bitmap; + size_t large_free_bitmap; + size_t block_size; + size_t compact_size; + zend_mm_segment *segments_list; + zend_mm_storage *storage; + size_t real_size; + size_t real_peak; + size_t limit; + size_t size; + size_t peak; + size_t reserve_size; + void *reserve; + int overflow; + int internal; +#if ZEND_MM_CACHE + unsigned int cached; + zend_mm_free_block *cache[ZEND_MM_NUM_BUCKETS]; +#endif + zend_mm_free_block *free_buckets[ZEND_MM_NUM_BUCKETS*2]; + zend_mm_free_block *large_free_buckets[ZEND_MM_NUM_BUCKETS]; + zend_mm_free_block *rest_buckets[2]; + int rest_count; +#if ZEND_MM_CACHE_STAT + struct { + int count; + int max_count; + int hit; + int miss; + } cache_stat[ZEND_MM_NUM_BUCKETS+1]; +#endif +}; + +#endif diff --git a/sapi/phttpd/php_phttpd.h b/sapi/phttpd/php_phttpd.h index 47ce22d8f5..af53d188e2 100644 --- a/sapi/phttpd/php_phttpd.h +++ b/sapi/phttpd/php_phttpd.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/phttpd/phttpd.c b/sapi/phttpd/phttpd.c index db1eb600f1..d47cdc94cc 100644 --- a/sapi/phttpd/phttpd.c +++ b/sapi/phttpd/phttpd.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -24,7 +24,7 @@ #ifdef HAVE_PHTTPD #include "ext/standard/info.h" - + #ifndef ZTS #error PHTTPD module is only useable in thread-safe mode #endif @@ -34,7 +34,7 @@ typedef struct { struct connectioninfo *cip; struct stat sb; -} phttpd_globals_struct; +} phttpd_globals_struct; static int ph_globals_id; @@ -53,7 +53,7 @@ php_phttpd_startup(sapi_module_struct *sapi_module) } static int -php_phttpd_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) +php_phttpd_sapi_ub_write(const char *str, uint str_length) { int sent_bytes; @@ -67,16 +67,16 @@ php_phttpd_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) } static int -php_phttpd_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC) +php_phttpd_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers) { char *header_name, *header_content; char *p; - + 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 { @@ -84,7 +84,7 @@ php_phttpd_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_str } while (*header_content == ' '); fd_printf(PHG(cip)->fd,"%s: %s\n", header_name, header_content); - + *p = ':'; } @@ -94,54 +94,54 @@ php_phttpd_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_str } static int -php_phttpd_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +php_phttpd_sapi_send_headers(sapi_headers_struct *sapi_headers) { 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) +php_phttpd_sapi_read_cookies(void) { /* 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; */ fprintf(stderr,"***php_phttpd_sapi_read_cookies\n"); - + return 0; } static int -php_phttpd_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) +php_phttpd_sapi_read_post(char *buf, uint count_bytes) { /* 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; */ fprintf(stderr,"***php_phttpd_sapi_read_post\n"); @@ -151,10 +151,10 @@ php_phttpd_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) static sapi_module_struct phttpd_sapi_module = { "phttpd", "PHTTPD", - + php_phttpd_startup, /* startup */ php_module_shutdown_wrapper, /* shutdown */ - + NULL, /* activate */ NULL, /* deactivate */ @@ -164,14 +164,14 @@ static sapi_module_struct phttpd_sapi_module = { 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, /* Get request time */ @@ -181,7 +181,7 @@ static sapi_module_struct phttpd_sapi_module = { }; static void -php_phttpd_request_ctor(TSRMLS_D TSRMLS_DC) +php_phttpd_request_ctor(void) { memset(&SG(request_info), 0, sizeof(sapi_globals_struct)); /* pfusch! */ @@ -199,12 +199,12 @@ php_phttpd_request_ctor(TSRMLS_D TSRMLS_DC) 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); @@ -214,37 +214,37 @@ php_phttpd_request_ctor(TSRMLS_D TSRMLS_DC) 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) +php_phttpd_request_dtor(void) { free(SG(request_info).path_translated); } -int php_doit(TSRMLS_D) +int php_doit(void) { struct stat sb; zend_file_handle file_handle; struct httpinfo *hip = PHG(cip)->hip; - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { return -1; } @@ -253,9 +253,9 @@ int php_doit(TSRMLS_D) file_handle.free_filename = 0; /* - php_phttpd_hash_environment(TSRMLS_C); + php_phttpd_hash_environment(); */ - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); php_request_shutdown(NULL); return SG(sapi_headers).http_response_code; @@ -281,18 +281,17 @@ int pm_request(struct connectioninfo *cip) { struct httpinfo *hip = cip->hip; int status; - TSRMLS_FETCH(); - if (strcasecmp(hip->method, "GET") == 0 || + 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; + php_phttpd_request_ctor(); + status = php_doit(); + php_phttpd_request_dtor(); + + return status; } else { return -2; } diff --git a/sapi/pi3web/README b/sapi/pi3web/README index e3e523e940..e7726edcf4 100644 --- a/sapi/pi3web/README +++ b/sapi/pi3web/README @@ -1,36 +1,36 @@ -PHP5 Module +PHP7 Module ========== -This module requires PHP5 as thread safe shared library. Have a look +This module requires PHP7 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: +You should have checked out and built the PHP7 source package from the +PHP CVS tree into the Pi3Web source directory called 'PHP7' first. Then +build PHP7 as Pi3Web module and after that build the Pi3Web PHP7 wrapper: -1. Checkout PHP5 +1. Checkout PHP7 ================ 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 +cvs -z3 -d :pserver:cvsread@cvs.php.net:/repository co php7 You must also checkout the TSRM and the ZEND module from the ZEND cvs tree -into the PHP5 root directory +into the PHP7 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. Build PHP7 ============= 2.1 POSIX --------- -cd ./php5 +cd ./php7 ./buildconf ./configure --with-pi3web make @@ -41,10 +41,10 @@ other required downloads from the php website - bison 1.25 - bindlib32 - number4.tar.gz -nmake php5dllts.mak +nmake php7dllts.mak -3. Build Pi3Web PHP5 wrapper +3. Build Pi3Web PHP7 wrapper ============================ -Run make in the Pi3Web /Source/PHP5 directory. +Run make in the Pi3Web /Source/PHP7 directory. For further information refer to http://www.php.net/version4/ diff --git a/sapi/pi3web/config.m4 b/sapi/pi3web/config.m4 index 347a74ca06..42ff164394 100644 --- a/sapi/pi3web/config.m4 +++ b/sapi/pi3web/config.m4 @@ -17,7 +17,7 @@ if test "$PHP_PI3WEB" != "no"; then PHP_ADD_INCLUDE($PI3PATH/PiAPI) PHP_ADD_INCLUDE($PI3PATH/Pi2API) PHP_ADD_INCLUDE($PI3PATH/Pi3API) - PHP_ADD_INCLUDE($PI3PATH/PHP5) + PHP_ADD_INCLUDE($PI3PATH/PHP7) PHP_SELECT_SAPI(pi3web, shared, pi3web_sapi.c) INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PI3PATH/bin/" fi diff --git a/sapi/pi3web/config.w32 b/sapi/pi3web/config.w32 index a5393e621b..9441784468 100644 --- a/sapi/pi3web/config.w32 +++ b/sapi/pi3web/config.w32 @@ -8,7 +8,7 @@ if (PHP_PI3WEB != "no") { 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'); + SAPI('pi3web', 'pi3web_sapi.c', 'php' + PHP_VERSION + 'pi3web.dll', '/D PHP7PI3WEB_EXPORTS'); AC_DEFINE('WITH_PI3WEB', 1); } else { WARNING('Pi3Web not enabled; headers/libraries not found'); diff --git a/sapi/pi3web/php5pi3web.dsp b/sapi/pi3web/php5pi3web.dsp deleted file mode 100644 index bb5a248802..0000000000 --- a/sapi/pi3web/php5pi3web.dsp +++ /dev/null @@ -1,136 +0,0 @@ -# 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 index 4817a67eee..a91660ca6f 100644 --- a/sapi/pi3web/pi3web_sapi.c +++ b/sapi/pi3web/pi3web_sapi.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -52,7 +52,7 @@ static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS) 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 ); + 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"); @@ -71,7 +71,7 @@ static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS) 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><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"); @@ -81,10 +81,10 @@ static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS) /* --- loop over all registered server variables --- */ for(; pIter && PIDBIterator_atValidElement( pIter ); PIDBIterator_next( pIter ) ) - { + { PCHAR pKey; PIDBIterator_current( pIter, &pKey ); - if ( !pKey ) { /* sanity */ continue; }; + if ( !pKey ) { /* sanity */ continue; }; variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; if (lpCB->GetServerVariable(lpCB->ConnID, pKey, variable_buf, &variable_len) @@ -120,11 +120,11 @@ static zend_module_entry php_pi3web_module = { }; -static int zend_pi3web_ub_write(const char *str, uint str_length TSRMLS_DC) +static int zend_pi3web_ub_write(const char *str, uint str_length) { DWORD num_bytes = str_length; LPCONTROL_BLOCK cb; - + cb = (LPCONTROL_BLOCK) SG(server_context); if ( !IWasLoaded ) return 0; @@ -136,19 +136,19 @@ static int zend_pi3web_ub_write(const char *str, uint str_length TSRMLS_DC) } -static int sapi_pi3web_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_pi3web_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers) { return SAPI_HEADER_ADD; } -static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length TSRMLS_DC) +static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length) { *total_length += sapi_header->header_len+2; } -static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr TSRMLS_DC) +static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr) { memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len); *combined_headers_ptr += sapi_header->header_len; @@ -159,30 +159,30 @@ static void concat_header(sapi_header_struct *sapi_header, char **combined_heade } -static int sapi_pi3web_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_pi3web_send_headers(sapi_headers_struct *sapi_headers) { 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); + sapi_get_default_content_type_header(&default_content_type); + accumulate_header_length(&default_content_type, (void *) &total_length); } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) accumulate_header_length, (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); /* 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); + concat_header(&default_content_type, (void *) &combined_headers_ptr); 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); + zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) concat_header, (void *) &combined_headers_ptr); *combined_headers_ptr++ = '\r'; *combined_headers_ptr++ = '\n'; *combined_headers_ptr = 0; @@ -209,7 +209,7 @@ static int php_pi3web_startup(sapi_module_struct *sapi_module) } -static int sapi_pi3web_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static int sapi_pi3web_read_post(char *buffer, uint count_bytes) { LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); DWORD read_from_buf=0; @@ -235,14 +235,14 @@ static int sapi_pi3web_read_post(char *buffer, uint count_bytes TSRMLS_DC) } 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) +static char *sapi_pi3web_read_cookies(void) { LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); char variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE]; @@ -263,7 +263,7 @@ static char *sapi_pi3web_read_cookies(TSRMLS_D) return NULL; } -static void init_request_info(LPCONTROL_BLOCK lpCB TSRMLS_DC) +static void init_request_info(LPCONTROL_BLOCK lpCB) { SG(server_context) = lpCB; SG(request_info).request_method = lpCB->lpszMethod; @@ -277,30 +277,30 @@ static void init_request_info(LPCONTROL_BLOCK lpCB TSRMLS_DC) SG(sapi_headers).http_response_code = 200; } -static void sapi_pi3web_register_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_pi3web_register_variables(zval *track_vars_array) { 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 ); + PIDBIterator *pIter = PIDB_getIterator( pDB, PIDBTYPE_STRING, 0, 0 ); - /* --- loop over all registered server variables --- */ + /* --- loop over all registered server variables --- */ for(; pIter && PIDBIterator_atValidElement( pIter ); PIDBIterator_next( pIter ) ) - { + { PCHAR pKey; PIDBIterator_current( pIter, &pKey ); - if ( !pKey ) { /* sanity */ continue; }; + 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); + php_register_variable(pKey, static_variable_buf, track_vars_array); } 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); + php_register_variable(pKey, variable_buf, track_vars_array); } efree(variable_buf); } @@ -312,7 +312,7 @@ static void sapi_pi3web_register_variables(zval *track_vars_array TSRMLS_DC) 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); + php_register_variable("PHP_SELF", static_variable_buf, track_vars_array); } } @@ -342,11 +342,10 @@ static sapi_module_struct pi3web_sapi_module = { STANDARD_SAPI_MODULE_PROPERTIES }; -MODULE_API DWORD PHP5_wrapper(LPCONTROL_BLOCK lpCB) +MODULE_API DWORD PHP7_wrapper(LPCONTROL_BLOCK lpCB) { zend_file_handle file_handle = {0}; int iRet = PIAPI_COMPLETED; - TSRMLS_FETCH(); zend_first_try { file_handle.filename = lpCB->lpszFileName; @@ -354,20 +353,20 @@ MODULE_API DWORD PHP5_wrapper(LPCONTROL_BLOCK lpCB) file_handle.type = ZEND_HANDLE_FILENAME; file_handle.opened_path = NULL; - init_request_info(lpCB TSRMLS_CC); - php_request_startup(TSRMLS_C); + init_request_info(lpCB); + php_request_startup(); switch ( lpCB->dwBehavior ) { case PHP_MODE_STANDARD: - iRet = ( php_execute_script( &file_handle TSRMLS_CC ) ) ? + iRet = ( php_execute_script( &file_handle ) ) ? 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 ) + if ( open_file_for_scanning( &file_handle ) == SUCCESS ) { php_get_highlight_struct( &syntax_highlighter_ini ); - zend_highlight( &syntax_highlighter_ini TSRMLS_CC ); + zend_highlight( &syntax_highlighter_ini ); } else { @@ -380,10 +379,10 @@ MODULE_API DWORD PHP5_wrapper(LPCONTROL_BLOCK lpCB) ctr.line = "Content-Type: text/plain"; ctr.line_len = strlen(ctr.line); - - sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC); + + sapi_header_op(SAPI_HEADER_REPLACE, &ctr); } - if ( open_file_for_scanning( &file_handle TSRMLS_CC ) == SUCCESS ) + if ( open_file_for_scanning( &file_handle ) == SUCCESS ) { zend_indent(); } @@ -393,7 +392,7 @@ MODULE_API DWORD PHP5_wrapper(LPCONTROL_BLOCK lpCB) }; break; case PHP_MODE_LINT: - iRet = (php_lint_script(&file_handle TSRMLS_CC) == SUCCESS) ? + iRet = (php_lint_script(&file_handle) == SUCCESS) ? PIAPI_COMPLETED : PIAPI_ERROR; break; default: @@ -411,7 +410,7 @@ MODULE_API DWORD PHP5_wrapper(LPCONTROL_BLOCK lpCB) return iRet; } -MODULE_API BOOL PHP5_startup() { +MODULE_API BOOL PHP7_startup() { tsrm_startup(1, 1, 0, NULL); sapi_startup(&pi3web_sapi_module); if (pi3web_sapi_module.startup) { @@ -421,7 +420,7 @@ MODULE_API BOOL PHP5_startup() { return IWasLoaded; }; -MODULE_API BOOL PHP5_shutdown() { +MODULE_API BOOL PHP7_shutdown() { if (pi3web_sapi_module.shutdown) { pi3web_sapi_module.shutdown(&pi3web_sapi_module); }; diff --git a/sapi/pi3web/pi3web_sapi.h b/sapi/pi3web/pi3web_sapi.h index d229fec53f..70eec611b4 100644 --- a/sapi/pi3web/pi3web_sapi.h +++ b/sapi/pi3web/pi3web_sapi.h @@ -3,10 +3,10 @@ #ifdef PHP_WIN32 # include <windows.h> -# ifdef PHP5PI3WEB_EXPORTS -# define MODULE_API __declspec(dllexport) +# ifdef PHP7PI3WEB_EXPORTS +# define MODULE_API __declspec(dllexport) # else -# define MODULE_API __declspec(dllimport) +# define MODULE_API __declspec(dllimport) # endif #else # if defined(__GNUC__) && __GNUC__ >= 4 @@ -86,9 +86,9 @@ typedef struct _CONTROL_BLOCK { } CONTROL_BLOCK, *LPCONTROL_BLOCK; -MODULE_API DWORD PHP5_wrapper(LPCONTROL_BLOCK lpCB); -MODULE_API BOOL PHP5_startup(); -MODULE_API BOOL PHP5_shutdown(); +MODULE_API DWORD PHP7_wrapper(LPCONTROL_BLOCK lpCB); +MODULE_API BOOL PHP7_startup(); +MODULE_API BOOL PHP7_shutdown(); // the following type declaration is for the server side typedef DWORD ( * PFN_WRAPPERFUNC )( CONTROL_BLOCK *pCB ); diff --git a/sapi/roxen/README b/sapi/roxen/README index d834a0000e..59c215cba0 100644 --- a/sapi/roxen/README +++ b/sapi/roxen/README @@ -8,9 +8,9 @@ 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 PHP5 +This solution now works fine and is recommended. Multiple PHP7 requests will be run in parallell. The maximum number of parallell -PHP5-execution is limited to the number of handle threads Roxen is +PHP7-execution is limited to the number of handle threads Roxen is started with. Support for this module is lacking. Please contact Roxen Internet diff --git a/sapi/roxen/TODO b/sapi/roxen/TODO index 248f36f52e..47143f1be1 100644 --- a/sapi/roxen/TODO +++ b/sapi/roxen/TODO @@ -10,18 +10,18 @@ BUGS: And another error (when trying to include a class) Recursive mutex locks! - /Usr/local/pike/7.0.54/lib/modules/PHP5.so.Interpreter: - run("/home/www/www.tx.pl/news/test.php",mapping[3],modules/scripting/php5.pike.PHPScript(),modules/scripting/php5.pike.PHPScript.done) - modules/scripting/php5.pike:169: run() + /Usr/local/pike/7.0.54/lib/modules/PHP7.so.Interpreter: + run("/home/www/www.tx.pl/news/test.php",mapping[3],modules/scripting/php7.pike.PHPScript(),modules/scripting/php7.pike.PHPScript.done) + modules/scripting/php7.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/PHP5.so.Interpreter: - run("/home/www/biall.com.pl/index.php3",mapping[2],modules/scripting/php5.pike.PHPScript(),modules/scripting/php5.pike.PHPScript.done) - modules/scripting/php5.pike:169: run() + callback!/usr/local/pike/7.0.54/lib/modules/PHP7.so.Interpreter: + run("/home/www/biall.com.pl/index.php3",mapping[2],modules/scripting/php7.pike.PHPScript(),modules/scripting/php7.pike.PHPScript.done) + modules/scripting/php7.pike:169: run() base_server/roxen.pike:569: handler_thread(3). diff --git a/sapi/roxen/config.m4 b/sapi/roxen/config.m4 index 7601b0c1ed..d536ac571b 100644 --- a/sapi/roxen/config.m4 +++ b/sapi/roxen/config.m4 @@ -36,7 +36,7 @@ if test "$PHP_ROXEN" != "no"; then 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/PHP5.so" + INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PIKE_MODULE_DIR/PHP7.so" RESULT="yes Pike binary used: $PIKE Pike include dir: $PIKE_INCLUDE_DIR diff --git a/sapi/roxen/roxen.c b/sapi/roxen/roxen.c index 070b47706b..4afba3829c 100644 --- a/sapi/roxen/roxen.c +++ b/sapi/roxen/roxen.c @@ -1,6 +1,6 @@ -/* +/* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -25,7 +25,7 @@ #include "php_ini.h" #include "php_globals.h" #include "SAPI.h" -#include "php_main.h" +#include "php_main.h" #include "ext/standard/info.h" #include "php_version.h" @@ -36,7 +36,7 @@ #endif -/* Pike Include Files +/* 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. @@ -95,7 +95,7 @@ static php_roxen_request *current_request = NULL; # define THIS current_request #endif -/* File descriptor integer. Used to write directly to the FD without +/* File descriptor integer. Used to write directly to the FD without * passing Pike */ #define MY_FD (THIS->my_fd) @@ -121,10 +121,10 @@ static PIKE_MUTEX_T roxen_php_execution_lock; # 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_INIT_LOCK() # define PHP_LOCK(X) # define PHP_UNLOCK(X) -# define PHP_DESTROY() +# define PHP_DESTROY() #endif /* _REENTRANT */ extern int fd_from_object(struct object *o); @@ -153,7 +153,7 @@ 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. + * php-script is the same as the current thread, it fails. */ static int current_thread = -1; @@ -161,7 +161,7 @@ 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; @@ -211,7 +211,7 @@ INLINE static int lookup_integer_header(char *headername, int default_value) */ static int -php_roxen_low_ub_write(const char *str, uint str_length TSRMLS_DC) { +php_roxen_low_ub_write(const char *str, uint str_length) { int sent_bytes = 0; struct pike_string *to_write = NULL; #ifdef ROXEN_USE_ZTS @@ -242,7 +242,7 @@ php_roxen_low_ub_write(const char *str, uint str_length TSRMLS_DC) { */ static int -php_roxen_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) +php_roxen_sapi_ub_write(const char *str, uint str_length) { #ifdef ROXEN_USE_ZTS GET_THIS(); @@ -264,7 +264,7 @@ php_roxen_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) PG(connection_status) = PHP_CONNECTION_ABORTED; zend_bailout(); return sent_bytes; - case EINTR: + case EINTR: case EWOULDBLOCK: continue; } @@ -274,7 +274,7 @@ php_roxen_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) } } } else { - THREAD_SAFE_RUN(sent_bytes = php_roxen_low_ub_write(str, str_length TSRMLS_CC), + THREAD_SAFE_RUN(sent_bytes = php_roxen_low_ub_write(str, str_length), "write"); } return sent_bytes; @@ -300,7 +300,7 @@ static void php_roxen_set_header(char *header_name, char *value, char *p) s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind); if(!s_headermap) { - struct svalue mappie; + struct svalue mappie; mappie.type = PIKE_T_MAPPING; headermap = allocate_mapping(1); mappie.u.mapping = headermap; @@ -319,17 +319,17 @@ static void php_roxen_set_header(char *header_name, char *value, char *p) } /* - * php_roxen_sapi_header_handler() sets a HTTP reply header to be + * 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) + sapi_headers_struct *sapi_headers) { char *header_name, *header_content, *p; header_name = sapi_header->header; header_content = p = strchr(header_name, ':'); - + if(p) { do { header_content++; @@ -346,7 +346,7 @@ php_roxen_sapi_header_handler(sapi_header_struct *sapi_header, */ static int -php_roxen_low_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +php_roxen_low_send_headers(sapi_headers_struct *sapi_headers) { struct pike_string *ind; struct svalue *s_headermap; @@ -359,10 +359,10 @@ php_roxen_low_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) zend_bailout(); return SAPI_HEADER_SEND_FAILED; } - ind = make_shared_string(" _headers"); + 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); @@ -370,15 +370,15 @@ php_roxen_low_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) 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) +php_roxen_sapi_send_headers(sapi_headers_struct *sapi_headers) { int res = 0; - THREAD_SAFE_RUN(res = php_roxen_low_send_headers(sapi_headers TSRMLS_CC), "send headers"); + THREAD_SAFE_RUN(res = php_roxen_low_send_headers(sapi_headers), "send headers"); return res; } @@ -393,8 +393,7 @@ INLINE static int php_roxen_low_read_post(char *buf, uint count_bytes) #ifdef ROXEN_USE_ZTS GET_THIS(); #endif - TSRMLS_FETCH(); - + if(!MY_FD_OBJ->prog) { PG(connection_status) = PHP_CONNECTION_ABORTED; @@ -414,20 +413,20 @@ INLINE static int php_roxen_low_read_post(char *buf, uint count_bytes) } static int -php_roxen_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) +php_roxen_sapi_read_post(char *buf, uint count_bytes) { 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) +php_roxen_sapi_read_cookies(void) { char *cookies; cookies = lookup_string_header("HTTP_COOKIE", NULL); @@ -448,7 +447,7 @@ static void php_info_roxen(ZEND_MODULE_INFO_FUNC_ARGS) 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", + snprintf(buf, 511, "%d day(s), %02d:%02d:%02d", uptime / 86400, (uptime / 3600) % 24, (uptime / 60) % 60, @@ -521,7 +520,7 @@ static sapi_module_struct roxen_sapi_module = { &zvalue, sizeof(zval *), NULL) static void -php_roxen_hash_environment(TSRMLS_D) +php_roxen_hash_environment(void) { int i; char buf[512]; @@ -551,13 +550,13 @@ php_roxen_hash_environment(TSRMLS_D) zvalue->type = IS_STRING; zvalue->value.str.len = val->u.string->len; zvalue->value.str.val = estrndup(val->u.string->str, zvalue->value.str.len); - + zend_hash_update(&EG(symbol_table), buf, buf_len + 1, &zvalue, sizeof(zval *), NULL); } } free_array(indices); } - + /* MAKE_STD_ZVAL(zvalue); zvalue->type = IS_LONG; @@ -571,7 +570,7 @@ php_roxen_hash_environment(TSRMLS_D) * "executes" the script */ -static int php_roxen_module_main(TSRMLS_D) +static int php_roxen_module_main(void) { int res, len; char *dir; @@ -586,14 +585,14 @@ static int php_roxen_module_main(TSRMLS_D) file_handle.opened_path = NULL; THREADS_ALLOW(); - res = php_request_startup(TSRMLS_C); + res = php_request_startup(); THREADS_DISALLOW(); if(res == FAILURE) { return 0; } - php_roxen_hash_environment(TSRMLS_C); + php_roxen_hash_environment(); THREADS_ALLOW(); - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); php_request_shutdown(NULL); THREADS_DISALLOW(); return 1; @@ -614,15 +613,14 @@ void f_php_roxen_request_handler(INT32 args) #ifdef ROXEN_USE_ZTS GET_THIS(); #endif - TSRMLS_FETCH(); if(current_thread == th_self()) - php_error(E_WARNING, "PHP5.Interpreter->run: Tried to run a PHP-script from a PHP " + php_error(E_WARNING, "PHP7.Interpreter->run: Tried to run a PHP-script from a PHP " "callback!"); - get_all_args("PHP5.Interpreter->run", args, "%S%m%O%*", &script, + get_all_args("PHP7.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, "PHP5.Interpreter->run: Bad argument 4, expected function.\n"); + if(done_callback->type != PIKE_T_FUNCTION) + php_error(E_WARNING, "PHP7.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 @@ -648,24 +646,24 @@ void f_php_roxen_request_handler(INT32 args) 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; + /* 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, "PHP5.Interpreter->run: my_fd object not open or not an FD.\n"); + php_error(E_WARNING, "PHP7.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); + + status = php_roxen_module_main(); current_thread = -1; - + apply_svalue(done_callback, 0); pop_stack(); pop_n_elems(args); @@ -694,7 +692,7 @@ void pike_module_init( void ) tsrm_startup(1, 1, 0, NULL); #ifdef ROXEN_USE_ZTS ts_allocate_id(&roxen_globals_id, sizeof(php_roxen_request), NULL, NULL); -#endif +#endif #endif sapi_startup(&roxen_sapi_module); /*php_roxen_startup(&roxen_sapi_module); removed - should be called from SAPI activation*/ diff --git a/sapi/thttpd/config.m4 b/sapi/thttpd/config.m4 index 371edaee84..fddb709d92 100644 --- a/sapi/thttpd/config.m4 +++ b/sapi/thttpd/config.m4 @@ -25,10 +25,10 @@ if test "$PHP_THTTPD" != "no"; then fi PHP_TARGET_RDYNAMIC INSTALL_IT="\ - echo 'PHP_LIBS = -L. -lphp5 \$(PHP_LIBS) \$(EXTRA_LIBS)' > $THTTPD/php_makefile; \ + echo 'PHP_LIBS = -L. -lphp7 \$(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; \ - rm -f $THTTPD/php_thttpd.c $THTTPD/php_thttpd.h $THTTPD/libphp5.a; \ + rm -f $THTTPD/php_thttpd.c $THTTPD/php_thttpd.h $THTTPD/libphp7.a; \ \$(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/;\ $patch" diff --git a/sapi/thttpd/php_thttpd.h b/sapi/thttpd/php_thttpd.h index bd6dc7c1c9..ace252a356 100644 --- a/sapi/thttpd/php_thttpd.h +++ b/sapi/thttpd/php_thttpd.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/thttpd/thttpd.c b/sapi/thttpd/thttpd.c index dbd5626961..ad4e8e366e 100644 --- a/sapi/thttpd/thttpd.c +++ b/sapi/thttpd/thttpd.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -27,7 +27,7 @@ #include "php_ini.h" #include "zend_highlight.h" -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" #include <sys/time.h> #include <sys/types.h> @@ -64,16 +64,16 @@ static php_thttpd_globals thttpd_globals; #define TG(v) (thttpd_globals.v) #endif -static int sapi_thttpd_ub_write(const char *str, uint str_length TSRMLS_DC) +static int sapi_thttpd_ub_write(const char *str, uint str_length) { int n; uint sent = 0; - + if (TG(sbuf).c != 0) { smart_str_appendl_ex(&TG(sbuf), str, str_length, 1); return str_length; } - + while (str_length > 0) { PHP_SYS_CALL(n = send(TG(hc)->conn_fd, str, str_length, 0);); @@ -103,7 +103,7 @@ static int sapi_thttpd_ub_write(const char *str, uint str_length TSRMLS_DC) # endif #endif -static int do_writev(struct iovec *vec, int nvec, int len TSRMLS_DC) +static int do_writev(struct iovec *vec, int nvec, int len) { int n; @@ -148,7 +148,7 @@ static int do_writev(struct iovec *vec, int nvec, int len TSRMLS_DC) smart_str_appendl_ex(&TG(sbuf), vec->iov_base, vec->iov_len, 1); } } - + return 0; } @@ -170,7 +170,7 @@ static int do_writev(struct iovec *vec, int nvec, int len TSRMLS_DC) #define KA_NO "Connection: close\r\n" #define DEF_CT "Content-Type: text/html\r\n" -static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers) { char buf[1024], *p; VEC_BASE(); @@ -178,15 +178,15 @@ static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) zend_llist_position pos; sapi_header_struct *h; size_t len = 0; - + if (!SG(sapi_headers).http_status_line) { ADD_VEC_S("HTTP/1.1 "); - p = smart_str_print_long(buf+sizeof(buf)-1, + p = zend_print_long_to_buf(buf+sizeof(buf)-1, SG(sapi_headers).http_response_code); ADD_VEC(p, strlen(p)); ADD_VEC_S(" HTTP\r\n"); } else { - ADD_VEC(SG(sapi_headers).http_status_line, + ADD_VEC(SG(sapi_headers).http_status_line, strlen(SG(sapi_headers).http_status_line)); ADD_VEC("\r\n", 2); } @@ -198,7 +198,7 @@ static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) h = zend_llist_get_first_ex(&sapi_headers->headers, &pos); while (h) { - + switch (h->header[0]) { case 'c': case 'C': if (!TG(seen_cl) && strncasecmp(h->header, CL_TOKEN, sizeof(CL_TOKEN)-1) == 0) { @@ -211,12 +211,12 @@ static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) ADD_VEC(h->header, h->header_len); #ifndef SERIALIZE_HEADERS if (n >= COMBINE_HEADERS - 1) { - len = do_writev(vec, n, len TSRMLS_CC); + len = do_writev(vec, n, len); n = 0; } #endif ADD_VEC("\r\n", 2); - + h = zend_llist_get_next_ex(&sapi_headers->headers, &pos); } @@ -226,13 +226,13 @@ static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) TG(hc)->do_keep_alive = 0; ADD_VEC(KA_NO, sizeof(KA_NO)-1); } - + ADD_VEC("\r\n", 2); #ifdef SERIALIZE_HEADERS - sapi_thttpd_ub_write(vec_str.c, vec_str.len TSRMLS_CC); -#else - do_writev(vec, n, len TSRMLS_CC); + sapi_thttpd_ub_write(vec_str.c, vec_str.len); +#else + do_writev(vec, n, len); #endif VEC_FREE(); @@ -245,7 +245,7 @@ static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) #define CONSUME_BYTES(n) do { TG(hc)->checked_idx += (n); } while (0) -static int sapi_thttpd_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static int sapi_thttpd_read_post(char *buffer, uint count_bytes) { size_t read_bytes = 0; @@ -255,45 +255,45 @@ static int sapi_thttpd_read_post(char *buffer, uint count_bytes TSRMLS_DC) TG(unconsumed_length) -= read_bytes; CONSUME_BYTES(read_bytes); } - + return read_bytes; } -static char *sapi_thttpd_read_cookies(TSRMLS_D) +static char *sapi_thttpd_read_cookies(void) { return TG(hc)->cookie; } #define BUF_SIZE 512 #define ADD_STRING_EX(name,buf) \ - php_register_variable(name, buf, track_vars_array TSRMLS_CC) + php_register_variable(name, buf, track_vars_array) #define ADD_STRING(name) ADD_STRING_EX((name), buf) -static void sapi_thttpd_register_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_thttpd_register_variables(zval *track_vars_array) { 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); + php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array); + php_register_variable("SERVER_SOFTWARE", SERVER_SOFTWARE, track_vars_array); + php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array); + php_register_variable("REQUEST_METHOD", (char *) SG(request_info).request_method, track_vars_array); + php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array); + php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, track_vars_array); if (TG(hc)->one_one) { - php_register_variable("SERVER_PROTOCOL", "HTTP/1.1", track_vars_array TSRMLS_CC); + php_register_variable("SERVER_PROTOCOL", "HTTP/1.1", track_vars_array); } else { - php_register_variable("SERVER_PROTOCOL", "HTTP/1.0", track_vars_array TSRMLS_CC); + php_register_variable("SERVER_PROTOCOL", "HTTP/1.0", track_vars_array); } - p = httpd_ntoa(&TG(hc)->client_addr); - + p = httpd_ntoa(&TG(hc)->client_addr); + ADD_STRING_EX("REMOTE_ADDR", p); ADD_STRING_EX("REMOTE_HOST", p); ADD_STRING_EX("SERVER_PORT", - smart_str_print_long(buf + sizeof(buf) - 1, + zend_print_long_to_buf(buf + sizeof(buf) - 1, TG(hc)->hs->port)); buf[0] = '/'; @@ -306,7 +306,7 @@ static void sapi_thttpd_register_variables(zval *track_vars_array TSRMLS_DC) #define CONDADD(name, field) \ if (TG(hc)->field[0]) { \ - php_register_variable(#name, TG(hc)->field, track_vars_array TSRMLS_CC); \ + php_register_variable(#name, TG(hc)->field, track_vars_array); \ } CONDADD(QUERY_STRING, query); @@ -323,12 +323,12 @@ static void sapi_thttpd_register_variables(zval *track_vars_array TSRMLS_DC) if (TG(hc)->contentlength != -1) { ADD_STRING_EX("CONTENT_LENGTH", - smart_str_print_long(buf + sizeof(buf) - 1, + zend_print_long_to_buf(buf + sizeof(buf) - 1, TG(hc)->contentlength)); } if (TG(hc)->authorization[0]) - php_register_variable("AUTH_TYPE", "Basic", track_vars_array TSRMLS_CC); + php_register_variable("AUTH_TYPE", "Basic", track_vars_array); } static PHP_MINIT_FUNCTION(thttpd) @@ -354,6 +354,7 @@ static int php_thttpd_startup(sapi_module_struct *sapi_module) #if PHP_API_VERSION >= 20020918 if (php_module_startup(sapi_module, &php_thttpd_module, 1) == FAILURE) { #else + /* No here to zend_startup_module() as 5.6 and older does not have that parameter */ if (php_module_startup(sapi_module) == FAILURE || zend_startup_module(&php_thttpd_module) == FAILURE) { #endif @@ -362,7 +363,7 @@ static int php_thttpd_startup(sapi_module_struct *sapi_module) return SUCCESS; } -static int sapi_thttpd_get_fd(int *nfd TSRMLS_DC) +static int sapi_thttpd_get_fd(int *nfd) { if (nfd) *nfd = TG(hc)->conn_fd; return SUCCESS; @@ -371,10 +372,10 @@ static int sapi_thttpd_get_fd(int *nfd TSRMLS_DC) static sapi_module_struct thttpd_sapi_module = { "thttpd", "thttpd", - + php_thttpd_startup, php_module_shutdown_wrapper, - + NULL, /* activate */ NULL, /* deactivate */ @@ -384,7 +385,7 @@ static sapi_module_struct thttpd_sapi_module = { NULL, /* getenv */ php_error, - + NULL, sapi_thttpd_send_headers, NULL, @@ -407,32 +408,32 @@ static sapi_module_struct thttpd_sapi_module = { sapi_thttpd_get_fd }; -static void thttpd_module_main(int show_source TSRMLS_DC) +static void thttpd_module_main(int show_source) { zend_file_handle file_handle; - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { return; } - + if (show_source) { zend_syntax_highlighter_ini syntax_highlighter_ini; php_get_highlight_struct(&syntax_highlighter_ini); - highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC); + highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini); } else { file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = SG(request_info).path_translated; file_handle.free_filename = 0; file_handle.opened_path = NULL; - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); } - + php_request_shutdown(NULL); } -static void thttpd_request_ctor(TSRMLS_D) +static void thttpd_request_ctor(void) { smart_str s = {0}; @@ -445,7 +446,7 @@ static void thttpd_request_ctor(TSRMLS_D) 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); @@ -461,13 +462,13 @@ static void thttpd_request_ctor(TSRMLS_D) : TG(hc)->contentlength; TG(unconsumed_length) = SG(request_info).content_length; - - php_handle_auth_data(TG(hc)->authorization TSRMLS_CC); + + php_handle_auth_data(TG(hc)->authorization); } -static void thttpd_request_dtor(TSRMLS_D) +static void thttpd_request_dtor(void) { - smart_str_free_ex(&TG(sbuf), 1); + smart_str_free(&TG(sbuf)); if (SG(request_info).query_string) free(SG(request_info).query_string); free(SG(request_info).request_uri); @@ -527,7 +528,7 @@ static httpd_conn *duplicate_conn(httpd_conn *hc, httpd_conn *nhc) #define HANDLE_STR(m) nhc->m = nhc->m ? strdup(nhc->m) : NULL HANDLE_STRINGS(); #undef HANDLE_STR - + return nhc; } @@ -542,7 +543,7 @@ static httpd_conn *dequeue_request(void) { httpd_conn *ret = NULL; qreq_t *m; - + tsrm_mutex_lock(qr_lock); if (queued_requests) { m = queued_requests; @@ -552,7 +553,7 @@ static httpd_conn *dequeue_request(void) free(m); } tsrm_mutex_unlock(qr_lock); - + return ret; } @@ -562,7 +563,7 @@ static void queue_request(httpd_conn *hc) { qreq_t *m; httpd_conn *nhc; - + /* Mark as long-running request */ hc->file_address = (char *) 1; @@ -572,17 +573,17 @@ static void queue_request(httpd_conn *hc) */ 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 threshold */ 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); } @@ -595,7 +596,7 @@ static void queue_request(httpd_conn *hc) tsrm_mutex_unlock(qr_lock); } -static off_t thttpd_real_php_request(httpd_conn *hc, int TSRMLS_DC); +static off_t thttpd_real_php_request(httpd_conn *hc, int); static void *worker_thread(void *dummy) { @@ -614,7 +615,7 @@ static void *worker_thread(void *dummy) thread_atomic_dec(nr_free_threads); - thttpd_real_php_request(hc, 0 TSRMLS_CC); + thttpd_real_php_request(hc, 0); shutdown(hc->conn_fd, 0); destroy_conn(hc); free(hc); @@ -653,7 +654,7 @@ static void remove_dead_conn(int fd) #endif -static off_t thttpd_real_php_request(httpd_conn *hc, int show_source TSRMLS_DC) +static off_t thttpd_real_php_request(httpd_conn *hc, int show_source) { TG(hc) = hc; hc->bytes_sent = 0; @@ -662,26 +663,26 @@ static off_t thttpd_real_php_request(httpd_conn *hc, int show_source TSRMLS_DC) hc->should_linger = 1; hc->do_keep_alive = 0; } - + if (hc->contentlength != -1 && SIZEOF_UNCONSUMED_BYTES() < hc->contentlength) { hc->read_body_into_mem = 1; return 0; } - - thttpd_request_ctor(TSRMLS_C); - thttpd_module_main(show_source TSRMLS_CC); + thttpd_request_ctor(); + + thttpd_module_main(show_source); /* disable kl, if no content-length was seen or Connection: was set */ if (TG(seen_cl) == 0 || TG(seen_cn) == 1) { TG(hc)->do_keep_alive = 0; } - + if (TG(sbuf).c != 0) { if (TG(hc)->response) free(TG(hc)->response); - + TG(hc)->response = TG(sbuf).c; TG(hc)->responselen = TG(sbuf).len; TG(hc)->maxresponse = TG(sbuf).a; @@ -691,7 +692,7 @@ static off_t thttpd_real_php_request(httpd_conn *hc, int show_source TSRMLS_DC) TG(sbuf).a = 0; } - thttpd_request_dtor(TSRMLS_C); + thttpd_request_dtor(); return 0; } @@ -701,32 +702,27 @@ off_t thttpd_php_request(httpd_conn *hc, int show_source) #ifdef ZTS queue_request(hc); #else - TSRMLS_FETCH(); - return thttpd_real_php_request(hc, show_source TSRMLS_CC); + return thttpd_real_php_request(hc, show_source); #endif } -void thttpd_register_on_close(void (*arg)(int)) +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(); #ifndef PREMIUM_THTTPD TG(hc)->file_address = (char *) 1; #endif @@ -750,9 +746,8 @@ void thttpd_php_init(void) sapi_startup(&thttpd_sapi_module); thttpd_sapi_module.startup(&thttpd_sapi_module); - + { - TSRMLS_FETCH(); SG(server_context) = (void *) 1; } @@ -760,7 +755,6 @@ void thttpd_php_init(void) void thttpd_php_shutdown(void) { - TSRMLS_FETCH(); if (SG(server_context) != NULL) { thttpd_sapi_module.shutdown(&thttpd_sapi_module); diff --git a/sapi/thttpd/thttpd_patch b/sapi/thttpd/thttpd_patch index f6e45d5f15..1463d8fe0a 100644 --- a/sapi/thttpd/thttpd_patch +++ b/sapi/thttpd/thttpd_patch @@ -34,7 +34,7 @@ diff -ur thttpd-2.21b/Makefile.in thttpd-2.21b-cool/Makefile.in this: $(ALL) -thttpd: $(OBJ) -+thttpd: $(OBJ) libphp5.a ++thttpd: $(OBJ) libphp7.a @rm -f $@ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(NETLIBS) @@ -240,7 +240,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c + +#define SMART_STR_USE_REALLOC + -+#include "ext/standard/php_smart_str.h" ++#include "zend_smart_str.h" static void -send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod ) diff --git a/sapi/tux/README b/sapi/tux/README index 92c021123f..3c5ebc56ba 100644 --- a/sapi/tux/README +++ b/sapi/tux/README @@ -56,31 +56,31 @@ BUILD INSTRUCTIONS $ ./configure --help - 3. Touch a file in your web-root 'php5.tux'. This will - cause requests to '/php5.tux' to be redirected to the - userspace module php5.tux. + 3. Touch a file in your web-root 'php7.tux'. This will + cause requests to '/php7.tux' to be redirected to the + userspace module php7.tux. 4. Start TUX with something like - # tux -d -t 8 -r /www -m /tux-modules php5.tux + # tux -d -t 8 -r /www -m /tux-modules php7.tux (daemon mode, eight threads, web-root /www, modules in - /tux-modules, load php5.tux) + /tux-modules, load php7.tux) BEFORE running this command, the kernel side of TUX has to be properly setup. 5. Try to access - http://yourserver/php5.tux?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000 + http://yourserver/php7.tux?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000 It should display the PHP credits page. To access a script /foo/bar.php, use - http://yourserver/php5.tux?/foo/bar.php + http://yourserver/php7.tux?/foo/bar.php Parameters can be appended: - http://yourserver/php5.tux?/foo/bar.php&var=value + http://yourserver/php7.tux?/foo/bar.php&var=value diff --git a/sapi/tux/config.m4 b/sapi/tux/config.m4 index 06788be757..db4be82cf1 100644 --- a/sapi/tux/config.m4 +++ b/sapi/tux/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_WITH(tux,, AC_MSG_CHECKING([for TUX]) if test "$PHP_TUX" != "no"; then - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PHP_TUX/php5.tux.so" + INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PHP_TUX/php7.tux.so" AC_CHECK_HEADERS(tuxmodule.h,[:],[AC_MSG_ERROR([Cannot find tuxmodule.h])]) PHP_SELECT_SAPI(tux, shared, php_tux.c) AC_MSG_RESULT([$PHP_TUX]) diff --git a/sapi/tux/php_tux.c b/sapi/tux/php_tux.c index 290c88c766..11755e18e2 100644 --- a/sapi/tux/php_tux.c +++ b/sapi/tux/php_tux.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -21,7 +21,7 @@ #include "php_main.h" #include "php_variables.h" -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" #include "tuxmodule.h" @@ -49,20 +49,20 @@ 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) +static int sapi_tux_ub_write(const char *str, uint str_length) { 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(); @@ -75,7 +75,7 @@ static int sapi_tux_ub_write(const char *str, uint str_length TSRMLS_DC) } estr = str + str_length; - + while (str < estr) { n = send(TG(req)->sock, str, estr - str, 0); @@ -83,14 +83,14 @@ static int sapi_tux_ub_write(const char *str, uint str_length TSRMLS_DC) php_handle_aborted_connection(); if (n == -1 && errno == EAGAIN) continue; - if (n <= 0) + if (n <= 0) return n; str += n; } n = str_length - (estr - str); - + TG(req)->bytes_sent += n; return n; @@ -107,35 +107,34 @@ static int sapi_tux_send_headers(sapi_headers_struct *sapi_headers) 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 = slprintf(status_line, 30, "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 + 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) { @@ -144,7 +143,7 @@ static int sapi_tux_send_headers(sapi_headers_struct *sapi_headers) } vec[n].iov_base = "\r\n"; vec[n++].iov_len = 2; - + h = zend_llist_get_next_ex(&sapi_headers->headers, &pos); } @@ -154,7 +153,7 @@ static int sapi_tux_send_headers(sapi_headers_struct *sapi_headers) TG(number_vec) = n; TG(header_vec) = vec; - + return SAPI_HEADER_SENT_SUCCESSFULLY; } @@ -162,7 +161,6 @@ 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; @@ -170,7 +168,7 @@ static int sapi_tux_read_post(char *buffer, uint count_bytes) return 0; TG(read_post_data) = 1; - + return TG(req)->objectlen; #else return 0; @@ -179,33 +177,31 @@ static int sapi_tux_read_post(char *buffer, uint count_bytes) 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) + php_register_variable(name, buf, track_vars_array) -static void sapi_tux_register_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_tux_register_variables(zval *track_vars_array) { char buf[BUF_SIZE + 1]; char *p; sapi_header_line ctr = {0}; - + ctr.line = buf; ctr.line_len = slprintf(buf, sizeof(buf), "Server: %s", TUXAPI_version); - sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC); - - php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array TSRMLS_CC); - php_register_variable("SERVER_SOFTWARE", TUXAPI_version, track_vars_array TSRMLS_CC); - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array TSRMLS_CC); - php_register_variable("REQUEST_METHOD", (char *) SG(request_info).request_method, track_vars_array TSRMLS_CC); - php_register_variable("DOCUMENT_ROOT", TUXAPI_docroot, track_vars_array TSRMLS_CC); - php_register_variable("SERVER_NAME", TUXAPI_servername, track_vars_array TSRMLS_CC); - php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array TSRMLS_CC); - php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, track_vars_array TSRMLS_CC); + sapi_header_op(SAPI_HEADER_REPLACE, &ctr); + + php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array); + php_register_variable("SERVER_SOFTWARE", TUXAPI_version, track_vars_array); + php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array); + php_register_variable("REQUEST_METHOD", (char *) SG(request_info).request_method, track_vars_array); + php_register_variable("DOCUMENT_ROOT", TUXAPI_docroot, track_vars_array); + php_register_variable("SERVER_NAME", TUXAPI_servername, track_vars_array); + php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array); + php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, track_vars_array); p = inet_ntoa(TG(req)->client_host); /* string representation of IPs are never larger than 512 bytes */ @@ -228,7 +224,7 @@ static void sapi_tux_register_variables(zval *track_vars_array TSRMLS_DC) #define CONDADD(name, field) \ if (TG(req)->field[0]) { \ - php_register_variable(#name, TG(req)->field, track_vars_array TSRMLS_CC); \ + php_register_variable(#name, TG(req)->field, track_vars_array); \ } CONDADD(HTTP_REFERER, referer); @@ -248,7 +244,7 @@ static void sapi_tux_register_variables(zval *track_vars_array TSRMLS_DC) #if 0 if (TG(hc)->authorization[0]) - php_register_variable("AUTH_TYPE", "Basic", track_vars_array TSRMLS_CC); + php_register_variable("AUTH_TYPE", "Basic", track_vars_array); #endif } @@ -265,10 +261,10 @@ static int php_tux_startup(sapi_module_struct *sapi_module) static sapi_module_struct tux_sapi_module = { "tux", "tux", - + php_tux_startup, php_module_shutdown_wrapper, - + NULL, /* activate */ NULL, /* deactivate */ @@ -278,7 +274,7 @@ static sapi_module_struct tux_sapi_module = { NULL, /* getenv */ php_error, - + NULL, sapi_tux_send_headers, NULL, @@ -293,7 +289,7 @@ static sapi_module_struct tux_sapi_module = { STANDARD_SAPI_MODULE_PROPERTIES }; -static void tux_module_main(TSRMLS_D) +static void tux_module_main(void) { zend_file_handle file_handle; @@ -302,15 +298,15 @@ static void tux_module_main(TSRMLS_D) file_handle.free_filename = 0; file_handle.opened_path = NULL; - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { return; } - - php_execute_script(&file_handle TSRMLS_CC); + + php_execute_script(&file_handle); php_request_shutdown(NULL); } -static void tux_request_ctor(TSRMLS_D) +static void tux_request_ctor(void) { char buf[1024]; int offset; @@ -319,7 +315,7 @@ static void tux_request_ctor(TSRMLS_D) smart_str s = {0}; char *p; - TG(number_vec) = 0; + TG(number_vec) = 0; TG(header_vec) = NULL; SG(request_info).query_string = strdup(TG(req)->query); @@ -330,7 +326,7 @@ static void tux_request_ctor(TSRMLS_D) 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); @@ -344,11 +340,11 @@ static void tux_request_ctor(TSRMLS_D) SG(request_info).content_length = 0; /* TG(req)->contentlength; */ #if 0 - php_handle_auth_data(TG(hc)->authorization TSRMLS_CC); + php_handle_auth_data(TG(hc)->authorization); #endif } -static void tux_request_dtor(TSRMLS_D) +static void tux_request_dtor(void) { if (TG(header_vec)) { /* free status_line */ @@ -366,14 +362,14 @@ 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 @@ -385,47 +381,43 @@ static void *separate_thread(void *bla) 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_ctor(); + + tux_module_main(); - tux_request_dtor(TSRMLS_C); + tux_request_dtor(); return tux(TG(tux_action), req); } -void tux_register_on_close(void (*arg)(int)) +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)); diff --git a/sapi/webjames/README b/sapi/webjames/README index 746a7762fb..15a7be3de0 100644 --- a/sapi/webjames/README +++ b/sapi/webjames/README @@ -16,7 +16,7 @@ http://www.webjames.alexwaugh.com/ BUILDING -$ cd php5 +$ cd php7 $ ./configure \ --host=arm-riscos-aof \ --with-webjames=../webjames/src \ diff --git a/sapi/webjames/php_webjames.h b/sapi/webjames/php_webjames.h index dd2e8ceff9..63a9b047fb 100644 --- a/sapi/webjames/php_webjames.h +++ b/sapi/webjames/php_webjames.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/webjames/webjames.c b/sapi/webjames/webjames.c index 7a054fb457..02c7dcf1c1 100644 --- a/sapi/webjames/webjames.c +++ b/sapi/webjames/webjames.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -39,7 +39,7 @@ 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) +static int sapi_webjames_ub_write(const char *str, uint str_length) /*unbuffered write - send data straight out to socket*/ { int totalbytes = 0; @@ -61,7 +61,7 @@ static int sapi_webjames_ub_write(const char *str, uint str_length TSRMLS_DC) return totalbytes; } -static void sapi_webjames_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) +static void sapi_webjames_send_header(sapi_header_struct *sapi_header, void *server_context) /*send an HTTP header*/ { char *header = sapi_header->header; @@ -84,7 +84,7 @@ static void sapi_webjames_send_header(sapi_header_struct *sapi_header, void *ser } } -static int sapi_webjames_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static int sapi_webjames_read_post(char *buffer, uint count_bytes) /*read some of the post data*/ { if (WG(conn)->body==NULL) return 0; @@ -94,26 +94,26 @@ static int sapi_webjames_read_post(char *buffer, uint count_bytes TSRMLS_DC) return count_bytes; } -static char *sapi_webjames_read_cookies(TSRMLS_D) +static char *sapi_webjames_read_cookies(void) { return WG(conn)->cookie; } #define BUF_SIZE 512 #define ADD_STRING(name,string)\ - php_register_variable(name, string, track_vars_array TSRMLS_CC) + php_register_variable(name, string, track_vars_array) #define ADD_NUM(name,field) {\ snprintf(buf, BUF_SIZE, "%d", WG(conn)->field);\ - php_register_variable(name, buf, track_vars_array TSRMLS_CC);\ + php_register_variable(name, buf, track_vars_array);\ } #define ADD_FIELD(name, field) \ if (WG(conn)->field) { \ - php_register_variable(name, WG(conn)->field, track_vars_array TSRMLS_CC); \ + php_register_variable(name, WG(conn)->field, track_vars_array); \ } -static void sapi_webjames_register_variables(zval *track_vars_array TSRMLS_DC) +static void sapi_webjames_register_variables(zval *track_vars_array) { char buf[BUF_SIZE + 1]; char *docroot; @@ -137,7 +137,7 @@ static void sapi_webjames_register_variables(zval *track_vars_array TSRMLS_DC) 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); @@ -163,7 +163,7 @@ static void sapi_webjames_register_variables(zval *track_vars_array TSRMLS_DC) ADD_FIELD("HTTP_ACCEPT_ENCODING", acceptencoding); } -static void webjames_module_main(TSRMLS_D) +static void webjames_module_main(void) { zend_file_handle file_handle; FILE *fp=NULL; @@ -208,18 +208,17 @@ static void webjames_module_main(TSRMLS_D) file_handle.free_filename = 0; file_handle.opened_path = NULL; - if (php_request_startup(TSRMLS_C) == FAILURE) { + if (php_request_startup() == FAILURE) { return; } - - php_execute_script(&file_handle TSRMLS_CC); + + php_execute_script(&file_handle); 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); @@ -228,14 +227,13 @@ static void webjames_php_close(struct connection *conn, int 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); + webjames_module_main(); WG(oldclose)(WG(conn), 0); } @@ -260,7 +258,7 @@ static zend_module_entry php_webjames_module = { NULL, php_info_webjames, #if ZEND_MODULE_API_NO >= 20010901 - WEBJAMES_SAPI_VERSION, + WEBJAMES_SAPI_VERSION, #endif STANDARD_MODULE_PROPERTIES }; @@ -309,7 +307,6 @@ static sapi_module_struct sapi_module = { 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*/ |
