static void php_filter_init_globals(zend_filter_globals *filter_globals) /* {{{ */
{
- filter_globals->post_array = NULL;
- filter_globals->get_array = NULL;
- filter_globals->cookie_array = NULL;
- filter_globals->env_array = NULL;
- filter_globals->server_array = NULL;
- filter_globals->session_array = NULL;
+ ZVAL_UNDEF(&filter_globals->post_array);
+ ZVAL_UNDEF(&filter_globals->get_array);
+ ZVAL_UNDEF(&filter_globals->cookie_array);
+ ZVAL_UNDEF(&filter_globals->env_array);
+ ZVAL_UNDEF(&filter_globals->server_array);
+ ZVAL_UNDEF(&filter_globals->session_array);
filter_globals->default_filter = FILTER_DEFAULT;
}
/* }}} */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
#define VAR_ARRAY_COPY_DTOR(a) \
- if (IF_G(a)) { \
+ if (!Z_ISUNDEF(IF_G(a))) { \
zval_ptr_dtor(&IF_G(a)); \
- IF_G(a) = NULL; \
+ ZVAL_UNDEF(&IF_G(a)); \
}
PHP_RSHUTDOWN_FUNCTION(filter)
static unsigned int php_sapi_filter_init(TSRMLS_D)
{
- IF_G(get_array) = NULL;
- IF_G(post_array) = NULL;
- IF_G(cookie_array) = NULL;
- IF_G(server_array) = NULL;
- IF_G(env_array) = NULL;
- IF_G(session_array) = NULL;
+ ZVAL_UNDEF(&IF_G(get_array));
+ ZVAL_UNDEF(&IF_G(post_array));
+ ZVAL_UNDEF(&IF_G(cookie_array));
+ ZVAL_UNDEF(&IF_G(server_array));
+ ZVAL_UNDEF(&IF_G(env_array));
+ ZVAL_UNDEF(&IF_G(session_array));
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, long filter, long flags, zval *options, char* charset, zend_bool copy TSRMLS_DC) /* {{{ */
{
filter_list_entry filter_func;
/* #49274, fatal error with object without a toString method
Fails nicely instead of getting a recovarable fatal error. */
- if (Z_TYPE_PP(value) == IS_OBJECT) {
+ if (Z_TYPE_P(value) == IS_OBJECT) {
zend_class_entry *ce;
- ce = Z_OBJCE_PP(value);
+ ce = Z_OBJCE_P(value);
if (!ce->__tostring) {
- ZVAL_FALSE(*value);
+ ZVAL_FALSE(value);
return;
}
}
/* Here be strings */
- convert_to_string(*value);
-
- filter_func.function(*value, flags, options, charset TSRMLS_CC);
-
- if (
- options && (Z_TYPE_P(options) == IS_ARRAY || Z_TYPE_P(options) == IS_OBJECT) &&
- ((flags & FILTER_NULL_ON_FAILURE && Z_TYPE_PP(value) == IS_NULL) ||
- (!(flags & FILTER_NULL_ON_FAILURE) && Z_TYPE_PP(value) == IS_BOOL && Z_LVAL_PP(value) == 0)) &&
- zend_hash_exists(HASH_OF(options), "default", sizeof("default"))
- ) {
- zval **tmp;
- if (zend_hash_find(HASH_OF(options), "default", sizeof("default"), (void **)&tmp) == SUCCESS) {
- MAKE_COPY_ZVAL(tmp, *value);
+ convert_to_string(value);
+
+ filter_func.function(value, flags, options, charset TSRMLS_CC);
+
+ if (options && (Z_TYPE_P(options) == IS_ARRAY || Z_TYPE_P(options) == IS_OBJECT) &&
+ ((flags & FILTER_NULL_ON_FAILURE && Z_TYPE_P(value) == IS_NULL) ||
+ (!(flags & FILTER_NULL_ON_FAILURE) && Z_TYPE_P(value) == IS_FALSE)) &&
+ zend_hash_str_exists(HASH_OF(options), "default", sizeof("default") - 1)) {
+ zval *tmp;
+ if ((tmp = zend_hash_str_find(HASH_OF(options), "default", sizeof("default") - 1)) != NULL) {
+ ZVAL_COPY(value, tmp);
}
}
}
assert(*val != NULL);
-#define PARSE_CASE(s,a,t) \
- case s: \
- if (!IF_G(a)) { \
- ALLOC_ZVAL(array_ptr); \
- array_init(array_ptr); \
- INIT_PZVAL(array_ptr); \
- IF_G(a) = array_ptr; \
- } else { \
- array_ptr = IF_G(a); \
- } \
- orig_array_ptr = PG(http_globals)[t]; \
+#define PARSE_CASE(s,a,t) \
+ case s: \
+ if (Z_ISUNDEF(IF_G(a))) { \
+ array_init(&IF_G(a)); \
+ } \
+ array_ptr = &IF_G(a); \
+ orig_array_ptr = &PG(http_globals)[t]; \
break;
switch (arg) {
* to have the same (plain text) cookie name for the same path and we should not overwrite
* more specific cookies with the less specific ones.
*/
- if (arg == PARSE_COOKIE && orig_array_ptr && zend_symtable_exists(Z_ARRVAL_P(orig_array_ptr), var, strlen(var)+1)) {
+ if (arg == PARSE_COOKIE && orig_array_ptr &&
+ zend_symtable_str_exists(Z_ARRVAL_P(orig_array_ptr), var, strlen(var))) {
return 0;
}
if (array_ptr) {
/* Store the RAW variable internally */
- Z_STRLEN(raw_var) = val_len;
- Z_STRVAL(raw_var) = estrndup(*val, val_len);
- Z_TYPE(raw_var) = IS_STRING;
-
+ ZVAL_STRINGL(&raw_var, *val, val_len);
php_register_variable_ex(var, &raw_var, array_ptr TSRMLS_CC);
}
if (val_len) {
/* Register mangled variable */
- Z_STRLEN(new_var) = val_len;
- Z_TYPE(new_var) = IS_STRING;
-
if (IF_G(default_filter) != FILTER_UNSAFE_RAW) {
- zval *tmp_new_var = &new_var;
- Z_STRVAL(new_var) = estrndup(*val, val_len);
- INIT_PZVAL(tmp_new_var);
- php_zval_filter(&tmp_new_var, IF_G(default_filter), IF_G(default_filter_flags), NULL, NULL/*charset*/, 0 TSRMLS_CC);
+ ZVAL_STRINGL(&new_var, *val, val_len);
+ php_zval_filter(&new_var, IF_G(default_filter), IF_G(default_filter_flags), NULL, NULL, 0 TSRMLS_CC);
} else {
- Z_STRVAL(new_var) = estrndup(*val, val_len);
+ ZVAL_STRINGL(&new_var, *val, val_len);
}
} else { /* empty string */
ZVAL_EMPTY_STRING(&new_var);
} else {
*val = estrdup("");
}
- zval_dtor(&new_var);
+ zval_ptr_dtor(&new_var);
}
return retval;
}
/* }}} */
-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, long filter, long flags, zval *options, char *charset, zend_bool copy TSRMLS_DC) /* {{{ */
{
- if (Z_TYPE_PP(value) == IS_ARRAY) {
- zval **element;
- HashPosition pos;
+ if (Z_TYPE_P(value) == IS_ARRAY) {
+ zval *element;
- if (Z_ARRVAL_PP(value)->nApplyCount > 1) {
+ if (Z_ARRVAL_P(value)->u.v.nApplyCount > 1) {
return;
}
- for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(value), &pos);
- zend_hash_get_current_data_ex(Z_ARRVAL_PP(value), (void **) &element, &pos) == SUCCESS;
- zend_hash_move_forward_ex(Z_ARRVAL_PP(value), &pos)
- ) {
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(value), element) {
SEPARATE_ZVAL_IF_NOT_REF(element);
- if (Z_TYPE_PP(element) == IS_ARRAY) {
- Z_ARRVAL_PP(element)->nApplyCount++;
+ if (Z_TYPE_P(element) == IS_ARRAY) {
+ Z_ARRVAL_P(element)->u.v.nApplyCount++;
php_zval_filter_recursive(element, filter, flags, options, charset, copy TSRMLS_CC);
- Z_ARRVAL_PP(element)->nApplyCount--;
+ Z_ARRVAL_P(element)->u.v.nApplyCount--;
} else {
php_zval_filter(element, filter, flags, options, charset, copy TSRMLS_CC);
}
- }
+ } ZEND_HASH_FOREACH_END();
} else {
php_zval_filter(value, filter, flags, options, charset, copy TSRMLS_CC);
}
switch (arg) {
case PARSE_GET:
- array_ptr = IF_G(get_array);
+ array_ptr = &IF_G(get_array);
break;
case PARSE_POST:
- array_ptr = IF_G(post_array);
+ array_ptr = &IF_G(post_array);
break;
case PARSE_COOKIE:
- array_ptr = IF_G(cookie_array);
+ array_ptr = &IF_G(cookie_array);
break;
case PARSE_SERVER:
if (PG(auto_globals_jit)) {
- zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
+ zend_string *name = STR_INIT("_SERVER", sizeof("_SERVER") - 1, 0);
+ zend_is_auto_global(name TSRMLS_CC);
+ STR_RELEASE(name);
}
- array_ptr = IF_G(server_array);
+ array_ptr = &IF_G(server_array);
break;
case PARSE_ENV:
if (PG(auto_globals_jit)) {
- zend_is_auto_global("_ENV", sizeof("_ENV")-1 TSRMLS_CC);
+ zend_string *name = STR_INIT("_ENV", sizeof("_ENV") - 1, 0);
+ zend_is_auto_global(name TSRMLS_CC);
+ STR_RELEASE(name);
}
- array_ptr = IF_G(env_array) ? IF_G(env_array) : PG(http_globals)[TRACK_VARS_ENV];
+ array_ptr = &IF_G(env_array) ? &IF_G(env_array) : &PG(http_globals)[TRACK_VARS_ENV];
break;
case PARSE_SESSION:
/* FIXME: Implement session source */
*/
PHP_FUNCTION(filter_has_var)
{
- long arg;
- char *var;
- int var_len;
- zval *array_ptr = NULL;
+ long arg;
+ zend_string *var;
+ zval *array_ptr = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &arg, &var, &var_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lS", &arg, &var) == FAILURE) {
RETURN_FALSE;
}
array_ptr = php_filter_get_storage(arg TSRMLS_CC);
- if (array_ptr && HASH_OF(array_ptr) && zend_hash_exists(HASH_OF(array_ptr), var, var_len + 1)) {
+ if (array_ptr && HASH_OF(array_ptr) && zend_hash_exists(HASH_OF(array_ptr), var)) {
RETURN_TRUE;
}
}
/* }}} */
-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, long filter, zval *filter_args, const int copy, long filter_flags TSRMLS_DC) /* {{{ */
{
- zval *options = NULL;
- zval **option;
- char *charset = NULL;
+ zval *options = NULL;
+ zval *option;
+ char *charset = NULL;
- if (filter_args && Z_TYPE_PP(filter_args) != IS_ARRAY) {
+ if (filter_args && Z_TYPE_P(filter_args) != IS_ARRAY) {
long lval;
PHP_FILTER_GET_LONG_OPT(filter_args, lval);
filter = lval;
}
} else if (filter_args) {
- if (zend_hash_find(HASH_OF(*filter_args), "filter", sizeof("filter"), (void **)&option) == SUCCESS) {
+ if ((option = zend_hash_str_find(HASH_OF(filter_args), "filter", sizeof("filter") - 1)) != NULL) {
PHP_FILTER_GET_LONG_OPT(option, filter);
}
- if (zend_hash_find(HASH_OF(*filter_args), "flags", sizeof("flags"), (void **)&option) == SUCCESS) {
+ if ((option = zend_hash_str_find(HASH_OF(filter_args), "flags", sizeof("flags") - 1)) != NULL) {
PHP_FILTER_GET_LONG_OPT(option, filter_flags);
if (!(filter_flags & FILTER_REQUIRE_ARRAY || filter_flags & FILTER_FORCE_ARRAY)) {
}
}
- if (zend_hash_find(HASH_OF(*filter_args), "options", sizeof("options"), (void **)&option) == SUCCESS) {
+ if ((option = zend_hash_str_find(HASH_OF(filter_args), "options", sizeof("options") - 1)) != NULL) {
if (filter != FILTER_CALLBACK) {
- if (Z_TYPE_PP(option) == IS_ARRAY) {
- options = *option;
+ if (Z_TYPE_P(option) == IS_ARRAY) {
+ options = option;
}
} else {
- options = *option;
+ options = option;
filter_flags = 0;
}
}
}
- if (Z_TYPE_PP(filtered) == IS_ARRAY) {
+ if (Z_TYPE_P(filtered) == IS_ARRAY) {
if (filter_flags & FILTER_REQUIRE_SCALAR) {
if (copy) {
SEPARATE_ZVAL(filtered);
}
- zval_dtor(*filtered);
+ zval_ptr_dtor(filtered);
if (filter_flags & FILTER_NULL_ON_FAILURE) {
- ZVAL_NULL(*filtered);
+ ZVAL_NULL(filtered);
} else {
- ZVAL_FALSE(*filtered);
+ ZVAL_FALSE(filtered);
}
return;
}
if (copy) {
SEPARATE_ZVAL(filtered);
}
- zval_dtor(*filtered);
+ zval_ptr_dtor(filtered);
if (filter_flags & FILTER_NULL_ON_FAILURE) {
- ZVAL_NULL(*filtered);
+ ZVAL_NULL(filtered);
} else {
- ZVAL_FALSE(*filtered);
+ ZVAL_FALSE(filtered);
}
return;
}
php_zval_filter(filtered, filter, filter_flags, options, charset, copy TSRMLS_CC);
if (filter_flags & FILTER_FORCE_ARRAY) {
- zval *tmp;
-
- ALLOC_ZVAL(tmp);
- MAKE_COPY_ZVAL(filtered, tmp);
-
- zval_dtor(*filtered);
-
- array_init(*filtered);
- add_next_index_zval(*filtered, tmp);
+ zval tmp;
+ ZVAL_COPY_VALUE(&tmp, filtered);
+ array_init(filtered);
+ add_next_index_zval(filtered, &tmp);
}
}
/* }}} */
-static void php_filter_array_handler(zval *input, zval **op, zval *return_value, zend_bool add_empty TSRMLS_DC) /* {{{ */
+static void php_filter_array_handler(zval *input, zval *op, zval *return_value, zend_bool add_empty TSRMLS_DC) /* {{{ */
{
- char *arg_key;
- uint arg_key_len;
ulong index;
- HashPosition pos;
- zval **tmp, **arg_elm;
+ zend_string *arg_key;
+ zval *tmp, *arg_elm;
if (!op) {
- zval_dtor(return_value);
- MAKE_COPY_ZVAL(&input, return_value);
- php_filter_call(&return_value, FILTER_DEFAULT, NULL, 0, FILTER_REQUIRE_ARRAY TSRMLS_CC);
- } else if (Z_TYPE_PP(op) == IS_LONG) {
- zval_dtor(return_value);
- MAKE_COPY_ZVAL(&input, return_value);
- php_filter_call(&return_value, Z_LVAL_PP(op), NULL, 0, FILTER_REQUIRE_ARRAY TSRMLS_CC);
- } else if (Z_TYPE_PP(op) == IS_ARRAY) {
+ zval_ptr_dtor(return_value);
+ ZVAL_COPY(return_value, input);
+ php_filter_call(return_value, FILTER_DEFAULT, NULL, 0, FILTER_REQUIRE_ARRAY TSRMLS_CC);
+ } else if (Z_TYPE_P(op) == IS_LONG) {
+ zval_ptr_dtor(return_value);
+ ZVAL_COPY(return_value, input);
+ php_filter_call(return_value, Z_LVAL_P(op), NULL, 0, FILTER_REQUIRE_ARRAY TSRMLS_CC);
+ } else if (Z_TYPE_P(op) == IS_ARRAY) {
array_init(return_value);
- zend_hash_internal_pointer_reset(Z_ARRVAL_PP(op));
- for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(op), &pos);
- zend_hash_get_current_data_ex(Z_ARRVAL_PP(op), (void **) &arg_elm, &pos) == SUCCESS;
- zend_hash_move_forward_ex(Z_ARRVAL_PP(op), &pos))
- {
- if (zend_hash_get_current_key_ex(Z_ARRVAL_PP(op), &arg_key, &arg_key_len, &index, 0, &pos) != HASH_KEY_IS_STRING) {
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(op), index, arg_key, arg_elm) {
+ if (arg_key == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Numeric keys are not allowed in the definition array");
- zval_dtor(return_value);
+ zval_ptr_dtor(return_value);
RETURN_FALSE;
}
- if (arg_key_len < 2) {
+ if (arg_key->len == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty keys are not allowed in the definition array");
- zval_dtor(return_value);
+ zval_ptr_dtor(return_value);
RETURN_FALSE;
}
- if (zend_hash_find(Z_ARRVAL_P(input), arg_key, arg_key_len, (void **)&tmp) != SUCCESS) {
+ if ((tmp = zend_hash_find(Z_ARRVAL_P(input), arg_key)) == NULL) {
if (add_empty) {
- add_assoc_null_ex(return_value, arg_key, arg_key_len);
+ add_assoc_null_ex(return_value, arg_key->val, arg_key->len);
}
} else {
- zval *nval;
-
- ALLOC_ZVAL(nval);
- MAKE_COPY_ZVAL(tmp, nval);
-
+ zval nval;
+ ZVAL_DUP_DEREF(&nval, tmp);
php_filter_call(&nval, -1, arg_elm, 0, FILTER_REQUIRE_SCALAR TSRMLS_CC);
- add_assoc_zval_ex(return_value, arg_key, arg_key_len, nval);
+ zend_hash_update(Z_ARRVAL_P(return_value), arg_key, &nval);
}
- }
+ } ZEND_HASH_FOREACH_END();
} else {
RETURN_FALSE;
}
*/
PHP_FUNCTION(filter_input)
{
- long fetch_from, filter = FILTER_DEFAULT;
- zval **filter_args = NULL, **tmp;
- zval *input = NULL;
- char *var;
- int var_len;
+ long 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, &var_len, &filter, &filter_args) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lS|lz", &fetch_from, &var, &filter, &filter_args) == FAILURE) {
return;
}
input = php_filter_get_storage(fetch_from TSRMLS_CC);
- if (!input || !HASH_OF(input) || zend_hash_find(HASH_OF(input), var, var_len + 1, (void **)&tmp) != SUCCESS) {
+ if (!input || !HASH_OF(input) || (tmp = zend_hash_find(HASH_OF(input), var)) == NULL) {
long filter_flags = 0;
- zval **option, **opt, **def;
+ zval *option, *opt, *def;
if (filter_args) {
- if (Z_TYPE_PP(filter_args) == IS_LONG) {
- filter_flags = Z_LVAL_PP(filter_args);
- } else if (Z_TYPE_PP(filter_args) == IS_ARRAY && zend_hash_find(HASH_OF(*filter_args), "flags", sizeof("flags"), (void **)&option) == SUCCESS) {
+ if (Z_TYPE_P(filter_args) == IS_LONG) {
+ filter_flags = Z_LVAL_P(filter_args);
+ } else if (Z_TYPE_P(filter_args) == IS_ARRAY && (option = zend_hash_str_find(HASH_OF(filter_args), "flags", sizeof("flags") - 1)) != NULL) {
PHP_FILTER_GET_LONG_OPT(option, filter_flags);
}
- if (Z_TYPE_PP(filter_args) == IS_ARRAY &&
- zend_hash_find(HASH_OF(*filter_args), "options", sizeof("options"), (void **)&opt) == SUCCESS &&
- Z_TYPE_PP(opt) == IS_ARRAY &&
- zend_hash_find(HASH_OF(*opt), "default", sizeof("default"), (void **)&def) == SUCCESS
- ) {
- MAKE_COPY_ZVAL(def, return_value);
+ if (Z_TYPE_P(filter_args) == IS_ARRAY &&
+ (opt = zend_hash_str_find(HASH_OF(filter_args), "options", sizeof("options") - 1)) != NULL &&
+ Z_TYPE_P(opt) == IS_ARRAY &&
+ (def = zend_hash_str_find(HASH_OF(opt), "default", sizeof("default") - 1)) != NULL) {
+ ZVAL_COPY(return_value, def);
return;
}
}
}
}
- MAKE_COPY_ZVAL(tmp, return_value);
+ ZVAL_DUP(return_value, tmp);
- php_filter_call(&return_value, filter, filter_args, 1, FILTER_REQUIRE_SCALAR TSRMLS_CC);
+ php_filter_call(return_value, filter, filter_args, 1, FILTER_REQUIRE_SCALAR TSRMLS_CC);
}
/* }}} */
PHP_FUNCTION(filter_var)
{
long filter = FILTER_DEFAULT;
- zval **filter_args = NULL, *data;
+ 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/|lz", &data, &filter, &filter_args) == FAILURE) {
return;
}
RETURN_FALSE;
}
- MAKE_COPY_ZVAL(&data, return_value);
+ ZVAL_COPY(return_value, data);
- php_filter_call(&return_value, filter, filter_args, 1, FILTER_REQUIRE_SCALAR TSRMLS_CC);
+ php_filter_call(return_value, filter, filter_args, 1, FILTER_REQUIRE_SCALAR TSRMLS_CC);
}
/* }}} */
PHP_FUNCTION(filter_input_array)
{
long fetch_from;
- zval *array_input = NULL, **op = NULL;
+ 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, "l|zb", &fetch_from, &op, &add_empty) == FAILURE) {
return;
}
- if (op
- && (Z_TYPE_PP(op) != IS_ARRAY)
- && (Z_TYPE_PP(op) == IS_LONG && !PHP_FILTER_ID_EXISTS(Z_LVAL_PP(op)))
- ) {
+ if (op && (Z_TYPE_P(op) != IS_ARRAY) && (Z_TYPE_P(op) == IS_LONG && !PHP_FILTER_ID_EXISTS(Z_LVAL_P(op)))) {
RETURN_FALSE;
}
if (!array_input || !HASH_OF(array_input)) {
long filter_flags = 0;
- zval **option;
+ zval *option;
if (op) {
- if (Z_TYPE_PP(op) == IS_LONG) {
- filter_flags = Z_LVAL_PP(op);
- } else if (Z_TYPE_PP(op) == IS_ARRAY && zend_hash_find(HASH_OF(*op), "flags", sizeof("flags"), (void **)&option) == SUCCESS) {
+ if (Z_TYPE_P(op) == IS_LONG) {
+ filter_flags = Z_LVAL_P(op);
+ } else if (Z_TYPE_P(op) == IS_ARRAY && (option = zend_hash_str_find(HASH_OF(op), "flags", sizeof("flags") - 1)) != NULL) {
PHP_FILTER_GET_LONG_OPT(option, filter_flags);
}
}
*/
PHP_FUNCTION(filter_var_array)
{
- zval *array_input = NULL, **op = NULL;
+ zval *array_input = NULL, *op = NULL;
zend_bool add_empty = 1;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|Zb", &array_input, &op, &add_empty) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|zb", &array_input, &op, &add_empty) == FAILURE) {
return;
}
- if (op
- && (Z_TYPE_PP(op) != IS_ARRAY)
- && (Z_TYPE_PP(op) == IS_LONG && !PHP_FILTER_ID_EXISTS(Z_LVAL_PP(op)))
- ) {
+ if (op && (Z_TYPE_P(op) != IS_ARRAY) && (Z_TYPE_P(op) == IS_LONG && !PHP_FILTER_ID_EXISTS(Z_LVAL_P(op)))) {
RETURN_FALSE;
}
/* {{{ FETCH_LONG_OPTION(var_name, option_name) */
-#define FETCH_LONG_OPTION(var_name, option_name) \
- var_name = 0; \
- var_name##_set = 0; \
- if (option_array) { \
- if (zend_hash_find(HASH_OF(option_array), option_name, sizeof(option_name), (void **) &option_val) == SUCCESS) { \
- PHP_FILTER_GET_LONG_OPT(option_val, var_name); \
- var_name##_set = 1; \
- } \
+#define FETCH_LONG_OPTION(var_name, option_name) \
+ var_name = 0; \
+ var_name##_set = 0; \
+ if (option_array) { \
+ if ((option_val = zend_hash_str_find(HASH_OF(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \
+ PHP_FILTER_GET_LONG_OPT(option_val, var_name); \
+ var_name##_set = 1; \
+ } \
}
/* }}} */
/* {{{ FETCH_STRING_OPTION(var_name, option_name) */
-#define FETCH_STRING_OPTION(var_name, option_name) \
- var_name = NULL; \
- var_name##_set = 0; \
- var_name##_len = 0; \
- if (option_array) { \
- if (zend_hash_find(HASH_OF(option_array), option_name, sizeof(option_name), (void **) &option_val) == SUCCESS) { \
- if (Z_TYPE_PP(option_val) == IS_STRING) { \
- var_name = Z_STRVAL_PP(option_val); \
- var_name##_len = Z_STRLEN_PP(option_val); \
- var_name##_set = 1; \
- } \
- } \
+#define FETCH_STRING_OPTION(var_name, option_name) \
+ var_name = NULL; \
+ var_name##_set = 0; \
+ var_name##_len = 0; \
+ if (option_array) { \
+ if ((option_val = zend_hash_str_find(HASH_OF(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \
+ if (Z_TYPE_P(option_val) == IS_STRING) { \
+ var_name = Z_STRVAL_P(option_val); \
+ var_name##_len = Z_STRLEN_P(option_val); \
+ var_name##_set = 1; \
+ } \
+ } \
+ }
+/* }}} */
+
+/* {{{ FETCH_STR_OPTION(var_name, option_name) */
+#define FETCH_STR_OPTION(var_name, option_name) \
+ var_name = NULL; \
+ var_name##_set = 0; \
+ if (option_array) { \
+ if ((option_val = zend_hash_str_find(HASH_OF(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \
+ if (Z_TYPE_P(option_val) == IS_STRING) { \
+ var_name = Z_STR_P(option_val); \
+ var_name##_set = 1; \
+ } \
+ } \
}
/* }}} */
void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
{
- zval **option_val;
- long 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;
+ zval *option_val;
+ long 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;
char *p;
/* Parse options */
if (error > 0 || (min_range_set && (ctx_value < min_range)) || (max_range_set && (ctx_value > max_range))) {
RETURN_VALIDATION_FAILED
} else {
- zval_dtor(value);
- Z_TYPE_P(value) = IS_LONG;
- Z_LVAL_P(value) = ctx_value;
+ zval_ptr_dtor(value);
+ ZVAL_LONG(value, ctx_value);
return;
}
}
int len;
char *str, *end;
char *num, *p;
-
- zval **option_val;
+ zval *option_val;
char *decimal;
int decimal_set, decimal_len;
char dec_sep = '.';
switch (is_numeric_string(num, p - num, &lval, &dval, 0)) {
case IS_LONG:
- zval_dtor(value);
- Z_TYPE_P(value) = IS_DOUBLE;
- Z_DVAL_P(value) = lval;
+ zval_ptr_dtor(value);
+ ZVAL_DOUBLE(value, lval);
break;
case IS_DOUBLE:
if ((!dval && p - num > 1 && strpbrk(num, "123456789")) || !zend_finite(dval)) {
goto error;
}
- zval_dtor(value);
- Z_TYPE_P(value) = IS_DOUBLE;
- Z_DVAL_P(value) = dval;
+ zval_ptr_dtor(value);
+ ZVAL_DOUBLE(value, dval);
break;
default:
error:
void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
{
- zval **option_val;
- char *regexp;
- int regexp_len;
- long option_flags;
- int regexp_set, option_flags_set;
-
- pcre *re = NULL;
+ zval *option_val;
+ zend_string *regexp;
+ long option_flags;
+ int regexp_set, option_flags_set;
+ pcre *re = NULL;
pcre_extra *pcre_extra = NULL;
int preg_options = 0;
-
- int ovector[3];
- int matches;
+ int ovector[3];
+ int matches;
/* Parse options */
- FETCH_STRING_OPTION(regexp, "regexp");
+ FETCH_STR_OPTION(regexp, "regexp");
FETCH_LONG_OPTION(option_flags, "flags");
if (!regexp_set) {
*
*/
const char regexp[] = "/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD";
-
pcre *re = NULL;
pcre_extra *pcre_extra = NULL;
int preg_options = 0;
int ovector[150]; /* Needs to be a multiple of 3 */
int matches;
+ zend_string *sregexp;
/* The maximum length of an e-mail address is 320 octets, per RFC 2821. */
RETURN_VALIDATION_FAILED
}
- re = pcre_get_compiled_regex((char *)regexp, &pcre_extra, &preg_options TSRMLS_CC);
+ sregexp = STR_INIT(regexp, sizeof(regexp) - 1, 0);
+ re = pcre_get_compiled_regex(sregexp, &pcre_extra, &preg_options TSRMLS_CC);
if (!re) {
+ STR_RELEASE(sregexp);
RETURN_VALIDATION_FAILED
}
+ STR_RELEASE(sregexp);
matches = pcre_exec(re, NULL, Z_STRVAL_P(value), Z_STRLEN_P(value), 0, 0, ovector, 3);
/* 0 means that the vector is too small to hold all the captured substring offsets */
char separator;
char *exp_separator;
long ret = 0;
- zval **option_val;
+ zval *option_val;
FETCH_STRING_OPTION(exp_separator, "separator");