PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/filter - filter.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 330 364 90.7 %
Date: 2014-10-30 Functions: 22 22 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2014 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: Rasmus Lerdorf <rasmus@php.net>                             |
      16             :   |          Derick Rethans <derick@php.net>                             |
      17             :   |          Pierre-A. Joye <pierre@php.net>                             |
      18             :   |          Ilia Alshanetsky <iliaa@php.net>                            |
      19             :   +----------------------------------------------------------------------+
      20             : */
      21             : 
      22             : /* $Id: 530dce6f53302e8041f9c7cf79634f61ee747830 $ */
      23             : 
      24             : #ifdef HAVE_CONFIG_H
      25             : #include "config.h"
      26             : #endif
      27             : 
      28             : #include "php_filter.h"
      29             : 
      30             : ZEND_DECLARE_MODULE_GLOBALS(filter)
      31             : 
      32             : #include "filter_private.h"
      33             : 
      34             : typedef struct filter_list_entry {
      35             :         const char *name;
      36             :         int    id;
      37             :         void (*function)(PHP_INPUT_FILTER_PARAM_DECL);
      38             : } filter_list_entry;
      39             : 
      40             : /* {{{ filter_list */
      41             : static const filter_list_entry filter_list[] = {
      42             :         { "int",             FILTER_VALIDATE_INT,           php_filter_int             },
      43             :         { "boolean",         FILTER_VALIDATE_BOOLEAN,       php_filter_boolean         },
      44             :         { "float",           FILTER_VALIDATE_FLOAT,         php_filter_float           },
      45             : 
      46             :         { "validate_regexp", FILTER_VALIDATE_REGEXP,        php_filter_validate_regexp },
      47             :         { "validate_url",    FILTER_VALIDATE_URL,           php_filter_validate_url    },
      48             :         { "validate_email",  FILTER_VALIDATE_EMAIL,         php_filter_validate_email  },
      49             :         { "validate_ip",     FILTER_VALIDATE_IP,            php_filter_validate_ip     },
      50             :         { "validate_mac",    FILTER_VALIDATE_MAC,           php_filter_validate_mac    },
      51             : 
      52             :         { "string",          FILTER_SANITIZE_STRING,        php_filter_string          },
      53             :         { "stripped",        FILTER_SANITIZE_STRING,        php_filter_string          },
      54             :         { "encoded",         FILTER_SANITIZE_ENCODED,       php_filter_encoded         },
      55             :         { "special_chars",   FILTER_SANITIZE_SPECIAL_CHARS, php_filter_special_chars   },
      56             :         { "full_special_chars",   FILTER_SANITIZE_FULL_SPECIAL_CHARS, php_filter_full_special_chars   },
      57             :         { "unsafe_raw",      FILTER_UNSAFE_RAW,             php_filter_unsafe_raw      },
      58             :         { "email",           FILTER_SANITIZE_EMAIL,         php_filter_email           },
      59             :         { "url",             FILTER_SANITIZE_URL,           php_filter_url             },
      60             :         { "number_int",      FILTER_SANITIZE_NUMBER_INT,    php_filter_number_int      },
      61             :         { "number_float",    FILTER_SANITIZE_NUMBER_FLOAT,  php_filter_number_float    },
      62             :         { "magic_quotes",    FILTER_SANITIZE_MAGIC_QUOTES,  php_filter_magic_quotes    },
      63             : 
      64             :         { "callback",        FILTER_CALLBACK,               php_filter_callback        },
      65             : };
      66             : /* }}} */
      67             : 
      68             : #ifndef PARSE_ENV
      69             : #define PARSE_ENV 4
      70             : #endif
      71             : 
      72             : #ifndef PARSE_SERVER
      73             : #define PARSE_SERVER 5
      74             : #endif
      75             : 
      76             : #ifndef PARSE_SESSION
      77             : #define PARSE_SESSION 6
      78             : #endif
      79             : 
      80             : static unsigned int php_sapi_filter(int arg, char *var, char **val, size_t val_len, size_t *new_val_len TSRMLS_DC);
      81             : static unsigned int php_sapi_filter_init(TSRMLS_D);
      82             : 
      83             : /* {{{ arginfo */
      84             : ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_input, 0, 0, 2)
      85             :         ZEND_ARG_INFO(0, type)
      86             :         ZEND_ARG_INFO(0, variable_name)
      87             :         ZEND_ARG_INFO(0, filter)
      88             :         ZEND_ARG_INFO(0, options)
      89             : ZEND_END_ARG_INFO()
      90             : 
      91             : ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_var, 0, 0, 1)
      92             :         ZEND_ARG_INFO(0, variable)
      93             :         ZEND_ARG_INFO(0, filter)
      94             :         ZEND_ARG_INFO(0, options)
      95             : ZEND_END_ARG_INFO()
      96             : 
      97             : ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_input_array, 0, 0, 1)
      98             :         ZEND_ARG_INFO(0, type)
      99             :         ZEND_ARG_INFO(0, definition)
     100             :         ZEND_ARG_INFO(0, add_empty)
     101             : ZEND_END_ARG_INFO()
     102             : 
     103             : ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_var_array, 0, 0, 1)
     104             :         ZEND_ARG_INFO(0, data)
     105             :         ZEND_ARG_INFO(0, definition)
     106             :         ZEND_ARG_INFO(0, add_empty)
     107             : ZEND_END_ARG_INFO()
     108             : 
     109             : ZEND_BEGIN_ARG_INFO(arginfo_filter_list, 0)
     110             : ZEND_END_ARG_INFO()
     111             : 
     112             : ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_has_var, 0, 0, 2)
     113             :         ZEND_ARG_INFO(0, type)
     114             :         ZEND_ARG_INFO(0, variable_name)
     115             : ZEND_END_ARG_INFO()
     116             : 
     117             : ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_id, 0, 0, 1)
     118             :         ZEND_ARG_INFO(0, filtername)
     119             : ZEND_END_ARG_INFO()
     120             : /* }}} */
     121             : 
     122             : /* {{{ filter_functions[]
     123             :  */
     124             : static const zend_function_entry filter_functions[] = {
     125             :         PHP_FE(filter_input,            arginfo_filter_input)
     126             :         PHP_FE(filter_var,              arginfo_filter_var)
     127             :         PHP_FE(filter_input_array,      arginfo_filter_input_array)
     128             :         PHP_FE(filter_var_array,        arginfo_filter_var_array)
     129             :         PHP_FE(filter_list,             arginfo_filter_list)
     130             :         PHP_FE(filter_has_var,          arginfo_filter_has_var)
     131             :         PHP_FE(filter_id,               arginfo_filter_id)
     132             :         PHP_FE_END
     133             : };
     134             : /* }}} */
     135             : 
     136             : /* {{{ filter_module_entry
     137             :  */
     138             : zend_module_entry filter_module_entry = {
     139             : #if ZEND_MODULE_API_NO >= 20010901
     140             :         STANDARD_MODULE_HEADER,
     141             : #endif
     142             :         "filter",
     143             :         filter_functions,
     144             :         PHP_MINIT(filter),
     145             :         PHP_MSHUTDOWN(filter),
     146             :         NULL,
     147             :         PHP_RSHUTDOWN(filter),
     148             :         PHP_MINFO(filter),
     149             :         "0.11.0",
     150             :         STANDARD_MODULE_PROPERTIES
     151             : };
     152             : /* }}} */
     153             : 
     154             : #ifdef COMPILE_DL_FILTER
     155             : ZEND_GET_MODULE(filter)
     156             : #endif
     157             : 
     158       20423 : static PHP_INI_MH(UpdateDefaultFilter) /* {{{ */
     159             : {
     160       20423 :         int i, size = sizeof(filter_list) / sizeof(filter_list_entry);
     161             : 
     162      285902 :         for (i = 0; i < size; ++i) {
     163      285902 :                 if ((strcasecmp(new_value->val, filter_list[i].name) == 0)) {
     164       20423 :                         IF_G(default_filter) = filter_list[i].id;
     165       20423 :                         return SUCCESS;
     166             :                 }
     167             :         }
     168             :         /* Fallback to the default filter */
     169           0 :         IF_G(default_filter) = FILTER_DEFAULT;
     170           0 :         return SUCCESS;
     171             : }
     172             : /* }}} */
     173             : 
     174             : /* {{{ PHP_INI
     175             :  */
     176       20423 : static PHP_INI_MH(OnUpdateFlags)
     177             : {
     178       20423 :         if (!new_value) {
     179       20417 :                 IF_G(default_filter_flags) = FILTER_FLAG_NO_ENCODE_QUOTES;
     180             :         } else {
     181           6 :                 IF_G(default_filter_flags) = atoi(new_value->val);
     182             :         }
     183       20423 :         return SUCCESS;
     184             : }
     185             : 
     186             : PHP_INI_BEGIN()
     187             :         STD_PHP_INI_ENTRY("filter.default",   "unsafe_raw", PHP_INI_SYSTEM|PHP_INI_PERDIR, UpdateDefaultFilter, default_filter, zend_filter_globals, filter_globals)
     188             :         PHP_INI_ENTRY("filter.default_flags", NULL,     PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateFlags)
     189             : PHP_INI_END()
     190             : /* }}} */
     191             : 
     192       20423 : static void php_filter_init_globals(zend_filter_globals *filter_globals) /* {{{ */
     193             : {
     194       20423 :         ZVAL_UNDEF(&filter_globals->post_array);
     195       20423 :         ZVAL_UNDEF(&filter_globals->get_array);
     196       20423 :         ZVAL_UNDEF(&filter_globals->cookie_array);
     197       20423 :         ZVAL_UNDEF(&filter_globals->env_array);
     198       20423 :         ZVAL_UNDEF(&filter_globals->server_array);
     199       20423 :         ZVAL_UNDEF(&filter_globals->session_array);
     200       20423 :         filter_globals->default_filter = FILTER_DEFAULT;
     201       20423 : }
     202             : /* }}} */
     203             : 
     204             : #define PARSE_REQUEST 99
     205             : 
     206             : /* {{{ PHP_MINIT_FUNCTION
     207             :  */
     208       20423 : PHP_MINIT_FUNCTION(filter)
     209             : {
     210       20423 :         ZEND_INIT_MODULE_GLOBALS(filter, php_filter_init_globals, NULL);
     211             : 
     212       20423 :         REGISTER_INI_ENTRIES();
     213             : 
     214       20423 :         REGISTER_LONG_CONSTANT("INPUT_POST",  PARSE_POST,     CONST_CS | CONST_PERSISTENT);
     215       20423 :         REGISTER_LONG_CONSTANT("INPUT_GET",           PARSE_GET,              CONST_CS | CONST_PERSISTENT);
     216       20423 :         REGISTER_LONG_CONSTANT("INPUT_COOKIE",        PARSE_COOKIE,   CONST_CS | CONST_PERSISTENT);
     217       20423 :         REGISTER_LONG_CONSTANT("INPUT_ENV",           PARSE_ENV,              CONST_CS | CONST_PERSISTENT);
     218       20423 :         REGISTER_LONG_CONSTANT("INPUT_SERVER",        PARSE_SERVER,   CONST_CS | CONST_PERSISTENT);
     219       20423 :         REGISTER_LONG_CONSTANT("INPUT_SESSION", PARSE_SESSION,        CONST_CS | CONST_PERSISTENT);
     220       20423 :         REGISTER_LONG_CONSTANT("INPUT_REQUEST", PARSE_REQUEST,        CONST_CS | CONST_PERSISTENT);
     221             : 
     222       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_NONE", FILTER_FLAG_NONE, CONST_CS | CONST_PERSISTENT);
     223             : 
     224       20423 :         REGISTER_LONG_CONSTANT("FILTER_REQUIRE_SCALAR", FILTER_REQUIRE_SCALAR, CONST_CS | CONST_PERSISTENT);
     225       20423 :         REGISTER_LONG_CONSTANT("FILTER_REQUIRE_ARRAY", FILTER_REQUIRE_ARRAY, CONST_CS | CONST_PERSISTENT);
     226       20423 :         REGISTER_LONG_CONSTANT("FILTER_FORCE_ARRAY", FILTER_FORCE_ARRAY, CONST_CS | CONST_PERSISTENT);
     227       20423 :         REGISTER_LONG_CONSTANT("FILTER_NULL_ON_FAILURE", FILTER_NULL_ON_FAILURE, CONST_CS | CONST_PERSISTENT);
     228             : 
     229       20423 :         REGISTER_LONG_CONSTANT("FILTER_VALIDATE_INT", FILTER_VALIDATE_INT, CONST_CS | CONST_PERSISTENT);
     230       20423 :         REGISTER_LONG_CONSTANT("FILTER_VALIDATE_BOOLEAN", FILTER_VALIDATE_BOOLEAN, CONST_CS | CONST_PERSISTENT);
     231       20423 :         REGISTER_LONG_CONSTANT("FILTER_VALIDATE_FLOAT", FILTER_VALIDATE_FLOAT, CONST_CS | CONST_PERSISTENT);
     232             : 
     233       20423 :         REGISTER_LONG_CONSTANT("FILTER_VALIDATE_REGEXP", FILTER_VALIDATE_REGEXP, CONST_CS | CONST_PERSISTENT);
     234       20423 :         REGISTER_LONG_CONSTANT("FILTER_VALIDATE_URL", FILTER_VALIDATE_URL, CONST_CS | CONST_PERSISTENT);
     235       20423 :         REGISTER_LONG_CONSTANT("FILTER_VALIDATE_EMAIL", FILTER_VALIDATE_EMAIL, CONST_CS | CONST_PERSISTENT);
     236       20423 :         REGISTER_LONG_CONSTANT("FILTER_VALIDATE_IP", FILTER_VALIDATE_IP, CONST_CS | CONST_PERSISTENT);
     237       20423 :         REGISTER_LONG_CONSTANT("FILTER_VALIDATE_MAC", FILTER_VALIDATE_MAC, CONST_CS | CONST_PERSISTENT);
     238             : 
     239       20423 :         REGISTER_LONG_CONSTANT("FILTER_DEFAULT", FILTER_DEFAULT, CONST_CS | CONST_PERSISTENT);
     240       20423 :         REGISTER_LONG_CONSTANT("FILTER_UNSAFE_RAW", FILTER_UNSAFE_RAW, CONST_CS | CONST_PERSISTENT);
     241             : 
     242       20423 :         REGISTER_LONG_CONSTANT("FILTER_SANITIZE_STRING", FILTER_SANITIZE_STRING, CONST_CS | CONST_PERSISTENT);
     243       20423 :         REGISTER_LONG_CONSTANT("FILTER_SANITIZE_STRIPPED", FILTER_SANITIZE_STRING, CONST_CS | CONST_PERSISTENT);
     244       20423 :         REGISTER_LONG_CONSTANT("FILTER_SANITIZE_ENCODED", FILTER_SANITIZE_ENCODED, CONST_CS | CONST_PERSISTENT);
     245       20423 :         REGISTER_LONG_CONSTANT("FILTER_SANITIZE_SPECIAL_CHARS", FILTER_SANITIZE_SPECIAL_CHARS, CONST_CS | CONST_PERSISTENT);
     246       20423 :         REGISTER_LONG_CONSTANT("FILTER_SANITIZE_FULL_SPECIAL_CHARS", FILTER_SANITIZE_FULL_SPECIAL_CHARS, CONST_CS | CONST_PERSISTENT);
     247       20423 :         REGISTER_LONG_CONSTANT("FILTER_SANITIZE_EMAIL", FILTER_SANITIZE_EMAIL, CONST_CS | CONST_PERSISTENT);
     248       20423 :         REGISTER_LONG_CONSTANT("FILTER_SANITIZE_URL", FILTER_SANITIZE_URL, CONST_CS | CONST_PERSISTENT);
     249       20423 :         REGISTER_LONG_CONSTANT("FILTER_SANITIZE_NUMBER_INT", FILTER_SANITIZE_NUMBER_INT, CONST_CS | CONST_PERSISTENT);
     250       20423 :         REGISTER_LONG_CONSTANT("FILTER_SANITIZE_NUMBER_FLOAT", FILTER_SANITIZE_NUMBER_FLOAT, CONST_CS | CONST_PERSISTENT);
     251       20423 :         REGISTER_LONG_CONSTANT("FILTER_SANITIZE_MAGIC_QUOTES", FILTER_SANITIZE_MAGIC_QUOTES, CONST_CS | CONST_PERSISTENT);
     252             : 
     253       20423 :         REGISTER_LONG_CONSTANT("FILTER_CALLBACK", FILTER_CALLBACK, CONST_CS | CONST_PERSISTENT);
     254             : 
     255       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_ALLOW_OCTAL", FILTER_FLAG_ALLOW_OCTAL, CONST_CS | CONST_PERSISTENT);
     256       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_ALLOW_HEX", FILTER_FLAG_ALLOW_HEX, CONST_CS | CONST_PERSISTENT);
     257             : 
     258       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_STRIP_LOW", FILTER_FLAG_STRIP_LOW, CONST_CS | CONST_PERSISTENT);
     259       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_STRIP_HIGH", FILTER_FLAG_STRIP_HIGH, CONST_CS | CONST_PERSISTENT);
     260       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_STRIP_BACKTICK", FILTER_FLAG_STRIP_BACKTICK, CONST_CS | CONST_PERSISTENT);
     261       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_ENCODE_LOW", FILTER_FLAG_ENCODE_LOW, CONST_CS | CONST_PERSISTENT);
     262       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_ENCODE_HIGH", FILTER_FLAG_ENCODE_HIGH, CONST_CS | CONST_PERSISTENT);
     263       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_ENCODE_AMP", FILTER_FLAG_ENCODE_AMP, CONST_CS | CONST_PERSISTENT);
     264       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_NO_ENCODE_QUOTES", FILTER_FLAG_NO_ENCODE_QUOTES, CONST_CS | CONST_PERSISTENT);
     265       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_EMPTY_STRING_NULL", FILTER_FLAG_EMPTY_STRING_NULL, CONST_CS | CONST_PERSISTENT);
     266             : 
     267       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_ALLOW_FRACTION", FILTER_FLAG_ALLOW_FRACTION, CONST_CS | CONST_PERSISTENT);
     268       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_ALLOW_THOUSAND", FILTER_FLAG_ALLOW_THOUSAND, CONST_CS | CONST_PERSISTENT);
     269       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_ALLOW_SCIENTIFIC", FILTER_FLAG_ALLOW_SCIENTIFIC, CONST_CS | CONST_PERSISTENT);
     270             : 
     271       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_SCHEME_REQUIRED", FILTER_FLAG_SCHEME_REQUIRED, CONST_CS | CONST_PERSISTENT);
     272       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_HOST_REQUIRED", FILTER_FLAG_HOST_REQUIRED, CONST_CS | CONST_PERSISTENT);
     273       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_PATH_REQUIRED", FILTER_FLAG_PATH_REQUIRED, CONST_CS | CONST_PERSISTENT);
     274       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_QUERY_REQUIRED", FILTER_FLAG_QUERY_REQUIRED, CONST_CS | CONST_PERSISTENT);
     275             : 
     276       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_IPV4", FILTER_FLAG_IPV4, CONST_CS | CONST_PERSISTENT);
     277       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_IPV6", FILTER_FLAG_IPV6, CONST_CS | CONST_PERSISTENT);
     278       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_NO_RES_RANGE", FILTER_FLAG_NO_RES_RANGE, CONST_CS | CONST_PERSISTENT);
     279       20423 :         REGISTER_LONG_CONSTANT("FILTER_FLAG_NO_PRIV_RANGE", FILTER_FLAG_NO_PRIV_RANGE, CONST_CS | CONST_PERSISTENT);
     280             : 
     281       20423 :         sapi_register_input_filter(php_sapi_filter, php_sapi_filter_init TSRMLS_CC);
     282             : 
     283       20423 :         return SUCCESS;
     284             : }
     285             : /* }}} */
     286             : 
     287             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     288             :  */
     289       20457 : PHP_MSHUTDOWN_FUNCTION(filter)
     290             : {
     291       20457 :         UNREGISTER_INI_ENTRIES();
     292             : 
     293       20457 :         return SUCCESS;
     294             : }
     295             : /* }}} */
     296             : 
     297             : /* {{{ PHP_RSHUTDOWN_FUNCTION
     298             :  */
     299             : #define VAR_ARRAY_COPY_DTOR(a)   \
     300             :         if (!Z_ISUNDEF(IF_G(a))) {   \
     301             :                 zval_ptr_dtor(&IF_G(a)); \
     302             :                 ZVAL_UNDEF(&IF_G(a));    \
     303             :         }
     304             : 
     305       20416 : PHP_RSHUTDOWN_FUNCTION(filter)
     306             : {
     307       20416 :         VAR_ARRAY_COPY_DTOR(get_array)
     308       20416 :         VAR_ARRAY_COPY_DTOR(post_array)
     309       20416 :         VAR_ARRAY_COPY_DTOR(cookie_array)
     310       20416 :         VAR_ARRAY_COPY_DTOR(server_array)
     311       20416 :         VAR_ARRAY_COPY_DTOR(env_array)
     312       20416 :         VAR_ARRAY_COPY_DTOR(session_array)
     313       20416 :         return SUCCESS;
     314             : }
     315             : /* }}} */
     316             : 
     317             : /* {{{ PHP_MINFO_FUNCTION
     318             :  */
     319         143 : PHP_MINFO_FUNCTION(filter)
     320             : {
     321         143 :         php_info_print_table_start();
     322         143 :         php_info_print_table_row( 2, "Input Validation and Filtering", "enabled" );
     323         143 :         php_info_print_table_row( 2, "Revision", "$Id: 530dce6f53302e8041f9c7cf79634f61ee747830 $");
     324         143 :         php_info_print_table_end();
     325             : 
     326         143 :         DISPLAY_INI_ENTRIES();
     327         143 : }
     328             : /* }}} */
     329             : 
     330         984 : static filter_list_entry php_find_filter(zend_long id) /* {{{ */
     331             : {
     332         984 :         int i, size = sizeof(filter_list) / sizeof(filter_list_entry);
     333             : 
     334        8007 :         for (i = 0; i < size; ++i) {
     335        8002 :                 if (filter_list[i].id == id) {
     336         979 :                         return filter_list[i];
     337             :                 }
     338             :         }
     339             :         /* Fallback to "string" filter */
     340          70 :         for (i = 0; i < size; ++i) {
     341          70 :                 if (filter_list[i].id == FILTER_DEFAULT) {
     342           5 :                         return filter_list[i];
     343             :                 }
     344             :         }
     345             :         /* To shut up GCC */
     346           0 :         return filter_list[0];
     347             : }
     348             : /* }}} */
     349             : 
     350       20380 : static unsigned int php_sapi_filter_init(TSRMLS_D)
     351             : {
     352       20380 :         ZVAL_UNDEF(&IF_G(get_array));
     353       20380 :         ZVAL_UNDEF(&IF_G(post_array));
     354       20380 :         ZVAL_UNDEF(&IF_G(cookie_array));
     355       20380 :         ZVAL_UNDEF(&IF_G(server_array));
     356       20380 :         ZVAL_UNDEF(&IF_G(env_array));
     357       20380 :         ZVAL_UNDEF(&IF_G(session_array));
     358       20380 :         return SUCCESS;
     359             : }
     360             : 
     361         984 : static void php_zval_filter(zval *value, zend_long filter, zend_long flags, zval *options, char* charset, zend_bool copy TSRMLS_DC) /* {{{ */
     362             : {
     363             :         filter_list_entry  filter_func;
     364             : 
     365         984 :         filter_func = php_find_filter(filter);
     366             : 
     367         984 :         if (!filter_func.id) {
     368             :                 /* Find default filter */
     369           0 :                 filter_func = php_find_filter(FILTER_DEFAULT);
     370             :         }
     371             : 
     372         984 :         if (copy) {
     373        1605 :                 SEPARATE_ZVAL(value);
     374             :         }
     375             : 
     376             :         /* #49274, fatal error with object without a toString method
     377             :           Fails nicely instead of getting a recovarable fatal error. */
     378         984 :         if (Z_TYPE_P(value) == IS_OBJECT) {
     379             :                 zend_class_entry *ce;
     380             : 
     381           2 :                 ce = Z_OBJCE_P(value);
     382           2 :                 if (!ce->__tostring) {
     383           1 :                         ZVAL_FALSE(value);
     384           1 :                         return;
     385             :                 }
     386             :         }
     387             : 
     388             :         /* Here be strings */
     389         983 :         convert_to_string(value);
     390             : 
     391         983 :         filter_func.function(value, flags, options, charset TSRMLS_CC);
     392             : 
     393        1244 :         if (options && (Z_TYPE_P(options) == IS_ARRAY || Z_TYPE_P(options) == IS_OBJECT) &&
     394          41 :                 ((flags & FILTER_NULL_ON_FAILURE && Z_TYPE_P(value) == IS_NULL) || 
     395          41 :                 (!(flags & FILTER_NULL_ON_FAILURE) && Z_TYPE_P(value) == IS_FALSE)) &&
     396          26 :                 zend_hash_str_exists(HASH_OF(options), "default", sizeof("default") - 1)) {
     397             :                 zval *tmp; 
     398           1 :                 if ((tmp = zend_hash_str_find(HASH_OF(options), "default", sizeof("default") - 1)) != NULL) {
     399           1 :                         ZVAL_COPY(value, tmp);
     400             :                 }
     401             :         }
     402             : }
     403             : /* }}} */
     404             : 
     405      100486 : static unsigned int php_sapi_filter(int arg, char *var, char **val, size_t val_len, size_t *new_val_len TSRMLS_DC) /* {{{ */
     406             : {
     407             :         zval  new_var, raw_var;
     408      100486 :         zval *array_ptr = NULL, *orig_array_ptr = NULL;
     409      100486 :         int retval = 0;
     410             : 
     411             :         assert(*val != NULL);
     412             : 
     413             : #define PARSE_CASE(s,a,t)                               \
     414             :                 case s:                                         \
     415             :                         if (Z_ISUNDEF(IF_G(a))) {                       \
     416             :                                 array_init(&IF_G(a));                               \
     417             :                         }                                                                               \
     418             :                         array_ptr = &IF_G(a);                               \
     419             :                         orig_array_ptr = &PG(http_globals)[t];      \
     420             :                         break;
     421             : 
     422      100486 :         switch (arg) {
     423         117 :                 PARSE_CASE(PARSE_POST,    post_array,    TRACK_VARS_POST)
     424         235 :                 PARSE_CASE(PARSE_GET,     get_array,     TRACK_VARS_GET)
     425          39 :                 PARSE_CASE(PARSE_COOKIE,  cookie_array,  TRACK_VARS_COOKIE)
     426       99976 :                 PARSE_CASE(PARSE_SERVER,  server_array,  TRACK_VARS_SERVER)
     427           0 :                 PARSE_CASE(PARSE_ENV,     env_array,     TRACK_VARS_ENV)
     428             : 
     429             :                 case PARSE_STRING: /* PARSE_STRING is used by parse_str() function */
     430         119 :                         retval = 1;
     431             :                         break;
     432             :         }
     433             : 
     434             :         /* 
     435             :          * According to rfc2965, more specific paths are listed above the less specific ones.
     436             :          * If we encounter a duplicate cookie name, we should skip it, since it is not possible
     437             :          * to have the same (plain text) cookie name for the same path and we should not overwrite
     438             :          * more specific cookies with the less specific ones.
     439             :         */
     440      100525 :         if (arg == PARSE_COOKIE && orig_array_ptr &&
     441          39 :                         zend_symtable_str_exists(Z_ARRVAL_P(orig_array_ptr), var, strlen(var))) {
     442           3 :                 return 0;
     443             :         }
     444             : 
     445      100483 :         if (array_ptr) {
     446             :                 /* Store the RAW variable internally */
     447      200728 :                 ZVAL_STRINGL(&raw_var, *val, val_len);
     448      100364 :                 php_register_variable_ex(var, &raw_var, array_ptr TSRMLS_CC);
     449             :         }
     450             : 
     451      100483 :         if (val_len) {
     452             :                 /* Register mangled variable */
     453       80198 :                 if (IF_G(default_filter) != FILTER_UNSAFE_RAW) {
     454          18 :                         ZVAL_STRINGL(&new_var, *val, val_len);
     455           9 :                         php_zval_filter(&new_var, IF_G(default_filter), IF_G(default_filter_flags), NULL, NULL, 0 TSRMLS_CC);
     456             :                 } else {
     457      160378 :                         ZVAL_STRINGL(&new_var, *val, val_len);
     458             :                 }
     459             :         } else { /* empty string */
     460       20285 :                 ZVAL_EMPTY_STRING(&new_var);
     461             :         }
     462             : 
     463      100483 :         if (orig_array_ptr) {
     464      100364 :                 php_register_variable_ex(var, &new_var, orig_array_ptr TSRMLS_CC);
     465             :         }
     466             : 
     467      100483 :         if (retval) {
     468         119 :                 if (new_val_len) {
     469         111 :                         *new_val_len = Z_STRLEN(new_var);
     470             :                 }
     471         119 :                 efree(*val);
     472         119 :                 if (Z_STRLEN(new_var)) {
     473         112 :                         *val = estrndup(Z_STRVAL(new_var), Z_STRLEN(new_var));
     474             :                 } else {
     475           7 :                         *val = estrdup("");
     476             :                 }
     477         119 :                 zval_ptr_dtor(&new_var);
     478             :         }
     479             : 
     480      100483 :         return retval;
     481             : }
     482             : /* }}} */
     483             : 
     484          21 : static void php_zval_filter_recursive(zval *value, zend_long filter, zend_long flags, zval *options, char *charset, zend_bool copy TSRMLS_DC) /* {{{ */
     485             : {
     486          21 :         if (Z_TYPE_P(value) == IS_ARRAY) {
     487             :                 zval *element;
     488             : 
     489          21 :                 if (Z_ARRVAL_P(value)->u.v.nApplyCount > 1) {
     490           0 :                         return;
     491             :                 }
     492             : 
     493         111 :                 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(value), element) {
     494          45 :                         ZVAL_DEREF(element);
     495         114 :                         SEPARATE_ZVAL_NOREF(element);
     496          45 :                         if (Z_TYPE_P(element) == IS_ARRAY) {
     497           6 :                                 Z_ARRVAL_P(element)->u.v.nApplyCount++;
     498           6 :                                 php_zval_filter_recursive(element, filter, flags, options, charset, copy TSRMLS_CC);
     499           6 :                                 Z_ARRVAL_P(element)->u.v.nApplyCount--;
     500             :                         } else {
     501          39 :                                 php_zval_filter(element, filter, flags, options, charset, copy TSRMLS_CC);
     502             :                         }
     503             :                 } ZEND_HASH_FOREACH_END();
     504             :         } else {
     505           0 :                 php_zval_filter(value, filter, flags, options, charset, copy TSRMLS_CC);
     506             :         }
     507             : }
     508             : /* }}} */
     509             : 
     510          48 : static zval *php_filter_get_storage(zend_long arg TSRMLS_DC)/* {{{ */
     511             : 
     512             : {
     513          48 :         zval *array_ptr = NULL;
     514             : 
     515          48 :         switch (arg) {
     516             :                 case PARSE_GET:
     517          23 :                         array_ptr = &IF_G(get_array);
     518          23 :                         break;
     519             :                 case PARSE_POST:
     520          14 :                         array_ptr = &IF_G(post_array);
     521          14 :                         break;
     522             :                 case PARSE_COOKIE:
     523           7 :                         array_ptr = &IF_G(cookie_array);
     524           7 :                         break;
     525             :                 case PARSE_SERVER:
     526           2 :                         if (PG(auto_globals_jit)) {
     527           2 :                                 zend_string *name = zend_string_init("_SERVER", sizeof("_SERVER") - 1, 0);
     528           2 :                                 zend_is_auto_global(name TSRMLS_CC);
     529             :                                 zend_string_release(name);
     530             :                         }
     531           2 :                         array_ptr = &IF_G(server_array);
     532           2 :                         break;
     533             :                 case PARSE_ENV:
     534           0 :                         if (PG(auto_globals_jit)) {
     535           0 :                                 zend_string *name = zend_string_init("_ENV", sizeof("_ENV") - 1, 0);
     536           0 :                                 zend_is_auto_global(name TSRMLS_CC);
     537             :                                 zend_string_release(name);
     538             :                         }
     539           0 :                         array_ptr = &IF_G(env_array) ? &IF_G(env_array) : &PG(http_globals)[TRACK_VARS_ENV];
     540           0 :                         break;
     541             :                 case PARSE_SESSION:
     542             :                         /* FIXME: Implement session source */
     543           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "INPUT_SESSION is not yet implemented");
     544           0 :                         break;
     545             :                 case PARSE_REQUEST:
     546             :                         /* FIXME: Implement request source */
     547           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "INPUT_REQUEST is not yet implemented");
     548             :                         break;
     549             :         }
     550             : 
     551          48 :         return array_ptr;
     552             : }
     553             : /* }}} */
     554             : 
     555             : /* {{{ proto mixed filter_has_var(constant type, string variable_name)
     556             :  * Returns true if the variable with the name 'name' exists in source.
     557             :  */
     558          31 : PHP_FUNCTION(filter_has_var)
     559             : {
     560             :         zend_long         arg;
     561             :         zend_string *var;
     562          31 :         zval        *array_ptr = NULL;
     563             : 
     564          31 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lS", &arg, &var) == FAILURE) {
     565           9 :                 RETURN_FALSE;
     566             :         }
     567             : 
     568          22 :         array_ptr = php_filter_get_storage(arg TSRMLS_CC);
     569             : 
     570          62 :         if (array_ptr && HASH_OF(array_ptr) && zend_hash_exists(HASH_OF(array_ptr), var)) {
     571           9 :                 RETURN_TRUE;
     572             :         }
     573             : 
     574          13 :         RETURN_FALSE;
     575             : }
     576             : /* }}} */
     577             : 
     578         956 : static void php_filter_call(zval *filtered, zend_long filter, zval *filter_args, const int copy, zend_long filter_flags TSRMLS_DC) /* {{{ */
     579             : {
     580         956 :         zval *options = NULL;
     581             :         zval *option;
     582         956 :         char *charset = NULL;
     583             : 
     584        1847 :         if (filter_args && Z_TYPE_P(filter_args) != IS_ARRAY) {
     585         162 :                 zend_long lval = zval_get_long(filter_args);
     586             : 
     587         162 :                 if (filter != -1) { /* handler for array apply */
     588             :                         /* filter_args is the filter_flags */
     589         151 :                         filter_flags = lval;
     590             : 
     591         151 :                         if (!(filter_flags & FILTER_REQUIRE_ARRAY ||  filter_flags & FILTER_FORCE_ARRAY)) {
     592         146 :                                 filter_flags |= FILTER_REQUIRE_SCALAR;
     593             :                         }
     594             :                 } else {
     595          11 :                         filter = lval;
     596             :                 }
     597         794 :         } else if (filter_args) {
     598         567 :                 if ((option = zend_hash_str_find(HASH_OF(filter_args), "filter", sizeof("filter") - 1)) != NULL) {
     599           9 :                         filter = zval_get_long(option);
     600             :                 }
     601             : 
     602         567 :                 if ((option = zend_hash_str_find(HASH_OF(filter_args), "flags", sizeof("flags") - 1)) != NULL) {
     603         311 :                         filter_flags = zval_get_long(option);
     604             : 
     605         311 :                         if (!(filter_flags & FILTER_REQUIRE_ARRAY ||  filter_flags & FILTER_FORCE_ARRAY)) {
     606         300 :                                 filter_flags |= FILTER_REQUIRE_SCALAR;
     607             :                         }
     608             :                 }
     609             : 
     610         567 :                 if ((option = zend_hash_str_find(HASH_OF(filter_args), "options", sizeof("options") - 1)) != NULL) {
     611         254 :                         if (filter != FILTER_CALLBACK) {
     612         217 :                                 if (Z_TYPE_P(option) == IS_ARRAY) {
     613          37 :                                         options = option;
     614             :                                 }
     615             :                         } else {
     616          37 :                                 options = option;
     617          37 :                                 filter_flags = 0;
     618             :                         }
     619             :                 }
     620             :         }
     621             : 
     622         956 :         if (Z_TYPE_P(filtered) == IS_ARRAY) {
     623          19 :                 if (filter_flags & FILTER_REQUIRE_SCALAR) {
     624           4 :                         if (copy) {
     625           4 :                                 SEPARATE_ZVAL(filtered);
     626             :                         }
     627           4 :                         zval_ptr_dtor(filtered);
     628           4 :                         if (filter_flags & FILTER_NULL_ON_FAILURE) {
     629           0 :                                 ZVAL_NULL(filtered);
     630             :                         } else {
     631           4 :                                 ZVAL_FALSE(filtered);
     632             :                         }
     633           4 :                         return;
     634             :                 }
     635          15 :                 php_zval_filter_recursive(filtered, filter, filter_flags, options, charset, copy TSRMLS_CC);
     636          15 :                 return;
     637             :         }
     638         937 :         if (filter_flags & FILTER_REQUIRE_ARRAY) {
     639           1 :                 if (copy) {
     640           1 :                         SEPARATE_ZVAL(filtered);
     641             :                 }
     642           1 :                 zval_ptr_dtor(filtered);
     643           1 :                 if (filter_flags & FILTER_NULL_ON_FAILURE) {
     644           0 :                         ZVAL_NULL(filtered);
     645             :                 } else {
     646           1 :                         ZVAL_FALSE(filtered);
     647             :                 }
     648           1 :                 return;
     649             :         }
     650             : 
     651         936 :         php_zval_filter(filtered, filter, filter_flags, options, charset, copy TSRMLS_CC);
     652         936 :         if (filter_flags & FILTER_FORCE_ARRAY) {
     653             :                 zval tmp;
     654           5 :                 ZVAL_COPY_VALUE(&tmp, filtered);
     655           5 :                 array_init(filtered);
     656           5 :                 add_next_index_zval(filtered, &tmp);
     657             :         }
     658             : }
     659             : /* }}} */
     660             : 
     661          23 : static void php_filter_array_handler(zval *input, zval *op, zval *return_value, zend_bool add_empty TSRMLS_DC) /* {{{ */
     662             : {
     663             :         zend_string *arg_key;
     664             :         zval *tmp, *arg_elm;
     665             : 
     666          23 :         if (!op) {
     667           2 :                 zval_ptr_dtor(return_value);
     668           2 :                 ZVAL_DUP(return_value, input);
     669           2 :                 php_filter_call(return_value, FILTER_DEFAULT, NULL, 0, FILTER_REQUIRE_ARRAY TSRMLS_CC);
     670          21 :         } else if (Z_TYPE_P(op) == IS_LONG) {
     671           1 :                 zval_ptr_dtor(return_value);
     672           1 :                 ZVAL_DUP(return_value, input);
     673           1 :                 php_filter_call(return_value, Z_LVAL_P(op), NULL, 0, FILTER_REQUIRE_ARRAY TSRMLS_CC);
     674          20 :         } else if (Z_TYPE_P(op) == IS_ARRAY) {
     675          15 :                 array_init(return_value);
     676             : 
     677          81 :                 ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(op), arg_key, arg_elm) {
     678          34 :                         if (arg_key == NULL) {
     679           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Numeric keys are not allowed in the definition array");
     680           0 :                                 zval_ptr_dtor(return_value);
     681           0 :                                 RETURN_FALSE;
     682             :                         }
     683          34 :                         if (arg_key->len == 0) {
     684           2 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty keys are not allowed in the definition array");
     685           2 :                                 zval_ptr_dtor(return_value);
     686           2 :                                 RETURN_FALSE;
     687             :                         }
     688          32 :                         if ((tmp = zend_hash_find(Z_ARRVAL_P(input), arg_key)) == NULL) {
     689          10 :                                 if (add_empty) {
     690           9 :                                         add_assoc_null_ex(return_value, arg_key->val, arg_key->len);
     691             :                                 }
     692             :                         } else {
     693             :                                 zval nval;
     694          22 :                                 ZVAL_DEREF(tmp);
     695          22 :                                 ZVAL_DUP(&nval, tmp);
     696          22 :                                 php_filter_call(&nval, -1, arg_elm, 0, FILTER_REQUIRE_SCALAR TSRMLS_CC);
     697          22 :                                 zend_hash_update(Z_ARRVAL_P(return_value), arg_key, &nval);
     698             :                         }
     699             :                 } ZEND_HASH_FOREACH_END();
     700             :         } else {
     701           5 :                 RETURN_FALSE;
     702             :         }
     703             : }
     704             : /* }}} */
     705             : 
     706             : /* {{{ proto mixed filter_input(constant type, string variable_name [, long filter [, mixed options]])
     707             :  * Returns the filtered variable 'name'* from source `type`.
     708             :  */
     709          26 : PHP_FUNCTION(filter_input)
     710             : {
     711          26 :         zend_long fetch_from, filter = FILTER_DEFAULT;
     712          26 :         zval *filter_args = NULL, *tmp;
     713          26 :         zval *input = NULL;
     714             :         zend_string *var;
     715             : 
     716          26 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lS|lz", &fetch_from, &var, &filter, &filter_args) == FAILURE) {
     717           1 :                 return;
     718             :         }
     719             : 
     720          25 :         if (!PHP_FILTER_ID_EXISTS(filter)) {
     721           0 :                 RETURN_FALSE;
     722             :         }
     723             : 
     724          25 :         input = php_filter_get_storage(fetch_from TSRMLS_CC);
     725             : 
     726          75 :         if (!input || !HASH_OF(input) || (tmp = zend_hash_find(HASH_OF(input), var)) == NULL) {
     727           5 :                 zend_long filter_flags = 0;
     728             :                 zval *option, *opt, *def;
     729           5 :                 if (filter_args) {
     730           2 :                         if (Z_TYPE_P(filter_args) == IS_LONG) {
     731           0 :                                 filter_flags = Z_LVAL_P(filter_args);
     732           3 :                         } else if (Z_TYPE_P(filter_args) == IS_ARRAY && (option = zend_hash_str_find(HASH_OF(filter_args), "flags", sizeof("flags") - 1)) != NULL) {
     733           1 :                                 filter_flags = zval_get_long(option);
     734             :                         }
     735           5 :                         if (Z_TYPE_P(filter_args) == IS_ARRAY && 
     736           2 :                                 (opt = zend_hash_str_find(HASH_OF(filter_args), "options", sizeof("options") - 1)) != NULL &&
     737             :                                 Z_TYPE_P(opt) == IS_ARRAY &&
     738           1 :                                 (def = zend_hash_str_find(HASH_OF(opt), "default", sizeof("default") - 1)) != NULL) {
     739           1 :                                 ZVAL_COPY(return_value, def);
     740           1 :                                 return;
     741             :                         }
     742             :                 }
     743             : 
     744             :                 /* The FILTER_NULL_ON_FAILURE flag inverts the usual return values of
     745             :                  * the function: normally when validation fails false is returned, and
     746             :                  * when the input value doesn't exist NULL is returned. With the flag
     747             :                  * set, NULL and false should be returned, respectively. Ergo, although
     748             :                  * the code below looks incorrect, it's actually right. */
     749           4 :                 if (filter_flags & FILTER_NULL_ON_FAILURE) {
     750           0 :                         RETURN_FALSE;
     751             :                 } else {
     752           4 :                         RETURN_NULL();
     753             :                 }
     754             :         }
     755             : 
     756          20 :         ZVAL_DUP(return_value, tmp);
     757             : 
     758          20 :         php_filter_call(return_value, filter, filter_args, 1, FILTER_REQUIRE_SCALAR TSRMLS_CC);
     759             : }
     760             : /* }}} */
     761             : 
     762             : /* {{{ proto mixed filter_var(mixed variable [, long filter [, mixed options]])
     763             :  * Returns the filtered version of the vriable.
     764             :  */
     765         917 : PHP_FUNCTION(filter_var)
     766             : {
     767         917 :         zend_long filter = FILTER_DEFAULT;
     768         917 :         zval *filter_args = NULL, *data;
     769             : 
     770         917 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/|lz", &data, &filter, &filter_args) == FAILURE) {
     771           4 :                 return;
     772             :         }
     773             : 
     774         913 :         if (!PHP_FILTER_ID_EXISTS(filter)) {
     775           2 :                 RETURN_FALSE;
     776             :         }
     777             : 
     778         911 :         ZVAL_DUP(return_value, data);
     779             : 
     780         911 :         php_filter_call(return_value, filter, filter_args, 1, FILTER_REQUIRE_SCALAR TSRMLS_CC);
     781             : }
     782             : /* }}} */
     783             : 
     784             : /* {{{ proto mixed filter_input_array(constant type, [, mixed options [, bool add_empty]]])
     785             :  * Returns an array with all arguments defined in 'definition'.
     786             :  */
     787           1 : PHP_FUNCTION(filter_input_array)
     788             : {
     789             :         zend_long    fetch_from;
     790           1 :         zval   *array_input = NULL, *op = NULL;
     791           1 :         zend_bool add_empty = 1;
     792             : 
     793           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|zb",  &fetch_from, &op, &add_empty) == FAILURE) {
     794           0 :                 return;
     795             :         }
     796             : 
     797           2 :         if (op && (Z_TYPE_P(op) != IS_ARRAY) && (Z_TYPE_P(op) == IS_LONG && !PHP_FILTER_ID_EXISTS(Z_LVAL_P(op)))) {
     798           0 :                 RETURN_FALSE;
     799             :         }
     800             : 
     801           1 :         array_input = php_filter_get_storage(fetch_from TSRMLS_CC);
     802             : 
     803           2 :         if (!array_input || !HASH_OF(array_input)) {
     804           0 :                 zend_long filter_flags = 0;
     805             :                 zval *option;
     806           0 :                 if (op) {
     807           0 :                         if (Z_TYPE_P(op) == IS_LONG) {
     808           0 :                                 filter_flags = Z_LVAL_P(op);
     809           0 :                         } else if (Z_TYPE_P(op) == IS_ARRAY && (option = zend_hash_str_find(HASH_OF(op), "flags", sizeof("flags") - 1)) != NULL) {
     810           0 :                                 filter_flags = zval_get_long(option);
     811             :                         }
     812             :                 }
     813             : 
     814             :                 /* The FILTER_NULL_ON_FAILURE flag inverts the usual return values of
     815             :                  * the function: normally when validation fails false is returned, and
     816             :                  * when the input value doesn't exist NULL is returned. With the flag
     817             :                  * set, NULL and false should be returned, respectively. Ergo, although
     818             :                  * the code below looks incorrect, it's actually right. */
     819           0 :                 if (filter_flags & FILTER_NULL_ON_FAILURE) {
     820           0 :                         RETURN_FALSE;
     821             :                 } else {
     822           0 :                         RETURN_NULL();
     823             :                 }
     824             :         }
     825             : 
     826           1 :         php_filter_array_handler(array_input, op, return_value, add_empty TSRMLS_CC);
     827             : }
     828             : /* }}} */
     829             : 
     830             : /* {{{ proto mixed filter_var_array(array data, [, mixed options [, bool add_empty]]])
     831             :  * Returns an array with all arguments defined in 'definition'.
     832             :  */
     833          31 : PHP_FUNCTION(filter_var_array)
     834             : {
     835          31 :         zval *array_input = NULL, *op = NULL;
     836          31 :         zend_bool add_empty = 1;
     837             : 
     838          31 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|zb",  &array_input, &op, &add_empty) == FAILURE) {
     839           1 :                 return;
     840             :         }
     841             : 
     842          72 :         if (op && (Z_TYPE_P(op) != IS_ARRAY) && (Z_TYPE_P(op) == IS_LONG && !PHP_FILTER_ID_EXISTS(Z_LVAL_P(op)))) {
     843           8 :                 RETURN_FALSE;
     844             :         }
     845             : 
     846          22 :         php_filter_array_handler(array_input, op, return_value, add_empty TSRMLS_CC);
     847             : }
     848             : /* }}} */
     849             : 
     850             : /* {{{ proto filter_list()
     851             :  * Returns a list of all supported filters */
     852           3 : PHP_FUNCTION(filter_list)
     853             : {
     854           3 :         int i, size = sizeof(filter_list) / sizeof(filter_list_entry);
     855             : 
     856           3 :         if (zend_parse_parameters_none() == FAILURE) {
     857           1 :                 return;
     858             :         }
     859             : 
     860           2 :         array_init(return_value);
     861          42 :         for (i = 0; i < size; ++i) {
     862          40 :                 add_next_index_string(return_value, (char *)filter_list[i].name);
     863             :         }
     864             : }
     865             : /* }}} */
     866             : 
     867             : /* {{{ proto filter_id(string filtername)
     868             :  * Returns the filter ID belonging to a named filter */
     869         208 : PHP_FUNCTION(filter_id)
     870             : {
     871             :         int i;
     872             :         size_t filter_len;
     873         208 :         int size = sizeof(filter_list) / sizeof(filter_list_entry);
     874             :         char *filter;
     875             : 
     876         208 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filter, &filter_len) == FAILURE) {
     877           2 :                 return;
     878             :         }
     879             : 
     880        2178 :         for (i = 0; i < size; ++i) {
     881        2176 :                 if (strcmp(filter_list[i].name, filter) == 0) {
     882         204 :                         RETURN_LONG(filter_list[i].id);
     883             :                 }
     884             :         }
     885             : 
     886           2 :         RETURN_FALSE;
     887             : }
     888             : /* }}} */
     889             : 
     890             : /*
     891             :  * Local variables:
     892             :  * tab-width: 4
     893             :  * c-basic-offset: 4
     894             :  * End:
     895             :  * vim600: noet sw=4 ts=4 fdm=marker
     896             :  * vim<600: noet sw=4 ts=4
     897             :  */

Generated by: LCOV version 1.10

Generated at Thu, 30 Oct 2014 07:41:30 +0000 (6 hours ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.