mirror of
https://github.com/php/php-src.git
synced 2026-03-27 17:52:16 +01:00
Cheaper checking
This commit is contained in:
@@ -206,17 +206,11 @@ PHPAPI int php_setcookie(zend_string *name, zend_string *value, time_t expires,
|
||||
return result;
|
||||
}
|
||||
|
||||
static int php_head_parse_cookie_options_array(zval *options, zend_long *expires, zend_string **path, zend_string **domain, zend_bool *secure, zend_bool *httponly, zend_string **samesite) {
|
||||
static void php_head_parse_cookie_options_array(zval *options, zend_long *expires, zend_string **path, zend_string **domain, zend_bool *secure, zend_bool *httponly, zend_string **samesite) {
|
||||
int found = 0;
|
||||
zend_string *key;
|
||||
zval *value;
|
||||
|
||||
if (*path) {
|
||||
*path = NULL;
|
||||
php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), key, value) {
|
||||
if (key) {
|
||||
if (zend_string_equals_literal_ci(key, "expires")) {
|
||||
@@ -249,8 +243,6 @@ static int php_head_parse_cookie_options_array(zval *options, zend_long *expires
|
||||
if (found == 0 && zend_hash_num_elements(Z_ARRVAL_P(options)) > 0) {
|
||||
php_error_docref(NULL, E_WARNING, "No valid options were found in the given array");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* {{{ proto bool setcookie(string name [, string value [, int expires [, string path [, string domain [, bool secure[, bool httponly]]]]]])
|
||||
@@ -276,10 +268,11 @@ PHP_FUNCTION(setcookie)
|
||||
|
||||
if (expires_or_options) {
|
||||
if (Z_TYPE_P(expires_or_options) == IS_ARRAY) {
|
||||
if (!php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite)) {
|
||||
RETVAL_FALSE;
|
||||
goto cleanup;
|
||||
if (UNEXPECTED(ZEND_NUM_ARGS() > 3)) {
|
||||
php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite);
|
||||
} else {
|
||||
expires = zval_get_long(expires_or_options);
|
||||
}
|
||||
@@ -291,7 +284,6 @@ PHP_FUNCTION(setcookie)
|
||||
RETVAL_FALSE;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (expires_or_options && Z_TYPE_P(expires_or_options) == IS_ARRAY) {
|
||||
if (path) {
|
||||
zend_string_release(path);
|
||||
@@ -314,7 +306,7 @@ PHP_FUNCTION(setrawcookie)
|
||||
zval *expires_or_options = NULL;
|
||||
zend_string *name, *value = NULL, *path = NULL, *domain = NULL, *samesite = NULL;
|
||||
zend_long expires = 0;
|
||||
zend_bool secure = 0, httponly = 0, options_array = 0;
|
||||
zend_bool secure = 0, httponly = 0;
|
||||
|
||||
ZEND_PARSE_PARAMETERS_START(1, 7)
|
||||
Z_PARAM_STR(name)
|
||||
@@ -329,11 +321,11 @@ PHP_FUNCTION(setrawcookie)
|
||||
|
||||
if (expires_or_options) {
|
||||
if (Z_TYPE_P(expires_or_options) == IS_ARRAY) {
|
||||
options_array = 1;
|
||||
if (!php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite)) {
|
||||
RETVAL_FALSE;
|
||||
goto cleanup;
|
||||
if (UNEXPECTED(ZEND_NUM_ARGS() > 3)) {
|
||||
php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite);
|
||||
} else {
|
||||
expires = Z_LVAL_P(expires_or_options);
|
||||
}
|
||||
@@ -345,8 +337,7 @@ PHP_FUNCTION(setrawcookie)
|
||||
RETVAL_FALSE;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (options_array) {
|
||||
if (expires_or_options && Z_TYPE_P(expires_or_options) == IS_ARRAY) {
|
||||
if (path) {
|
||||
zend_string_release(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user