mkoppanen                                Thu, 24 Dec 2009 13:12:03 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=292595

Log:
Changed stream_resolve_include_path to use zend_resolve_path
backported stream_resolve_include_path to PHP 5.3
backported stream_resolve_include_path test to PHP 5.3

Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/standard/basic_functions.c
    U   php/php-src/branches/PHP_5_3/ext/standard/streamsfuncs.c
    U   php/php-src/branches/PHP_5_3/ext/standard/streamsfuncs.h
    A   
php/php-src/branches/PHP_5_3/ext/standard/tests/streams/stream_resolve_include_path.phpt
    U   php/php-src/trunk/ext/standard/streamsfuncs.c

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2009-12-24 13:07:33 UTC (rev 292594)
+++ php/php-src/branches/PHP_5_3/NEWS   2009-12-24 13:12:03 UTC (rev 292595)
@@ -29,6 +29,7 @@
 - Added support for CURLOPT_CERTINFO. FR #49253.
   (Linus Nielsen Feltzing <li...@haxx.se>)
 - Added client-side server name indication support in openssl. (Arnaud)
+- Added stream_resolve_include_path() (Mikko)

 - Improved fix for bug #50006 (Segfault caused by uksort()). (Stas)


Modified: php/php-src/branches/PHP_5_3/ext/standard/basic_functions.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/basic_functions.c 2009-12-24 
13:07:33 UTC (rev 292594)
+++ php/php-src/branches/PHP_5_3/ext/standard/basic_functions.c 2009-12-24 
13:12:03 UTC (rev 292595)
@@ -2010,6 +2010,10 @@
 ZEND_BEGIN_ARG_INFO(arginfo_stream_get_wrappers, 0)
 ZEND_END_ARG_INFO()

+ZEND_BEGIN_ARG_INFO(arginfo_stream_resolve_include_path, 0)
+       ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO(arginfo_stream_is_local, 0)
        ZEND_ARG_INFO(0, stream)
 ZEND_END_ARG_INFO()
@@ -3115,6 +3119,7 @@
        PHP_FE(stream_wrapper_restore,                                          
                                        arginfo_stream_wrapper_restore)
        PHP_FE(stream_get_wrappers,                                             
                                                arginfo_stream_get_wrappers)
        PHP_FE(stream_get_transports,                                           
                                        arginfo_stream_get_transports)
+       PHP_FE(stream_resolve_include_path,                                     
                                        arginfo_stream_resolve_include_path)
        PHP_FE(stream_is_local,                                                 
                                        arginfo_stream_is_local)
        PHP_FE(get_headers,                                                     
                                                        arginfo_get_headers)


Modified: php/php-src/branches/PHP_5_3/ext/standard/streamsfuncs.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/streamsfuncs.c    2009-12-24 
13:07:33 UTC (rev 292594)
+++ php/php-src/branches/PHP_5_3/ext/standard/streamsfuncs.c    2009-12-24 
13:12:03 UTC (rev 292595)
@@ -1442,6 +1442,26 @@
 }
 /* }}} */

+/* {{{ proto string stream_resolve_include_path(string filename)
+Determine what file will be opened by calls to fopen() with a relative path */
+PHP_FUNCTION(stream_resolve_include_path)
+{
+       char *filename, *resolved_path;
+       int filename_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, 
&filename_len) == FAILURE) {
+               return;
+       }
+
+       resolved_path = zend_resolve_path(filename, filename_len TSRMLS_CC);
+
+       if (resolved_path) {
+               RETURN_STRING(resolved_path, 0);
+       }
+       RETURN_FALSE;
+}
+/* }}} */
+
 /* {{{ proto bool stream_is_local(resource stream|string url) U
 */
 PHP_FUNCTION(stream_is_local)

Modified: php/php-src/branches/PHP_5_3/ext/standard/streamsfuncs.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/streamsfuncs.h    2009-12-24 
13:07:33 UTC (rev 292594)
+++ php/php-src/branches/PHP_5_3/ext/standard/streamsfuncs.h    2009-12-24 
13:12:03 UTC (rev 292595)
@@ -56,6 +56,7 @@
 PHP_FUNCTION(stream_filter_remove);
 PHP_FUNCTION(stream_socket_enable_crypto);
 PHP_FUNCTION(stream_socket_shutdown);
+PHP_FUNCTION(stream_resolve_include_path);
 PHP_FUNCTION(stream_is_local);
 PHP_FUNCTION(stream_supports_lock);


Added: 
php/php-src/branches/PHP_5_3/ext/standard/tests/streams/stream_resolve_include_path.phpt
===================================================================
--- 
php/php-src/branches/PHP_5_3/ext/standard/tests/streams/stream_resolve_include_path.phpt
                            (rev 0)
+++ 
php/php-src/branches/PHP_5_3/ext/standard/tests/streams/stream_resolve_include_path.phpt
    2009-12-24 13:12:03 UTC (rev 292595)
