cvs: php4 / php.ini-dist /ext/standard var_unserializer.c /main main.c php_globals.h
| From: | Derick Rethans | Date: | Mon, 26 Nov 2001 21:04:21 +0000 |
| Subject: | cvs: php4 / php.ini-dist /ext/standard var_unserializer.c /main main.c php_globals.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-8316@lists.php.net to get a copy of this message | ||
derick Mon Nov 26 16:04:21 2001 EDT
Modified files:
/php4 php.ini-dist
/php4/ext/standard var_unserializer.c
/php4/main main.c php_globals.h
Log:
- Adding a callback mechanism to the unserializer. (patch by Bernd
Roemer <berndr@bonn.edu>)
#- An explainatory e-mail will be send to php-dev
Index: php4/php.ini-dist
diff -u php4/php.ini-dist:1.103 php4/php.ini-dist:1.104
--- php4/php.ini-dist:1.103 Mon Nov 26 05:55:46 2001
+++ php4/php.ini-dist Mon Nov 26 16:04:20 2001
@@ -94,6 +94,15 @@
; Setting an output handler automatically turns on output buffering.
output_handler =
+; The unserialize callback function will called (with the undefind class'
+; name as parameter), if the unserializer finds an undefined class
+; which should be instanciated.
+; A warning appears if the specified function is not defined, or if the
+; function doesn't include/implement the missing class.
+; So only set this entry, if you really want to implement such a
+; callback-function.
+unserialize_callback_func=
+
; Transparent output compression using the zlib library
; Valid values for this option are 'off', 'on', or a specific buffer size
; to be used for compression (default is 4KB)
Index: php4/ext/standard/var_unserializer.c
diff -u php4/ext/standard/var_unserializer.c:1.2 php4/ext/standard/var_unserializer.c:1.3
--- php4/ext/standard/var_unserializer.c:1.2 Fri Nov 16 11:34:14 2001
+++ php4/ext/standard/var_unserializer.c Mon Nov 26 16:04:21 2001
@@ -371,6 +371,13 @@
zend_class_entry *ce;
int incomplete_class = 0;
+ char *rval_temp;
+
+ zval *user_func;
+ zval *retval_ptr;
+ zval **args[1];
+ zval *arg_func_name;
+
INIT_PZVAL(*rval);
len2 = len = parse_iv(start + 2);
if (len == 0)
@@ -385,12 +392,34 @@
}
}
- if (zend_hash_find(EG(class_table), class_name, len2 + 1, (void **) &ce) != SUCCESS) {
- incomplete_class = 1;
- ce = PHP_IC_ENTRY;
- } else
- efree(class_name);
+ if (zend_hash_find(CG(class_table), class_name, len2 + 1, (void **) &ce) != SUCCESS) {
+ if (PG(unserialize_callback_func) == NULL) {
+ incomplete_class = 1;
+ ce = PHP_IC_ENTRY;
+ } else {
+ MAKE_STD_ZVAL(user_func);
+ ZVAL_STRING(user_func, PG(unserialize_callback_func), 1);
+ args[0] = &arg_func_name;
+ MAKE_STD_ZVAL(arg_func_name);
+ ZVAL_STRING(arg_func_name, class_name, 1);
+
+ if (call_user_function_ex(CG(function_table), NULL, user_func, &retval_ptr, 1, args, 0, NULL
TSRMLS_CC) != SUCCESS) {
+ zend_error(E_WARNING, "'unserialize_callback_func' defined (%s) but not
found", user_func->value.str.val);
+ incomplete_class = 1;
+ ce = PHP_IC_ENTRY;
+ } else {
+ if (zend_hash_find(CG(class_table), class_name, len2 + 1, (void **) &ce) != SUCCESS) {
+ zend_error(E_WARNING, "'unserialize_callback_func' (%s) hasn't defined the
class it was called for", user_func->value.str.val);
+ incomplete_class = 1;
+ ce = PHP_IC_ENTRY;
+ } else
+ efree(class_name);
+ }
+ }
+ } else
+ efree(class_name);
+
*p = YYCURSOR;
elements = object_common1(UNSERIALIZE_PASSTHRU, ce);
Index: php4/main/main.c
diff -u php4/main/main.c:1.412 php4/main/main.c:1.413
--- php4/main/main.c:1.412 Mon Nov 26 13:57:44 2001
+++ php4/main/main.c Mon Nov 26 16:04:21 2001
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: main.c,v 1.412 2001/11/26 18:57:44 sterling Exp $ */
+/* $Id: main.c,v 1.413 2001/11/26 21:04:21 derick Exp $ */
/* {{{ includes
*/
@@ -239,6 +239,7 @@
STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("y2k_compliance", "0", PHP_INI_ALL, OnUpdateBool, y2k_compliance, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateStringUnempty, unserialize_callback_func, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
Index: php4/main/php_globals.h
diff -u php4/main/php_globals.h:1.70 php4/main/php_globals.h:1.71
--- php4/main/php_globals.h:1.70 Sat Aug 11 18:55:00 2001
+++ php4/main/php_globals.h Mon Nov 26 16:04:21 2001
@@ -66,6 +66,8 @@
char *output_handler;
+ char *unserialize_callback_func;
+
char *safe_mode_exec_dir;
long memory_limit;