1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| #ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_rename.h"
static int le_rename;
ZEND_BEGIN_ARG_INFO_EX(arginfo_function_rename, 0, 0, 2)
ZEND_ARG_INFO(0, orig_func)
ZEND_ARG_INFO(0, new_func)
ZEND_END_ARG_INFO()
/* {{{ rename_functions[]
*
* Every user visible function must have an entry in rename_functions[].
*/
const zend_function_entry rename_functions[] = {
PHP_FE(function_rename, arginfo_function_rename)
{NULL,NULL,NULL}
};
/* }}} */
/* {{{ rename_module_entry
*/
zend_module_entry rename_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"rename",
rename_functions,
PHP_MINIT(rename),
PHP_MSHUTDOWN(rename),
NULL,
NULL,
PHP_MINFO(rename),
#if ZEND_MODULE_API_NO >= 20010901
"0.1",
#endif
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_RENAME
ZEND_GET_MODULE(rename)
#endif
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(rename)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(rename)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(comuto)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
PHP_RSHUTDOWN_FUNCTION(comuto)
{
return SUCCESS;
}
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(rename)
{
php_info_print_table_start();
php_info_print_table_header(2, "rename support", "enabled");
php_info_print_table_end();
}
/* }}} */
/* {{{ proto string function_rename(string orig_func, string new_func)
*/
PHP_FUNCTION(function_rename)
{
char *orig_func, *new_func, *orig_lower, *new_lower;
int orig_func_len, new_func_len, i;
zend_function *func;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &orig_func, &orig_func_len, &new_func, &new_func_len) == FAILURE) {
return;
}
// Normalize the source function name to lower case.
orig_lower = malloc(orig_func_len+1);
for (i = 0; i < orig_func_len; i ++) {
orig_lower[i] = tolower(orig_func[i]);
}
orig_lower[i] = 0;
// Normalize the destination function name to lower case.
new_lower = malloc(new_func_len + 1);
for (i = 0; i < new_func_len; i++) {
new_lower[i] = tolower(new_func[i]);
}
new_lower[i] = 0;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &orig_func, &orig_func_len, &new_func, &new_func_len) == FAILURE) {
return;
}
if(zend_hash_find(EG(function_table), orig_lower, orig_func_len + 1, (void **) &func) == FAILURE) {
zend_error(E_WARNING, "cannot find %s()", orig_func);
RETURN_FALSE;
}
if(zend_hash_exists(EG(function_table), new_lower, new_func_len + 1)) {
zend_error(E_WARNING, "%s() already exists", new_func);
RETURN_FALSE;
}
if(zend_hash_add(EG(function_table), new_lower, new_func_len + 1, func, sizeof(zend_function), NULL) == FAILURE) {
zend_error(E_WARNING, "cannot rename %s()", orig_func);
RETURN_FALSE;
}
if(zend_hash_del(EG(function_table), orig_lower, orig_func_len + 1) == FAILURE) {
zend_error(E_WARNING, "cannot rename %s()", orig_func);
RETURN_FALSE;
}
RETURN_TRUE;
} |
Partager