cvs: pecl /phk PHK.c PHK_Mgr.c PHK_Stream.c PHK_Stream.h package.xml php_phk.c php_phk.h utils.c utils.h /phk/tests 002_techinfo.phpt
| From: | Francois Laupretre | Date: | Sat, 19 Jan 2008 02:54:39 +0000 |
| Subject: | cvs: pecl /phk PHK.c PHK_Mgr.c PHK_Stream.c PHK_Stream.h package.xml php_phk.c php_phk.h utils.c utils.h /phk/tests 002_techinfo.phpt | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-9559@lists.php.net to get a copy of this message | ||
francois Sat Jan 19 02:54:39 2008 UTC
Modified files:
/pecl/phk PHK.c PHK_Mgr.c PHK_Stream.c PHK_Stream.h package.xml
php_phk.c php_phk.h utils.c utils.h
/pecl/phk/tests 002_techinfo.phpt
Log:
Bug fixes
http://cvs.php.net/viewvc.cgi/pecl/phk/PHK.c?r1=1.4&r2=1.5&diff_format=u Index: pecl/phk/PHK.c diff -u pecl/phk/PHK.c:1.4 pecl/phk/PHK.c:1.5 --- pecl/phk/PHK.c:1.4 Thu Jan 10 02:34:52 2008 +++ pecl/phk/PHK.c Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: PHK.c,v 1.4 2008/01/10 02:34:52 francois Exp $ */ +/* $Id: PHK.c,v 1.5 2008/01/19 02:54:38 francois Exp $ */ #define PHK_VERSION "1.4.0" @@ -76,7 +76,9 @@ \ DBG_MSG("Entering PHK::" #_func); \ CHECK_MEM(); \ - FIND_HKEY(Z_OBJPROP_P(getThis()),m,&_tmp); \ + if (FIND_HKEY(Z_OBJPROP_P(getThis()),mp_property_name,&_tmp)!=SUCCESS) { ; \ + EXCEPTION_ABORT("Accessing invalid or unmounted object"); \ + } \ mp= *((PHK_Mnt_Info **)(Z_STRVAL_PP(_tmp))); /*---------------------------------------------------------------*/ @@ -142,8 +144,8 @@ static void PHK_set_mp_property(zval * obj, PHK_Mnt_Info * mp TSRMLS_DC) { - add_property_stringl_ex(obj, "m", 2, (char *) (&mp), sizeof(mp), - 1 TSRMLS_CC); + zend_update_property_stringl(Z_OBJCE_P(obj),obj,"m",1,(char *)(&mp) + , sizeof(mp) TSRMLS_CC); } /*---------------------------------------------------------------*/ @@ -953,6 +955,24 @@ /* }}} */ /*---------------------------------------------------------------*/ +/* {{{ proto void PHK::accel_techinfo() */ + +static PHP_METHOD(PHK, accel_techinfo) +{ + if (sapi_module.phpinfo_as_text) { + php_printf("Using PHK Accelerator: Yes\n"); + php_printf("Accelerator Version: %s\n", PHK_ACCEL_VERSION); + } else { + php_printf("<table border=0>"); + php_printf("<tr><td>Using PHK Accelerator: </td><td>Yes</td></tr>"); + php_printf("<tr><td>Accelerator Version: </td><td>%s</td></tr>", + PHK_ACCEL_VERSION); + php_printf("</table>"); + } +} + +/* }}} */ +/*---------------------------------------------------------------*/ /* {{{ proto string PHK::prolog(string file, mixed &cmd, mixed &ret) */ /* Undocumented - called by the PHK runtime code only */ @@ -967,6 +987,12 @@ DBG_MSG("Entering Prolog"); + /* Workaround to PHP bug #39903 (__COMPILER_HALT_OFFSET__ already defined) */ + /* Not perfect but can suppress further notice messages */ + + (void)zend_hash_del(EG(zend_constants),"__COMPILER_HALT_OFFSET__" + ,sizeof("__COMPILER_HALT_OFFSET__")); + if (zend_parse_parameters (ZEND_NUM_ARGS()TSRMLS_CC, "zzz", &file, &cmd, &ret) == FAILURE) EXCEPTION_ABORT_1("Cannot parse parameters", 0); @@ -1067,7 +1093,8 @@ ZEND_END_ARG_INFO() /*---------------------------------------------------------------*/ - static zend_function_entry PHK_functions[] = { + +static zend_function_entry PHK_functions[] = { PHP_ME(PHK, need_php_runtime, UT_noarg_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_ME(PHK, __construct, UT_1arg_arginfo, ZEND_ACC_PUBLIC) @@ -1105,6 +1132,8 @@ PHP_ME(PHK, __call, UT_2args_arginfo, ZEND_ACC_PUBLIC) PHP_ME(PHK, prolog, PHK_prolog_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(PHK, accel_techinfo, UT_noarg_arginfo, + ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) {NULL, NULL, NULL, 0, 0} }; @@ -1155,6 +1184,9 @@ INIT_CLASS_ENTRY(ce, "PHK", PHK_functions); entry = zend_register_internal_class(&ce TSRMLS_CC); + + zend_declare_property_null(entry,"m",1,ZEND_ACC_PRIVATE TSRMLS_CC); + set_constants(entry); /*--- Init mime table */ http://cvs.php.net/viewvc.cgi/pecl/phk/PHK_Mgr.c?r1=1.5&r2=1.6&diff_format=u Index: pecl/phk/PHK_Mgr.c diff -u pecl/phk/PHK_Mgr.c:1.5 pecl/phk/PHK_Mgr.c:1.6 --- pecl/phk/PHK_Mgr.c:1.5 Fri Jan 11 23:26:59 2008 +++ pecl/phk/PHK_Mgr.c Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: PHK_Mgr.c,v 1.5 2008/01/11 23:26:59 francois Exp $ */ +/* $Id: PHK_Mgr.c,v 1.6 2008/01/19 02:54:38 francois Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -32,7 +32,6 @@ #include "utils.h" #include "PHK.h" #include "PHK_Mgr.h" -#include "phk_stream_parse_uri2.h" ZEND_EXTERN_MODULE_GLOBALS(phk) @@ -75,7 +74,7 @@ static int tmp_mnt_num; -MutexDeclare(persistent_mtab); +static MutexDeclare(persistent_mtab); /*---------------------------------------------------------------*/ @@ -873,14 +872,13 @@ zval subpath, tmp_mnt, tmp_parent_mnt; int len; char *p; - php_stream_statbuf ssb; PHK_Mnt_Info *parent_mp; time_t mti; INIT_PHK_MGR_COMPUTE_MNT(); if (PHK_Mgr_is_a_phk_uri(path TSRMLS_CC)) { /* Sub-package */ - _phk_stream_parse_uri2(path, NULL, NULL, &tmp_parent_mnt, + PHK_Stream_parse_uri(path, NULL, NULL, &tmp_parent_mnt, &subpath TSRMLS_CC); if (EG(exception)) ABORT_PHK_MGR_COMPUTE_MNT(); @@ -909,27 +907,11 @@ ZVAL_ADDREF(parent_mp->mtime); } } else { - if (php_stream_stat_path(Z_STRVAL_P(path), &ssb) != 0) { - THROW_EXCEPTION_1("%s: File not found", Z_STRVAL_P(path)); - ABORT_PHK_MGR_COMPUTE_MNT(); - } -#ifdef NETWARE - mti = ssb.sb.st_mtime.tv_sec; -#else - mti = ssb.sb.st_mtime; -#endif + ut_path_unique_id('p',path,mnt,&mti TSRMLS_CC); + if (EG(exception)) ABORT_PHK_MGR_COMPUTE_MNT(); if (parent_mpp) (*parent_mpp) = NULL; - if (mnt) { - spprintf(&p, 256, "%lX_%lX_%lX", - (unsigned long) (ssb.sb.st_dev) - , (unsigned long) (ssb.sb.st_ino), - (unsigned long) mti); - MAKE_STD_ZVAL(*mnt); - ZVAL_STRING((*mnt), p, 0); - } - if (mtime) { if (*mtime) zval_ptr_dtor(mtime); MAKE_STD_ZVAL((*mtime)); @@ -1143,7 +1125,7 @@ HashTable *opt_ht; char *p; - DBG_MSG1("Entering PHK_Mgr_get_persistent_data(%s)", Z_STRVAL_P(mnt)); + DBG_MSG1("Entering PHK_Mgr_get_or_create_persistent_data(%s)", Z_STRVAL_P(mnt)); INIT_PHK_GET_OR_CREATE_PERSISTENT_DATA(); http://cvs.php.net/viewvc.cgi/pecl/phk/PHK_Stream.c?r1=1.4&r2=1.5&diff_format=u Index: pecl/phk/PHK_Stream.c diff -u pecl/phk/PHK_Stream.c:1.4 pecl/phk/PHK_Stream.c:1.5 --- pecl/phk/PHK_Stream.c:1.4 Thu Jan 10 02:34:52 2008 +++ pecl/phk/PHK_Stream.c Sat Jan 19 02:54:38 2008 @@ -16,14 +16,16 @@ +----------------------------------------------------------------------+ */ -/* $Id: PHK_Stream.c,v 1.4 2008/01/10 02:34:52 francois Exp $ */ +/* $Id: PHK_Stream.c,v 1.5 2008/01/19 02:54:38 francois Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" +#include "SAPI.h" #include "php_streams.h" +#include "php_variables.h" #include "ext/standard/basic_functions.h" #include "streams/php_streams_int.h" #include "zend_hash.h" @@ -32,7 +34,6 @@ #include "PHK_Stream.h" #include "PHK_Mgr.h" -#include "phk_stream_parse_uri2.h" #include "utils.h" ZEND_EXTERN_MODULE_GLOBALS(phk) @@ -363,7 +364,7 @@ DBG_MSG("do_stat: Parsing uri"); INIT_ZVAL(z_uri); ZVAL_STRINGL(&z_uri, uri, uri_len, 0); - _phk_stream_parse_uri2(&z_uri, &(dp->z_command) + PHK_Stream_parse_uri(&z_uri, &(dp->z_command) , &(dp->z_params), &(dp->z_mnt), &(dp->z_path) TSRMLS_CC); if (EG(exception)) { @@ -632,7 +633,7 @@ /*-- Parse the URI */ - _phk_stream_parse_uri2(&z_uri, &(dp->z_command), &(dp->z_params) + PHK_Stream_parse_uri(&z_uri, &(dp->z_command), &(dp->z_params) , &(dp->z_mnt), &(dp->z_path) TSRMLS_CC); if (EG(exception)) { DBG_MSG("generic_open:Invalid uri"); @@ -723,6 +724,135 @@ context STREAMS_CC TSRMLS_CC); } +/*---------------------------------------------------------------*/ + +static void PHK_Stream_parse_uri(zval * uri, zval * z_command, + zval * z_params, zval * z_mnt, + zval * z_path TSRMLS_DC) +{ + char *cmdp, *ampp, *path, *p, *res, *urip; + int cmd_len, path_len, mnt_len, slash1, uri_len; + + DBG_MSG("Entering PHK_Stream_parse_uri"); + /*DBG_MSG1("parse_uri: on entry, uri=<%s>",Z_STRVAL_P(uri));*/ + + /* Check that it is a phk uri (should always succed) */ + + if (!PHK_Mgr_is_a_phk_uri(uri TSRMLS_CC)) { + EXCEPTION_ABORT_1("%s: Not a PHK URI", Z_STRVAL_P(uri)); + } + + urip = Z_STRVAL_P(uri) + 6; /* Remove 'phk://' */ + uri_len = Z_STRLEN_P(uri) - 6; + + while ((*urip) == '/') { /* Suppress leading '/' chars */ + urip++; + uri_len--; + } + + /*DBG_MSG2("parse_uri: after stripping, uri=<%s> - uri_len=%d",urip,uri_len);*/ + + for (p = urip, cmdp = ampp = NULL, mnt_len = uri_len, slash1 = + 1, cmd_len = 0;; p++) { + if ((*p) == '\0') + break; + switch (*p) { + case '\\': + (*p) = '/'; + case '/': + if (slash1) { + slash1 = 0; + mnt_len = p - urip; + } + break; + + case '?': + if (slash1) { + slash1 = 0; + mnt_len = p - urip; + } + uri_len = p - urip; + cmdp = p + 1; + if ((*cmdp) == '\0') { + EXCEPTION_ABORT_1("%s: Empty command", Z_STRVAL_P(uri)); + } + break; + + case '&': + if (!cmdp) { /* Parameters before command */ + EXCEPTION_ABORT_1("%s: Parameters before command", + Z_STRVAL_P(uri)); + } + cmd_len = p - cmdp; + ampp = p + 1; + + if (z_params) { + zval_dtor(z_params); + res = estrdup(ampp); /* Leaked ? */ + array_init(z_params); + DBG_MSG1 + ("parse_uri: calling sapi_module.treat_data, ampp=<%s>", + ampp); + sapi_module.treat_data(PARSE_STRING, res, + z_params TSRMLS_CC); + } + break; + } + } + + if (cmdp && (cmd_len == 0)) + cmd_len = p - cmdp; /* Command without argument */ + + p = &(urip[uri_len - 1]); + while (uri_len && (*(p--) == '/')) + uri_len--; /* Suppress trailing '/' */ + + /*DBG_MSG2("parse_uri: after stripping2, uri=<%s> - uri_len=%d",urip,uri_len);*/ + /*DBG_MSG1("parse_uri: after stripping2, mnt_len=%d",mnt_len);*/ + /*DBG_MSG1("parse_uri: after stripping2, cmd_len=%d",cmd_len);*/ + + path_len = 0; + path = ""; + if ((mnt_len = MIN(uri_len, mnt_len)) != 0) { /* Not a global command */ + if (uri_len > (mnt_len + 1)) { + path_len = uri_len - mnt_len - 1; + path = &(urip[mnt_len + 1]); + } + } + + if ((!cmdp) && (!mnt_len)) + THROW_EXCEPTION_1("Empty URI", NULL); + +/* Return values */ + + if (z_command) { + zval_dtor(z_command); + if (cmdp) { + ZVAL_STRINGL(z_command, cmdp, cmd_len, 1); + } else { + ZVAL_NULL(z_command); + } + } + + if (z_mnt) { + zval_dtor(z_mnt); + if (mnt_len) { + ZVAL_STRINGL(z_mnt, urip, mnt_len, 1); + } else { + ZVAL_NULL(z_mnt); + } + } + + if (z_path) { + zval_dtor(z_path); + if (path_len) { + ZVAL_STRINGL(z_path, path, path_len, 1); + } else { + ZVAL_NULL(z_path); + } + } +} + /*--------------------*/ /* A PHK URI is opcode-cacheable if : - it corresponds to a currently mounted package, @@ -777,7 +907,7 @@ NULL, /* rename */ NULL, /* mkdir */ NULL /* rmdir */ -#ifdef ZEND_ENGINE_SUPPORTS_CACHE_KEY_WRAPPER_OPS +#ifdef STREAMS_SUPPORT_CACHE_KEY , PHK_Stream_cache_key /* cache_key */ #endif }; http://cvs.php.net/viewvc.cgi/pecl/phk/PHK_Stream.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/phk/PHK_Stream.h diff -u pecl/phk/PHK_Stream.h:1.2 pecl/phk/PHK_Stream.h:1.3 --- pecl/phk/PHK_Stream.h:1.2 Thu Dec 20 01:01:36 2007 +++ pecl/phk/PHK_Stream.h Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: PHK_Stream.h,v 1.2 2007/12/20 01:01:36 francois Exp $ */ +/* $Id: PHK_Stream.h,v 1.3 2008/01/19 02:54:38 francois Exp $ */ static int MINIT_PHK_Stream(TSRMLS_D); static int MSHUTDOWN_PHK_Stream(TSRMLS_D); @@ -29,4 +29,8 @@ zval * z_params_p, zval * z_path_p, zval * z_cache_p TSRMLS_DC); +static void PHK_Stream_parse_uri(zval * uri, zval * z_command, + zval * z_params, zval * z_mnt, + zval * z_path TSRMLS_DC); + /*============================================================================*/ http://cvs.php.net/viewvc.cgi/pecl/phk/package.xml?r1=1.4&r2=1.5&diff_format=u Index: pecl/phk/package.xml diff -u pecl/phk/package.xml:1.4 pecl/phk/package.xml:1.5 --- pecl/phk/package.xml:1.4 Thu Jan 10 02:34:52 2008 +++ pecl/phk/package.xml Sat Jan 19 02:54:38 2008 @@ -49,8 +49,6 @@ <file name="PHK_Mgr.c" role="src"/> <file name="PHK_Mgr.h" role="src"/> <file name="php_phk.c" role="src"/> - <file name="phk_stream_parse_uri2.c" role="src"/> - <file name="phk_stream_parse_uri2.h" role="src"/> <file name="php_phk.c" role="src"/> <file name="php_phk.h" role="src"/> <file name="utils.c" role="src"/> http://cvs.php.net/viewvc.cgi/pecl/phk/php_phk.c?r1=1.4&r2=1.5&diff_format=u Index: pecl/phk/php_phk.c diff -u pecl/phk/php_phk.c:1.4 pecl/phk/php_phk.c:1.5 --- pecl/phk/php_phk.c:1.4 Thu Jan 10 02:34:52 2008 +++ pecl/phk/php_phk.c Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_phk.c,v 1.4 2008/01/10 02:34:52 francois Exp $ */ +/* $Id: php_phk.c,v 1.5 2008/01/19 02:54:38 francois Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -35,7 +35,6 @@ #include "PHK_Stream.h" #include "PHK_Mgr.h" #include "PHK.h" -#include "phk_stream_parse_uri2.h" /*------------------------*/ @@ -45,6 +44,8 @@ ZEND_GET_MODULE(phk) #endif +static int init_done=0; + /*------------------------*/ #include "utils.c" @@ -52,7 +53,6 @@ #include "PHK_Stream.c" #include "PHK_Mgr.c" #include "PHK.c" -#include "phk_stream_parse_uri2.c" /*---------------------------------------------------------------*/ /* phpinfo() output */ @@ -63,31 +63,12 @@ php_info_print_table_row(2, "PHK Accelerator", "enabled"); php_info_print_table_row(2, "Version", PHK_ACCEL_VERSION); - php_info_print_table_row(2, "Cache used", - PHK_Cache_cache_name(TSRMLS_C)); + php_info_print_table_row(2, "Cache used",PHK_Cache_cache_name(TSRMLS_C)); php_info_print_table_end(); } /*---------------------------------------------------------------*/ - -static PHP_FUNCTION(_phk_techinfo) -{ - if (sapi_module.phpinfo_as_text) { - php_printf("Using PHK Accelerator: Yes\n"); - php_printf("Accelerator Version: %s\n", PHK_ACCEL_VERSION); - } else { - php_printf("<table border=0>"); - php_printf - ("<tr><td>Using PHK Accelerator: </td><td>Yes</td></tr>"); - php_printf - ("<tr><td>Accelerator Version: </td><td>%s</td></tr>", - PHK_ACCEL_VERSION); - php_printf("</table>"); - } -} - -/*---------------------------------------------------------------*/ /* Initialize a new zend_phk_globals struct during thread spin-up */ static void phk_globals_ctor(zend_phk_globals * globals TSRMLS_DC) @@ -119,11 +100,8 @@ INIT_ZVAL(CZVAL(null)); ZVAL_NULL(&CZVAL(null)); - INIT_ZVAL(CZVAL(slash)); - ZVAL_STRING(&CZVAL(slash), "/", 0); - - INIT_ZVAL(CZVAL(application_x_httpd_php)); - ZVAL_STRING(&CZVAL(application_x_httpd_php), "application/x-httpd-php", 0); + INIT_CZVAL_VALUE(slash,"/"); + INIT_CZVAL_VALUE(application_x_httpd_php,"application/x-httpd-php"); INIT_CZVAL(PHK_Stream_Backend); INIT_CZVAL(PHK_Backend); @@ -168,7 +146,7 @@ INIT_HKEY(max_php_version); INIT_HKEY(mime_types); INIT_HKEY(web_run_script); - INIT_HKEY(m); + INIT_HKEY_VALUE(mp_property_name,MP_PROPERTY_NAME); INIT_HKEY(web_main_redirect); INIT_HKEY(_PHK_path); INIT_HKEY(ORIG_PATH_INFO); @@ -181,12 +159,15 @@ INIT_HKEY(automap); INIT_HKEY(phk_stream_backend); INIT_HKEY(eaccelerator_get); + INIT_HKEY(phk); } /*---------------------------------------------------------------*/ static PHP_RINIT_FUNCTION(phk) { + if (!init_done) return SUCCESS; + DBG_INIT(); if (RINIT_utils(TSRMLS_C) == FAILURE) return FAILURE; @@ -206,6 +187,8 @@ static PHP_RSHUTDOWN_FUNCTION(phk) { + if (!init_done) return SUCCESS; + if (RSHUTDOWN_PHK(TSRMLS_C) == FAILURE) return FAILURE; if (RSHUTDOWN_PHK_Mgr(TSRMLS_C) == FAILURE) return FAILURE; @@ -223,13 +206,20 @@ static PHP_MINIT_FUNCTION(phk) { + build_constant_values(); + + /* Handle case where the PHK extension is dynamically loaded from a + PHK package (as when Automap.phk registers extensions). In this case, + we must not define anything/ */ + + if (EG(class_table) && HKEY_EXISTS(EG(class_table),phk)) return SUCCESS; + else init_done=1; + ZEND_INIT_MODULE_GLOBALS(phk, phk_globals_ctor, NULL); REGISTER_STRING_CONSTANT("PHK_ACCEL_VERSION", PHK_ACCEL_VERSION, CONST_CS | CONST_PERSISTENT); - build_constant_values(); - if (MINIT_utils(TSRMLS_C) == FAILURE) return FAILURE; if (MINIT_PHK_Cache(TSRMLS_C) == FAILURE) return FAILURE; @@ -247,6 +237,8 @@ static PHP_MSHUTDOWN_FUNCTION(phk) { + if (!init_done) return SUCCESS; + #ifndef ZTS phk_globals_dtor(&phk_globals TSRMLS_CC); #endif @@ -264,22 +256,6 @@ return SUCCESS; } -/*-- Function entries --*/ - -static ZEND_BEGIN_ARG_INFO_EX(phk_stream_parse_uri2_arginfo, 0, 0, 5) -ZEND_ARG_INFO(0, uri) -ZEND_ARG_INFO(1, command) -ZEND_ARG_INFO(1, params) -ZEND_ARG_INFO(1, mnt) -ZEND_ARG_INFO(1, path) -ZEND_END_ARG_INFO() - -static function_entry phk_functions[] = { - PHP_FE(_phk_techinfo, UT_noarg_arginfo) - PHP_FE(_phk_stream_parse_uri2, phk_stream_parse_uri2_arginfo) - {NULL, NULL, NULL, 0, 0} -}; - /*-- Module definition --*/ zend_module_entry phk_module_entry = { @@ -287,7 +263,7 @@ STANDARD_MODULE_HEADER, #endif PHP_PHK_EXTNAME, - phk_functions, + NULL, PHP_MINIT(phk), PHP_MSHUTDOWN(phk), PHP_RINIT(phk), http://cvs.php.net/viewvc.cgi/pecl/phk/php_phk.h?r1=1.5&r2=1.6&diff_format=u Index: pecl/phk/php_phk.h diff -u pecl/phk/php_phk.h:1.5 pecl/phk/php_phk.h:1.6 --- pecl/phk/php_phk.h:1.5 Fri Jan 11 23:26:59 2008 +++ pecl/phk/php_phk.h Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_phk.h,v 1.5 2008/01/11 23:26:59 francois Exp $ */ +/* $Id: php_phk.h,v 1.6 2008/01/19 02:54:38 francois Exp $ */ /*#define PHK_DEBUG*/ @@ -33,7 +33,7 @@ /*---------------------------------------------------------------*/ -#define PHK_ACCEL_VERSION "1.1.0" +#define PHK_ACCEL_VERSION "1.4.0" #define PHK_ACCEL_MIN_VERSION "1.4.0" @@ -43,12 +43,6 @@ #define phpext_phk_ptr &phk_module_entry -/* Condition is experimental and will change */ - -#if ZEND_EXTENSION_API_NO >= 220071023 -# define ZEND_ENGINE_SUPPORTS_CACHE_KEY_WRAPPER_OPS -#endif - /*---------------------------------------------------------------*/ static DECLARE_CZVAL(false); @@ -99,7 +93,7 @@ static DECLARE_HKEY(max_php_version); static DECLARE_HKEY(mime_types); static DECLARE_HKEY(web_run_script); -static DECLARE_HKEY(m); +static DECLARE_HKEY(mp_property_name); static DECLARE_HKEY(web_main_redirect); static DECLARE_HKEY(_PHK_path); static DECLARE_HKEY(ORIG_PATH_INFO); @@ -112,6 +106,7 @@ static DECLARE_HKEY(automap); static DECLARE_HKEY(phk_stream_backend); static DECLARE_HKEY(eaccelerator_get); +static DECLARE_HKEY(phk); /*----- Mount flags --------*/ @@ -189,4 +184,11 @@ #endif /*---------------------------------------------------------------*/ + +/* We need a private property here, so that it cannot be accessed nor + modified by a malicious PHP script */ + +#define MP_PROPERTY_NAME "\0PHK\0m" + +/*---------------------------------------------------------------*/ #endif /* PHP_PHK_H */ http://cvs.php.net/viewvc.cgi/pecl/phk/utils.c?r1=1.4&r2=1.5&diff_format=u Index: pecl/phk/utils.c diff -u pecl/phk/utils.c:1.4 pecl/phk/utils.c:1.5 --- pecl/phk/utils.c:1.4 Thu Jan 10 02:34:52 2008 +++ pecl/phk/utils.c Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: utils.c,v 1.4 2008/01/10 02:34:52 francois Exp $ */ +/* $Id: utils.c,v 1.5 2008/01/19 02:54:38 francois Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -39,6 +39,9 @@ #ifdef HAVE_UNISTD_H #include <unistd.h> #endif +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif #include "php.h" #include "zend_execute.h" @@ -52,6 +55,14 @@ #include "utils.h" /*============================================================================*/ + +static HashTable simul_inodes; + +static unsigned long simul_inode_index; + +static MutexDeclare(simul_inodes); + +/*============================================================================*/ /* Generic arginfo structures */ static ZEND_BEGIN_ARG_INFO_EX(UT_noarg_arginfo, 0, 0, 0) @@ -91,6 +102,27 @@ ZEND_END_ARG_INFO() /*============================================================================*/ +/*--- Init persistent data */ + +static void ut_init_persistent_data(TSRMLS_D) +{ + MutexSetup(simul_inodes); + + zend_hash_init(&simul_inodes, 16, NULL,NULL, 1); + + simul_inode_index = 1; +} + +/*---------------------------------------------------------------*/ + +static void ut_shutdown_persistent_data(TSRMLS_D) +{ + zend_hash_destroy(&simul_inodes); + + MutexShutdown(simul_inodes); +} + +/*---------------------------------------------------------------*/ static inline void *_allocate(void *ptr, size_t size, int persistent) { @@ -396,6 +428,15 @@ /*---------------------------------------------------------------*/ +static void ut_load_extension_file(zval *file TSRMLS_DC) +{ + if (!ut_call_user_function_bool(NULL,&CZVAL(dl),1,&file TSRMLS_CC)) { + THROW_EXCEPTION_1("%s: Cannot load extension",Z_STRVAL_P(file)); + } +} + +/*---------------------------------------------------------------*/ + #ifdef PHP_WIN32 #define _UT_LE_PREFIX "php_" #else @@ -404,22 +445,18 @@ static void ut_load_extension(char *name, int len TSRMLS_DC) { - zval zv,*zp; + zval zv; char *p; - int status; if (ut_extension_loaded(name, len TSRMLS_CC)) return; spprintf(&p,1024,_UT_LE_PREFIX "%s." PHP_SHLIB_SUFFIX,name); INIT_ZVAL(zv); - zp=&zv; - ZVAL_STRING(zp,p,0); + ZVAL_STRING(&zv,p,0); - status=ut_call_user_function_bool(NULL,&CZVAL(dl),1,&zp TSRMLS_CC); + ut_load_extension_file(&zv TSRMLS_CC); - zval_dtor(zp); - - if (!status) THROW_EXCEPTION_1("%s: Cannot load extension",name); + zval_dtor(&zv); } /*---------------------------------------------------------------*/ @@ -903,6 +940,58 @@ return i; } +/*---------------------------------------------------------------*/ + +static void ut_path_unique_id(char prefix, zval * path, zval ** mnt + , time_t *mtp TSRMLS_DC) +{ + char *p; + php_stream_statbuf ssb; + time_t mtime; + unsigned long inode,dev,*lp,hash; + int rlen; + char resolved_path_buff[MAXPATHLEN]; + + if (php_stream_stat_path(Z_STRVAL_P(path), &ssb) != 0) { + EXCEPTION_ABORT_1("%s: Cannot stat",Z_STRVAL_P(path)); + } + + dev=(unsigned long) ssb.sb.st_dev; + inode=(unsigned long) ssb.sb.st_ino; + +#ifdef NETWARE + mtime= ssb.sb.st_mtime.tv_sec; +#else + mtime = ssb.sb.st_mtime; +#endif + + if (mnt) { + if (!inode) { + if (!VCWD_REALPATH(Z_STRVAL_P(path), resolved_path_buff)) + EXCEPTION_ABORT_1("%s: Cannot compute realpath",Z_STRVAL_P(path)); + + rlen=strlen(resolved_path_buff)+1; + hash=zend_get_hash_value(resolved_path_buff,rlen); + + MutexLock(simul_inodes); + if (zend_hash_quick_find(&simul_inodes,resolved_path_buff + ,rlen,hash,(void **)(&lp))==SUCCESS) inode=(*lp); + else { + inode=simul_inode_index++; + zend_hash_quick_add(&simul_inodes,resolved_path_buff + ,rlen,hash,(void *)(&inode),sizeof(inode),NULL); + } + MutexUnlock(simul_inodes); + } + + spprintf(&p, 256, "%c_%lX_%lX_%lX", prefix, dev, inode, mtime); + MAKE_STD_ZVAL(*mnt); + ZVAL_STRING((*mnt), p, 0); + } + + if (mtp) (*mtp)=mtime; +} + /*========================================================================*/ static void ut_build_constants(TSRMLS_D) @@ -923,6 +1012,8 @@ { ut_build_constants(TSRMLS_C); + ut_init_persistent_data(TSRMLS_C); + return SUCCESS; } @@ -930,6 +1021,8 @@ static int MSHUTDOWN_utils(TSRMLS_D) { + ut_shutdown_persistent_data(TSRMLS_C); + return SUCCESS; } http://cvs.php.net/viewvc.cgi/pecl/phk/utils.h?r1=1.5&r2=1.6&diff_format=u Index: pecl/phk/utils.h diff -u pecl/phk/utils.h:1.5 pecl/phk/utils.h:1.6 --- pecl/phk/utils.h:1.5 Fri Jan 11 23:26:59 2008 +++ pecl/phk/utils.h Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: utils.h,v 1.5 2008/01/11 23:26:59 francois Exp $ */ +/* $Id: utils.h,v 1.6 2008/01/19 02:54:38 francois Exp $ */ #ifndef FLP_UTILS_H #define FLP_UTILS_H 1 @@ -48,20 +48,24 @@ #define DECLARE_CZVAL(name) zval CZVAL(name) -#define INIT_CZVAL(name) \ +#define INIT_CZVAL(name) INIT_CZVAL_VALUE(name, #name) + +#define INIT_CZVAL_VALUE(name,value) \ { \ INIT_ZVAL(CZVAL(name)); \ - ZVAL_STRING(&(CZVAL(name)), #name,0); \ + ZVAL_STRING(&(CZVAL(name)), value,0); \ } #define HKEY(name) ( hkey_ ## name ) #define DECLARE_HKEY(name) HKEY_STRUCT HKEY(name) -#define INIT_HKEY(name) \ +#define INIT_HKEY(name) INIT_HKEY_VALUE(name, #name) + +#define INIT_HKEY_VALUE(name,value) \ { \ - HKEY(name).string= #name ; \ - HKEY(name).len=sizeof( #name ); \ + HKEY(name).string= value ; \ + HKEY(name).len=sizeof( value ); \ HKEY(name).hash=zend_get_hash_value(HKEY(name).string,HKEY(name).len); \ } @@ -363,6 +367,7 @@ zval ** args TSRMLS_DC); static int ut_extension_loaded(char *name, int len TSRMLS_DC); +static void ut_load_extension_file(zval *file TSRMLS_DC); static void ut_load_extension(char *name, int len TSRMLS_DC); static void ut_require(char *string, zval * ret TSRMLS_DC); static inline int ut_strings_are_equal(zval * zp1, zval * zp2 TSRMLS_DC); @@ -390,6 +395,7 @@ static inline int ut_is_uri(char *path, int len TSRMLS_DC); static char *ut_mk_absolute_path(char *path, int len, int *reslen, int separ TSRMLS_DC); static int ut_rtrim(char *p TSRMLS_DC); +static void ut_path_unique_id(char prefix, zval * path, zval ** mnt, time_t *mtp TSRMLS_DC); /*============================================================================*/ #endif /* FLP_UTILS_H */ http://cvs.php.net/viewvc.cgi/pecl/phk/tests/002_techinfo.phpt?r1=1.1&r2=1.2&diff_format=u Index: pecl/phk/tests/002_techinfo.phpt diff -u pecl/phk/tests/002_techinfo.phpt:1.1 pecl/phk/tests/002_techinfo.phpt:1.2 --- pecl/phk/tests/002_techinfo.phpt:1.1 Tue Nov 27 21:52:26 2007 +++ pecl/phk/tests/002_techinfo.phpt Sat Jan 19 02:54:38 2008 @@ -4,7 +4,7 @@ <?php if (!extension_loaded("phk")) print "skip"; ?> --FILE-- <?php -_phk_techinfo(); +PHK::techinfo(); ?> ===DONE=== --EXPECT--
http://cvs.php.net/viewvc.cgi/pecl/phk/PHK.c?r1=1.4&r2=1.5&diff_format=u Index: pecl/phk/PHK.c diff -u pecl/phk/PHK.c:1.4 pecl/phk/PHK.c:1.5 --- pecl/phk/PHK.c:1.4 Thu Jan 10 02:34:52 2008 +++ pecl/phk/PHK.c Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: PHK.c,v 1.4 2008/01/10 02:34:52 francois Exp $ */ +/* $Id: PHK.c,v 1.5 2008/01/19 02:54:38 francois Exp $ */ #define PHK_VERSION "1.4.0" @@ -76,7 +76,9 @@ \ DBG_MSG("Entering PHK::" #_func); \ CHECK_MEM(); \ - FIND_HKEY(Z_OBJPROP_P(getThis()),m,&_tmp); \ + if (FIND_HKEY(Z_OBJPROP_P(getThis()),mp_property_name,&_tmp)!=SUCCESS) { ; \ + EXCEPTION_ABORT("Accessing invalid or unmounted object"); \ + } \ mp= *((PHK_Mnt_Info **)(Z_STRVAL_PP(_tmp))); /*---------------------------------------------------------------*/ @@ -142,8 +144,8 @@ static void PHK_set_mp_property(zval * obj, PHK_Mnt_Info * mp TSRMLS_DC) { - add_property_stringl_ex(obj, "m", 2, (char *) (&mp), sizeof(mp), - 1 TSRMLS_CC); + zend_update_property_stringl(Z_OBJCE_P(obj),obj,"m",1,(char *)(&mp) + , sizeof(mp) TSRMLS_CC); } /*---------------------------------------------------------------*/ @@ -953,6 +955,24 @@ /* }}} */ /*---------------------------------------------------------------*/ +/* {{{ proto void PHK::accel_techinfo() */ + +static PHP_METHOD(PHK, accel_techinfo) +{ + if (sapi_module.phpinfo_as_text) { + php_printf("Using PHK Accelerator: Yes\n"); + php_printf("Accelerator Version: %s\n", PHK_ACCEL_VERSION); + } else { + php_printf("<table border=0>"); + php_printf("<tr><td>Using PHK Accelerator: </td><td>Yes</td></tr>"); + php_printf("<tr><td>Accelerator Version: </td><td>%s</td></tr>", + PHK_ACCEL_VERSION); + php_printf("</table>"); + } +} + +/* }}} */ +/*---------------------------------------------------------------*/ /* {{{ proto string PHK::prolog(string file, mixed &cmd, mixed &ret) */ /* Undocumented - called by the PHK runtime code only */ @@ -967,6 +987,12 @@ DBG_MSG("Entering Prolog"); + /* Workaround to PHP bug #39903 (__COMPILER_HALT_OFFSET__ already defined) */ + /* Not perfect but can suppress further notice messages */ + + (void)zend_hash_del(EG(zend_constants),"__COMPILER_HALT_OFFSET__" + ,sizeof("__COMPILER_HALT_OFFSET__")); + if (zend_parse_parameters (ZEND_NUM_ARGS()TSRMLS_CC, "zzz", &file, &cmd, &ret) == FAILURE) EXCEPTION_ABORT_1("Cannot parse parameters", 0); @@ -1067,7 +1093,8 @@ ZEND_END_ARG_INFO() /*---------------------------------------------------------------*/ - static zend_function_entry PHK_functions[] = { + +static zend_function_entry PHK_functions[] = { PHP_ME(PHK, need_php_runtime, UT_noarg_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_ME(PHK, __construct, UT_1arg_arginfo, ZEND_ACC_PUBLIC) @@ -1105,6 +1132,8 @@ PHP_ME(PHK, __call, UT_2args_arginfo, ZEND_ACC_PUBLIC) PHP_ME(PHK, prolog, PHK_prolog_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(PHK, accel_techinfo, UT_noarg_arginfo, + ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) {NULL, NULL, NULL, 0, 0} }; @@ -1155,6 +1184,9 @@ INIT_CLASS_ENTRY(ce, "PHK", PHK_functions); entry = zend_register_internal_class(&ce TSRMLS_CC); + + zend_declare_property_null(entry,"m",1,ZEND_ACC_PRIVATE TSRMLS_CC); + set_constants(entry); /*--- Init mime table */ http://cvs.php.net/viewvc.cgi/pecl/phk/PHK_Mgr.c?r1=1.5&r2=1.6&diff_format=u Index: pecl/phk/PHK_Mgr.c diff -u pecl/phk/PHK_Mgr.c:1.5 pecl/phk/PHK_Mgr.c:1.6 --- pecl/phk/PHK_Mgr.c:1.5 Fri Jan 11 23:26:59 2008 +++ pecl/phk/PHK_Mgr.c Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: PHK_Mgr.c,v 1.5 2008/01/11 23:26:59 francois Exp $ */ +/* $Id: PHK_Mgr.c,v 1.6 2008/01/19 02:54:38 francois Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -32,7 +32,6 @@ #include "utils.h" #include "PHK.h" #include "PHK_Mgr.h" -#include "phk_stream_parse_uri2.h" ZEND_EXTERN_MODULE_GLOBALS(phk) @@ -75,7 +74,7 @@ static int tmp_mnt_num; -MutexDeclare(persistent_mtab); +static MutexDeclare(persistent_mtab); /*---------------------------------------------------------------*/ @@ -873,14 +872,13 @@ zval subpath, tmp_mnt, tmp_parent_mnt; int len; char *p; - php_stream_statbuf ssb; PHK_Mnt_Info *parent_mp; time_t mti; INIT_PHK_MGR_COMPUTE_MNT(); if (PHK_Mgr_is_a_phk_uri(path TSRMLS_CC)) { /* Sub-package */ - _phk_stream_parse_uri2(path, NULL, NULL, &tmp_parent_mnt, + PHK_Stream_parse_uri(path, NULL, NULL, &tmp_parent_mnt, &subpath TSRMLS_CC); if (EG(exception)) ABORT_PHK_MGR_COMPUTE_MNT(); @@ -909,27 +907,11 @@ ZVAL_ADDREF(parent_mp->mtime); } } else { - if (php_stream_stat_path(Z_STRVAL_P(path), &ssb) != 0) { - THROW_EXCEPTION_1("%s: File not found", Z_STRVAL_P(path)); - ABORT_PHK_MGR_COMPUTE_MNT(); - } -#ifdef NETWARE - mti = ssb.sb.st_mtime.tv_sec; -#else - mti = ssb.sb.st_mtime; -#endif + ut_path_unique_id('p',path,mnt,&mti TSRMLS_CC); + if (EG(exception)) ABORT_PHK_MGR_COMPUTE_MNT(); if (parent_mpp) (*parent_mpp) = NULL; - if (mnt) { - spprintf(&p, 256, "%lX_%lX_%lX", - (unsigned long) (ssb.sb.st_dev) - , (unsigned long) (ssb.sb.st_ino), - (unsigned long) mti); - MAKE_STD_ZVAL(*mnt); - ZVAL_STRING((*mnt), p, 0); - } - if (mtime) { if (*mtime) zval_ptr_dtor(mtime); MAKE_STD_ZVAL((*mtime)); @@ -1143,7 +1125,7 @@ HashTable *opt_ht; char *p; - DBG_MSG1("Entering PHK_Mgr_get_persistent_data(%s)", Z_STRVAL_P(mnt)); + DBG_MSG1("Entering PHK_Mgr_get_or_create_persistent_data(%s)", Z_STRVAL_P(mnt)); INIT_PHK_GET_OR_CREATE_PERSISTENT_DATA(); http://cvs.php.net/viewvc.cgi/pecl/phk/PHK_Stream.c?r1=1.4&r2=1.5&diff_format=u Index: pecl/phk/PHK_Stream.c diff -u pecl/phk/PHK_Stream.c:1.4 pecl/phk/PHK_Stream.c:1.5 --- pecl/phk/PHK_Stream.c:1.4 Thu Jan 10 02:34:52 2008 +++ pecl/phk/PHK_Stream.c Sat Jan 19 02:54:38 2008 @@ -16,14 +16,16 @@ +----------------------------------------------------------------------+ */ -/* $Id: PHK_Stream.c,v 1.4 2008/01/10 02:34:52 francois Exp $ */ +/* $Id: PHK_Stream.c,v 1.5 2008/01/19 02:54:38 francois Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" +#include "SAPI.h" #include "php_streams.h" +#include "php_variables.h" #include "ext/standard/basic_functions.h" #include "streams/php_streams_int.h" #include "zend_hash.h" @@ -32,7 +34,6 @@ #include "PHK_Stream.h" #include "PHK_Mgr.h" -#include "phk_stream_parse_uri2.h" #include "utils.h" ZEND_EXTERN_MODULE_GLOBALS(phk) @@ -363,7 +364,7 @@ DBG_MSG("do_stat: Parsing uri"); INIT_ZVAL(z_uri); ZVAL_STRINGL(&z_uri, uri, uri_len, 0); - _phk_stream_parse_uri2(&z_uri, &(dp->z_command) + PHK_Stream_parse_uri(&z_uri, &(dp->z_command) , &(dp->z_params), &(dp->z_mnt), &(dp->z_path) TSRMLS_CC); if (EG(exception)) { @@ -632,7 +633,7 @@ /*-- Parse the URI */ - _phk_stream_parse_uri2(&z_uri, &(dp->z_command), &(dp->z_params) + PHK_Stream_parse_uri(&z_uri, &(dp->z_command), &(dp->z_params) , &(dp->z_mnt), &(dp->z_path) TSRMLS_CC); if (EG(exception)) { DBG_MSG("generic_open:Invalid uri"); @@ -723,6 +724,135 @@ context STREAMS_CC TSRMLS_CC); } +/*---------------------------------------------------------------*/ + +static void PHK_Stream_parse_uri(zval * uri, zval * z_command, + zval * z_params, zval * z_mnt, + zval * z_path TSRMLS_DC) +{ + char *cmdp, *ampp, *path, *p, *res, *urip; + int cmd_len, path_len, mnt_len, slash1, uri_len; + + DBG_MSG("Entering PHK_Stream_parse_uri"); + /*DBG_MSG1("parse_uri: on entry, uri=<%s>",Z_STRVAL_P(uri));*/ + + /* Check that it is a phk uri (should always succed) */ + + if (!PHK_Mgr_is_a_phk_uri(uri TSRMLS_CC)) { + EXCEPTION_ABORT_1("%s: Not a PHK URI", Z_STRVAL_P(uri)); + } + + urip = Z_STRVAL_P(uri) + 6; /* Remove 'phk://' */ + uri_len = Z_STRLEN_P(uri) - 6; + + while ((*urip) == '/') { /* Suppress leading '/' chars */ + urip++; + uri_len--; + } + + /*DBG_MSG2("parse_uri: after stripping, uri=<%s> - uri_len=%d",urip,uri_len);*/ + + for (p = urip, cmdp = ampp = NULL, mnt_len = uri_len, slash1 = + 1, cmd_len = 0;; p++) { + if ((*p) == '\0') + break; + switch (*p) { + case '\\': + (*p) = '/'; + case '/': + if (slash1) { + slash1 = 0; + mnt_len = p - urip; + } + break; + + case '?': + if (slash1) { + slash1 = 0; + mnt_len = p - urip; + } + uri_len = p - urip; + cmdp = p + 1; + if ((*cmdp) == '\0') { + EXCEPTION_ABORT_1("%s: Empty command", Z_STRVAL_P(uri)); + } + break; + + case '&': + if (!cmdp) { /* Parameters before command */ + EXCEPTION_ABORT_1("%s: Parameters before command", + Z_STRVAL_P(uri)); + } + cmd_len = p - cmdp; + ampp = p + 1; + + if (z_params) { + zval_dtor(z_params); + res = estrdup(ampp); /* Leaked ? */ + array_init(z_params); + DBG_MSG1 + ("parse_uri: calling sapi_module.treat_data, ampp=<%s>", + ampp); + sapi_module.treat_data(PARSE_STRING, res, + z_params TSRMLS_CC); + } + break; + } + } + + if (cmdp && (cmd_len == 0)) + cmd_len = p - cmdp; /* Command without argument */ + + p = &(urip[uri_len - 1]); + while (uri_len && (*(p--) == '/')) + uri_len--; /* Suppress trailing '/' */ + + /*DBG_MSG2("parse_uri: after stripping2, uri=<%s> - uri_len=%d",urip,uri_len);*/ + /*DBG_MSG1("parse_uri: after stripping2, mnt_len=%d",mnt_len);*/ + /*DBG_MSG1("parse_uri: after stripping2, cmd_len=%d",cmd_len);*/ + + path_len = 0; + path = ""; + if ((mnt_len = MIN(uri_len, mnt_len)) != 0) { /* Not a global command */ + if (uri_len > (mnt_len + 1)) { + path_len = uri_len - mnt_len - 1; + path = &(urip[mnt_len + 1]); + } + } + + if ((!cmdp) && (!mnt_len)) + THROW_EXCEPTION_1("Empty URI", NULL); + +/* Return values */ + + if (z_command) { + zval_dtor(z_command); + if (cmdp) { + ZVAL_STRINGL(z_command, cmdp, cmd_len, 1); + } else { + ZVAL_NULL(z_command); + } + } + + if (z_mnt) { + zval_dtor(z_mnt); + if (mnt_len) { + ZVAL_STRINGL(z_mnt, urip, mnt_len, 1); + } else { + ZVAL_NULL(z_mnt); + } + } + + if (z_path) { + zval_dtor(z_path); + if (path_len) { + ZVAL_STRINGL(z_path, path, path_len, 1); + } else { + ZVAL_NULL(z_path); + } + } +} + /*--------------------*/ /* A PHK URI is opcode-cacheable if : - it corresponds to a currently mounted package, @@ -777,7 +907,7 @@ NULL, /* rename */ NULL, /* mkdir */ NULL /* rmdir */ -#ifdef ZEND_ENGINE_SUPPORTS_CACHE_KEY_WRAPPER_OPS +#ifdef STREAMS_SUPPORT_CACHE_KEY , PHK_Stream_cache_key /* cache_key */ #endif }; http://cvs.php.net/viewvc.cgi/pecl/phk/PHK_Stream.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/phk/PHK_Stream.h diff -u pecl/phk/PHK_Stream.h:1.2 pecl/phk/PHK_Stream.h:1.3 --- pecl/phk/PHK_Stream.h:1.2 Thu Dec 20 01:01:36 2007 +++ pecl/phk/PHK_Stream.h Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: PHK_Stream.h,v 1.2 2007/12/20 01:01:36 francois Exp $ */ +/* $Id: PHK_Stream.h,v 1.3 2008/01/19 02:54:38 francois Exp $ */ static int MINIT_PHK_Stream(TSRMLS_D); static int MSHUTDOWN_PHK_Stream(TSRMLS_D); @@ -29,4 +29,8 @@ zval * z_params_p, zval * z_path_p, zval * z_cache_p TSRMLS_DC); +static void PHK_Stream_parse_uri(zval * uri, zval * z_command, + zval * z_params, zval * z_mnt, + zval * z_path TSRMLS_DC); + /*============================================================================*/ http://cvs.php.net/viewvc.cgi/pecl/phk/package.xml?r1=1.4&r2=1.5&diff_format=u Index: pecl/phk/package.xml diff -u pecl/phk/package.xml:1.4 pecl/phk/package.xml:1.5 --- pecl/phk/package.xml:1.4 Thu Jan 10 02:34:52 2008 +++ pecl/phk/package.xml Sat Jan 19 02:54:38 2008 @@ -49,8 +49,6 @@ <file name="PHK_Mgr.c" role="src"/> <file name="PHK_Mgr.h" role="src"/> <file name="php_phk.c" role="src"/> - <file name="phk_stream_parse_uri2.c" role="src"/> - <file name="phk_stream_parse_uri2.h" role="src"/> <file name="php_phk.c" role="src"/> <file name="php_phk.h" role="src"/> <file name="utils.c" role="src"/> http://cvs.php.net/viewvc.cgi/pecl/phk/php_phk.c?r1=1.4&r2=1.5&diff_format=u Index: pecl/phk/php_phk.c diff -u pecl/phk/php_phk.c:1.4 pecl/phk/php_phk.c:1.5 --- pecl/phk/php_phk.c:1.4 Thu Jan 10 02:34:52 2008 +++ pecl/phk/php_phk.c Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_phk.c,v 1.4 2008/01/10 02:34:52 francois Exp $ */ +/* $Id: php_phk.c,v 1.5 2008/01/19 02:54:38 francois Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -35,7 +35,6 @@ #include "PHK_Stream.h" #include "PHK_Mgr.h" #include "PHK.h" -#include "phk_stream_parse_uri2.h" /*------------------------*/ @@ -45,6 +44,8 @@ ZEND_GET_MODULE(phk) #endif +static int init_done=0; + /*------------------------*/ #include "utils.c" @@ -52,7 +53,6 @@ #include "PHK_Stream.c" #include "PHK_Mgr.c" #include "PHK.c" -#include "phk_stream_parse_uri2.c" /*---------------------------------------------------------------*/ /* phpinfo() output */ @@ -63,31 +63,12 @@ php_info_print_table_row(2, "PHK Accelerator", "enabled"); php_info_print_table_row(2, "Version", PHK_ACCEL_VERSION); - php_info_print_table_row(2, "Cache used", - PHK_Cache_cache_name(TSRMLS_C)); + php_info_print_table_row(2, "Cache used",PHK_Cache_cache_name(TSRMLS_C)); php_info_print_table_end(); } /*---------------------------------------------------------------*/ - -static PHP_FUNCTION(_phk_techinfo) -{ - if (sapi_module.phpinfo_as_text) { - php_printf("Using PHK Accelerator: Yes\n"); - php_printf("Accelerator Version: %s\n", PHK_ACCEL_VERSION); - } else { - php_printf("<table border=0>"); - php_printf - ("<tr><td>Using PHK Accelerator: </td><td>Yes</td></tr>"); - php_printf - ("<tr><td>Accelerator Version: </td><td>%s</td></tr>", - PHK_ACCEL_VERSION); - php_printf("</table>"); - } -} - -/*---------------------------------------------------------------*/ /* Initialize a new zend_phk_globals struct during thread spin-up */ static void phk_globals_ctor(zend_phk_globals * globals TSRMLS_DC) @@ -119,11 +100,8 @@ INIT_ZVAL(CZVAL(null)); ZVAL_NULL(&CZVAL(null)); - INIT_ZVAL(CZVAL(slash)); - ZVAL_STRING(&CZVAL(slash), "/", 0); - - INIT_ZVAL(CZVAL(application_x_httpd_php)); - ZVAL_STRING(&CZVAL(application_x_httpd_php), "application/x-httpd-php", 0); + INIT_CZVAL_VALUE(slash,"/"); + INIT_CZVAL_VALUE(application_x_httpd_php,"application/x-httpd-php"); INIT_CZVAL(PHK_Stream_Backend); INIT_CZVAL(PHK_Backend); @@ -168,7 +146,7 @@ INIT_HKEY(max_php_version); INIT_HKEY(mime_types); INIT_HKEY(web_run_script); - INIT_HKEY(m); + INIT_HKEY_VALUE(mp_property_name,MP_PROPERTY_NAME); INIT_HKEY(web_main_redirect); INIT_HKEY(_PHK_path); INIT_HKEY(ORIG_PATH_INFO); @@ -181,12 +159,15 @@ INIT_HKEY(automap); INIT_HKEY(phk_stream_backend); INIT_HKEY(eaccelerator_get); + INIT_HKEY(phk); } /*---------------------------------------------------------------*/ static PHP_RINIT_FUNCTION(phk) { + if (!init_done) return SUCCESS; + DBG_INIT(); if (RINIT_utils(TSRMLS_C) == FAILURE) return FAILURE; @@ -206,6 +187,8 @@ static PHP_RSHUTDOWN_FUNCTION(phk) { + if (!init_done) return SUCCESS; + if (RSHUTDOWN_PHK(TSRMLS_C) == FAILURE) return FAILURE; if (RSHUTDOWN_PHK_Mgr(TSRMLS_C) == FAILURE) return FAILURE; @@ -223,13 +206,20 @@ static PHP_MINIT_FUNCTION(phk) { + build_constant_values(); + + /* Handle case where the PHK extension is dynamically loaded from a + PHK package (as when Automap.phk registers extensions). In this case, + we must not define anything/ */ + + if (EG(class_table) && HKEY_EXISTS(EG(class_table),phk)) return SUCCESS; + else init_done=1; + ZEND_INIT_MODULE_GLOBALS(phk, phk_globals_ctor, NULL); REGISTER_STRING_CONSTANT("PHK_ACCEL_VERSION", PHK_ACCEL_VERSION, CONST_CS | CONST_PERSISTENT); - build_constant_values(); - if (MINIT_utils(TSRMLS_C) == FAILURE) return FAILURE; if (MINIT_PHK_Cache(TSRMLS_C) == FAILURE) return FAILURE; @@ -247,6 +237,8 @@ static PHP_MSHUTDOWN_FUNCTION(phk) { + if (!init_done) return SUCCESS; + #ifndef ZTS phk_globals_dtor(&phk_globals TSRMLS_CC); #endif @@ -264,22 +256,6 @@ return SUCCESS; } -/*-- Function entries --*/ - -static ZEND_BEGIN_ARG_INFO_EX(phk_stream_parse_uri2_arginfo, 0, 0, 5) -ZEND_ARG_INFO(0, uri) -ZEND_ARG_INFO(1, command) -ZEND_ARG_INFO(1, params) -ZEND_ARG_INFO(1, mnt) -ZEND_ARG_INFO(1, path) -ZEND_END_ARG_INFO() - -static function_entry phk_functions[] = { - PHP_FE(_phk_techinfo, UT_noarg_arginfo) - PHP_FE(_phk_stream_parse_uri2, phk_stream_parse_uri2_arginfo) - {NULL, NULL, NULL, 0, 0} -}; - /*-- Module definition --*/ zend_module_entry phk_module_entry = { @@ -287,7 +263,7 @@ STANDARD_MODULE_HEADER, #endif PHP_PHK_EXTNAME, - phk_functions, + NULL, PHP_MINIT(phk), PHP_MSHUTDOWN(phk), PHP_RINIT(phk), http://cvs.php.net/viewvc.cgi/pecl/phk/php_phk.h?r1=1.5&r2=1.6&diff_format=u Index: pecl/phk/php_phk.h diff -u pecl/phk/php_phk.h:1.5 pecl/phk/php_phk.h:1.6 --- pecl/phk/php_phk.h:1.5 Fri Jan 11 23:26:59 2008 +++ pecl/phk/php_phk.h Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_phk.h,v 1.5 2008/01/11 23:26:59 francois Exp $ */ +/* $Id: php_phk.h,v 1.6 2008/01/19 02:54:38 francois Exp $ */ /*#define PHK_DEBUG*/ @@ -33,7 +33,7 @@ /*---------------------------------------------------------------*/ -#define PHK_ACCEL_VERSION "1.1.0" +#define PHK_ACCEL_VERSION "1.4.0" #define PHK_ACCEL_MIN_VERSION "1.4.0" @@ -43,12 +43,6 @@ #define phpext_phk_ptr &phk_module_entry -/* Condition is experimental and will change */ - -#if ZEND_EXTENSION_API_NO >= 220071023 -# define ZEND_ENGINE_SUPPORTS_CACHE_KEY_WRAPPER_OPS -#endif - /*---------------------------------------------------------------*/ static DECLARE_CZVAL(false); @@ -99,7 +93,7 @@ static DECLARE_HKEY(max_php_version); static DECLARE_HKEY(mime_types); static DECLARE_HKEY(web_run_script); -static DECLARE_HKEY(m); +static DECLARE_HKEY(mp_property_name); static DECLARE_HKEY(web_main_redirect); static DECLARE_HKEY(_PHK_path); static DECLARE_HKEY(ORIG_PATH_INFO); @@ -112,6 +106,7 @@ static DECLARE_HKEY(automap); static DECLARE_HKEY(phk_stream_backend); static DECLARE_HKEY(eaccelerator_get); +static DECLARE_HKEY(phk); /*----- Mount flags --------*/ @@ -189,4 +184,11 @@ #endif /*---------------------------------------------------------------*/ + +/* We need a private property here, so that it cannot be accessed nor + modified by a malicious PHP script */ + +#define MP_PROPERTY_NAME "\0PHK\0m" + +/*---------------------------------------------------------------*/ #endif /* PHP_PHK_H */ http://cvs.php.net/viewvc.cgi/pecl/phk/utils.c?r1=1.4&r2=1.5&diff_format=u Index: pecl/phk/utils.c diff -u pecl/phk/utils.c:1.4 pecl/phk/utils.c:1.5 --- pecl/phk/utils.c:1.4 Thu Jan 10 02:34:52 2008 +++ pecl/phk/utils.c Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: utils.c,v 1.4 2008/01/10 02:34:52 francois Exp $ */ +/* $Id: utils.c,v 1.5 2008/01/19 02:54:38 francois Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -39,6 +39,9 @@ #ifdef HAVE_UNISTD_H #include <unistd.h> #endif +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif #include "php.h" #include "zend_execute.h" @@ -52,6 +55,14 @@ #include "utils.h" /*============================================================================*/ + +static HashTable simul_inodes; + +static unsigned long simul_inode_index; + +static MutexDeclare(simul_inodes); + +/*============================================================================*/ /* Generic arginfo structures */ static ZEND_BEGIN_ARG_INFO_EX(UT_noarg_arginfo, 0, 0, 0) @@ -91,6 +102,27 @@ ZEND_END_ARG_INFO() /*============================================================================*/ +/*--- Init persistent data */ + +static void ut_init_persistent_data(TSRMLS_D) +{ + MutexSetup(simul_inodes); + + zend_hash_init(&simul_inodes, 16, NULL,NULL, 1); + + simul_inode_index = 1; +} + +/*---------------------------------------------------------------*/ + +static void ut_shutdown_persistent_data(TSRMLS_D) +{ + zend_hash_destroy(&simul_inodes); + + MutexShutdown(simul_inodes); +} + +/*---------------------------------------------------------------*/ static inline void *_allocate(void *ptr, size_t size, int persistent) { @@ -396,6 +428,15 @@ /*---------------------------------------------------------------*/ +static void ut_load_extension_file(zval *file TSRMLS_DC) +{ + if (!ut_call_user_function_bool(NULL,&CZVAL(dl),1,&file TSRMLS_CC)) { + THROW_EXCEPTION_1("%s: Cannot load extension",Z_STRVAL_P(file)); + } +} + +/*---------------------------------------------------------------*/ + #ifdef PHP_WIN32 #define _UT_LE_PREFIX "php_" #else @@ -404,22 +445,18 @@ static void ut_load_extension(char *name, int len TSRMLS_DC) { - zval zv,*zp; + zval zv; char *p; - int status; if (ut_extension_loaded(name, len TSRMLS_CC)) return; spprintf(&p,1024,_UT_LE_PREFIX "%s." PHP_SHLIB_SUFFIX,name); INIT_ZVAL(zv); - zp=&zv; - ZVAL_STRING(zp,p,0); + ZVAL_STRING(&zv,p,0); - status=ut_call_user_function_bool(NULL,&CZVAL(dl),1,&zp TSRMLS_CC); + ut_load_extension_file(&zv TSRMLS_CC); - zval_dtor(zp); - - if (!status) THROW_EXCEPTION_1("%s: Cannot load extension",name); + zval_dtor(&zv); } /*---------------------------------------------------------------*/ @@ -903,6 +940,58 @@ return i; } +/*---------------------------------------------------------------*/ + +static void ut_path_unique_id(char prefix, zval * path, zval ** mnt + , time_t *mtp TSRMLS_DC) +{ + char *p; + php_stream_statbuf ssb; + time_t mtime; + unsigned long inode,dev,*lp,hash; + int rlen; + char resolved_path_buff[MAXPATHLEN]; + + if (php_stream_stat_path(Z_STRVAL_P(path), &ssb) != 0) { + EXCEPTION_ABORT_1("%s: Cannot stat",Z_STRVAL_P(path)); + } + + dev=(unsigned long) ssb.sb.st_dev; + inode=(unsigned long) ssb.sb.st_ino; + +#ifdef NETWARE + mtime= ssb.sb.st_mtime.tv_sec; +#else + mtime = ssb.sb.st_mtime; +#endif + + if (mnt) { + if (!inode) { + if (!VCWD_REALPATH(Z_STRVAL_P(path), resolved_path_buff)) + EXCEPTION_ABORT_1("%s: Cannot compute realpath",Z_STRVAL_P(path)); + + rlen=strlen(resolved_path_buff)+1; + hash=zend_get_hash_value(resolved_path_buff,rlen); + + MutexLock(simul_inodes); + if (zend_hash_quick_find(&simul_inodes,resolved_path_buff + ,rlen,hash,(void **)(&lp))==SUCCESS) inode=(*lp); + else { + inode=simul_inode_index++; + zend_hash_quick_add(&simul_inodes,resolved_path_buff + ,rlen,hash,(void *)(&inode),sizeof(inode),NULL); + } + MutexUnlock(simul_inodes); + } + + spprintf(&p, 256, "%c_%lX_%lX_%lX", prefix, dev, inode, mtime); + MAKE_STD_ZVAL(*mnt); + ZVAL_STRING((*mnt), p, 0); + } + + if (mtp) (*mtp)=mtime; +} + /*========================================================================*/ static void ut_build_constants(TSRMLS_D) @@ -923,6 +1012,8 @@ { ut_build_constants(TSRMLS_C); + ut_init_persistent_data(TSRMLS_C); + return SUCCESS; } @@ -930,6 +1021,8 @@ static int MSHUTDOWN_utils(TSRMLS_D) { + ut_shutdown_persistent_data(TSRMLS_C); + return SUCCESS; } http://cvs.php.net/viewvc.cgi/pecl/phk/utils.h?r1=1.5&r2=1.6&diff_format=u Index: pecl/phk/utils.h diff -u pecl/phk/utils.h:1.5 pecl/phk/utils.h:1.6 --- pecl/phk/utils.h:1.5 Fri Jan 11 23:26:59 2008 +++ pecl/phk/utils.h Sat Jan 19 02:54:38 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: utils.h,v 1.5 2008/01/11 23:26:59 francois Exp $ */ +/* $Id: utils.h,v 1.6 2008/01/19 02:54:38 francois Exp $ */ #ifndef FLP_UTILS_H #define FLP_UTILS_H 1 @@ -48,20 +48,24 @@ #define DECLARE_CZVAL(name) zval CZVAL(name) -#define INIT_CZVAL(name) \ +#define INIT_CZVAL(name) INIT_CZVAL_VALUE(name, #name) + +#define INIT_CZVAL_VALUE(name,value) \ { \ INIT_ZVAL(CZVAL(name)); \ - ZVAL_STRING(&(CZVAL(name)), #name,0); \ + ZVAL_STRING(&(CZVAL(name)), value,0); \ } #define HKEY(name) ( hkey_ ## name ) #define DECLARE_HKEY(name) HKEY_STRUCT HKEY(name) -#define INIT_HKEY(name) \ +#define INIT_HKEY(name) INIT_HKEY_VALUE(name, #name) + +#define INIT_HKEY_VALUE(name,value) \ { \ - HKEY(name).string= #name ; \ - HKEY(name).len=sizeof( #name ); \ + HKEY(name).string= value ; \ + HKEY(name).len=sizeof( value ); \ HKEY(name).hash=zend_get_hash_value(HKEY(name).string,HKEY(name).len); \ } @@ -363,6 +367,7 @@ zval ** args TSRMLS_DC); static int ut_extension_loaded(char *name, int len TSRMLS_DC); +static void ut_load_extension_file(zval *file TSRMLS_DC); static void ut_load_extension(char *name, int len TSRMLS_DC); static void ut_require(char *string, zval * ret TSRMLS_DC); static inline int ut_strings_are_equal(zval * zp1, zval * zp2 TSRMLS_DC); @@ -390,6 +395,7 @@ static inline int ut_is_uri(char *path, int len TSRMLS_DC); static char *ut_mk_absolute_path(char *path, int len, int *reslen, int separ TSRMLS_DC); static int ut_rtrim(char *p TSRMLS_DC); +static void ut_path_unique_id(char prefix, zval * path, zval ** mnt, time_t *mtp TSRMLS_DC); /*============================================================================*/ #endif /* FLP_UTILS_H */ http://cvs.php.net/viewvc.cgi/pecl/phk/tests/002_techinfo.phpt?r1=1.1&r2=1.2&diff_format=u Index: pecl/phk/tests/002_techinfo.phpt diff -u pecl/phk/tests/002_techinfo.phpt:1.1 pecl/phk/tests/002_techinfo.phpt:1.2 --- pecl/phk/tests/002_techinfo.phpt:1.1 Tue Nov 27 21:52:26 2007 +++ pecl/phk/tests/002_techinfo.phpt Sat Jan 19 02:54:38 2008 @@ -4,7 +4,7 @@ <?php if (!extension_loaded("phk")) print "skip"; ?> --FILE-- <?php -_phk_techinfo(); +PHK::techinfo(); ?> ===DONE=== --EXPECT--