From d666c05427729a100f394cc30d69be54a8ba350d Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Tue, 3 Oct 2006 16:28:02 +0000 Subject: [PATCH] PHP6 Update for get_included_files() and export of path decode for Zend --- Zend/zend.c | 21 +++++++++++++++++++++ Zend/zend.h | 2 ++ Zend/zend_builtin_functions.c | 22 ++++++++++++++-------- main/main.c | 9 +++++++++ 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/Zend/zend.c b/Zend/zend.c index 02b8e470af..6da0946a85 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -56,6 +56,7 @@ ZEND_API zend_class_entry *zend_standard_class_def = NULL; ZEND_API int (*zend_printf)(const char *format, ...); ZEND_API zend_write_func_t zend_write; ZEND_API int (*zend_path_encode)(char **encpath, int *encpath_len, const UChar *path, int path_len TSRMLS_DC); +ZEND_API int (*zend_path_decode)(UChar **decpath, int *decpath_len, const char *path, int path_len TSRMLS_DC); ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path); ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC); ZEND_API void (*zend_block_interruptions)(void); @@ -624,6 +625,22 @@ static int zend_path_encode_wrapper(char **encpath, int *encpath_len, const UCha return SUCCESS; } +static int zend_path_decode_wrapper(UChar **decpath, int *decpath_len, const char *path, int path_len TSRMLS_DC) +{ + UErrorCode status = U_ZERO_ERROR; + + zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(filesystem_encoding_conv)), decpath, decpath_len, path, path_len, &status); + + if (U_FAILURE(status)) { + efree(*decpath); + *decpath = NULL; + *decpath_len = 0; + return FAILURE; + } + + return SUCCESS; +} + static FILE *zend_fopen_wrapper(const char *filename, char **opened_path) { if (opened_path) { @@ -1012,6 +1029,10 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i if (!zend_path_encode) { zend_path_encode = zend_path_encode_wrapper; } + zend_path_decode = utility_functions->path_decode_function; + if (!zend_path_decode) { + zend_path_decode = zend_path_decode_wrapper; + } zend_fopen = utility_functions->fopen_function; if (!zend_fopen) { zend_fopen = zend_fopen_wrapper; diff --git a/Zend/zend.h b/Zend/zend.h index 6a626b83ca..f822c56bdc 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -411,6 +411,7 @@ typedef struct _zend_utility_functions { int (*printf_function)(const char *format, ...); int (*write_function)(const char *str, uint str_length); int (*path_encode_function)(char **encpath, int *encpath_len, const UChar *path, int path_len TSRMLS_DC); + int (*path_decode_function)(UChar **decpath, int *decpath_len, const char *path, int path_len TSRMLS_DC); FILE *(*fopen_function)(const char *filename, char **opened_path); void (*message_handler)(long message, void *data); void (*block_interruptions)(void); @@ -557,6 +558,7 @@ BEGIN_EXTERN_C() extern ZEND_API int (*zend_printf)(const char *format, ...); extern ZEND_API zend_write_func_t zend_write; extern ZEND_API int (*zend_path_encode)(char **encpath, int *encpath_len, const UChar *path, int path_len TSRMLS_DC); +extern ZEND_API int (*zend_path_decode)(UChar **decpath, int *decpath_len, const char *path, int path_len TSRMLS_DC); extern ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path); extern ZEND_API void (*zend_block_interruptions)(void); extern ZEND_API void (*zend_unblock_interruptions)(void); diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 0bc5e35a2a..def6eda486 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1197,22 +1197,28 @@ ZEND_FUNCTION(crash) #endif /* ZEND_DEBUG */ -/* {{{ proto array get_included_files(void) - Returns an array with the file names that were include_once()'d */ +/* {{{ proto array get_included_files(void) U + Returns an array with the file names that were included (includes require and once varieties) */ ZEND_FUNCTION(get_included_files) { + HashPosition pos; + UChar *ustr; zstr entry; + int len, ustr_len; + if (ZEND_NUM_ARGS() != 0) { ZEND_WRONG_PARAM_COUNT(); } array_init(return_value); - zend_hash_internal_pointer_reset(&EG(included_files)); - while (zend_hash_get_current_key(&EG(included_files), &entry, NULL, 0) == HASH_KEY_IS_STRING) { - /* UTODO Not sure this should be runtime encoding.. maybe filename encoding - * instead */ - add_next_index_rt_string(return_value, entry.s, 1); - zend_hash_move_forward(&EG(included_files)); + zend_hash_internal_pointer_reset_ex(&EG(included_files), &pos); + while (zend_hash_get_current_key_ex(&EG(included_files), &entry, &len, NULL, 0, &pos) == HASH_KEY_IS_STRING) { + if (UG(unicode) && SUCCESS == zend_path_decode(&ustr, &ustr_len, entry.s, len - 1 TSRMLS_CC)) { + add_next_index_unicodel(return_value, ustr, ustr_len, 0); + } else { + add_next_index_stringl(return_value, entry.s, len - 1, 1); + } + zend_hash_move_forward_ex(&EG(included_files), &pos); } } /* }}} */ diff --git a/main/main.c b/main/main.c index 73bfdc89f0..d70451866e 100644 --- a/main/main.c +++ b/main/main.c @@ -983,6 +983,14 @@ static int php_path_encode_for_zend(char **encpath, int *encpath_len, const UCha } /* }}} */ +/* {{{ php_path_decode_for_zend + */ +static int php_path_decode_for_zend(UChar **decpath, int *decpath_len, const char *path, int path_len TSRMLS_DC) +{ + return php_stream_path_decode(NULL, decpath, decpath_len, path, path_len, 0, NULL); +} +/* }}} */ + /* {{{ php_fopen_wrapper_for_zend */ static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path) @@ -1550,6 +1558,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod zuf.printf_function = php_printf; zuf.write_function = php_output_wrapper; zuf.path_encode_function = php_path_encode_for_zend; + zuf.path_decode_function = php_path_decode_for_zend; zuf.fopen_function = php_fopen_wrapper_for_zend; zuf.message_handler = php_message_handler_for_zend; zuf.block_interruptions = sapi_module.block_interruptions; -- 2.40.0