diff options
author | Stanley Sufficool <ssufficool@php.net> | 2014-10-20 21:33:32 -0700 |
---|---|---|
committer | Stanley Sufficool <ssufficool@php.net> | 2014-10-20 21:33:32 -0700 |
commit | 8defcb855ab01d9c8ab4759cb793d80149b55a8c (patch) | |
tree | ed51eb30a2cbc92b102557498fb3e4113da1bb07 /ext/session/mod_user.c | |
parent | 9c7dbb0487f5991fde03873ea8f5e66d6688415f (diff) | |
parent | baddb1c73a170ef1d2c31bd54cddbc6e1ab596b9 (diff) | |
download | php-git-8defcb855ab01d9c8ab4759cb793d80149b55a8c.tar.gz |
Merge branch 'master' of https://git.php.net/push/php-src
* 'master' of https://git.php.net/push/php-src: (6215 commits)
Extra comma
Moved proxy object support in ASSIGN_ADD (and family) from VM to slow paths of corresponding operators
Simplification
zend_get_property_info_quick() cleanup and optimization
initialize lineno before calling compile file file in phar
Use ADDREF instead of DUP, it must be enough.
Removed old irrelevant comment
fixed compilation error
Fix bug #68262: Broken reference across cloned objects
export functions needed for phpdbg
Fixed compilation
Optimized property access handlers. Removed EG(std_property_info).
Fixed bug #68199 (PDO::pgsqlGetNotify doesn't support NOTIFY payloads)
Don't make difference between undefined and unaccessible properies when call __get() and family
Don't make useless CSE
array_pop/array_shift optimization
check for zlib headers as well as lib for mysqlnd
a realpath cache key can be int or float, catching this
News entry for new curl constants
News entry for new curl constants
...
Diffstat (limited to 'ext/session/mod_user.c')
-rw-r--r-- | ext/session/mod_user.c | 122 |
1 files changed, 67 insertions, 55 deletions
diff --git a/ext/session/mod_user.c b/ext/session/mod_user.c index 1b606b9a33..5d474deab5 100644 --- a/ext/session/mod_user.c +++ b/ext/session/mod_user.c @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2013 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -28,7 +28,6 @@ ps_module ps_mod_user = { #define SESS_ZVAL_LONG(val, a) \ { \ - MAKE_STD_ZVAL(a); \ ZVAL_LONG(a, val); \ } @@ -40,58 +39,73 @@ ps_module ps_mod_user = { #define SESS_ZVAL_STRINGN(vl, ln, a) \ { \ - MAKE_STD_ZVAL(a); \ - ZVAL_STRINGL(a, vl, ln, 1); \ + ZVAL_STRINGL(a, vl, ln); \ } -static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC) +#define SESS_ZVAL_STR(vl, a) \ +{ \ + ZVAL_STR_COPY(a, vl); \ +} + +static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval TSRMLS_DC) { int i; - zval *retval = NULL; - - MAKE_STD_ZVAL(retval); if (call_user_function(EG(function_table), NULL, func, retval, argc, argv TSRMLS_CC) == FAILURE) { - zval_ptr_dtor(&retval); - retval = NULL; + zval_ptr_dtor(retval); + ZVAL_UNDEF(retval); + } else if (Z_ISUNDEF_P(retval)) { + ZVAL_NULL(retval); } - for (i = 0; i < argc; i++) { zval_ptr_dtor(&argv[i]); } - - return retval; } #define STDVARS \ - zval *retval = NULL; \ + zval retval; \ int ret = FAILURE #define PSF(a) PS(mod_user_names).name.ps_##a -#define FINISH \ - if (retval) { \ - convert_to_long(retval); \ - ret = Z_LVAL_P(retval); \ - zval_ptr_dtor(&retval); \ - } \ +#define FINISH \ + if (Z_TYPE(retval) != IS_UNDEF) { \ + if (Z_TYPE(retval) == IS_TRUE) { \ + ret = SUCCESS; \ + } else if (Z_TYPE(retval) == IS_FALSE) { \ + ret = FAILURE; \ + } else if ((Z_TYPE(retval) == IS_LONG) && (Z_LVAL(retval) == -1)) { \ + /* BC for clever users - Deprecate me */ \ + ret = FAILURE; \ + } else if ((Z_TYPE(retval) == IS_LONG) && (Z_LVAL(retval) == 0)) { \ + /* BC for clever users - Deprecate me */ \ + ret = SUCCESS; \ + } else { \ + if (!EG(exception)) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, \ + "Session callback expects true/false return value"); \ + } \ + ret = FAILURE; \ + zval_ptr_dtor(&retval); \ + } \ + } \ return ret PS_OPEN_FUNC(user) { - zval *args[2]; + zval args[2]; STDVARS; - if (PSF(open) == NULL) { + if (Z_ISUNDEF(PSF(open))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "user session functions not defined"); return FAILURE; } - SESS_ZVAL_STRING((char*)save_path, args[0]); - SESS_ZVAL_STRING((char*)session_name, args[1]); + SESS_ZVAL_STRING((char*)save_path, &args[0]); + SESS_ZVAL_STRING((char*)session_name, &args[1]); - retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC); + ps_call_handler(&PSF(open), 2, args, &retval TSRMLS_CC); PS(mod_user_implemented) = 1; FINISH; @@ -108,7 +122,7 @@ PS_CLOSE_FUNC(user) } zend_try { - retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC); + ps_call_handler(&PSF(close), 0, NULL, &retval TSRMLS_CC); } zend_catch { bailout = 1; } zend_end_try(); @@ -116,7 +130,7 @@ PS_CLOSE_FUNC(user) PS(mod_user_implemented) = 0; if (bailout) { - if (retval) { + if (!Z_ISUNDEF(retval)) { zval_ptr_dtor(&retval); } zend_bailout(); @@ -127,17 +141,16 @@ PS_CLOSE_FUNC(user) PS_READ_FUNC(user) { - zval *args[1]; + zval args[1]; STDVARS; - SESS_ZVAL_STRING((char*)key, args[0]); + SESS_ZVAL_STR(key, &args[0]); - retval = ps_call_handler(PSF(read), 1, args TSRMLS_CC); + ps_call_handler(&PSF(read), 1, args, &retval TSRMLS_CC); - if (retval) { - if (Z_TYPE_P(retval) == IS_STRING) { - *val = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); - *vallen = Z_STRLEN_P(retval); + if (!Z_ISUNDEF(retval)) { + if (Z_TYPE(retval) == IS_STRING) { + *val = zend_string_copy(Z_STR(retval)); ret = SUCCESS; } zval_ptr_dtor(&retval); @@ -148,37 +161,37 @@ PS_READ_FUNC(user) PS_WRITE_FUNC(user) { - zval *args[2]; + zval args[2]; STDVARS; - SESS_ZVAL_STRING((char*)key, args[0]); - SESS_ZVAL_STRINGN((char*)val, vallen, args[1]); + SESS_ZVAL_STR(key, &args[0]); + SESS_ZVAL_STR(val, &args[1]); - retval = ps_call_handler(PSF(write), 2, args TSRMLS_CC); + ps_call_handler(&PSF(write), 2, args, &retval TSRMLS_CC); FINISH; } PS_DESTROY_FUNC(user) { - zval *args[1]; + zval args[1]; STDVARS; - SESS_ZVAL_STRING((char*)key, args[0]); + SESS_ZVAL_STR(key, &args[0]); - retval = ps_call_handler(PSF(destroy), 1, args TSRMLS_CC); + ps_call_handler(&PSF(destroy), 1, args, &retval TSRMLS_CC); FINISH; } PS_GC_FUNC(user) { - zval *args[1]; + zval args[1]; STDVARS; - SESS_ZVAL_LONG(maxlifetime, args[0]); + SESS_ZVAL_LONG(maxlifetime, &args[0]); - retval = ps_call_handler(PSF(gc), 1, args TSRMLS_CC); + ps_call_handler(&PSF(gc), 1, args, &retval TSRMLS_CC); FINISH; } @@ -186,19 +199,18 @@ PS_GC_FUNC(user) PS_CREATE_SID_FUNC(user) { /* maintain backwards compatibility */ - if (PSF(create_sid) != NULL) { - char *id = NULL; - zval *retval = NULL; + if (!Z_ISUNDEF(PSF(create_sid))) { + zend_string *id = NULL; + zval retval; - retval = ps_call_handler(PSF(create_sid), 0, NULL TSRMLS_CC); + ps_call_handler(&PSF(create_sid), 0, NULL, &retval TSRMLS_CC); - if (retval) { - if (Z_TYPE_P(retval) == IS_STRING) { - id = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + if (!Z_ISUNDEF(retval)) { + if (Z_TYPE(retval) == IS_STRING) { + id = zend_string_copy(Z_STR(retval)); } zval_ptr_dtor(&retval); - } - else { + } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "No session id returned by function"); return NULL; } @@ -212,7 +224,7 @@ PS_CREATE_SID_FUNC(user) } /* function as defined by PS_MOD */ - return php_session_create_id(mod_data, newlen TSRMLS_CC); + return php_session_create_id(mod_data TSRMLS_CC); } /* |