diff options
Diffstat (limited to 'ext/standard/basic_functions.c')
| -rw-r--r-- | ext/standard/basic_functions.c | 318 |
1 files changed, 158 insertions, 160 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index f34be0d109..cb9be32852 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) 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 | @@ -75,15 +75,8 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; # include <unistd.h> #endif -#if HAVE_STRING_H -# include <string.h> -#else -# include <strings.h> -#endif - -#if HAVE_LOCALE_H -# include <locale.h> -#endif +#include <string.h> +#include <locale.h> #if HAVE_SYS_MMAN_H # include <sys/mman.h> @@ -127,10 +120,6 @@ typedef struct _user_tick_function_entry { static void user_shutdown_function_dtor(zval *zv); static void user_tick_function_dtor(user_tick_function_entry *tick_function_entry); -static HashTable basic_submodules; - -#undef sprintf - /* {{{ arginfo */ /* {{{ main/main.c */ ZEND_BEGIN_ARG_INFO(arginfo_set_time_limit, 0) @@ -390,13 +379,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_array_slice, 0, 0, 2) ZEND_ARG_INFO(0, preserve_keys) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_array_merge, 0, 0, 1) - ZEND_ARG_INFO(0, arr1) /* ARRAY_INFO(0, arg, 0) */ +ZEND_BEGIN_ARG_INFO_EX(arginfo_array_merge, 0, 0, 0) ZEND_ARG_VARIADIC_INFO(0, arrays) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_array_merge_recursive, 0, 0, 1) - ZEND_ARG_INFO(0, arr1) /* ARRAY_INFO(0, arg, 0) */ +ZEND_BEGIN_ARG_INFO_EX(arginfo_array_merge_recursive, 0, 0, 0) ZEND_ARG_VARIADIC_INFO(0, arrays) ZEND_END_ARG_INFO() @@ -1864,6 +1851,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_password_verify, 0, 0, 2) ZEND_ARG_INFO(0, password) ZEND_ARG_INFO(0, hash) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(arginfo_password_algos, 0) +ZEND_END_ARG_INFO(); /* }}} */ /* {{{ proc_open.c */ #ifdef PHP_CAN_SUPPORT_PROC_OPEN @@ -2173,12 +2162,10 @@ ZEND_BEGIN_ARG_INFO(arginfo_nl_langinfo, 0) ZEND_END_ARG_INFO() #endif -#ifdef HAVE_STRCOLL ZEND_BEGIN_ARG_INFO(arginfo_strcoll, 0) ZEND_ARG_INFO(0, str1) ZEND_ARG_INFO(0, str2) ZEND_END_ARG_INFO() -#endif ZEND_BEGIN_ARG_INFO_EX(arginfo_trim, 0, 0, 1) ZEND_ARG_INFO(0, str) @@ -2726,6 +2713,16 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_sapi_windows_cp_conv, 0, 0, 3) ZEND_ARG_INFO(0, out_codepage) ZEND_ARG_TYPE_INFO(0, subject, IS_STRING, 0) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sapi_windows_set_ctrl_handler, 0, 0, 1) + ZEND_ARG_INFO(0, callable) + ZEND_ARG_INFO(0, add) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sapi_windows_generate_ctrl_event, 0, 0, 1) + ZEND_ARG_INFO(0, event) + ZEND_ARG_INFO(0, pid) +ZEND_END_ARG_INFO() #endif /* }}} */ /* }}} */ @@ -2787,7 +2784,7 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(strripos, arginfo_strripos) PHP_FE(strrev, arginfo_strrev) PHP_FE(hebrev, arginfo_hebrev) - PHP_FE(hebrevc, arginfo_hebrevc) + PHP_DEP_FE(hebrevc, arginfo_hebrevc) PHP_FE(nl2br, arginfo_nl2br) PHP_FE(basename, arginfo_basename) PHP_FE(dirname, arginfo_dirname) @@ -2804,13 +2801,10 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(substr_compare, arginfo_substr_compare) PHP_FE(utf8_encode, arginfo_utf8_encode) PHP_FE(utf8_decode, arginfo_utf8_decode) - -#ifdef HAVE_STRCOLL PHP_FE(strcoll, arginfo_strcoll) -#endif #ifdef HAVE_STRFMON - PHP_FE(money_format, arginfo_money_format) + PHP_DEP_FE(money_format, arginfo_money_format) #endif PHP_FE(substr, arginfo_substr) @@ -2930,6 +2924,7 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(password_get_info, arginfo_password_get_info) PHP_FE(password_needs_rehash, arginfo_password_needs_rehash) PHP_FE(password_verify, arginfo_password_verify) + PHP_FE(password_algos, arginfo_password_algos) PHP_FE(convert_uuencode, arginfo_convert_uuencode) PHP_FE(convert_uudecode, arginfo_convert_uudecode) @@ -3010,14 +3005,14 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(quoted_printable_decode, arginfo_quoted_printable_decode) PHP_FE(quoted_printable_encode, arginfo_quoted_printable_encode) - PHP_FE(convert_cyr_string, arginfo_convert_cyr_string) + PHP_DEP_FE(convert_cyr_string, arginfo_convert_cyr_string) PHP_FE(get_current_user, arginfo_get_current_user) PHP_FE(set_time_limit, arginfo_set_time_limit) PHP_FE(header_register_callback, arginfo_header_register_callback) PHP_FE(get_cfg_var, arginfo_get_cfg_var) - PHP_FE(get_magic_quotes_gpc, arginfo_get_magic_quotes_gpc) - PHP_FE(get_magic_quotes_runtime, arginfo_get_magic_quotes_runtime) + PHP_DEP_FE(get_magic_quotes_gpc, arginfo_get_magic_quotes_gpc) + PHP_DEP_FE(get_magic_quotes_runtime, arginfo_get_magic_quotes_runtime) PHP_FE(error_log, arginfo_error_log) PHP_FE(error_get_last, arginfo_error_get_last) @@ -3052,7 +3047,7 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(ini_restore, arginfo_ini_restore) PHP_FE(get_include_path, arginfo_get_include_path) PHP_FE(set_include_path, arginfo_set_include_path) - PHP_FE(restore_include_path, arginfo_restore_include_path) + PHP_DEP_FE(restore_include_path, arginfo_restore_include_path) PHP_FE(setcookie, arginfo_setcookie) PHP_FE(setrawcookie, arginfo_setrawcookie) @@ -3114,7 +3109,7 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FALIAS(is_integer, is_int, arginfo_is_int) PHP_FALIAS(is_long, is_int, arginfo_is_int) PHP_FALIAS(is_double, is_float, arginfo_is_float) - PHP_FALIAS(is_real, is_float, arginfo_is_float) + PHP_DEP_FALIAS(is_real, is_float, arginfo_is_float) PHP_FE(is_numeric, arginfo_is_numeric) PHP_FE(is_string, arginfo_is_string) PHP_FE(is_array, arginfo_is_array) @@ -3296,7 +3291,7 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ /* functions from mail.c */ PHP_FE(mail, arginfo_mail) - PHP_FE(ezmlm_hash, arginfo_ezmlm_hash) + PHP_DEP_FE(ezmlm_hash, arginfo_ezmlm_hash) /* functions from syslog.c */ #ifdef HAVE_SYSLOG_H @@ -3440,6 +3435,8 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(sapi_windows_cp_get, arginfo_sapi_windows_cp_get) PHP_FE(sapi_windows_cp_is_utf8, arginfo_sapi_windows_cp_is_utf8) PHP_FE(sapi_windows_cp_conv, arginfo_sapi_windows_cp_conv) + PHP_FE(sapi_windows_set_ctrl_handler, arginfo_sapi_windows_set_ctrl_handler) + PHP_FE(sapi_windows_generate_ctrl_event, arginfo_sapi_windows_generate_ctrl_event) #endif PHP_FE_END }; @@ -3580,32 +3577,21 @@ PHPAPI double php_get_inf(void) /* {{{ */ /* }}} */ #define BASIC_MINIT_SUBMODULE(module) \ - if (PHP_MINIT(module)(INIT_FUNC_ARGS_PASSTHRU) == SUCCESS) {\ - BASIC_ADD_SUBMODULE(module); \ + if (PHP_MINIT(module)(INIT_FUNC_ARGS_PASSTHRU) != SUCCESS) {\ + return FAILURE; \ } -#define BASIC_ADD_SUBMODULE(module) \ - zend_hash_str_add_empty_element(&basic_submodules, #module, strlen(#module)); - #define BASIC_RINIT_SUBMODULE(module) \ - if (zend_hash_str_exists(&basic_submodules, #module, strlen(#module))) { \ - PHP_RINIT(module)(INIT_FUNC_ARGS_PASSTHRU); \ - } + PHP_RINIT(module)(INIT_FUNC_ARGS_PASSTHRU); #define BASIC_MINFO_SUBMODULE(module) \ - if (zend_hash_str_exists(&basic_submodules, #module, strlen(#module))) { \ - PHP_MINFO(module)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); \ - } + PHP_MINFO(module)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); #define BASIC_RSHUTDOWN_SUBMODULE(module) \ - if (zend_hash_str_exists(&basic_submodules, #module, strlen(#module))) { \ - PHP_RSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS_PASSTHRU); \ - } + PHP_RSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS_PASSTHRU); #define BASIC_MSHUTDOWN_SUBMODULE(module) \ - if (zend_hash_str_exists(&basic_submodules, #module, strlen(#module))) { \ - PHP_MSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS_PASSTHRU); \ - } + PHP_MSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_MINIT_FUNCTION(basic) /* {{{ */ { @@ -3621,8 +3607,6 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */ #endif #endif - zend_hash_init(&basic_submodules, 0, NULL, NULL, 1); - BG(incomplete_class) = incomplete_class_entry = php_create_incomplete_class(); REGISTER_LONG_CONSTANT("CONNECTION_ABORTED", PHP_CONNECTION_ABORTED, CONST_CS | CONST_PERSISTENT); @@ -3683,9 +3667,7 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */ register_html_constants(INIT_FUNC_ARGS_PASSTHRU); register_string_constants(INIT_FUNC_ARGS_PASSTHRU); - BASIC_ADD_SUBMODULE(dl) - BASIC_ADD_SUBMODULE(mail) - BASIC_ADD_SUBMODULE(streams) + BASIC_MINIT_SUBMODULE(var) BASIC_MINIT_SUBMODULE(file) BASIC_MINIT_SUBMODULE(pack) BASIC_MINIT_SUBMODULE(browscap) @@ -3694,7 +3676,7 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */ BASIC_MINIT_SUBMODULE(password) BASIC_MINIT_SUBMODULE(mt_rand) -#if defined(HAVE_LOCALECONV) && defined(ZTS) +#if defined(ZTS) BASIC_MINIT_SUBMODULE(localeconv) #endif @@ -3778,13 +3760,13 @@ PHP_MSHUTDOWN_FUNCTION(basic) /* {{{ */ BASIC_MSHUTDOWN_SUBMODULE(url_scanner_ex) BASIC_MSHUTDOWN_SUBMODULE(file) BASIC_MSHUTDOWN_SUBMODULE(standard_filters) -#if defined(HAVE_LOCALECONV) && defined(ZTS) +#if defined(ZTS) BASIC_MSHUTDOWN_SUBMODULE(localeconv) #endif BASIC_MSHUTDOWN_SUBMODULE(crypt) BASIC_MSHUTDOWN_SUBMODULE(random) + BASIC_MSHUTDOWN_SUBMODULE(password) - zend_hash_destroy(&basic_submodules); return SUCCESS; } /* }}} */ @@ -3841,7 +3823,9 @@ PHP_RSHUTDOWN_FUNCTION(basic) /* {{{ */ ZVAL_UNDEF(&BG(strtok_zval)); BG(strtok_string) = NULL; #ifdef HAVE_PUTENV + tsrm_env_lock(); zend_hash_destroy(&BG(putenv_ht)); + tsrm_env_unlock(); #endif BG(mt_rand_is_seeded) = 0; @@ -4150,11 +4134,22 @@ PHP_FUNCTION(getenv) } } #else + + tsrm_env_lock(); + /* system method returns a const */ ptr = getenv(str); + if (ptr) { - RETURN_STRING(ptr); + RETVAL_STRING(ptr); } + + tsrm_env_unlock(); + + if (ptr) { + return; + } + #endif RETURN_FALSE; } @@ -4205,6 +4200,7 @@ PHP_FUNCTION(putenv) } #endif + tsrm_env_lock(); zend_hash_str_del(&BG(putenv_ht), pe.key, pe.key_len); /* find previous value */ @@ -4265,6 +4261,7 @@ PHP_FUNCTION(putenv) tzset(); } #endif + tsrm_env_unlock(); #if defined(PHP_WIN32) free(keyw); free(valw); @@ -4341,7 +4338,7 @@ static int parse_opts(char * opts, opt_struct ** result) (*opts >= 97 && *opts <= 122) /* a - z */ ) { paras->opt_char = *opts; - paras->need_param = (*(++opts) == ':') ? 1 : 0; + paras->need_param = *(++opts) == ':'; paras->opt_name = NULL; if (paras->need_param == 1) { opts++; @@ -4376,13 +4373,12 @@ PHP_FUNCTION(getopt) Z_PARAM_STRING(options, options_len) Z_PARAM_OPTIONAL Z_PARAM_ARRAY(p_longopts) - Z_PARAM_ZVAL_DEREF(zoptind) + Z_PARAM_ZVAL(zoptind) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* Init zoptind to 1 */ if (zoptind) { - zval_ptr_dtor(zoptind); - ZVAL_LONG(zoptind, 1); + ZEND_TRY_ASSIGN_REF_LONG(zoptind, 1); } /* Get argv from the global symbol table. We calculate argc ourselves @@ -4530,7 +4526,7 @@ PHP_FUNCTION(getopt) /* Set zoptind to php_optind */ if (zoptind) { - ZVAL_LONG(zoptind, php_optind); + ZEND_TRY_ASSIGN_REF_LONG(zoptind, php_optind); } free_longopts(orig_opts); @@ -4637,30 +4633,30 @@ PHP_FUNCTION(time_nanosleep) Make the script sleep until the specified time */ PHP_FUNCTION(time_sleep_until) { - double d_ts, c_ts; + double target_secs; struct timeval tm; struct timespec php_req, php_rem; + uint64_t current_ns, target_ns, diff_ns; + const uint64_t ns_per_sec = 1000000000; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(d_ts) + Z_PARAM_DOUBLE(target_secs) ZEND_PARSE_PARAMETERS_END(); if (gettimeofday((struct timeval *) &tm, NULL) != 0) { RETURN_FALSE; } - c_ts = (double)(d_ts - tm.tv_sec - tm.tv_usec / 1000000.00); - if (c_ts < 0) { + target_ns = (uint64_t) (target_secs * ns_per_sec); + current_ns = ((uint64_t) tm.tv_sec) * ns_per_sec + ((uint64_t) tm.tv_usec) * 1000; + if (target_ns < current_ns) { php_error_docref(NULL, E_WARNING, "Sleep until to time is less than current time"); RETURN_FALSE; } - php_req.tv_sec = (time_t) c_ts; - if (php_req.tv_sec > c_ts) { /* rounding up occurred */ - php_req.tv_sec--; - } - /* 1sec = 1000000000 nanoseconds */ - php_req.tv_nsec = (long) ((c_ts - php_req.tv_sec) * 1000000000.00); + diff_ns = target_ns - current_ns; + php_req.tv_sec = (time_t) (diff_ns / ns_per_sec); + php_req.tv_nsec = (long) (diff_ns % ns_per_sec); while (nanosleep(&php_req, &php_rem)) { if (errno == EINTR) { @@ -4688,25 +4684,47 @@ PHP_FUNCTION(get_current_user) } /* }}} */ -/* {{{ add_config_entry_cb +static void add_config_entries(HashTable *hash, zval *return_value); + +/* {{{ add_config_entry */ -static int add_config_entry_cb(zval *entry, int num_args, va_list args, zend_hash_key *hash_key) +static void add_config_entry(zend_ulong h, zend_string *key, zval *entry, zval *retval) { - zval *retval = (zval *)va_arg(args, zval*); - zval tmp; - if (Z_TYPE_P(entry) == IS_STRING) { - if (hash_key->key) { - add_assoc_str_ex(retval, ZSTR_VAL(hash_key->key), ZSTR_LEN(hash_key->key), zend_string_copy(Z_STR_P(entry))); + zend_string *str = Z_STR_P(entry); + if (!ZSTR_IS_INTERNED(str)) { + if (!(GC_FLAGS(str) & GC_PERSISTENT)) { + zend_string_addref(str); + } else { + str = zend_string_init(ZSTR_VAL(str), ZSTR_LEN(str), 0); + } + } + + if (key) { + add_assoc_str_ex(retval, ZSTR_VAL(key), ZSTR_LEN(key), str); } else { - add_index_str(retval, hash_key->h, zend_string_copy(Z_STR_P(entry))); + add_index_str(retval, h, str); } } else if (Z_TYPE_P(entry) == IS_ARRAY) { + zval tmp; array_init(&tmp); - zend_hash_apply_with_arguments(Z_ARRVAL_P(entry), add_config_entry_cb, 1, tmp); - zend_hash_update(Z_ARRVAL_P(retval), hash_key->key, &tmp); + add_config_entries(Z_ARRVAL_P(entry), &tmp); + zend_hash_update(Z_ARRVAL_P(retval), key, &tmp); } - return 0; +} +/* }}} */ + +/* {{{ add_config_entries + */ +static void add_config_entries(HashTable *hash, zval *return_value) /* {{{ */ +{ + zend_ulong h; + zend_string *key; + zval *zv; + + ZEND_HASH_FOREACH_KEY_VAL(hash, h, key, zv) + add_config_entry(h, key, zv, return_value); + ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -4727,7 +4745,7 @@ PHP_FUNCTION(get_cfg_var) if (retval) { if (Z_TYPE_P(retval) == IS_ARRAY) { array_init(return_value); - zend_hash_apply_with_arguments(Z_ARRVAL_P(retval), add_config_entry_cb, 1, return_value); + add_config_entries(Z_ARRVAL_P(retval), return_value); return; } else { RETURN_STRING(Z_STRVAL_P(retval)); @@ -4897,7 +4915,7 @@ PHP_FUNCTION(error_clear_last) } /* }}} */ -/* {{{ proto mixed call_user_func(mixed function_name [, mixed parmeter] [, mixed ...]) +/* {{{ proto mixed call_user_func(mixed function_name [, mixed parameter] [, mixed ...]) Call a user function which is the first parameter Warning: This function is special-cased by zend_compile.c and so is usually bypassed */ PHP_FUNCTION(call_user_func) @@ -4950,7 +4968,7 @@ PHP_FUNCTION(call_user_func_array) } /* }}} */ -/* {{{ proto mixed forward_static_call(mixed function_name [, mixed parmeter] [, mixed ...]) U +/* {{{ proto mixed forward_static_call(mixed function_name [, mixed parameter] [, mixed ...]) U Call a user function which is the first parameter */ PHP_FUNCTION(forward_static_call) { @@ -5057,7 +5075,7 @@ static int user_shutdown_function_call(zval *zv) /* {{{ */ return 0; } - if (call_user_function(EG(function_table), NULL, + if (call_user_function(NULL, NULL, &shutdown_function_entry->arguments[0], &retval, shutdown_function_entry->arg_count - 1, @@ -5078,7 +5096,7 @@ static void user_tick_function_call(user_tick_function_entry *tick_fe) /* {{{ */ if (! tick_fe->calling) { tick_fe->calling = 1; - if (call_user_function( EG(function_table), NULL, + if (call_user_function(NULL, NULL, function, &retval, tick_fe->arg_count - 1, @@ -5307,11 +5325,7 @@ PHP_FUNCTION(php_strip_whitespace) php_output_start_default(); - memset(&file_handle, 0, sizeof(file_handle)); - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = filename; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; + zend_stream_init_filename(&file_handle, filename); zend_save_lexical_state(&original_lex_state); if (open_file_for_scanning(&file_handle) == FAILURE) { zend_restore_lexical_state(&original_lex_state); @@ -5344,7 +5358,10 @@ PHP_FUNCTION(highlight_string) Z_PARAM_OPTIONAL Z_PARAM_BOOL(i) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - convert_to_string_ex(expr); + + if (!try_convert_to_string(expr)) { + return; + } if (i) { php_output_start_default(); @@ -5407,64 +5424,17 @@ PHP_FUNCTION(ini_get) } /* }}} */ -static int php_ini_get_option(zval *zv, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ -{ - zend_ini_entry *ini_entry = Z_PTR_P(zv); - zval *ini_array = va_arg(args, zval *); - int module_number = va_arg(args, int); - int details = va_arg(args, int); - zval option; - - if (module_number != 0 && ini_entry->module_number != module_number) { - return 0; - } - - if (hash_key->key == NULL || - ZSTR_VAL(hash_key->key)[0] != 0 - ) { - if (details) { - array_init(&option); - - if (ini_entry->orig_value) { - add_assoc_str(&option, "global_value", zend_string_copy(ini_entry->orig_value)); - } else if (ini_entry->value) { - add_assoc_str(&option, "global_value", zend_string_copy(ini_entry->value)); - } else { - add_assoc_null(&option, "global_value"); - } - - if (ini_entry->value) { - add_assoc_str(&option, "local_value", zend_string_copy(ini_entry->value)); - } else { - add_assoc_null(&option, "local_value"); - } - - add_assoc_long(&option, "access", ini_entry->modifiable); - - zend_symtable_update(Z_ARRVAL_P(ini_array), ini_entry->name, &option); - } else { - if (ini_entry->value) { - zval zv; - - ZVAL_STR_COPY(&zv, ini_entry->value); - zend_symtable_update(Z_ARRVAL_P(ini_array), ini_entry->name, &zv); - } else { - zend_symtable_update(Z_ARRVAL_P(ini_array), ini_entry->name, &EG(uninitialized_zval)); - } - } - } - return 0; -} -/* }}} */ - /* {{{ proto array ini_get_all([string extension[, bool details = true]]) Get all configuration options */ PHP_FUNCTION(ini_get_all) { char *extname = NULL; - size_t extname_len = 0, extnumber = 0; + size_t extname_len = 0, module_number = 0; zend_module_entry *module; zend_bool details = 1; + zend_string *key; + zend_ini_entry *ini_entry; + ZEND_PARSE_PARAMETERS_START(0, 2) Z_PARAM_OPTIONAL @@ -5479,11 +5449,50 @@ PHP_FUNCTION(ini_get_all) php_error_docref(NULL, E_WARNING, "Unable to find extension '%s'", extname); RETURN_FALSE; } - extnumber = module->module_number; + module_number = module->module_number; } array_init(return_value); - zend_hash_apply_with_arguments(EG(ini_directives), php_ini_get_option, 2, return_value, extnumber, details); + ZEND_HASH_FOREACH_STR_KEY_PTR(EG(ini_directives), key, ini_entry) { + zval option; + + if (module_number != 0 && ini_entry->module_number != module_number) { + continue; + } + + if (key == NULL || ZSTR_VAL(key)[0] != 0) { + if (details) { + array_init(&option); + + if (ini_entry->orig_value) { + add_assoc_str(&option, "global_value", zend_string_copy(ini_entry->orig_value)); + } else if (ini_entry->value) { + add_assoc_str(&option, "global_value", zend_string_copy(ini_entry->value)); + } else { + add_assoc_null(&option, "global_value"); + } + + if (ini_entry->value) { + add_assoc_str(&option, "local_value", zend_string_copy(ini_entry->value)); + } else { + add_assoc_null(&option, "local_value"); + } + + add_assoc_long(&option, "access", ini_entry->modifiable); + + zend_symtable_update(Z_ARRVAL_P(return_value), ini_entry->name, &option); + } else { + if (ini_entry->value) { + zval zv; + + ZVAL_STR_COPY(&zv, ini_entry->value); + zend_symtable_update(Z_ARRVAL_P(return_value), ini_entry->name, &zv); + } else { + zend_symtable_update(Z_ARRVAL_P(return_value), ini_entry->name, &EG(uninitialized_zval)); + } + } + } + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -6079,9 +6088,7 @@ PHP_FUNCTION(parse_ini_file) } /* Setup filehandle */ - memset(&fh, 0, sizeof(fh)); - fh.filename = filename; - fh.type = ZEND_HANDLE_FILENAME; + zend_stream_init_filename(&fh, filename); array_init(return_value); if (zend_parse_ini_file(&fh, 0, (int)scanner_mode, ini_parser_cb, return_value) == FAILURE) { @@ -6142,7 +6149,7 @@ PHP_FUNCTION(config_get_hash) /* {{{ */ HashTable *hash = php_ini_get_configuration_hash(); array_init(return_value); - zend_hash_apply_with_arguments(hash, add_config_entry_cb, 1, return_value); + add_config_entries(hash, return_value); } /* }}} */ #endif @@ -6169,12 +6176,3 @@ PHP_FUNCTION(sys_getloadavg) } /* }}} */ #endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ |
