dmitry Thu Mar 27 10:33:40 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/standard/tests/file include_streams.phpt
Modified files: /php-src NEWS /php-src/main fopen_wrappers.c php_streams.h /php-src/main/streams plain_wrapper.c streams.c Log: Added ability to use stream wrappers in include_path
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.151&r2=1.2027.2.547.2.965.2.152&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.547.2.965.2.151 php-src/NEWS:1.2027.2.547.2.965.2.152 --- php-src/NEWS:1.2027.2.547.2.965.2.151 Tue Mar 25 20:00:18 2008 +++ php-src/NEWS Thu Mar 27 10:33:39 2008 @@ -4,6 +4,7 @@ - Removed the experimental RPL (master/slave) functions from mysqli. (Andrey) - Dropped zend.ze1_compatibility_mode (Dmitry) +- Added ability to use stream wrappers in include_path (Gregory, Dmitry) - Added concept of "delayed early binding" that allows opcode caches to perform class declaration (early and/or run-time binding) in exactly the same order as vanila php. (Dmitry) http://cvs.php.net/viewvc.cgi/php-src/main/fopen_wrappers.c?r1=1.175.2.3.2.13.2.9&r2=1.175.2.3.2.13.2.10&diff_format=u Index: php-src/main/fopen_wrappers.c diff -u php-src/main/fopen_wrappers.c:1.175.2.3.2.13.2.9 php-src/main/fopen_wrappers.c:1.175.2.3.2.13.2.10 --- php-src/main/fopen_wrappers.c:1.175.2.3.2.13.2.9 Mon Mar 24 09:30:41 2008 +++ php-src/main/fopen_wrappers.c Thu Mar 27 10:33:40 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fopen_wrappers.c,v 1.175.2.3.2.13.2.9 2008/03/24 09:30:41 dmitry Exp $ */ +/* $Id: fopen_wrappers.c,v 1.175.2.3.2.13.2.10 2008/03/27 10:33:40 dmitry Exp $ */ /* {{{ includes */ @@ -447,14 +447,22 @@ char resolved_path[MAXPATHLEN]; char trypath[MAXPATHLEN]; const char *ptr, *end, *p; + char *actual_path; + php_stream_wrapper *wrapper; if (!filename) { return NULL; } - /* Don't resolve paths which contain protocol */ + /* Don't resolve paths which contain protocol (except of file://) */ for (p = filename; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++); if ((*p == ':') && (p - filename > 1) && (p[1] == '/') && (p[2] == '/')) { + wrapper = php_stream_locate_url_wrapper(filename, &actual_path, STREAM_OPEN_FOR_INCLUDE TSRMLS_CC); + if (wrapper == &php_plain_files_wrapper) { + if (tsrm_realpath(actual_path, resolved_path TSRMLS_CC)) { + return estrdup(resolved_path); + } + } return NULL; } @@ -473,7 +481,18 @@ ptr = path; while (ptr && *ptr) { - end = strchr(ptr, DEFAULT_DIR_SEPARATOR); + /* Check for stream wrapper */ + int is_stream_wrapper = 0; + + for (p = ptr; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++); + if ((*p == ':') && (p - ptr > 1) && (p[1] == '/') && (p[2] == '/')) { + /* .:// or ..:// is not a stream wrapper */ + if (p[-1] != '.' || p[-2] != '.' || p - 2 != ptr) { + p += 3; + is_stream_wrapper = 1; + } + } + end = strchr(p, DEFAULT_DIR_SEPARATOR); if (end) { if ((end-ptr) + 1 + filename_length + 1 >= MAXPATHLEN) { ptr = end + 1; @@ -494,7 +513,23 @@ memcpy(trypath+len+1, filename, filename_length+1); ptr = NULL; } - if (tsrm_realpath(trypath, resolved_path TSRMLS_CC)) { + actual_path = trypath; + if (is_stream_wrapper) { + wrapper = php_stream_locate_url_wrapper(trypath, &actual_path, STREAM_OPEN_FOR_INCLUDE TSRMLS_CC); + if (!wrapper) { + continue; + } else if (wrapper != &php_plain_files_wrapper) { + if (wrapper->wops->url_stat) { + php_stream_statbuf ssb; + + if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL TSRMLS_CC)) { + return estrdup(trypath); + } + } + continue; + } + } + if (tsrm_realpath(actual_path, resolved_path TSRMLS_CC)) { return estrdup(resolved_path); } } /* end provided path */ @@ -511,7 +546,27 @@ exec_fname_length + 1 + filename_length + 1 < MAXPATHLEN) { memcpy(trypath, exec_fname, exec_fname_length + 1); memcpy(trypath+exec_fname_length + 1, filename, filename_length+1); - if (tsrm_realpath(trypath, resolved_path TSRMLS_CC)) { + actual_path = trypath; + + /* Check for stream wrapper */ + for (p = trypath; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++); + if ((*p == ':') && (p - trypath > 1) && (p[1] == '/') && (p[2] == '/')) { + wrapper = php_stream_locate_url_wrapper(trypath, &actual_path, STREAM_OPEN_FOR_INCLUDE TSRMLS_CC); + if (!wrapper) { + return NULL; + } else if (wrapper != &php_plain_files_wrapper) { + if (wrapper->wops->url_stat) { + php_stream_statbuf ssb; + + if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL TSRMLS_CC)) { + return estrdup(trypath); + } + } + return NULL; + } + } + + if (tsrm_realpath(actual_path, resolved_path TSRMLS_CC)) { return estrdup(resolved_path); } } http://cvs.php.net/viewvc.cgi/php-src/main/php_streams.h?r1=1.103.2.1.2.4.2.2&r2=1.103.2.1.2.4.2.3&diff_format=u Index: php-src/main/php_streams.h diff -u php-src/main/php_streams.h:1.103.2.1.2.4.2.2 php-src/main/php_streams.h:1.103.2.1.2.4.2.3 --- php-src/main/php_streams.h:1.103.2.1.2.4.2.2 Mon Dec 31 07:17:17 2007 +++ php-src/main/php_streams.h Thu Mar 27 10:33:40 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_streams.h,v 1.103.2.1.2.4.2.2 2007/12/31 07:17:17 sebastian Exp $ */ +/* $Id: php_streams.h,v 1.103.2.1.2.4.2.3 2008/03/27 10:33:40 dmitry Exp $ */ #ifndef PHP_STREAMS_H #define PHP_STREAMS_H @@ -511,6 +511,9 @@ /* don't check allow_url_fopen and allow_url_include */ #define STREAM_DISABLE_URL_PROTECTION 0x00002000 +/* assume the path passed in exists and is fully expanded, avoiding syscalls */ +#define STREAM_ASSUME_REALPATH 0x00004000 + /* Antique - no longer has meaning */ #define IGNORE_URL_WIN 0 http://cvs.php.net/viewvc.cgi/php-src/main/streams/plain_wrapper.c?r1=1.52.2.6.2.23.2.5&r2=1.52.2.6.2.23.2.6&diff_format=u Index: php-src/main/streams/plain_wrapper.c diff -u php-src/main/streams/plain_wrapper.c:1.52.2.6.2.23.2.5 php-src/main/streams/plain_wrapper.c:1.52.2.6.2.23.2.6 --- php-src/main/streams/plain_wrapper.c:1.52.2.6.2.23.2.5 Mon Dec 31 07:17:17 2007 +++ php-src/main/streams/plain_wrapper.c Thu Mar 27 10:33:40 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: plain_wrapper.c,v 1.52.2.6.2.23.2.5 2007/12/31 07:17:17 sebastian Exp $ */ +/* $Id: plain_wrapper.c,v 1.52.2.6.2.23.2.6 2008/03/27 10:33:40 dmitry Exp $ */ #include "php.h" #include "php_globals.h" @@ -892,9 +892,13 @@ } return NULL; } - - if ((realpath = expand_filepath(filename, NULL TSRMLS_CC)) == NULL) { - return NULL; + + if (options & STREAM_ASSUME_REALPATH) { + realpath = estrdup(filename); + } else { + if ((realpath = expand_filepath(filename, NULL TSRMLS_CC)) == NULL) { + return NULL; + } } if (persistent) { http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.82.2.6.2.18.2.6&r2=1.82.2.6.2.18.2.7&diff_format=u Index: php-src/main/streams/streams.c diff -u php-src/main/streams/streams.c:1.82.2.6.2.18.2.6 php-src/main/streams/streams.c:1.82.2.6.2.18.2.7 --- php-src/main/streams/streams.c:1.82.2.6.2.18.2.6 Mon Mar 24 16:28:35 2008 +++ php-src/main/streams/streams.c Thu Mar 27 10:33:40 2008 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.82.2.6.2.18.2.6 2008/03/24 16:28:35 tony2001 Exp $ */ +/* $Id: streams.c,v 1.82.2.6.2.18.2.7 2008/03/27 10:33:40 dmitry Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -1754,6 +1754,7 @@ php_stream_wrapper *wrapper = NULL; char *path_to_open; int persistent = options & STREAM_OPEN_PERSISTENT; + char *resolved_path = NULL; char *copy_of_path = NULL; @@ -1765,11 +1766,24 @@ return NULL; } + if (options & USE_PATH) { + resolved_path = php_resolve_path(path, strlen(path), PG(include_path) TSRMLS_CC); + if (resolved_path) { + path = resolved_path; + /* we've found this file, don't re-check include_path or run realpath */ + options |= STREAM_ASSUME_REALPATH; + options &= ~USE_PATH; + } + } + path_to_open = path; wrapper = php_stream_locate_url_wrapper(path, &path_to_open, options TSRMLS_CC); if (options & STREAM_USE_URL && (!wrapper || !wrapper->is_url)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function may only be used against URLs"); + if (resolved_path) { + efree(resolved_path); + } return NULL; } @@ -1798,6 +1812,10 @@ } if (stream) { + if (opened_path && !*opened_path && resolved_path) { + *opened_path = resolved_path; + resolved_path = NULL; + } if (stream->orig_path) { pefree(stream->orig_path, persistent); } @@ -1816,12 +1834,18 @@ (options & STREAM_WILL_CAST) ? PHP_STREAM_PREFER_STDIO : PHP_STREAM_NO_PREFERENCE)) { case PHP_STREAM_UNCHANGED: + if (resolved_path) { + efree(resolved_path); + } return stream; case PHP_STREAM_RELEASED: if (newstream->orig_path) { pefree(newstream->orig_path, persistent); } newstream->orig_path = pestrdup(path, persistent); + if (resolved_path) { + efree(resolved_path); + } return newstream; default: php_stream_close(stream); @@ -1860,6 +1884,9 @@ pefree(copy_of_path, persistent); } #endif + if (resolved_path) { + efree(resolved_path); + } return stream; } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/include_streams.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/file/include_streams.phpt +++ php-src/ext/standard/tests/file/include_streams.phpt
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php