]> granicus.if.org Git - php/commitdiff
ported ext/filter
authorAnatol Belski <ab@php.net>
Tue, 19 Aug 2014 19:43:22 +0000 (21:43 +0200)
committerAnatol Belski <ab@php.net>
Tue, 19 Aug 2014 19:43:22 +0000 (21:43 +0200)
ext/filter/filter.c
ext/filter/logical_filters.c
ext/filter/php_filter.h
ext/filter/sanitizing_filters.c

index 092e9ad0a8c5516ff15129e47e4049311b340c2b..f84b001205ca8cddd02295d71eb87d4afe5da22f 100644 (file)
@@ -327,7 +327,7 @@ PHP_MINFO_FUNCTION(filter)
 }
 /* }}} */
 
-static filter_list_entry php_find_filter(long id) /* {{{ */
+static filter_list_entry php_find_filter(php_int_t id) /* {{{ */
 {
        int i, size = sizeof(filter_list) / sizeof(filter_list_entry);
 
@@ -358,7 +358,7 @@ static unsigned int php_sapi_filter_init(TSRMLS_D)
        return SUCCESS;
 }
 
-static void php_zval_filter(zval *value, long filter, long flags, zval *options, char* charset, zend_bool copy TSRMLS_DC) /* {{{ */
+static void php_zval_filter(zval *value, php_int_t filter, php_int_t flags, zval *options, char* charset, zend_bool copy TSRMLS_DC) /* {{{ */
 {
        filter_list_entry  filter_func;
 
@@ -481,7 +481,7 @@ static unsigned int php_sapi_filter(int arg, char *var, char **val, unsigned int
 }
 /* }}} */
 
-static void php_zval_filter_recursive(zval *value, long filter, long flags, zval *options, char *charset, zend_bool copy TSRMLS_DC) /* {{{ */
+static void php_zval_filter_recursive(zval *value, php_int_t filter, php_int_t flags, zval *options, char *charset, zend_bool copy TSRMLS_DC) /* {{{ */
 {
        if (Z_TYPE_P(value) == IS_ARRAY) {
                zval *element;
@@ -506,7 +506,7 @@ static void php_zval_filter_recursive(zval *value, long filter, long flags, zval
 }
 /* }}} */
 
-static zval *php_filter_get_storage(long arg TSRMLS_DC)/* {{{ */
+static zval *php_filter_get_storage(php_int_t arg TSRMLS_DC)/* {{{ */
 
 {
        zval *array_ptr = NULL;
@@ -556,11 +556,11 @@ static zval *php_filter_get_storage(long arg TSRMLS_DC)/* {{{ */
  */
 PHP_FUNCTION(filter_has_var)
 {
-       long         arg;
+       php_int_t         arg;
        zend_string *var;
        zval        *array_ptr = NULL;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lS", &arg, &var) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "iS", &arg, &var) == FAILURE) {
                RETURN_FALSE;
        }
 
@@ -574,14 +574,14 @@ PHP_FUNCTION(filter_has_var)
 }
 /* }}} */
 
-static void php_filter_call(zval *filtered, long filter, zval *filter_args, const int copy, long filter_flags TSRMLS_DC) /* {{{ */
+static void php_filter_call(zval *filtered, php_int_t filter, zval *filter_args, const int copy, php_int_t filter_flags TSRMLS_DC) /* {{{ */
 {
        zval *options = NULL;
        zval *option;
        char *charset = NULL;
 
        if (filter_args && Z_TYPE_P(filter_args) != IS_ARRAY) {
-               long lval;
+               php_int_t lval;
 
                PHP_FILTER_GET_LONG_OPT(filter_args, lval);
 
@@ -661,7 +661,7 @@ static void php_filter_call(zval *filtered, long filter, zval *filter_args, cons
 
 static void php_filter_array_handler(zval *input, zval *op, zval *return_value, zend_bool add_empty TSRMLS_DC) /* {{{ */
 {
-       ulong index;
+       php_uint_t index;
        zend_string *arg_key;
        zval *tmp, *arg_elm;
 
@@ -710,12 +710,12 @@ static void php_filter_array_handler(zval *input, zval *op, zval *return_value,
  */
 PHP_FUNCTION(filter_input)
 {
-       long fetch_from, filter = FILTER_DEFAULT;
+       php_int_t fetch_from, filter = FILTER_DEFAULT;
        zval *filter_args = NULL, *tmp;
        zval *input = NULL;
        zend_string *var;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lS|lz", &fetch_from, &var, &filter, &filter_args) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "iS|iz", &fetch_from, &var, &filter, &filter_args) == FAILURE) {
                return;
        }
 
@@ -726,7 +726,7 @@ PHP_FUNCTION(filter_input)
        input = php_filter_get_storage(fetch_from TSRMLS_CC);
 
        if (!input || !HASH_OF(input) || (tmp = zend_hash_find(HASH_OF(input), var)) == NULL) {
-               long filter_flags = 0;
+               php_int_t filter_flags = 0;
                zval *option, *opt, *def;
                if (filter_args) {
                        if (Z_TYPE_P(filter_args) == IS_INT) {
@@ -766,10 +766,10 @@ PHP_FUNCTION(filter_input)
  */
 PHP_FUNCTION(filter_var)
 {
-       long filter = FILTER_DEFAULT;
+       php_int_t filter = FILTER_DEFAULT;
        zval *filter_args = NULL, *data;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/|lz", &data, &filter, &filter_args) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/|iz", &data, &filter, &filter_args) == FAILURE) {
                return;
        }
 
@@ -788,11 +788,11 @@ PHP_FUNCTION(filter_var)
  */
 PHP_FUNCTION(filter_input_array)
 {
-       long    fetch_from;
+       php_int_t    fetch_from;
        zval   *array_input = NULL, *op = NULL;
        zend_bool add_empty = 1;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|zb",  &fetch_from, &op, &add_empty) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i|zb",  &fetch_from, &op, &add_empty) == FAILURE) {
                return;
        }
 
@@ -803,7 +803,7 @@ PHP_FUNCTION(filter_input_array)
        array_input = php_filter_get_storage(fetch_from TSRMLS_CC);
 
        if (!array_input || !HASH_OF(array_input)) {
-               long filter_flags = 0;
+               php_int_t filter_flags = 0;
                zval *option;
                if (op) {
                        if (Z_TYPE_P(op) == IS_INT) {
index 9884d0140153d6b02be847123a3893cee047a52c..5b2333343bf41a32d5f195f94c1c5fc2ae89e710 100644 (file)
@@ -80,8 +80,8 @@
 #define FORMAT_IPV4    4
 #define FORMAT_IPV6    6
 
-static int php_filter_parse_int(const char *str, unsigned int str_len, long *ret TSRMLS_DC) { /* {{{ */
-       long ctx_value;
+static int php_filter_parse_int(const char *str, unsigned int str_len, php_int_t *ret TSRMLS_DC) { /* {{{ */
+       php_int_t ctx_value;
        int sign = 0, digit = 0;
        const char *end = str + str_len;
 
@@ -115,9 +115,9 @@ static int php_filter_parse_int(const char *str, unsigned int str_len, long *ret
        while (str < end) {
                if (*str >= '0' && *str <= '9') {
                        digit = (*(str++) - '0');
-                       if ( (!sign) && ctx_value <= (LONG_MAX-digit)/10 ) {
+                       if ( (!sign) && ctx_value <= (PHP_INT_MAX-digit)/10 ) {
                                ctx_value = (ctx_value * 10) + digit;
-                       } else if ( sign && ctx_value >= (LONG_MIN+digit)/10) {
+                       } else if ( sign && ctx_value >= (PHP_INT_MIN+digit)/10) {
                                ctx_value = (ctx_value * 10) - digit;
                        } else {
                                return -1;
@@ -132,16 +132,16 @@ static int php_filter_parse_int(const char *str, unsigned int str_len, long *ret
 }
 /* }}} */
 
-static int php_filter_parse_octal(const char *str, unsigned int str_len, long *ret TSRMLS_DC) { /* {{{ */
-       unsigned long ctx_value = 0;
+static int php_filter_parse_octal(const char *str, unsigned int str_len, php_int_t *ret TSRMLS_DC) { /* {{{ */
+       php_uint_t ctx_value = 0;
        const char *end = str + str_len;
 
        while (str < end) {
                if (*str >= '0' && *str <= '7') {
-                       unsigned long n = ((*(str++)) - '0');
+                       php_uint_t n = ((*(str++)) - '0');
 
-                       if ((ctx_value > ((unsigned long)(~(long)0)) / 8) ||
-                               ((ctx_value = ctx_value * 8) > ((unsigned long)(~(long)0)) - n)) {
+                       if ((ctx_value > ((php_uint_t)(~(php_int_t)0)) / 8) ||
+                               ((ctx_value = ctx_value * 8) > ((php_uint_t)(~(php_int_t)0)) - n)) {
                                return -1;
                        }
                        ctx_value += n;
@@ -150,15 +150,15 @@ static int php_filter_parse_octal(const char *str, unsigned int str_len, long *r
                }
        }
        
-       *ret = (long)ctx_value;
+       *ret = (php_int_t)ctx_value;
        return 1;
 }
 /* }}} */
 
-static int php_filter_parse_hex(const char *str, unsigned int str_len, long *ret TSRMLS_DC) { /* {{{ */
-       unsigned long ctx_value = 0;
+static int php_filter_parse_hex(const char *str, unsigned int str_len, php_int_t *ret TSRMLS_DC) { /* {{{ */
+       php_uint_t ctx_value = 0;
        const char *end = str + str_len;
-       unsigned long n;
+       php_uint_t n;
 
        while (str < end) {
                if (*str >= '0' && *str <= '9') {
@@ -170,14 +170,14 @@ static int php_filter_parse_hex(const char *str, unsigned int str_len, long *ret
                } else {
                        return -1;
                }
-               if ((ctx_value > ((unsigned long)(~(long)0)) / 16) ||
-                       ((ctx_value = ctx_value * 16) > ((unsigned long)(~(long)0)) - n)) {
+               if ((ctx_value > ((php_uint_t)(~(php_int_t)0)) / 16) ||
+                       ((ctx_value = ctx_value * 16) > ((php_uint_t)(~(php_int_t)0)) - n)) {
                        return -1;
                }
                ctx_value += n;
        }
 
-       *ret = (long)ctx_value;
+       *ret = (php_int_t)ctx_value;
        return 1;
 }
 /* }}} */
@@ -185,11 +185,11 @@ static int php_filter_parse_hex(const char *str, unsigned int str_len, long *ret
 void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
 {
        zval *option_val;
-       long  min_range, max_range, option_flags;
+       php_int_t  min_range, max_range, option_flags;
        int   min_range_set, max_range_set;
        int   allow_octal = 0, allow_hex = 0;
        int       len, error = 0;
-       long  ctx_value;
+       php_int_t  ctx_value;
        char *p;
 
        /* Parse options */
@@ -327,7 +327,7 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
        char dec_sep = '.';
        char tsd_sep[3] = "',.";
 
-       long lval;
+       php_int_t lval;
        double dval;
 
        int first, n;
@@ -422,7 +422,7 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
 {
        zval *option_val;
        zend_string *regexp;
-       long option_flags;
+       php_int_t option_flags;
        int regexp_set, option_flags_set;
        pcre *re = NULL;
        pcre_extra *pcre_extra = NULL;
@@ -796,7 +796,7 @@ void php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
        int tokens, length, i, offset, exp_separator_set, exp_separator_len;
        char separator;
        char *exp_separator;
-       long ret = 0;
+       php_int_t ret = 0;
        zval *option_val;
 
        FETCH_STRING_OPTION(exp_separator, "separator");
index 9ebc18663b87391c248d9440c3308a086ab19503..05eb78d8857a146841146551d859374a60443f3f 100644 (file)
@@ -59,8 +59,8 @@ ZEND_BEGIN_MODULE_GLOBALS(filter)
        zval env_array;
        zval server_array;
        zval session_array;
-       long default_filter;
-       long default_filter_flags;
+       php_int_t default_filter;
+       php_int_t default_filter_flags;
 ZEND_END_MODULE_GLOBALS(filter)
 
 #ifdef ZTS
@@ -70,7 +70,7 @@ ZEND_END_MODULE_GLOBALS(filter)
 #endif
 
 
-#define PHP_INPUT_FILTER_PARAM_DECL zval *value, long flags, zval *option_array, char *charset TSRMLS_DC
+#define PHP_INPUT_FILTER_PARAM_DECL zval *value, php_int_t flags, zval *option_array, char *charset TSRMLS_DC
 void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL);
 void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL);
 void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL);
index e41b70493350ab4fb3eb85f855573ca4019a3ae3..98c939f68628869ec67112a9d47097385c337976 100644 (file)
@@ -41,7 +41,7 @@ static void php_filter_encode_html(zval *value, const unsigned char *chars)
        while (s < e) {
                if (chars[*s]) {
                        smart_str_appendl(&str, "&#", 2);
-                       smart_str_append_unsigned(&str, (unsigned long)*s);
+                       smart_str_append_unsigned(&str, (php_uint_t)*s);
                        smart_str_appendc(&str, ';');
                } else {
                        /* XXX: this needs to be optimized to work with blocks of 'safe' chars */
@@ -108,7 +108,7 @@ static void php_filter_encode_url(zval *value, const unsigned char* chars, const
        ZVAL_STR(value, str);
 }
 
-static void php_filter_strip(zval *value, long flags)
+static void php_filter_strip(zval *value, php_int_t flags)
 {
        unsigned char *str;
        int   i, c;