@@ -0,0 +1,37 @@
+--TEST--
+stream_resolve_include_path(string path)
+--FILE--
+<?php
+$include_path = __DIR__ . '/test_path';
+$include_path_nested = $include_path . '/nested';
+
+$include_path_file = $include_path . DIRECTORY_SEPARATOR . 'file';
+$include_path_nested_file = $include_path_nested . DIRECTORY_SEPARATOR . 
'file';
+
+mkdir($include_path);
+mkdir($include_path_nested);
+
+file_put_contents($include_path_file, 'include_path');
+file_put_contents($include_path_nested_file, 'include_path');
+
+var_dump(stream_resolve_include_path());
+
+set_include_path($include_path . PATH_SEPARATOR . $include_path_nested);
+var_dump(stream_resolve_include_path('file-does-not-exist'));
+
+set_include_path($include_path . PATH_SEPARATOR . $include_path_nested);
+var_dump(stream_resolve_include_path('file'));
+set_include_path($include_path_nested . PATH_SEPARATOR . $include_path);
+var_dump(stream_resolve_include_path('file'));
+
+unlink($include_path_nested_file);
+rmdir($include_path_nested);
+unlink($include_path_file);
+rmdir($include_path);
+--EXPECTF--
+Warning: stream_resolve_include_path() expects exactly 1 parameter, 0 given in 
%s on line %d
+NULL
+bool(false)
+string(%d) "%s/test_path/file"
+string(%d) "%s/test_path/nested/file"
+

Modified: php/php-src/trunk/ext/standard/streamsfuncs.c
===================================================================
--- php/php-src/trunk/ext/standard/streamsfuncs.c       2009-12-24 13:07:33 UTC 
(rev 292594)
+++ php/php-src/trunk/ext/standard/streamsfuncs.c       2009-12-24 13:12:03 UTC 
(rev 292595)
@@ -1668,63 +1668,32 @@
 }
 /* }}} */

-/* {{{ proto string stream_resolve_include_path(string filename[, resource 
context]) U
+/* {{{ proto string stream_resolve_include_path(string filename) U
 Determine what file will be opened by calls to fopen() with a relative path */
 PHP_FUNCTION(stream_resolve_include_path)
 {
-       zval **ppfilename, *zcontext = NULL;
-       char *filename, *ptr = PG(include_path), *end = ptr + (ptr ? 
strlen(ptr) : 0), buffer[MAXPATHLEN];
+       zval **ppz_filename, *pz_context = NULL;
+       char *filename, *resolved_path;
        int filename_len;
        php_stream_context *context = NULL;
-       struct stat sb;

-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|r", 
&ppfilename, &zcontext) == FAILURE ||
-               php_stream_path_param_encode(ppfilename, &filename, 
&filename_len, REPORT_ERRORS, context = php_stream_context_from_zval(zcontext, 
0)) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|r", 
&ppz_filename, &pz_context) == FAILURE ||
+               php_stream_path_param_encode(ppz_filename, &filename, 
&filename_len, REPORT_ERRORS, context = 
php_stream_context_from_zval(pz_context, 0)) == FAILURE) {
                return;
        }

-       while (ptr < end) {
-               char *s = strchr(ptr, DEFAULT_DIR_SEPARATOR);
-               UChar *upath;
-               int upath_len;
+       resolved_path = zend_resolve_path(filename, filename_len TSRMLS_CC);

-               if (!s) {
-                       s = end;
-               }
-
-               if (s == ptr) {
-                       ptr++;
-                       continue;
-               }
-
-               if ((s - ptr) + 1 + filename_len >= MAXPATHLEN) {
-                       /* Too long to try */
-                       ptr = s + 1;
-                       continue;
-               }
-
-               memcpy(buffer, ptr, s - ptr);
-               buffer[s - ptr] = '/';
-               memcpy(buffer + (s - ptr) + 1, filename, filename_len + 1);
-
-               if (php_check_open_basedir_ex(buffer, 0 TSRMLS_CC)) {
-                       ptr = s + 1;
-                       continue;
-               }
-
-               if (VCWD_STAT(buffer, &sb)) {
-                       ptr = s + 1;
-                       continue;
-               }
-
-               if (SUCCESS == php_stream_path_decode(NULL, &upath, &upath_len, 
buffer, (s - ptr) + 1 + filename_len, REPORT_ERRORS, context)) {
-                       RETURN_UNICODEL(upath, upath_len, 0);
+       if (resolved_path) {
+               UChar *ustr;
+               int ulen;
+               if (SUCCESS == zend_string_to_unicode(UG(utf8_conv), &ustr, 
&ulen, resolved_path, strlen(resolved_path) TSRMLS_CC)) {
+                       efree(resolved_path);
+                       RETURN_UNICODEL(ustr, ulen, 0);
                } else {
-                       /* Fallback */
-                       RETURN_STRINGL(buffer, (s - ptr) + 1 + filename_len, 1);
+                       RETURN_STRINGL(resolved_path, strlen(resolved_path), 1);
                }
        }
-
        RETURN_FALSE;
 }
 /* }}} */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to