From 8f17fbb900b3c53e3cc43be3f7ff4de4ee854c5f Mon Sep 17 00:00:00 2001 From: Andrei Zmievski Date: Thu, 16 Dec 1999 23:47:10 +0000 Subject: [PATCH] Added get_loaded_extensions(), extension_loaded(), and get_extension_funcs() functions. @ Added get_loaded_extensions(), extension_loaded(), and get_extension_funcs() functions. (Andrei) --- TODO | 5 +-- ext/standard/basic_functions.c | 73 ++++++++++++++++++++++++++++++++++ ext/standard/basic_functions.h | 4 ++ 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index d06a13c05f..0d0f87cf1c 100644 --- a/TODO +++ b/TODO @@ -26,10 +26,7 @@ ext/oci8 ext/standard ------------ * strpad() (Andrei) - * comparing arrays semantically (Andrei) - * get_loaded_extensions() - extension_loaded() - get_extension_funcs() (Andrei) + * comparing arrays semantically (like Python) (Andrei) * NOT binary safe: strtok() basename() diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index d92fbac3c5..8538ab0c66 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -309,6 +309,10 @@ function_entry basic_functions[] = { PHP_FE(connection_status, NULL) PHP_FE(ignore_user_abort, NULL) + PHP_FE(get_loaded_extensions, NULL) + PHP_FE(extension_loaded, NULL) + PHP_FE(get_extension_funcs, NULL) + {NULL, NULL, NULL} }; @@ -1500,6 +1504,75 @@ PHP_FUNCTION(getprotobynumber) /* }}} */ +static int php_add_extension_info(zend_module_entry *module, void *arg) +{ + zval *name_array = (zval *)arg; + add_next_index_string(name_array, module->name, 1); + return 0; +} + +/* {{{ proto array get_loaded_extensions(void) + Return an array containing names of loaded extensions */ +PHP_FUNCTION(get_loaded_extensions) +{ + if (ARG_COUNT(ht) != 0) { + WRONG_PARAM_COUNT; + } + + array_init(return_value); + zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void*)) php_add_extension_info, return_value); +} +/* }}} */ + + +/* {{{ proto bool extension_loaded(string extension_name) + Returns true if the named extension is loaded */ +PHP_FUNCTION(extension_loaded) +{ + zval **extension_name; + + if (ARG_COUNT(ht) != 1 || getParametersEx(1, &extension_name)) { + WRONG_PARAM_COUNT; + } + + convert_to_string_ex(extension_name); + if (zend_hash_exists(&module_registry, (*extension_name)->value.str.val, (*extension_name)->value.str.len+1)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + + +/* proto array get_extension_funcs(string extension_name) + Returns an array with the names of functions belonging to the named extension */ +PHP_FUNCTION(get_extension_funcs) +{ + zval **extension_name; + zend_module_entry *module; + zend_function_entry *func; + + if (ARG_COUNT(ht) != 1 || getParametersEx(1, &extension_name)) { + WRONG_PARAM_COUNT; + } + + convert_to_string_ex(extension_name); + if (zend_hash_find(&module_registry, (*extension_name)->value.str.val, + (*extension_name)->value.str.len+1, (void**)&module) == FAILURE) { + return; + } + + array_init(return_value); + func = module->functions; + while(func->fname) { + add_next_index_string(return_value, func->fname, 1); + func++; + } +} +/* }}} */ + + /* * Local variables: * tab-width: 4 diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 188f9ffc54..cde57adcb7 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -103,6 +103,10 @@ PHP_FUNCTION(getservbyport); PHP_FUNCTION(getprotobyname); PHP_FUNCTION(getprotobynumber); +PHP_FUNCTION(get_loaded_extensions); +PHP_FUNCTION(extension_loaded); +PHP_FUNCTION(get_extension_funcs); + #if MSVC5 typedef unsigned int php_stat_len; #else -- 2.40.0