xref: /PHP-7.3/ext/filter/callback_filter.c (revision 8d3f8ca1)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2018 The PHP Group                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Authors: Derick Rethans <derick@php.net>                             |
16   +----------------------------------------------------------------------+
17 */
18 
19 #include "php_filter.h"
20 
php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL)21 void php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL)
22 {
23 	zval retval;
24 	zval args[1];
25 	int status;
26 
27 	if (!option_array || !zend_is_callable(option_array, IS_CALLABLE_CHECK_NO_ACCESS, NULL)) {
28 		php_error_docref(NULL, E_WARNING, "First argument is expected to be a valid callback");
29 		zval_ptr_dtor(value);
30 		ZVAL_NULL(value);
31 		return;
32 	}
33 
34 	ZVAL_COPY(&args[0], value);
35 	status = call_user_function_ex(EG(function_table), NULL, option_array, &retval, 1, args, 0, NULL);
36 
37 	if (status == SUCCESS && !Z_ISUNDEF(retval)) {
38 		zval_ptr_dtor(value);
39 		ZVAL_COPY_VALUE(value, &retval);
40 	} else {
41 		zval_ptr_dtor(value);
42 		ZVAL_NULL(value);
43 	}
44 
45 	zval_ptr_dtor(&args[0]);
46 }
47 
48 /*
49  * Local variables:
50  * tab-width: 4
51  * c-basic-offset: 4
52  * End:
53  * vim600: noet sw=4 ts=4 fdm=marker
54  * vim<600: noet sw=4 ts=4
55  */
56