1999-12-12 14:22:55 +00:00
/*
1999-06-05 19:52:58 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2014-09-19 16:33:14 +00:00
| PHP Version 7 |
1999-06-05 19:52:58 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2016-01-01 17:19:27 +00:00
| Copyright ( c ) 1997 - 2016 The PHP Group |
1999-06-05 19:52:58 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 12:51:34 +00:00
| This source file is subject to version 3.01 of the PHP license , |
1999-07-16 13:13:16 +00:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-10 20:04:29 +00:00
| available through the world - wide - web at the following url : |
2006-01-01 12:51:34 +00:00
| http : //www.php.net/license/3_01.txt |
1999-07-16 13:13:16 +00:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
1999-06-05 19:52:58 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2000-07-10 10:09:15 +00:00
| Authors : Sascha Schumann < sascha @ schumann . cx > |
2002-05-13 17:28:38 +00:00
| Andrei Zmievski < andrei @ php . net > |
1999-06-05 19:52:58 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
2001-06-06 14:32:27 +00:00
/* $Id$ */
2001-05-24 10:07:29 +00:00
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
2000-02-11 13:41:30 +00:00
# include "php.h"
2000-02-11 15:59:30 +00:00
# ifdef PHP_WIN32
2010-06-08 13:46:19 +00:00
# include "win32 / winutil.h"
# include "win32 / time.h"
2000-02-11 13:41:30 +00:00
# else
2010-06-08 13:46:19 +00:00
# include <sys / time.h>
1999-06-06 18:22:17 +00:00
# endif
1999-06-05 19:52:58 +00:00
1999-12-12 14:16:55 +00:00
# include <sys/stat.h>
1999-09-11 17:20:31 +00:00
# include <fcntl.h>
1999-06-05 19:52:58 +00:00
# include "php_ini.h"
# include "SAPI.h"
2010-05-10 16:09:00 +00:00
# include "rfc1867.h"
# include "php_variables.h"
1999-06-05 19:52:58 +00:00
# include "php_session.h"
1999-06-06 19:53:59 +00:00
# include "ext/standard/md5.h"
2003-01-12 13:07:14 +00:00
# include "ext/standard/sha1.h"
1999-12-04 19:19:57 +00:00
# include "ext/standard/php_var.h"
2008-12-11 01:21:35 +00:00
# include "ext/date/php_date.h"
1999-09-01 14:20:15 +00:00
# include "ext/standard/php_lcg.h"
2000-09-20 01:22:55 +00:00
# include "ext/standard/url_scanner_ex.h"
2008-08-06 05:53:31 +00:00
# include "ext/standard/php_rand.h" /* for RAND_MAX */
2000-04-06 21:07:44 +00:00
# include "ext/standard/info.h"
2014-09-20 20:42:02 +00:00
# include "zend_smart_str.h"
2007-06-17 14:25:46 +00:00
# include "ext/standard/url.h"
2011-09-13 22:28:15 +00:00
# include "ext/standard/basic_functions.h"
2014-05-06 20:00:59 +00:00
# include "ext/standard/head.h"
2001-03-13 16:53:34 +00:00
2001-05-03 15:48:49 +00:00
# include "mod_files.h"
# include "mod_user.h"
2002-06-28 02:27:02 +00:00
# ifdef HAVE_LIBMM
# include "mod_mm.h"
# endif
2012-06-22 15:32:46 +00:00
PHPAPI ZEND_DECLARE_MODULE_GLOBALS ( ps )
2008-06-27 16:16:23 +00:00
2014-12-13 22:06:14 +00:00
static int php_session_rfc1867_callback ( unsigned int event , void * event_data , void * * extra ) ;
static int ( * php_session_rfc1867_orig_callback ) ( unsigned int event , void * event_data , void * * extra ) ;
2015-09-01 19:40:10 +00:00
static void php_session_track_init ( void ) ;
2010-05-10 16:09:00 +00:00
2011-09-13 22:28:15 +00:00
/* SessionHandler class */
zend_class_entry * php_session_class_entry ;
2012-01-04 01:16:45 +00:00
/* SessionHandlerInterface */
zend_class_entry * php_session_iface_entry ;
2013-06-27 11:33:56 +00:00
/* SessionIdInterface */
zend_class_entry * php_session_id_iface_entry ;
2015-01-21 10:13:59 +00:00
/* SessionUpdateTimestampHandler class */
zend_class_entry * php_session_update_timestamp_class_entry ;
/* SessionUpdateTimestampInterface */
zend_class_entry * php_session_update_timestamp_iface_entry ;
2008-08-06 05:53:31 +00:00
/* ***********
* Helpers *
* * * * * * * * * * * */
2008-06-27 16:16:23 +00:00
2008-08-06 05:53:31 +00:00
# define IF_SESSION_VARS() \
2014-03-28 10:46:25 +00:00
if ( Z_ISREF_P ( & PS ( http_session_vars ) ) & & Z_TYPE_P ( Z_REFVAL ( PS ( http_session_vars ) ) ) = = IS_ARRAY )
2001-05-01 17:01:51 +00:00
2003-12-14 23:24:50 +00:00
# define SESSION_CHECK_ACTIVE_STATE \
if ( PS ( session_status ) = = php_session_active ) { \
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " A session is active. You cannot change the session module's ini settings at this time " ) ; \
2003-12-14 23:24:50 +00:00
return FAILURE ; \
2008-08-06 05:53:31 +00:00
}
2003-12-14 23:24:50 +00:00
2015-02-02 03:53:41 +00:00
# define APPLY_TRANS_SID (PS(use_trans_sid) && !PS(use_only_cookies))
2014-12-13 22:06:14 +00:00
static void php_session_send_cookie ( void ) ;
2016-01-12 10:52:54 +00:00
static void php_session_abort ( void ) ;
2013-06-25 10:47:04 +00:00
2008-08-06 05:53:31 +00:00
/* Dispatched by RINIT and by php_session_destroy */
2014-12-13 22:06:14 +00:00
static inline void php_rinit_session_globals ( void ) /* { { { */
2000-05-26 13:02:11 +00:00
{
2015-01-21 10:13:59 +00:00
/* Do NOT init PS(mod_user_names) here! */
2008-08-06 05:53:31 +00:00
PS ( id ) = NULL ;
PS ( session_status ) = php_session_none ;
PS ( mod_data ) = NULL ;
2011-09-13 22:28:15 +00:00
PS ( mod_user_is_open ) = 0 ;
2015-01-21 10:13:59 +00:00
PS ( define_sid ) = 1 ;
PS ( session_vars ) = NULL ;
2014-03-26 15:23:54 +00:00
ZVAL_UNDEF ( & PS ( http_session_vars ) ) ;
2008-08-06 05:53:31 +00:00
}
/* }}} */
2002-05-12 12:51:42 +00:00
2008-08-06 05:53:31 +00:00
/* Dispatched by RSHUTDOWN and by php_session_destroy */
2014-12-13 22:06:14 +00:00
static inline void php_rshutdown_session_globals ( void ) /* { { { */
2008-08-06 05:53:31 +00:00
{
2015-01-21 10:13:59 +00:00
/* Do NOT destroy PS(mod_user_names) here! */
2014-05-03 08:06:27 +00:00
if ( ! Z_ISUNDEF ( PS ( http_session_vars ) ) ) {
2008-08-06 05:53:31 +00:00
zval_ptr_dtor ( & PS ( http_session_vars ) ) ;
2014-03-26 15:23:54 +00:00
ZVAL_UNDEF ( & PS ( http_session_vars ) ) ;
2008-08-06 05:53:31 +00:00
}
2011-09-13 22:28:15 +00:00
if ( PS ( mod_data ) | | PS ( mod_user_implemented ) ) {
2008-08-06 05:53:31 +00:00
zend_try {
2014-12-13 22:06:14 +00:00
PS ( mod ) - > s_close ( & PS ( mod_data ) ) ;
2008-08-06 05:53:31 +00:00
} zend_end_try ( ) ;
}
if ( PS ( id ) ) {
2014-08-25 17:24:55 +00:00
zend_string_release ( PS ( id ) ) ;
2015-03-16 15:00:46 +00:00
PS ( id ) = NULL ;
2002-05-12 12:51:42 +00:00
}
2015-01-21 10:13:59 +00:00
if ( PS ( session_vars ) ) {
zend_string_release ( PS ( session_vars ) ) ;
2015-03-16 15:11:02 +00:00
PS ( session_vars ) = NULL ;
2015-01-21 10:13:59 +00:00
}
2000-05-26 13:02:11 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
2000-05-26 13:02:11 +00:00
2014-12-13 22:06:14 +00:00
static int php_session_destroy ( void ) /* { { { */
2000-05-26 13:02:11 +00:00
{
2008-08-06 05:53:31 +00:00
int retval = SUCCESS ;
2003-12-14 23:24:50 +00:00
2008-08-06 05:53:31 +00:00
if ( PS ( session_status ) ! = php_session_active ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Trying to destroy uninitialized session " ) ;
2008-08-06 05:53:31 +00:00
return FAILURE ;
2002-11-20 17:15:00 +00:00
}
2003-12-14 23:24:50 +00:00
2014-12-13 22:06:14 +00:00
if ( PS ( id ) & & PS ( mod ) - > s_destroy ( & PS ( mod_data ) , PS ( id ) ) = = FAILURE ) {
2008-08-06 05:53:31 +00:00
retval = FAILURE ;
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Session object destruction failed " ) ;
2008-08-06 05:53:31 +00:00
}
2014-12-13 22:06:14 +00:00
php_rshutdown_session_globals ( ) ;
php_rinit_session_globals ( ) ;
2008-08-06 05:53:31 +00:00
return retval ;
2003-12-14 23:24:50 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
2003-12-14 23:24:50 +00:00
2014-12-13 22:06:14 +00:00
PHPAPI void php_add_session_var ( zend_string * name ) /* { { { */
2003-12-14 23:24:50 +00:00
{
2014-03-26 15:23:54 +00:00
zval * sym_track = NULL ;
2002-05-12 12:51:42 +00:00
2008-08-06 05:53:31 +00:00
IF_SESSION_VARS ( ) {
2014-03-28 10:46:25 +00:00
sym_track = zend_hash_find ( Z_ARRVAL_P ( Z_REFVAL ( PS ( http_session_vars ) ) ) , name ) ;
2008-08-06 05:53:31 +00:00
} else {
return ;
2002-05-12 12:51:42 +00:00
}
2003-08-26 02:03:41 +00:00
2010-04-21 01:27:22 +00:00
if ( sym_track = = NULL ) {
2014-03-26 15:23:54 +00:00
zval empty_var ;
2000-05-26 13:02:11 +00:00
2014-03-26 15:23:54 +00:00
ZVAL_NULL ( & empty_var ) ;
2014-04-15 11:40:40 +00:00
zend_hash_update ( Z_ARRVAL_P ( Z_REFVAL ( PS ( http_session_vars ) ) ) , name , & empty_var ) ;
2005-05-21 17:37:56 +00:00
}
}
2001-06-06 14:32:27 +00:00
/* }}} */
1999-06-05 19:52:58 +00:00
2014-12-13 22:06:14 +00:00
PHPAPI zval * php_set_session_var ( zend_string * name , zval * state_val , php_unserialize_data_t * var_hash ) /* { { { */
1999-12-04 17:02:04 +00:00
{
2010-04-21 01:27:22 +00:00
IF_SESSION_VARS ( ) {
2014-04-10 14:08:11 +00:00
return zend_hash_update ( Z_ARRVAL_P ( Z_REFVAL ( PS ( http_session_vars ) ) ) , name , state_val ) ;
2002-05-09 20:02:47 +00:00
}
2014-04-10 14:08:11 +00:00
return NULL ;
1999-12-04 17:02:04 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-12-04 17:02:04 +00:00
2014-12-13 22:06:14 +00:00
PHPAPI zval * php_get_session_var ( zend_string * name ) /* { { { */
1999-12-04 17:02:04 +00:00
{
2002-10-03 03:23:02 +00:00
IF_SESSION_VARS ( ) {
2014-03-28 10:46:25 +00:00
return zend_hash_find ( Z_ARRVAL_P ( Z_REFVAL ( PS ( http_session_vars ) ) ) , name ) ;
2002-09-23 14:04:50 +00:00
}
2014-03-26 15:23:54 +00:00
return NULL ;
1999-12-04 17:02:04 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-11-29 23:07:20 +00:00
2014-12-13 22:06:14 +00:00
static void php_session_track_init ( void ) /* { { { */
2000-09-01 15:24:58 +00:00
{
2014-03-28 10:46:25 +00:00
zval session_vars ;
2014-08-25 17:24:55 +00:00
zend_string * var_name = zend_string_init ( " _SESSION " , sizeof ( " _SESSION " ) - 1 , 0 ) ;
2010-04-15 16:36:08 +00:00
/* Unconditionally destroy existing array -- possible dirty data */
2014-12-13 22:06:14 +00:00
zend_delete_global_variable ( var_name ) ;
2002-05-09 20:02:47 +00:00
2014-05-03 08:06:27 +00:00
if ( ! Z_ISUNDEF ( PS ( http_session_vars ) ) ) {
2008-08-06 05:53:31 +00:00
zval_ptr_dtor ( & PS ( http_session_vars ) ) ;
}
2002-05-09 19:42:00 +00:00
2014-03-28 10:46:25 +00:00
array_init ( & session_vars ) ;
ZVAL_NEW_REF ( & PS ( http_session_vars ) , & session_vars ) ;
2014-04-15 11:40:40 +00:00
Z_ADDREF_P ( & PS ( http_session_vars ) ) ;
2015-02-13 19:20:39 +00:00
zend_hash_update_ind ( & EG ( symbol_table ) , var_name , & PS ( http_session_vars ) ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( var_name ) ;
2000-09-01 15:24:58 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
2000-09-01 15:24:58 +00:00
2014-12-13 22:06:14 +00:00
static zend_string * php_session_encode ( void ) /* { { { */
2000-09-01 15:24:58 +00:00
{
2008-08-06 05:53:31 +00:00
IF_SESSION_VARS ( ) {
if ( ! PS ( serializer ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Unknown session.serialize_handler. Failed to encode session object " ) ;
2014-03-26 15:23:54 +00:00
return NULL ;
2015-01-03 09:22:58 +00:00
}
2014-12-13 22:06:14 +00:00
return PS ( serializer ) - > encode ( ) ;
2008-08-06 05:53:31 +00:00
} else {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Cannot encode non-existent session " ) ;
2008-08-06 05:53:31 +00:00
}
2014-03-26 15:23:54 +00:00
return NULL ;
2008-08-06 05:53:31 +00:00
}
/* }}} */
2006-12-26 16:53:47 +00:00
2015-01-25 06:26:00 +00:00
static int php_session_decode ( zend_string * data ) /* { { { */
2008-08-06 05:53:31 +00:00
{
if ( ! PS ( serializer ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Unknown session.serialize_handler. Failed to decode session object " ) ;
2015-01-25 06:26:00 +00:00
return FAILURE ;
2008-08-06 05:53:31 +00:00
}
2015-06-30 01:05:24 +00:00
if ( PS ( serializer ) - > decode ( ZSTR_VAL ( data ) , ZSTR_LEN ( data ) ) = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_session_destroy ( ) ;
2015-09-01 19:40:10 +00:00
php_session_track_init ( ) ;
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Failed to decode session object. Session has been destroyed " ) ;
2015-01-25 06:26:00 +00:00
return FAILURE ;
2002-05-09 20:02:47 +00:00
}
2015-01-25 06:26:00 +00:00
return SUCCESS ;
2008-08-06 05:53:31 +00:00
}
/* }}} */
2002-05-09 20:02:47 +00:00
2008-08-06 05:53:31 +00:00
/*
* Note that we cannot use the BASE64 alphabet here , because
* it contains " / " and " + " : both are unacceptable for simple inclusion
* into URLs .
*/
2002-05-09 20:02:47 +00:00
2008-08-06 05:53:31 +00:00
static char hexconvtab [ ] = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,- " ;
2000-09-01 15:24:58 +00:00
2008-08-06 05:53:31 +00:00
enum {
PS_HASH_FUNC_MD5 ,
PS_HASH_FUNC_SHA1 ,
PS_HASH_FUNC_OTHER
} ;
2000-09-01 15:24:58 +00:00
2008-08-06 05:53:31 +00:00
/* returns a pointer to the byte after the last valid character in out */
static char * bin_to_readable ( char * in , size_t inlen , char * out , char nbits ) /* { { { */
1999-06-05 19:52:58 +00:00
{
2008-08-06 05:53:31 +00:00
unsigned char * p , * q ;
unsigned short w ;
int mask ;
int have ;
2002-05-09 20:02:47 +00:00
2014-03-26 15:23:54 +00:00
p = ( unsigned char * ) in ;
2008-08-06 05:53:31 +00:00
q = ( unsigned char * ) in + inlen ;
2003-01-16 07:21:49 +00:00
w = 0 ;
have = 0 ;
mask = ( 1 < < nbits ) - 1 ;
2008-08-06 05:53:31 +00:00
2003-01-16 07:21:49 +00:00
while ( 1 ) {
if ( have < nbits ) {
if ( p < q ) {
w | = * p + + < < have ;
have + = 8 ;
} else {
/* consumed everything? */
if ( have = = 0 ) break ;
/* No? We need a final round */
have = nbits ;
}
}
/* consume nbits */
* out + + = hexconvtab [ w & mask ] ;
w > > = nbits ;
have - = nbits ;
}
2008-08-06 05:53:31 +00:00
2003-01-16 07:21:49 +00:00
* out = ' \0 ' ;
return out ;
}
2008-08-06 05:53:31 +00:00
/* }}} */
2003-01-16 07:21:49 +00:00
2014-03-26 15:23:54 +00:00
PHPAPI zend_string * php_session_create_id ( PS_CREATE_SID_ARGS ) /* { { { */
1999-06-05 19:52:58 +00:00
{
2003-01-12 13:07:14 +00:00
PHP_MD5_CTX md5_context ;
PHP_SHA1_CTX sha1_context ;
2008-08-06 05:53:31 +00:00
# if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
2013-08-15 03:36:50 +00:00
void * hash_context = NULL ;
2008-08-06 05:53:31 +00:00
# endif
unsigned char * digest ;
2015-01-25 06:26:00 +00:00
size_t digest_len ;
2014-03-26 15:23:54 +00:00
char * buf ;
2002-05-09 20:02:47 +00:00
struct timeval tv ;
2014-03-26 15:23:54 +00:00
zval * array ;
zval * token ;
zend_string * outid ;
2003-01-12 13:07:14 +00:00
char * remote_addr = NULL ;
2002-05-09 20:02:47 +00:00
gettimeofday ( & tv , NULL ) ;
2008-08-06 05:53:31 +00:00
2015-02-13 19:20:39 +00:00
if ( ( array = zend_hash_str_find ( & EG ( symbol_table ) , " _SERVER " , sizeof ( " _SERVER " ) - 1 ) ) & &
2014-03-26 15:23:54 +00:00
Z_TYPE_P ( array ) = = IS_ARRAY & &
2014-08-04 09:56:27 +00:00
( token = zend_hash_str_find ( Z_ARRVAL_P ( array ) , " REMOTE_ADDR " , sizeof ( " REMOTE_ADDR " ) - 1 ) ) & &
Z_TYPE_P ( token ) = = IS_STRING
2009-05-18 16:10:09 +00:00
) {
2014-03-26 15:23:54 +00:00
remote_addr = Z_STRVAL_P ( token ) ;
2003-01-12 13:07:14 +00:00
}
2008-08-06 05:53:31 +00:00
/* maximum 15+19+19+10 bytes */
2014-12-13 22:06:14 +00:00
spprintf ( & buf , 0 , " %.15s%ld " ZEND_LONG_FMT " %0.8F " , remote_addr ? remote_addr : " " , tv . tv_sec , ( zend_long ) tv . tv_usec , php_combined_lcg ( ) * 10 ) ;
2003-01-12 13:07:14 +00:00
switch ( PS ( hash_func ) ) {
2008-08-06 05:53:31 +00:00
case PS_HASH_FUNC_MD5 :
PHP_MD5Init ( & md5_context ) ;
PHP_MD5Update ( & md5_context , ( unsigned char * ) buf , strlen ( buf ) ) ;
digest_len = 16 ;
break ;
case PS_HASH_FUNC_SHA1 :
PHP_SHA1Init ( & sha1_context ) ;
PHP_SHA1Update ( & sha1_context , ( unsigned char * ) buf , strlen ( buf ) ) ;
digest_len = 20 ;
break ;
# if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
case PS_HASH_FUNC_OTHER :
if ( ! PS ( hash_ops ) ) {
efree ( buf ) ;
2015-07-21 09:18:36 +00:00
php_error_docref ( NULL , E_ERROR , " Invalid session hash function " ) ;
2008-08-06 05:53:31 +00:00
return NULL ;
}
hash_context = emalloc ( PS ( hash_ops ) - > context_size ) ;
PS ( hash_ops ) - > hash_init ( hash_context ) ;
PS ( hash_ops ) - > hash_update ( hash_context , ( unsigned char * ) buf , strlen ( buf ) ) ;
digest_len = PS ( hash_ops ) - > digest_size ;
break ;
# endif /* HAVE_HASH_EXT */
default :
efree ( buf ) ;
2015-07-21 09:18:36 +00:00
php_error_docref ( NULL , E_ERROR , " Invalid session hash function " ) ;
2008-08-06 05:53:31 +00:00
return NULL ;
2003-01-12 13:07:14 +00:00
}
2009-07-17 14:21:59 +00:00
efree ( buf ) ;
2002-05-09 20:02:47 +00:00
if ( PS ( entropy_length ) > 0 ) {
2010-06-08 13:46:19 +00:00
# ifdef PHP_WIN32
2010-08-27 19:43:08 +00:00
unsigned char rbuf [ 2048 ] ;
2010-06-08 13:46:19 +00:00
size_t toread = PS ( entropy_length ) ;
2010-06-08 22:30:16 +00:00
2013-08-10 21:43:01 +00:00
if ( php_win32_get_random_bytes ( rbuf , MIN ( toread , sizeof ( rbuf ) ) ) = = SUCCESS ) {
2010-06-08 13:46:19 +00:00
switch ( PS ( hash_func ) ) {
case PS_HASH_FUNC_MD5 :
PHP_MD5Update ( & md5_context , rbuf , toread ) ;
break ;
case PS_HASH_FUNC_SHA1 :
PHP_SHA1Update ( & sha1_context , rbuf , toread ) ;
break ;
# if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
case PS_HASH_FUNC_OTHER :
PS ( hash_ops ) - > hash_update ( hash_context , rbuf , toread ) ;
break ;
# endif /* HAVE_HASH_EXT */
}
}
# else
2002-05-09 20:02:47 +00:00
int fd ;
fd = VCWD_OPEN ( PS ( entropy_file ) , O_RDONLY ) ;
if ( fd > = 0 ) {
2003-01-12 13:07:14 +00:00
unsigned char rbuf [ 2048 ] ;
2002-05-09 20:02:47 +00:00
int n ;
int to_read = PS ( entropy_length ) ;
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
while ( to_read > 0 ) {
2003-01-12 13:07:14 +00:00
n = read ( fd , rbuf , MIN ( to_read , sizeof ( rbuf ) ) ) ;
2002-05-09 20:02:47 +00:00
if ( n < = 0 ) break ;
2008-08-06 05:53:31 +00:00
2003-01-12 13:07:14 +00:00
switch ( PS ( hash_func ) ) {
2008-08-06 05:53:31 +00:00
case PS_HASH_FUNC_MD5 :
PHP_MD5Update ( & md5_context , rbuf , n ) ;
break ;
case PS_HASH_FUNC_SHA1 :
PHP_SHA1Update ( & sha1_context , rbuf , n ) ;
break ;
# if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
case PS_HASH_FUNC_OTHER :
PS ( hash_ops ) - > hash_update ( hash_context , rbuf , n ) ;
break ;
# endif /* HAVE_HASH_EXT */
2003-01-12 13:07:14 +00:00
}
2002-05-09 20:02:47 +00:00
to_read - = n ;
}
close ( fd ) ;
}
2010-06-08 13:46:19 +00:00
# endif
2002-05-09 20:02:47 +00:00
}
1999-06-05 19:52:58 +00:00
2008-08-06 05:53:31 +00:00
digest = emalloc ( digest_len + 1 ) ;
2003-01-12 13:07:14 +00:00
switch ( PS ( hash_func ) ) {
2008-08-06 05:53:31 +00:00
case PS_HASH_FUNC_MD5 :
PHP_MD5Final ( digest , & md5_context ) ;
break ;
case PS_HASH_FUNC_SHA1 :
PHP_SHA1Final ( digest , & sha1_context ) ;
break ;
# if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
case PS_HASH_FUNC_OTHER :
PS ( hash_ops ) - > hash_final ( digest , hash_context ) ;
efree ( hash_context ) ;
break ;
# endif /* HAVE_HASH_EXT */
2003-01-12 13:07:14 +00:00
}
2003-01-16 07:21:49 +00:00
if ( PS ( hash_bits_per_character ) < 4
| | PS ( hash_bits_per_character ) > 6 ) {
PS ( hash_bits_per_character ) = 4 ;
2003-01-12 13:07:14 +00:00
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " The ini setting hash_bits_per_character is out of range (should be 4, 5, or 6) - using 4 for now " ) ;
2002-05-09 20:02:47 +00:00
}
2015-01-03 09:22:58 +00:00
2014-08-25 17:24:55 +00:00
outid = zend_string_alloc ( ( digest_len + 2 ) * ( ( 8.0f / PS ( hash_bits_per_character ) + 0.5 ) ) , 0 ) ;
2015-06-30 01:05:24 +00:00
ZSTR_LEN ( outid ) = ( size_t ) ( bin_to_readable ( ( char * ) digest , digest_len , ZSTR_VAL ( outid ) , ( char ) PS ( hash_bits_per_character ) ) - ( char * ) & ZSTR_VAL ( outid ) ) ;
2008-08-06 05:53:31 +00:00
efree ( digest ) ;
2009-07-17 14:21:59 +00:00
return outid ;
2002-05-09 20:02:47 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
2002-05-09 19:42:00 +00:00
2013-06-25 10:47:04 +00:00
/* Default session id char validation function allowed by ps_modules.
* If you change the logic here , please also update the error message in
* ps_modules appropriately */
PHPAPI int php_session_valid_key ( const char * key ) /* { { { */
1999-06-05 19:52:58 +00:00
{
2013-06-25 10:47:04 +00:00
size_t len ;
const char * p ;
char c ;
int ret = SUCCESS ;
for ( p = key ; ( c = * p ) ; p + + ) {
/* valid characters are a..z,A..Z,0..9 */
if ( ! ( ( c > = ' a ' & & c < = ' z ' )
| | ( c > = ' A ' & & c < = ' Z ' )
| | ( c > = ' 0 ' & & c < = ' 9 ' )
| | c = = ' , '
| | c = = ' - ' ) ) {
ret = FAILURE ;
break ;
}
}
2002-05-09 20:02:47 +00:00
2013-06-25 10:47:04 +00:00
len = p - key ;
/* Somewhat arbitrary length limit here, but should be way more than
anyone needs and avoids file - level warnings later on if we exceed MAX_PATH */
if ( len = = 0 | | len > 128 ) {
ret = FAILURE ;
2006-01-15 16:51:18 +00:00
}
2013-06-25 10:47:04 +00:00
return ret ;
}
/* }}} */
2015-12-16 00:11:44 +00:00
static void php_session_gc ( void ) /* { { { */
{
int nrand ;
/* GC must be done before reading session data. */
if ( ( PS ( mod_data ) | | PS ( mod_user_implemented ) ) & & PS ( gc_probability ) > 0 ) {
int nrdels = - 1 ;
2015-12-16 00:34:41 +00:00
nrand = ( int ) ( ( float ) PS ( gc_divisor ) * php_combined_lcg ( ) ) ;
2015-12-16 00:11:44 +00:00
if ( nrand < PS ( gc_probability ) ) {
2015-12-16 00:34:41 +00:00
PS ( mod ) - > s_gc ( & PS ( mod_data ) , PS ( gc_maxlifetime ) , & nrdels ) ;
2015-12-16 00:11:44 +00:00
# ifdef SESSION_DEBUG
if ( nrdels ! = - 1 ) {
2015-12-16 00:34:41 +00:00
php_error_docref ( NULL , E_NOTICE , " purged %d expired session objects " , nrdels ) ;
2015-12-16 00:11:44 +00:00
}
# endif
}
}
} /* }}} */
2014-12-13 22:06:14 +00:00
static void php_session_initialize ( void ) /* { { { */
2013-06-25 10:47:04 +00:00
{
2014-03-28 10:46:25 +00:00
zend_string * val = NULL ;
2013-06-25 10:47:04 +00:00
2016-01-12 10:08:17 +00:00
PS ( session_status ) = php_session_active ;
2002-09-29 18:33:14 +00:00
if ( ! PS ( mod ) ) {
2016-01-12 10:08:17 +00:00
PS ( session_status ) = php_session_disabled ;
2015-07-21 09:18:36 +00:00
php_error_docref ( NULL , E_ERROR , " No storage module chosen - failed to initialize session " ) ;
2002-09-29 18:33:14 +00:00
return ;
}
2002-05-09 20:02:47 +00:00
/* Open session handler first */
2015-01-21 10:13:59 +00:00
if ( PS ( mod ) - > s_open ( & PS ( mod_data ) , PS ( save_path ) , PS ( session_name ) ) = = FAILURE
/* || PS(mod_data) == NULL */ /* FIXME: open must set valid PS(mod_data) with success */
) {
2016-01-12 10:52:54 +00:00
php_session_abort ( ) ;
2015-07-21 09:18:36 +00:00
php_error_docref ( NULL , E_ERROR , " Failed to initialize storage module: %s (path: %s) " , PS ( mod ) - > s_name , PS ( save_path ) ) ;
2002-05-09 20:02:47 +00:00
return ;
}
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
/* If there is no ID, use session module to create one */
2006-07-27 14:00:13 +00:00
if ( ! PS ( id ) ) {
2014-12-13 22:06:14 +00:00
PS ( id ) = PS ( mod ) - > s_create_sid ( & PS ( mod_data ) ) ;
2013-06-25 10:47:04 +00:00
if ( ! PS ( id ) ) {
2016-01-12 10:52:54 +00:00
php_session_abort ( ) ;
2015-07-21 09:18:36 +00:00
php_error_docref ( NULL , E_ERROR , " Failed to create session ID: %s (path: %s) " , PS ( mod ) - > s_name , PS ( save_path ) ) ;
2013-06-25 10:47:04 +00:00
return ;
}
2006-07-27 14:00:13 +00:00
if ( PS ( use_cookies ) ) {
PS ( send_cookie ) = 1 ;
}
2015-01-21 10:13:59 +00:00
} else if ( PS ( use_strict_mode ) & & PS ( mod ) - > s_validate_sid & &
PS ( mod ) - > s_validate_sid ( & PS ( mod_data ) , PS ( id ) ) = = FAILURE ) {
if ( PS ( id ) ) {
zend_string_release ( PS ( id ) ) ;
}
PS ( id ) = PS ( mod ) - > s_create_sid ( & PS ( mod_data ) ) ;
if ( ! PS ( id ) ) {
PS ( id ) = php_session_create_id ( NULL ) ;
}
if ( PS ( use_cookies ) ) {
PS ( send_cookie ) = 1 ;
}
2006-07-27 14:00:13 +00:00
}
2015-01-25 21:14:40 +00:00
2015-01-28 07:01:10 +00:00
php_session_reset_id ( ) ;
2013-06-25 10:47:04 +00:00
2015-12-16 00:11:44 +00:00
/* GC must be done before read */
php_session_gc ( ) ;
2002-05-09 20:02:47 +00:00
/* Read data */
2014-12-13 22:06:14 +00:00
php_session_track_init ( ) ;
2015-02-12 03:32:36 +00:00
if ( PS ( mod ) - > s_read ( & PS ( mod_data ) , PS ( id ) , & val , PS ( gc_maxlifetime ) ) = = FAILURE ) {
2016-01-12 10:52:54 +00:00
php_session_abort ( ) ;
2013-06-25 10:47:04 +00:00
/* Some broken save handler implementation returns FAILURE for non-existent session ID */
2014-01-15 02:03:07 +00:00
/* It's better to raise error for this, but disabled error for better compatibility */
2016-01-12 10:52:54 +00:00
php_error_docref ( NULL , E_WARNING , " Failed to read session data: %s (path: %s) " , PS ( mod ) - > s_name , PS ( save_path ) ) ;
return ;
2013-06-25 10:47:04 +00:00
}
2015-01-21 10:13:59 +00:00
if ( PS ( session_vars ) ) {
zend_string_release ( PS ( session_vars ) ) ;
PS ( session_vars ) = NULL ;
}
2013-06-25 10:47:04 +00:00
if ( val ) {
2015-01-21 10:13:59 +00:00
if ( PS ( lazy_write ) ) {
PS ( session_vars ) = zend_string_copy ( val ) ;
}
php_session_decode ( val ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( val ) ;
2013-06-25 10:47:04 +00:00
}
1999-06-05 19:52:58 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-06-05 19:52:58 +00:00
2015-01-28 05:22:22 +00:00
static void php_session_save_current_state ( int write ) /* { { { */
2002-10-03 03:23:02 +00:00
{
int ret = FAILURE ;
2008-08-06 05:53:31 +00:00
2015-01-28 05:22:22 +00:00
if ( write ) {
IF_SESSION_VARS ( ) {
if ( PS ( mod_data ) | | PS ( mod_user_implemented ) ) {
zend_string * val ;
val = php_session_encode ( ) ;
if ( val ) {
if ( PS ( lazy_write ) & & PS ( session_vars )
& & PS ( mod ) - > s_update_timestamp
& & PS ( mod ) - > s_update_timestamp ! = php_session_update_timestamp
2015-06-30 01:05:24 +00:00
& & ZSTR_LEN ( val ) = = ZSTR_LEN ( PS ( session_vars ) )
& & ! memcmp ( ZSTR_VAL ( val ) , ZSTR_VAL ( PS ( session_vars ) ) , ZSTR_LEN ( val ) )
2015-01-28 05:22:22 +00:00
) {
2015-02-12 03:32:36 +00:00
ret = PS ( mod ) - > s_update_timestamp ( & PS ( mod_data ) , PS ( id ) , val , PS ( gc_maxlifetime ) ) ;
2015-01-28 05:22:22 +00:00
} else {
2015-02-12 03:32:36 +00:00
ret = PS ( mod ) - > s_write ( & PS ( mod_data ) , PS ( id ) , val , PS ( gc_maxlifetime ) ) ;
2015-01-28 05:22:22 +00:00
}
zend_string_release ( val ) ;
2015-01-21 10:13:59 +00:00
} else {
2015-06-29 13:44:54 +00:00
ret = PS ( mod ) - > s_write ( & PS ( mod_data ) , PS ( id ) , ZSTR_EMPTY_ALLOC ( ) , PS ( gc_maxlifetime ) ) ;
2015-01-21 10:13:59 +00:00
}
2008-08-06 05:53:31 +00:00
}
2015-01-28 05:22:22 +00:00
if ( ( ret = = FAILURE ) & & ! EG ( exception ) ) {
php_error_docref ( NULL , E_WARNING , " Failed to write session data (%s). Please "
" verify that the current setting of session.save_path "
" is correct (%s) " ,
PS ( mod ) - > s_name ,
PS ( save_path ) ) ;
}
2008-08-06 05:53:31 +00:00
}
}
2011-09-13 22:28:15 +00:00
if ( PS ( mod_data ) | | PS ( mod_user_implemented ) ) {
2014-12-13 22:06:14 +00:00
PS ( mod ) - > s_close ( & PS ( mod_data ) ) ;
2008-08-06 05:53:31 +00:00
}
}
/* }}} */
/* *************************
* INI Settings / Handlers *
* * * * * * * * * * * * * * * * * * * * * * * * * */
static PHP_INI_MH ( OnUpdateSaveHandler ) /* { { { */
{
ps_module * tmp ;
SESSION_CHECK_ACTIVE_STATE ;
2015-06-30 01:05:24 +00:00
tmp = _php_find_ps_module ( ZSTR_VAL ( new_value ) ) ;
2008-08-06 05:53:31 +00:00
if ( PG ( modules_activated ) & & ! tmp ) {
int err_type ;
if ( stage = = ZEND_INI_STAGE_RUNTIME ) {
2015-07-21 09:18:36 +00:00
err_type = E_WARNING ;
2008-08-06 05:53:31 +00:00
} else {
err_type = E_ERROR ;
}
2009-05-18 16:10:09 +00:00
/* Do not output error when restoring ini options. */
2008-08-06 05:53:31 +00:00
if ( stage ! = ZEND_INI_STAGE_DEACTIVATE ) {
2015-06-30 01:05:24 +00:00
php_error_docref ( NULL , err_type , " Cannot find save handler '%s' " , ZSTR_VAL ( new_value ) ) ;
2008-08-06 05:53:31 +00:00
}
return FAILURE ;
}
2011-09-13 22:28:15 +00:00
PS ( default_mod ) = PS ( mod ) ;
2008-08-06 05:53:31 +00:00
PS ( mod ) = tmp ;
return SUCCESS ;
}
/* }}} */
static PHP_INI_MH ( OnUpdateSerializer ) /* { { { */
{
const ps_serializer * tmp ;
SESSION_CHECK_ACTIVE_STATE ;
2015-06-30 01:05:24 +00:00
tmp = _php_find_ps_serializer ( ZSTR_VAL ( new_value ) ) ;
2008-08-06 05:53:31 +00:00
if ( PG ( modules_activated ) & & ! tmp ) {
int err_type ;
if ( stage = = ZEND_INI_STAGE_RUNTIME ) {
2015-07-21 09:18:36 +00:00
err_type = E_WARNING ;
2008-08-06 05:53:31 +00:00
} else {
err_type = E_ERROR ;
}
2009-05-18 16:10:09 +00:00
/* Do not output error when restoring ini options. */
2008-08-06 05:53:31 +00:00
if ( stage ! = ZEND_INI_STAGE_DEACTIVATE ) {
2015-06-30 01:05:24 +00:00
php_error_docref ( NULL , err_type , " Cannot find serialization handler '%s' " , ZSTR_VAL ( new_value ) ) ;
2008-08-06 05:53:31 +00:00
}
return FAILURE ;
}
PS ( serializer ) = tmp ;
return SUCCESS ;
}
/* }}} */
static PHP_INI_MH ( OnUpdateTransSid ) /* { { { */
{
SESSION_CHECK_ACTIVE_STATE ;
2015-06-30 01:05:24 +00:00
if ( ! strncasecmp ( ZSTR_VAL ( new_value ) , " on " , sizeof ( " on " ) ) ) {
2008-08-06 05:53:31 +00:00
PS ( use_trans_sid ) = ( zend_bool ) 1 ;
} else {
2015-06-30 01:05:24 +00:00
PS ( use_trans_sid ) = ( zend_bool ) atoi ( ZSTR_VAL ( new_value ) ) ;
2008-08-06 05:53:31 +00:00
}
return SUCCESS ;
}
/* }}} */
static PHP_INI_MH ( OnUpdateSaveDir ) /* { { { */
{
/* Only do the safemode/open_basedir check at runtime */
if ( stage = = PHP_INI_STAGE_RUNTIME | | stage = = PHP_INI_STAGE_HTACCESS ) {
char * p ;
2015-06-30 01:05:24 +00:00
if ( memchr ( ZSTR_VAL ( new_value ) , ' \0 ' , ZSTR_LEN ( new_value ) ) ! = NULL ) {
2008-08-06 05:53:31 +00:00
return FAILURE ;
}
2010-01-31 18:06:29 +00:00
/* we do not use zend_memrchr() since path can contain ; itself */
2015-06-30 01:05:24 +00:00
if ( ( p = strchr ( ZSTR_VAL ( new_value ) , ' ; ' ) ) ) {
2010-01-31 18:06:29 +00:00
char * p2 ;
2008-08-06 05:53:31 +00:00
p + + ;
2010-01-31 18:06:29 +00:00
if ( ( p2 = strchr ( p , ' ; ' ) ) ) {
p = p2 + 1 ;
}
2008-08-06 05:53:31 +00:00
} else {
2015-06-30 01:05:24 +00:00
p = ZSTR_VAL ( new_value ) ;
2008-08-06 05:53:31 +00:00
}
2014-12-13 22:06:14 +00:00
if ( PG ( open_basedir ) & & * p & & php_check_open_basedir ( p ) ) {
2008-08-06 05:53:31 +00:00
return FAILURE ;
}
}
2009-05-18 16:10:09 +00:00
2014-12-13 22:06:14 +00:00
OnUpdateString ( entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage ) ;
2008-08-06 05:53:31 +00:00
return SUCCESS ;
}
/* }}} */
2013-06-28 23:07:44 +00:00
static PHP_INI_MH ( OnUpdateName ) /* { { { */
{
/* Numeric session.name won't work at all */
2015-06-30 01:05:24 +00:00
if ( ( ! ZSTR_LEN ( new_value ) | | is_numeric_string ( ZSTR_VAL ( new_value ) , ZSTR_LEN ( new_value ) , NULL , NULL , 0 ) ) ) {
2013-06-28 23:07:44 +00:00
int err_type ;
2014-01-16 06:41:12 +00:00
if ( stage = = ZEND_INI_STAGE_RUNTIME | | stage = = ZEND_INI_STAGE_ACTIVATE | | stage = = ZEND_INI_STAGE_STARTUP ) {
2015-07-21 09:18:36 +00:00
err_type = E_WARNING ;
2013-06-28 23:07:44 +00:00
} else {
err_type = E_ERROR ;
}
/* Do not output error when restoring ini options. */
if ( stage ! = ZEND_INI_STAGE_DEACTIVATE ) {
2015-06-30 01:05:24 +00:00
php_error_docref ( NULL , err_type , " session.name cannot be a numeric or empty '%s' " , ZSTR_VAL ( new_value ) ) ;
2013-06-28 23:07:44 +00:00
}
return FAILURE ;
}
2014-12-13 22:06:14 +00:00
OnUpdateStringUnempty ( entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage ) ;
2013-06-28 23:07:44 +00:00
return SUCCESS ;
}
/* }}} */
2008-08-06 05:53:31 +00:00
static PHP_INI_MH ( OnUpdateHashFunc ) /* { { { */
{
2014-08-25 17:24:55 +00:00
zend_long val ;
2008-08-06 05:53:31 +00:00
char * endptr = NULL ;
# if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
PS ( hash_ops ) = NULL ;
# endif
2015-06-30 01:05:24 +00:00
val = ZEND_STRTOL ( ZSTR_VAL ( new_value ) , & endptr , 10 ) ;
2008-08-06 05:53:31 +00:00
if ( endptr & & ( * endptr = = ' \0 ' ) ) {
/* Numeric value */
PS ( hash_func ) = val ? 1 : 0 ;
return SUCCESS ;
}
2015-06-30 01:05:24 +00:00
if ( ZSTR_LEN ( new_value ) = = ( sizeof ( " md5 " ) - 1 ) & &
strncasecmp ( ZSTR_VAL ( new_value ) , " md5 " , sizeof ( " md5 " ) - 1 ) = = 0 ) {
2008-08-06 05:53:31 +00:00
PS ( hash_func ) = PS_HASH_FUNC_MD5 ;
return SUCCESS ;
}
2015-06-30 01:05:24 +00:00
if ( ZSTR_LEN ( new_value ) = = ( sizeof ( " sha1 " ) - 1 ) & &
strncasecmp ( ZSTR_VAL ( new_value ) , " sha1 " , sizeof ( " sha1 " ) - 1 ) = = 0 ) {
2008-08-06 05:53:31 +00:00
PS ( hash_func ) = PS_HASH_FUNC_SHA1 ;
return SUCCESS ;
}
# if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) /* {{{ */
{
2015-06-30 01:05:24 +00:00
php_hash_ops * ops = ( php_hash_ops * ) php_hash_fetch_ops ( ZSTR_VAL ( new_value ) , ZSTR_LEN ( new_value ) ) ;
2008-08-06 05:53:31 +00:00
if ( ops ) {
PS ( hash_func ) = PS_HASH_FUNC_OTHER ;
PS ( hash_ops ) = ops ;
return SUCCESS ;
}
}
2009-04-06 11:45:25 +00:00
# endif /* HAVE_HASH_EXT }}} */
2008-08-06 05:53:31 +00:00
2015-06-30 01:05:24 +00:00
php_error_docref ( NULL , E_WARNING , " session.configuration 'session.hash_function' must be existing hash function. %s does not exist. " , ZSTR_VAL ( new_value ) ) ;
2008-08-06 05:53:31 +00:00
return FAILURE ;
}
/* }}} */
2010-05-10 16:09:00 +00:00
static PHP_INI_MH ( OnUpdateRfc1867Freq ) /* { { { */
{
2015-03-24 20:24:49 +00:00
int tmp ;
2015-06-30 01:05:24 +00:00
tmp = zend_atoi ( ZSTR_VAL ( new_value ) , ( int ) ZSTR_LEN ( new_value ) ) ;
2010-05-10 16:09:00 +00:00
if ( tmp < 0 ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " session.upload_progress.freq must be greater than or equal to zero " ) ;
2010-05-10 16:09:00 +00:00
return FAILURE ;
}
2015-06-30 01:05:24 +00:00
if ( ZSTR_LEN ( new_value ) > 0 & & ZSTR_VAL ( new_value ) [ ZSTR_LEN ( new_value ) - 1 ] = = ' % ' ) {
2010-05-10 16:09:00 +00:00
if ( tmp > 100 ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " session.upload_progress.freq cannot be over 100%% " ) ;
2010-05-10 16:09:00 +00:00
return FAILURE ;
}
PS ( rfc1867_freq ) = - tmp ;
} else {
PS ( rfc1867_freq ) = tmp ;
}
return SUCCESS ;
} /* }}} */
2008-08-06 05:53:31 +00:00
/* {{{ PHP_INI
*/
PHP_INI_BEGIN ( )
STD_PHP_INI_ENTRY ( " session.save_path " , " " , PHP_INI_ALL , OnUpdateSaveDir , save_path , php_ps_globals , ps_globals )
2013-06-28 23:07:44 +00:00
STD_PHP_INI_ENTRY ( " session.name " , " PHPSESSID " , PHP_INI_ALL , OnUpdateName , session_name , php_ps_globals , ps_globals )
2008-08-06 05:53:31 +00:00
PHP_INI_ENTRY ( " session.save_handler " , " files " , PHP_INI_ALL , OnUpdateSaveHandler )
2013-08-10 09:29:13 +00:00
STD_PHP_INI_BOOLEAN ( " session.auto_start " , " 0 " , PHP_INI_PERDIR , OnUpdateBool , auto_start , php_ps_globals , ps_globals )
2008-08-06 05:53:31 +00:00
STD_PHP_INI_ENTRY ( " session.gc_probability " , " 1 " , PHP_INI_ALL , OnUpdateLong , gc_probability , php_ps_globals , ps_globals )
STD_PHP_INI_ENTRY ( " session.gc_divisor " , " 100 " , PHP_INI_ALL , OnUpdateLong , gc_divisor , php_ps_globals , ps_globals )
STD_PHP_INI_ENTRY ( " session.gc_maxlifetime " , " 1440 " , PHP_INI_ALL , OnUpdateLong , gc_maxlifetime , php_ps_globals , ps_globals )
PHP_INI_ENTRY ( " session.serialize_handler " , " php " , PHP_INI_ALL , OnUpdateSerializer )
STD_PHP_INI_ENTRY ( " session.cookie_lifetime " , " 0 " , PHP_INI_ALL , OnUpdateLong , cookie_lifetime , php_ps_globals , ps_globals )
STD_PHP_INI_ENTRY ( " session.cookie_path " , " / " , PHP_INI_ALL , OnUpdateString , cookie_path , php_ps_globals , ps_globals )
STD_PHP_INI_ENTRY ( " session.cookie_domain " , " " , PHP_INI_ALL , OnUpdateString , cookie_domain , php_ps_globals , ps_globals )
STD_PHP_INI_BOOLEAN ( " session.cookie_secure " , " " , PHP_INI_ALL , OnUpdateBool , cookie_secure , php_ps_globals , ps_globals )
STD_PHP_INI_BOOLEAN ( " session.cookie_httponly " , " " , PHP_INI_ALL , OnUpdateBool , cookie_httponly , php_ps_globals , ps_globals )
STD_PHP_INI_BOOLEAN ( " session.use_cookies " , " 1 " , PHP_INI_ALL , OnUpdateBool , use_cookies , php_ps_globals , ps_globals )
STD_PHP_INI_BOOLEAN ( " session.use_only_cookies " , " 1 " , PHP_INI_ALL , OnUpdateBool , use_only_cookies , php_ps_globals , ps_globals )
2013-06-25 10:47:04 +00:00
STD_PHP_INI_BOOLEAN ( " session.use_strict_mode " , " 0 " , PHP_INI_ALL , OnUpdateBool , use_strict_mode , php_ps_globals , ps_globals )
2008-08-06 05:53:31 +00:00
STD_PHP_INI_ENTRY ( " session.referer_check " , " " , PHP_INI_ALL , OnUpdateString , extern_referer_chk , php_ps_globals , ps_globals )
2010-03-31 18:03:17 +00:00
# if HAVE_DEV_URANDOM
STD_PHP_INI_ENTRY ( " session.entropy_file " , " /dev/urandom " , PHP_INI_ALL , OnUpdateString , entropy_file , php_ps_globals , ps_globals )
STD_PHP_INI_ENTRY ( " session.entropy_length " , " 32 " , PHP_INI_ALL , OnUpdateLong , entropy_length , php_ps_globals , ps_globals )
# elif HAVE_DEV_ARANDOM
STD_PHP_INI_ENTRY ( " session.entropy_file " , " /dev/arandom " , PHP_INI_ALL , OnUpdateString , entropy_file , php_ps_globals , ps_globals )
STD_PHP_INI_ENTRY ( " session.entropy_length " , " 32 " , PHP_INI_ALL , OnUpdateLong , entropy_length , php_ps_globals , ps_globals )
# else
2008-08-06 05:53:31 +00:00
STD_PHP_INI_ENTRY ( " session.entropy_file " , " " , PHP_INI_ALL , OnUpdateString , entropy_file , php_ps_globals , ps_globals )
STD_PHP_INI_ENTRY ( " session.entropy_length " , " 0 " , PHP_INI_ALL , OnUpdateLong , entropy_length , php_ps_globals , ps_globals )
2010-03-31 18:03:17 +00:00
# endif
2008-08-06 05:53:31 +00:00
STD_PHP_INI_ENTRY ( " session.cache_limiter " , " nocache " , PHP_INI_ALL , OnUpdateString , cache_limiter , php_ps_globals , ps_globals )
STD_PHP_INI_ENTRY ( " session.cache_expire " , " 180 " , PHP_INI_ALL , OnUpdateLong , cache_expire , php_ps_globals , ps_globals )
PHP_INI_ENTRY ( " session.use_trans_sid " , " 0 " , PHP_INI_ALL , OnUpdateTransSid )
PHP_INI_ENTRY ( " session.hash_function " , " 0 " , PHP_INI_ALL , OnUpdateHashFunc )
STD_PHP_INI_ENTRY ( " session.hash_bits_per_character " , " 4 " , PHP_INI_ALL , OnUpdateLong , hash_bits_per_character , php_ps_globals , ps_globals )
2015-01-21 10:13:59 +00:00
STD_PHP_INI_BOOLEAN ( " session.lazy_write " , " 1 " , PHP_INI_ALL , OnUpdateBool , lazy_write , php_ps_globals , ps_globals )
2008-08-06 05:53:31 +00:00
2010-05-10 16:09:00 +00:00
/* Upload progress */
STD_PHP_INI_BOOLEAN ( " session.upload_progress.enabled " ,
" 1 " , ZEND_INI_PERDIR , OnUpdateBool , rfc1867_enabled , php_ps_globals , ps_globals )
2010-05-11 16:39:07 +00:00
STD_PHP_INI_BOOLEAN ( " session.upload_progress.cleanup " ,
" 1 " , ZEND_INI_PERDIR , OnUpdateBool , rfc1867_cleanup , php_ps_globals , ps_globals )
2010-05-10 16:09:00 +00:00
STD_PHP_INI_ENTRY ( " session.upload_progress.prefix " ,
2014-03-29 09:39:26 +00:00
" upload_progress_ " , ZEND_INI_PERDIR , OnUpdateString , rfc1867_prefix , php_ps_globals , ps_globals )
2010-05-10 16:09:00 +00:00
STD_PHP_INI_ENTRY ( " session.upload_progress.name " ,
2014-03-29 09:39:26 +00:00
" PHP_SESSION_UPLOAD_PROGRESS " , ZEND_INI_PERDIR , OnUpdateString , rfc1867_name , php_ps_globals , ps_globals )
2010-05-10 16:09:00 +00:00
STD_PHP_INI_ENTRY ( " session.upload_progress.freq " , " 1% " , ZEND_INI_PERDIR , OnUpdateRfc1867Freq , rfc1867_freq , php_ps_globals , ps_globals )
STD_PHP_INI_ENTRY ( " session.upload_progress.min_freq " ,
" 1 " , ZEND_INI_PERDIR , OnUpdateReal , rfc1867_min_freq , php_ps_globals , ps_globals )
2008-08-06 05:53:31 +00:00
/* Commented out until future discussion */
/* PHP_INI_ENTRY("session.encode_sources", "globals,track", PHP_INI_ALL, NULL) */
PHP_INI_END ( )
/* }}} */
/* ***************
* Serializers *
* * * * * * * * * * * * * * * */
2013-08-21 01:51:51 +00:00
PS_SERIALIZER_ENCODE_FUNC ( php_serialize ) /* {{{ */
{
smart_str buf = { 0 } ;
php_serialize_data_t var_hash ;
2015-01-21 10:13:59 +00:00
IF_SESSION_VARS ( ) {
PHP_VAR_SERIALIZE_INIT ( var_hash ) ;
php_var_serialize ( & buf , Z_REFVAL ( PS ( http_session_vars ) ) , & var_hash ) ;
PHP_VAR_SERIALIZE_DESTROY ( var_hash ) ;
}
2014-03-26 15:23:54 +00:00
return buf . s ;
2013-08-21 01:51:51 +00:00
}
/* }}} */
PS_SERIALIZER_DECODE_FUNC ( php_serialize ) /* {{{ */
{
const char * endptr = val + vallen ;
2014-03-26 15:23:54 +00:00
zval session_vars ;
2013-08-21 01:51:51 +00:00
php_unserialize_data_t var_hash ;
2014-08-25 17:24:55 +00:00
zend_string * var_name = zend_string_init ( " _SESSION " , sizeof ( " _SESSION " ) - 1 , 0 ) ;
2013-08-21 01:51:51 +00:00
2014-03-28 10:46:25 +00:00
ZVAL_NULL ( & session_vars ) ;
2013-08-21 01:51:51 +00:00
PHP_VAR_UNSERIALIZE_INIT ( var_hash ) ;
2015-01-21 10:13:59 +00:00
php_var_unserialize ( & session_vars , ( const unsigned char * * ) & val , ( const unsigned char * ) endptr , & var_hash ) ;
2013-08-21 01:51:51 +00:00
PHP_VAR_UNSERIALIZE_DESTROY ( var_hash ) ;
2014-05-03 08:06:27 +00:00
if ( ! Z_ISUNDEF ( PS ( http_session_vars ) ) ) {
2013-08-21 01:51:51 +00:00
zval_ptr_dtor ( & PS ( http_session_vars ) ) ;
}
2014-03-26 15:23:54 +00:00
if ( Z_TYPE ( session_vars ) = = IS_NULL ) {
2014-03-28 10:46:25 +00:00
array_init ( & session_vars ) ;
2015-01-03 09:22:58 +00:00
}
2014-03-28 10:46:25 +00:00
ZVAL_NEW_REF ( & PS ( http_session_vars ) , & session_vars ) ;
2014-04-15 11:40:40 +00:00
Z_ADDREF_P ( & PS ( http_session_vars ) ) ;
2015-02-13 19:20:39 +00:00
zend_hash_update_ind ( & EG ( symbol_table ) , var_name , & PS ( http_session_vars ) ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( var_name ) ;
2013-08-21 01:51:51 +00:00
return SUCCESS ;
}
/* }}} */
2008-08-06 05:53:31 +00:00
# define PS_BIN_NR_OF_BITS 8
# define PS_BIN_UNDEF (1<<(PS_BIN_NR_OF_BITS-1))
# define PS_BIN_MAX (PS_BIN_UNDEF-1)
PS_SERIALIZER_ENCODE_FUNC ( php_binary ) /* {{{ */
{
smart_str buf = { 0 } ;
php_serialize_data_t var_hash ;
PS_ENCODE_VARS ;
PHP_VAR_SERIALIZE_INIT ( var_hash ) ;
PS_ENCODE_LOOP (
2015-06-30 01:05:24 +00:00
if ( ZSTR_LEN ( key ) > PS_BIN_MAX ) continue ;
smart_str_appendc ( & buf , ( unsigned char ) ZSTR_LEN ( key ) ) ;
smart_str_appendl ( & buf , ZSTR_VAL ( key ) , ZSTR_LEN ( key ) ) ;
2014-12-13 22:06:14 +00:00
php_var_serialize ( & buf , struc , & var_hash ) ;
2008-08-06 05:53:31 +00:00
} else {
2015-06-30 01:05:24 +00:00
if ( ZSTR_LEN ( key ) > PS_BIN_MAX ) continue ;
smart_str_appendc ( & buf , ( unsigned char ) ( ZSTR_LEN ( key ) & PS_BIN_UNDEF ) ) ;
smart_str_appendl ( & buf , ZSTR_VAL ( key ) , ZSTR_LEN ( key ) ) ;
2008-08-06 05:53:31 +00:00
) ;
smart_str_0 ( & buf ) ;
PHP_VAR_SERIALIZE_DESTROY ( var_hash ) ;
2014-03-26 15:23:54 +00:00
return buf . s ;
2008-08-06 05:53:31 +00:00
}
/* }}} */
PS_SERIALIZER_DECODE_FUNC ( php_binary ) /* {{{ */
{
const char * p ;
const char * endptr = val + vallen ;
2014-03-26 15:23:54 +00:00
zval current ;
2008-08-06 05:53:31 +00:00
int has_value ;
2014-03-28 10:46:25 +00:00
int namelen ;
zend_string * name ;
2008-08-06 05:53:31 +00:00
php_unserialize_data_t var_hash ;
PHP_VAR_UNSERIALIZE_INIT ( var_hash ) ;
for ( p = val ; p < endptr ; ) {
2014-03-26 15:23:54 +00:00
zval * tmp ;
2008-08-06 05:53:31 +00:00
namelen = ( ( unsigned char ) ( * p ) ) & ( ~ PS_BIN_UNDEF ) ;
if ( namelen < 0 | | namelen > PS_BIN_MAX | | ( p + namelen ) > = endptr ) {
return FAILURE ;
}
has_value = * p & PS_BIN_UNDEF ? 0 : 1 ;
2014-08-25 17:24:55 +00:00
name = zend_string_init ( p + 1 , namelen , 0 ) ;
2008-08-06 05:53:31 +00:00
p + = namelen + 1 ;
2015-02-13 19:20:39 +00:00
if ( ( tmp = zend_hash_find ( & EG ( symbol_table ) , name ) ) ) {
if ( ( Z_TYPE_P ( tmp ) = = IS_ARRAY & & Z_ARRVAL_P ( tmp ) = = & EG ( symbol_table ) ) | | tmp = = & PS ( http_session_vars ) ) {
2015-09-02 15:25:00 +00:00
zend_string_release ( name ) ;
2008-08-06 05:53:31 +00:00
continue ;
}
}
if ( has_value ) {
2014-04-10 14:08:11 +00:00
ZVAL_UNDEF ( & current ) ;
2014-12-13 22:06:14 +00:00
if ( php_var_unserialize ( & current , ( const unsigned char * * ) & p , ( const unsigned char * ) endptr , & var_hash ) ) {
zval * zv = php_set_session_var ( name , & current , & var_hash ) ;
2014-04-10 14:08:11 +00:00
var_replace ( & var_hash , & current , zv ) ;
} else {
zval_ptr_dtor ( & current ) ;
2015-09-02 15:20:24 +00:00
zend_string_release ( name ) ;
2015-08-23 20:27:59 +00:00
PHP_VAR_UNSERIALIZE_DESTROY ( var_hash ) ;
return FAILURE ;
2008-08-06 05:53:31 +00:00
}
}
2014-03-28 10:46:25 +00:00
PS_ADD_VARL ( name ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( name ) ;
2008-08-06 05:53:31 +00:00
}
PHP_VAR_UNSERIALIZE_DESTROY ( var_hash ) ;
return SUCCESS ;
}
/* }}} */
# define PS_DELIMITER '|'
# define PS_UNDEF_MARKER '!'
PS_SERIALIZER_ENCODE_FUNC ( php ) /* {{{ */
{
smart_str buf = { 0 } ;
php_serialize_data_t var_hash ;
PS_ENCODE_VARS ;
PHP_VAR_SERIALIZE_INIT ( var_hash ) ;
PS_ENCODE_LOOP (
2015-06-30 01:05:24 +00:00
smart_str_appendl ( & buf , ZSTR_VAL ( key ) , ZSTR_LEN ( key ) ) ;
if ( memchr ( ZSTR_VAL ( key ) , PS_DELIMITER , ZSTR_LEN ( key ) ) | | memchr ( ZSTR_VAL ( key ) , PS_UNDEF_MARKER , ZSTR_LEN ( key ) ) ) {
2008-08-06 05:53:31 +00:00
PHP_VAR_SERIALIZE_DESTROY ( var_hash ) ;
smart_str_free ( & buf ) ;
2014-03-26 15:23:54 +00:00
return NULL ;
2008-08-06 05:53:31 +00:00
}
smart_str_appendc ( & buf , PS_DELIMITER ) ;
2014-12-13 22:06:14 +00:00
php_var_serialize ( & buf , struc , & var_hash ) ;
2008-08-06 05:53:31 +00:00
} else {
smart_str_appendc ( & buf , PS_UNDEF_MARKER ) ;
2015-06-30 01:05:24 +00:00
smart_str_appendl ( & buf , ZSTR_VAL ( key ) , ZSTR_LEN ( key ) ) ;
2008-08-06 05:53:31 +00:00
smart_str_appendc ( & buf , PS_DELIMITER ) ;
) ;
smart_str_0 ( & buf ) ;
PHP_VAR_SERIALIZE_DESTROY ( var_hash ) ;
2014-03-26 15:23:54 +00:00
return buf . s ;
2008-08-06 05:53:31 +00:00
}
/* }}} */
PS_SERIALIZER_DECODE_FUNC ( php ) /* {{{ */
{
const char * p , * q ;
const char * endptr = val + vallen ;
2014-04-10 14:08:11 +00:00
zval current ;
2008-08-06 05:53:31 +00:00
int has_value ;
2015-03-24 17:49:54 +00:00
ptrdiff_t namelen ;
2014-03-28 10:46:25 +00:00
zend_string * name ;
2008-08-06 05:53:31 +00:00
php_unserialize_data_t var_hash ;
PHP_VAR_UNSERIALIZE_INIT ( var_hash ) ;
p = val ;
while ( p < endptr ) {
2014-03-26 15:23:54 +00:00
zval * tmp ;
2008-08-06 05:53:31 +00:00
q = p ;
while ( * q ! = PS_DELIMITER ) {
if ( + + q > = endptr ) goto break_outer_loop ;
}
if ( p [ 0 ] = = PS_UNDEF_MARKER ) {
p + + ;
has_value = 0 ;
} else {
has_value = 1 ;
}
namelen = q - p ;
2014-08-25 17:24:55 +00:00
name = zend_string_init ( p , namelen , 0 ) ;
2008-08-06 05:53:31 +00:00
q + + ;
2015-02-13 19:20:39 +00:00
if ( ( tmp = zend_hash_find ( & EG ( symbol_table ) , name ) ) ) {
if ( ( Z_TYPE_P ( tmp ) = = IS_ARRAY & & Z_ARRVAL_P ( tmp ) = = & EG ( symbol_table ) ) | | tmp = = & PS ( http_session_vars ) ) {
2008-08-06 05:53:31 +00:00
goto skip ;
}
}
if ( has_value ) {
2014-04-10 14:08:11 +00:00
ZVAL_UNDEF ( & current ) ;
2014-12-13 22:06:14 +00:00
if ( php_var_unserialize ( & current , ( const unsigned char * * ) & q , ( const unsigned char * ) endptr , & var_hash ) ) {
zval * zv = php_set_session_var ( name , & current , & var_hash ) ;
2014-04-10 14:08:11 +00:00
var_replace ( & var_hash , & current , zv ) ;
} else {
zval_ptr_dtor ( & current ) ;
2015-08-23 20:27:59 +00:00
PHP_VAR_UNSERIALIZE_DESTROY ( var_hash ) ;
2015-09-02 08:21:47 +00:00
zend_string_release ( name ) ;
2015-08-23 20:27:59 +00:00
return FAILURE ;
2008-08-06 05:53:31 +00:00
}
}
2014-03-28 10:46:25 +00:00
PS_ADD_VARL ( name ) ;
2008-08-06 05:53:31 +00:00
skip :
2014-08-25 17:24:55 +00:00
zend_string_release ( name ) ;
2008-08-06 05:53:31 +00:00
p = q ;
}
break_outer_loop :
PHP_VAR_UNSERIALIZE_DESTROY ( var_hash ) ;
return SUCCESS ;
}
/* }}} */
2013-08-21 01:51:51 +00:00
# define MAX_SERIALIZERS 32
# define PREDEFINED_SERIALIZERS 3
2008-08-06 05:53:31 +00:00
static ps_serializer ps_serializers [ MAX_SERIALIZERS + 1 ] = {
2013-08-21 01:51:51 +00:00
PS_SERIALIZER_ENTRY ( php_serialize ) ,
2008-08-06 05:53:31 +00:00
PS_SERIALIZER_ENTRY ( php ) ,
PS_SERIALIZER_ENTRY ( php_binary )
} ;
2014-03-26 15:23:54 +00:00
PHPAPI int php_session_register_serializer ( const char * name , zend_string * ( * encode ) ( PS_SERIALIZER_ENCODE_ARGS ) , int ( * decode ) ( PS_SERIALIZER_DECODE_ARGS ) ) /* { { { */
2008-08-06 05:53:31 +00:00
{
int ret = - 1 ;
int i ;
for ( i = 0 ; i < MAX_SERIALIZERS ; i + + ) {
if ( ps_serializers [ i ] . name = = NULL ) {
ps_serializers [ i ] . name = name ;
ps_serializers [ i ] . encode = encode ;
ps_serializers [ i ] . decode = decode ;
ps_serializers [ i + 1 ] . name = NULL ;
ret = 0 ;
break ;
}
}
return ret ;
}
/* }}} */
/* *******************
* Storage Modules *
* * * * * * * * * * * * * * * * * * * */
2015-01-21 10:13:59 +00:00
# define MAX_MODULES 32
2008-08-06 05:53:31 +00:00
# define PREDEFINED_MODULES 2
static ps_module * ps_modules [ MAX_MODULES + 1 ] = {
ps_files_ptr ,
ps_user_ptr
} ;
PHPAPI int php_session_register_module ( ps_module * ptr ) /* { { { */
{
int ret = - 1 ;
int i ;
2002-10-03 05:53:45 +00:00
2008-08-06 05:53:31 +00:00
for ( i = 0 ; i < MAX_MODULES ; i + + ) {
if ( ! ps_modules [ i ] ) {
ps_modules [ i ] = ptr ;
ret = 0 ;
break ;
}
2002-05-09 20:02:47 +00:00
}
2008-08-06 05:53:31 +00:00
return ret ;
1999-06-05 19:52:58 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
2015-01-21 10:13:59 +00:00
/* Dummy PS module function */
PHPAPI int php_session_validate_sid ( PS_VALIDATE_SID_ARGS ) {
return SUCCESS ;
}
/* Dummy PS module function */
PHPAPI int php_session_update_timestamp ( PS_UPDATE_TIMESTAMP_ARGS ) {
return SUCCESS ;
}
2008-08-06 05:53:31 +00:00
/* ******************
* Cache Limiters *
* * * * * * * * * * * * * * * * * * */
typedef struct {
char * name ;
2014-12-13 22:06:14 +00:00
void ( * func ) ( void ) ;
2008-08-06 05:53:31 +00:00
} php_session_cache_limiter_t ;
# define CACHE_LIMITER(name) _php_cache_limiter_##name
2014-12-13 22:06:14 +00:00
# define CACHE_LIMITER_FUNC(name) static void CACHE_LIMITER(name)(void)
2008-08-06 05:53:31 +00:00
# define CACHE_LIMITER_ENTRY(name) { #name, CACHE_LIMITER(name) },
# define ADD_HEADER(a) sapi_add_header(a, strlen(a), 1);
# define MAX_STR 512
1999-06-05 19:52:58 +00:00
1999-12-12 14:16:55 +00:00
static char * month_names [ ] = {
2002-05-09 20:02:47 +00:00
" Jan " , " Feb " , " Mar " , " Apr " , " May " , " Jun " ,
" Jul " , " Aug " , " Sep " , " Oct " , " Nov " , " Dec "
1999-12-12 14:16:55 +00:00
} ;
1999-12-12 14:22:55 +00:00
static char * week_days [ ] = {
2002-05-09 20:02:47 +00:00
" Sun " , " Mon " , " Tue " , " Wed " , " Thu " , " Fri " , " Sat " , " Sun "
1999-12-12 14:16:55 +00:00
} ;
2008-08-06 05:53:31 +00:00
static inline void strcpy_gmt ( char * ubuf , time_t * when ) /* { { { */
1999-12-12 14:16:55 +00:00
{
2002-05-09 20:02:47 +00:00
char buf [ MAX_STR ] ;
2007-06-07 08:59:00 +00:00
struct tm tm , * res ;
2002-05-09 20:02:47 +00:00
int n ;
2008-08-06 05:53:31 +00:00
2007-06-07 08:59:00 +00:00
res = php_gmtime_r ( when , & tm ) ;
if ( ! res ) {
2013-07-15 22:14:05 +00:00
ubuf [ 0 ] = ' \0 ' ;
2007-06-07 08:59:00 +00:00
return ;
}
2008-08-06 05:53:31 +00:00
2007-02-27 03:28:17 +00:00
n = slprintf ( buf , sizeof ( buf ) , " %s, %02d %s %d %02d:%02d:%02d GMT " , /* SAFE */
2009-05-18 16:10:09 +00:00
week_days [ tm . tm_wday ] , tm . tm_mday ,
month_names [ tm . tm_mon ] , tm . tm_year + 1900 ,
tm . tm_hour , tm . tm_min ,
2002-05-09 20:02:47 +00:00
tm . tm_sec ) ;
memcpy ( ubuf , buf , n ) ;
ubuf [ n ] = ' \0 ' ;
1999-12-12 14:16:55 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-12-12 14:16:55 +00:00
2014-12-13 22:06:14 +00:00
static inline void last_modified ( void ) /* { { { */
1999-12-12 14:16:55 +00:00
{
2002-05-09 20:02:47 +00:00
const char * path ;
2014-08-25 18:22:49 +00:00
zend_stat_t sb ;
2002-05-09 20:02:47 +00:00
char buf [ MAX_STR + 1 ] ;
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
path = SG ( request_info ) . path_translated ;
if ( path ) {
if ( VCWD_STAT ( path , & sb ) = = - 1 ) {
return ;
}
1999-12-12 14:16:55 +00:00
2001-03-13 16:53:34 +00:00
# define LAST_MODIFIED "Last-Modified: "
2002-05-09 20:02:47 +00:00
memcpy ( buf , LAST_MODIFIED , sizeof ( LAST_MODIFIED ) - 1 ) ;
2009-11-03 21:21:34 +00:00
strcpy_gmt ( buf + sizeof ( LAST_MODIFIED ) - 1 , & sb . st_mtime ) ;
2003-04-27 16:04:53 +00:00
ADD_HEADER ( buf ) ;
2002-05-09 20:02:47 +00:00
}
1999-12-12 14:16:55 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-12-12 14:16:55 +00:00
2008-08-06 05:53:31 +00:00
# define EXPIRES "Expires: "
CACHE_LIMITER_FUNC ( public ) /* {{{ */
1999-12-12 14:16:55 +00:00
{
2002-05-09 20:02:47 +00:00
char buf [ MAX_STR + 1 ] ;
struct timeval tv ;
time_t now ;
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
gettimeofday ( & tv , NULL ) ;
now = tv . tv_sec + PS ( cache_expire ) * 60 ;
memcpy ( buf , EXPIRES , sizeof ( EXPIRES ) - 1 ) ;
strcpy_gmt ( buf + sizeof ( EXPIRES ) - 1 , & now ) ;
2003-04-27 16:04:53 +00:00
ADD_HEADER ( buf ) ;
2008-08-06 05:53:31 +00:00
2014-08-25 18:22:49 +00:00
snprintf ( buf , sizeof ( buf ) , " Cache-Control: public, max-age= " ZEND_LONG_FMT , PS ( cache_expire ) * 60 ) ; /* SAFE */
2003-04-27 16:04:53 +00:00
ADD_HEADER ( buf ) ;
2008-08-06 05:53:31 +00:00
2014-12-13 22:06:14 +00:00
last_modified ( ) ;
1999-12-12 14:16:55 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
2001-09-21 13:38:44 +00:00
2008-08-06 05:53:31 +00:00
CACHE_LIMITER_FUNC ( private_no_expire ) /* {{{ */
1999-12-12 14:16:55 +00:00
{
2002-05-09 20:02:47 +00:00
char buf [ MAX_STR + 1 ] ;
2008-08-06 05:53:31 +00:00
2015-04-12 20:35:57 +00:00
snprintf ( buf , sizeof ( buf ) , " Cache-Control: private, max-age= " ZEND_LONG_FMT , PS ( cache_expire ) * 60 ) ; /* SAFE */
2003-04-27 16:04:53 +00:00
ADD_HEADER ( buf ) ;
1999-12-12 14:16:55 +00:00
2014-12-13 22:06:14 +00:00
last_modified ( ) ;
1999-12-12 14:16:55 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-12-12 14:16:55 +00:00
2008-08-06 05:53:31 +00:00
CACHE_LIMITER_FUNC ( private ) /* {{{ */
2001-11-02 22:27:07 +00:00
{
2003-04-27 16:04:53 +00:00
ADD_HEADER ( " Expires: Thu, 19 Nov 1981 08:52:00 GMT " ) ;
2014-12-13 22:06:14 +00:00
CACHE_LIMITER ( private_no_expire ) ( ) ;
2001-11-02 22:27:07 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
2001-11-02 22:27:07 +00:00
2008-08-06 05:53:31 +00:00
CACHE_LIMITER_FUNC ( nocache ) /* {{{ */
1999-12-12 14:16:55 +00:00
{
2003-04-27 16:04:53 +00:00
ADD_HEADER ( " Expires: Thu, 19 Nov 1981 08:52:00 GMT " ) ;
2008-08-06 05:53:31 +00:00
2015-04-12 20:35:57 +00:00
/* For HTTP/1.1 conforming clients */
ADD_HEADER ( " Cache-Control: no-store, no-cache, must-revalidate " ) ;
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
/* For HTTP/1.0 conforming clients */
2003-04-27 16:04:53 +00:00
ADD_HEADER ( " Pragma: no-cache " ) ;
1999-12-12 14:16:55 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-12-12 14:16:55 +00:00
2000-09-06 14:16:12 +00:00
static php_session_cache_limiter_t php_session_cache_limiters [ ] = {
2002-05-12 12:51:42 +00:00
CACHE_LIMITER_ENTRY ( public )
CACHE_LIMITER_ENTRY ( private )
CACHE_LIMITER_ENTRY ( private_no_expire )
CACHE_LIMITER_ENTRY ( nocache )
2002-05-09 20:02:47 +00:00
{ 0 }
1999-12-12 14:16:55 +00:00
} ;
2014-12-13 22:06:14 +00:00
static int php_session_cache_limiter ( void ) /* { { { */
1999-12-12 14:16:55 +00:00
{
2002-05-09 20:02:47 +00:00
php_session_cache_limiter_t * lim ;
2002-10-03 15:10:36 +00:00
if ( PS ( cache_limiter ) [ 0 ] = = ' \0 ' ) return 0 ;
2016-01-12 10:08:17 +00:00
if ( PS ( session_status ) ! = php_session_active ) return - 1 ;
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
if ( SG ( headers_sent ) ) {
2014-12-13 22:06:14 +00:00
const char * output_start_filename = php_output_get_start_filename ( ) ;
int output_start_lineno = php_output_get_start_lineno ( ) ;
2002-05-09 20:02:47 +00:00
2016-01-12 10:52:54 +00:00
php_session_abort ( ) ;
2002-05-09 20:02:47 +00:00
if ( output_start_filename ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Cannot send session cache limiter - headers already sent (output started at %s:%d) " , output_start_filename , output_start_lineno ) ;
2002-05-09 20:02:47 +00:00
} else {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Cannot send session cache limiter - headers already sent " ) ;
2008-08-06 05:53:31 +00:00
}
2002-10-03 15:10:36 +00:00
return - 2 ;
2002-05-09 20:02:47 +00:00
}
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
for ( lim = php_session_cache_limiters ; lim - > name ; lim + + ) {
if ( ! strcasecmp ( lim - > name , PS ( cache_limiter ) ) ) {
2014-12-13 22:06:14 +00:00
lim - > func ( ) ;
2002-10-03 15:10:36 +00:00
return 0 ;
2002-05-09 20:02:47 +00:00
}
}
2002-10-03 15:10:36 +00:00
return - 1 ;
1999-12-12 14:16:55 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
/* *********************
* Cookie Management *
* * * * * * * * * * * * * * * * * * * * * */
1999-12-12 14:16:55 +00:00
2014-01-22 10:21:25 +00:00
/*
* Remove already sent session ID cookie .
* It must be directly removed from SG ( sapi_header ) because sapi_add_header_ex ( )
* removes all of matching cookie . i . e . It deletes all of Set - Cookie headers .
*/
2014-12-13 22:06:14 +00:00
static void php_session_remove_cookie ( void ) {
2014-01-22 10:21:25 +00:00
sapi_header_struct * header ;
zend_llist * l = & SG ( sapi_headers ) . headers ;
zend_llist_element * next ;
zend_llist_element * current ;
2014-08-19 12:20:56 +00:00
char * session_cookie ;
zend_string * e_session_name ;
2015-01-29 04:28:28 +00:00
size_t session_cookie_len ;
size_t len = sizeof ( " Set-Cookie " ) - 1 ;
2014-01-22 10:21:25 +00:00
2014-04-25 20:32:51 +00:00
e_session_name = php_url_encode ( PS ( session_name ) , strlen ( PS ( session_name ) ) ) ;
2015-06-30 01:05:24 +00:00
spprintf ( & session_cookie , 0 , " Set-Cookie: %s= " , ZSTR_VAL ( e_session_name ) ) ;
2014-08-25 17:24:55 +00:00
zend_string_free ( e_session_name ) ;
2014-01-22 10:21:25 +00:00
session_cookie_len = strlen ( session_cookie ) ;
current = l - > head ;
while ( current ) {
header = ( sapi_header_struct * ) ( current - > data ) ;
next = current - > next ;
if ( header - > header_len > len & & header - > header [ len ] = = ' : '
& & ! strncmp ( header - > header , session_cookie , session_cookie_len ) ) {
if ( current - > prev ) {
current - > prev - > next = next ;
} else {
l - > head = next ;
}
if ( next ) {
next - > prev = current - > prev ;
} else {
l - > tail = current - > prev ;
}
sapi_free_header ( header ) ;
efree ( current ) ;
- - l - > count ;
}
current = next ;
}
efree ( session_cookie ) ;
}
2014-12-13 22:06:14 +00:00
static void php_session_send_cookie ( void ) /* { { { */
1999-06-05 19:52:58 +00:00
{
2002-05-09 20:02:47 +00:00
smart_str ncookie = { 0 } ;
2014-03-26 15:23:54 +00:00
zend_string * date_fmt = NULL ;
zend_string * e_session_name , * e_id ;
2002-05-09 20:02:47 +00:00
if ( SG ( headers_sent ) ) {
2014-12-13 22:06:14 +00:00
const char * output_start_filename = php_output_get_start_filename ( ) ;
int output_start_lineno = php_output_get_start_lineno ( ) ;
2002-05-09 20:02:47 +00:00
if ( output_start_filename ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Cannot send session cookie - headers already sent by (output started at %s:%d) " , output_start_filename , output_start_lineno ) ;
2002-05-09 20:02:47 +00:00
} else {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Cannot send session cookie - headers already sent " ) ;
2008-08-06 05:53:31 +00:00
}
2002-05-09 20:02:47 +00:00
return ;
}
2008-08-06 05:53:31 +00:00
2007-06-16 07:48:07 +00:00
/* URL encode session_name and id because they might be user supplied */
2014-03-26 15:23:54 +00:00
e_session_name = php_url_encode ( PS ( session_name ) , strlen ( PS ( session_name ) ) ) ;
2015-06-30 01:05:24 +00:00
e_id = php_url_encode ( ZSTR_VAL ( PS ( id ) ) , ZSTR_LEN ( PS ( id ) ) ) ;
2002-05-09 20:02:47 +00:00
2014-06-18 13:50:27 +00:00
smart_str_appendl ( & ncookie , " Set-Cookie: " , sizeof ( " Set-Cookie: " ) - 1 ) ;
2015-06-30 01:05:24 +00:00
smart_str_appendl ( & ncookie , ZSTR_VAL ( e_session_name ) , ZSTR_LEN ( e_session_name ) ) ;
2002-05-09 20:02:47 +00:00
smart_str_appendc ( & ncookie , ' = ' ) ;
2015-06-30 01:05:24 +00:00
smart_str_appendl ( & ncookie , ZSTR_VAL ( e_id ) , ZSTR_LEN ( e_id ) ) ;
2008-08-06 05:53:31 +00:00
2014-08-25 17:24:55 +00:00
zend_string_release ( e_session_name ) ;
zend_string_release ( e_id ) ;
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
if ( PS ( cookie_lifetime ) > 0 ) {
struct timeval tv ;
2003-10-08 10:22:51 +00:00
time_t t ;
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
gettimeofday ( & tv , NULL ) ;
2003-10-08 10:22:51 +00:00
t = tv . tv_sec + PS ( cookie_lifetime ) ;
2008-08-06 05:53:31 +00:00
2003-10-08 10:22:51 +00:00
if ( t > 0 ) {
2014-12-13 22:06:14 +00:00
date_fmt = php_format_date ( " D, d-M-Y H:i:s T " , sizeof ( " D, d-M-Y H:i:s T " ) - 1 , t , 0 ) ;
2003-10-08 10:22:51 +00:00
smart_str_appends ( & ncookie , COOKIE_EXPIRES ) ;
2015-06-30 01:05:24 +00:00
smart_str_appendl ( & ncookie , ZSTR_VAL ( date_fmt ) , ZSTR_LEN ( date_fmt ) ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( date_fmt ) ;
2013-01-06 02:22:44 +00:00
smart_str_appends ( & ncookie , COOKIE_MAX_AGE ) ;
2014-08-25 17:24:55 +00:00
smart_str_append_long ( & ncookie , PS ( cookie_lifetime ) ) ;
2003-10-08 10:22:51 +00:00
}
2002-05-09 20:02:47 +00:00
}
if ( PS ( cookie_path ) [ 0 ] ) {
smart_str_appends ( & ncookie , COOKIE_PATH ) ;
smart_str_appends ( & ncookie , PS ( cookie_path ) ) ;
}
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
if ( PS ( cookie_domain ) [ 0 ] ) {
smart_str_appends ( & ncookie , COOKIE_DOMAIN ) ;
smart_str_appends ( & ncookie , PS ( cookie_domain ) ) ;
}
if ( PS ( cookie_secure ) ) {
smart_str_appends ( & ncookie , COOKIE_SECURE ) ;
}
2006-08-10 13:50:56 +00:00
if ( PS ( cookie_httponly ) ) {
smart_str_appends ( & ncookie , COOKIE_HTTPONLY ) ;
}
2002-05-09 20:02:47 +00:00
smart_str_0 ( & ncookie ) ;
2008-08-06 05:53:31 +00:00
2014-12-13 22:06:14 +00:00
php_session_remove_cookie ( ) ; /* remove already sent session ID cookie */
2006-07-12 15:28:44 +00:00
/* 'replace' must be 0 here, else a previous Set-Cookie
header , probably sent with setcookie ( ) will be replaced ! */
2015-06-30 01:05:24 +00:00
sapi_add_header_ex ( estrndup ( ZSTR_VAL ( ncookie . s ) , ZSTR_LEN ( ncookie . s ) ) , ZSTR_LEN ( ncookie . s ) , 0 , 0 ) ;
2014-03-28 10:46:25 +00:00
smart_str_free ( & ncookie ) ;
1999-06-05 19:52:58 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-06-05 19:52:58 +00:00
2014-12-13 22:06:14 +00:00
PHPAPI ps_module * _php_find_ps_module ( char * name ) /* { { { */
1999-06-05 19:52:58 +00:00
{
2002-05-09 20:02:47 +00:00
ps_module * ret = NULL ;
ps_module * * mod ;
int i ;
2008-08-06 05:53:31 +00:00
for ( i = 0 , mod = ps_modules ; i < MAX_MODULES ; i + + , mod + + ) {
2003-02-11 00:42:14 +00:00
if ( * mod & & ! strcasecmp ( name , ( * mod ) - > s_name ) ) {
2002-05-09 20:02:47 +00:00
ret = * mod ;
break ;
}
2008-08-06 05:53:31 +00:00
}
2002-05-09 20:02:47 +00:00
return ret ;
1999-06-05 19:52:58 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-06-05 19:52:58 +00:00
2014-12-13 22:06:14 +00:00
PHPAPI const ps_serializer * _php_find_ps_serializer ( char * name ) /* { { { */
1999-07-01 05:45:48 +00:00
{
2002-05-09 20:02:47 +00:00
const ps_serializer * ret = NULL ;
const ps_serializer * mod ;
1999-07-01 05:45:48 +00:00
2008-08-06 05:53:31 +00:00
for ( mod = ps_serializers ; mod - > name ; mod + + ) {
2002-05-09 20:02:47 +00:00
if ( ! strcasecmp ( name , mod - > name ) ) {
ret = mod ;
break ;
}
2008-08-06 05:53:31 +00:00
}
2002-05-09 20:02:47 +00:00
return ret ;
1999-07-01 05:45:48 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-07-01 05:45:48 +00:00
2014-12-13 22:06:14 +00:00
static void ppid2sid ( zval * ppid ) {
2015-06-28 14:30:58 +00:00
ZVAL_DEREF ( ppid ) ;
2015-01-29 04:50:56 +00:00
if ( Z_TYPE_P ( ppid ) = = IS_STRING ) {
2014-08-25 17:24:55 +00:00
PS ( id ) = zend_string_init ( Z_STRVAL_P ( ppid ) , Z_STRLEN_P ( ppid ) , 0 ) ;
2014-07-19 00:52:01 +00:00
PS ( send_cookie ) = 0 ;
2015-01-29 04:50:56 +00:00
} else {
PS ( id ) = NULL ;
PS ( send_cookie ) = 1 ;
2014-07-19 00:52:01 +00:00
}
}
1999-12-22 00:38:04 +00:00
2014-12-13 22:06:14 +00:00
PHPAPI void php_session_reset_id ( void ) /* { { { */
2003-02-18 19:29:38 +00:00
{
int module_number = PS ( module_number ) ;
2015-01-28 09:12:23 +00:00
zval * sid ;
2008-08-06 05:53:31 +00:00
2013-06-25 10:47:04 +00:00
if ( ! PS ( id ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Cannot set session ID - session ID is not initialized " ) ;
2013-06-25 10:47:04 +00:00
return ;
}
2006-02-10 07:39:13 +00:00
if ( PS ( use_cookies ) & & PS ( send_cookie ) ) {
2014-12-13 22:06:14 +00:00
php_session_send_cookie ( ) ;
2006-02-10 07:39:13 +00:00
PS ( send_cookie ) = 0 ;
2003-02-18 19:29:38 +00:00
}
2015-02-02 03:53:41 +00:00
/* If the SID constant exists, destroy it. */
2015-01-28 09:12:23 +00:00
/* We must not delete any items in EG(zend_contants) */
/* zend_hash_str_del(EG(zend_constants), "sid", sizeof("sid") - 1); */
sid = zend_get_constant_str ( " SID " , sizeof ( " SID " ) - 1 ) ;
2008-08-06 05:53:31 +00:00
2003-02-18 19:29:38 +00:00
if ( PS ( define_sid ) ) {
smart_str var = { 0 } ;
smart_str_appends ( & var , PS ( session_name ) ) ;
smart_str_appendc ( & var , ' = ' ) ;
2015-06-30 01:05:24 +00:00
smart_str_appends ( & var , ZSTR_VAL ( PS ( id ) ) ) ;
2003-02-18 19:29:38 +00:00
smart_str_0 ( & var ) ;
2015-01-28 09:12:23 +00:00
if ( sid ) {
zend_string_release ( Z_STR_P ( sid ) ) ;
2015-03-12 13:53:51 +00:00
ZVAL_NEW_STR ( sid , var . s ) ;
2015-01-28 09:12:23 +00:00
} else {
2015-06-30 01:05:24 +00:00
REGISTER_STRINGL_CONSTANT ( " SID " , ZSTR_VAL ( var . s ) , ZSTR_LEN ( var . s ) , 0 ) ;
2015-01-28 09:12:23 +00:00
smart_str_free ( & var ) ;
}
2003-02-18 19:29:38 +00:00
} else {
2015-01-28 09:12:23 +00:00
if ( sid ) {
zend_string_release ( Z_STR_P ( sid ) ) ;
ZVAL_EMPTY_STRING ( sid ) ;
} else {
REGISTER_STRINGL_CONSTANT ( " SID " , " " , 0 , 0 ) ;
}
2003-02-18 19:29:38 +00:00
}
2015-02-02 03:53:41 +00:00
if ( APPLY_TRANS_SID ) {
2015-09-08 09:52:31 +00:00
/* FIXME: Resetting vars are required when
2015-09-08 09:50:40 +00:00
session is stop / start / regenerated . However ,
php_url_scanner_reset_vars ( ) resets all vars
including other URL rewrites set by elsewhere . */
2015-02-02 03:53:41 +00:00
/* php_url_scanner_reset_vars(); */
2015-06-30 01:05:24 +00:00
php_url_scanner_add_var ( PS ( session_name ) , strlen ( PS ( session_name ) ) , ZSTR_VAL ( PS ( id ) ) , ZSTR_LEN ( PS ( id ) ) , 1 ) ;
2003-02-18 19:29:38 +00:00
}
}
2008-08-06 05:53:31 +00:00
/* }}} */
2014-12-13 22:06:14 +00:00
PHPAPI void php_session_start ( void ) /* { { { */
1999-06-05 22:15:49 +00:00
{
2014-03-26 15:23:54 +00:00
zval * ppid ;
zval * data ;
2008-08-06 05:53:31 +00:00
char * p , * value ;
2015-01-29 04:28:28 +00:00
size_t lensess ;
2002-05-09 20:02:47 +00:00
2008-08-06 05:53:31 +00:00
switch ( PS ( session_status ) ) {
case php_session_active :
php_error ( E_NOTICE , " A session had already been started - ignoring session_start() " ) ;
return ;
break ;
2004-09-30 12:19:59 +00:00
2008-08-06 05:53:31 +00:00
case php_session_disabled :
2014-03-26 15:23:54 +00:00
value = zend_ini_string ( " session.save_handler " , sizeof ( " session.save_handler " ) - 1 , 0 ) ;
2008-08-06 05:53:31 +00:00
if ( ! PS ( mod ) & & value ) {
2014-12-13 22:06:14 +00:00
PS ( mod ) = _php_find_ps_module ( value ) ;
2008-08-06 05:53:31 +00:00
if ( ! PS ( mod ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Cannot find save handler '%s' - session startup failed " , value ) ;
2008-08-06 05:53:31 +00:00
return ;
}
2004-09-30 12:19:59 +00:00
}
2014-03-26 15:23:54 +00:00
value = zend_ini_string ( " session.serialize_handler " , sizeof ( " session.serialize_handler " ) - 1 , 0 ) ;
2008-08-06 05:53:31 +00:00
if ( ! PS ( serializer ) & & value ) {
2014-12-13 22:06:14 +00:00
PS ( serializer ) = _php_find_ps_serializer ( value ) ;
2008-08-06 05:53:31 +00:00
if ( ! PS ( serializer ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Cannot find serialization handler '%s' - session startup failed " , value ) ;
2008-08-06 05:53:31 +00:00
return ;
}
2004-09-30 12:19:59 +00:00
}
2008-08-06 05:53:31 +00:00
PS ( session_status ) = php_session_none ;
/* fallthrough */
default :
case php_session_none :
2015-02-02 03:53:41 +00:00
/* Setup internal flags */
PS ( define_sid ) = ! PS ( use_only_cookies ) ; /* SID constant is defined when non-cookie ID is used */
PS ( send_cookie ) = PS ( use_cookies ) | | PS ( use_only_cookies ) ;
2003-06-10 03:56:23 +00:00
}
2002-05-09 20:02:47 +00:00
lensess = strlen ( PS ( session_name ) ) ;
2015-02-02 03:53:41 +00:00
/*
* Cookies are preferred , because initially cookie and get
* variables will be available .
* URL / POST session ID may be used when use_only_cookies = Off .
* session . use_strice_mode = On prevents session adoption .
* Session based file upload progress uses non - cookie ID .
*/
2002-05-09 20:02:47 +00:00
if ( ! PS ( id ) ) {
2015-06-28 14:30:58 +00:00
if ( PS ( use_cookies ) & & ( data = zend_hash_str_find ( & EG ( symbol_table ) , " _COOKIE " , sizeof ( " _COOKIE " ) - 1 ) ) ) {
ZVAL_DEREF ( data ) ;
if ( Z_TYPE_P ( data ) = = IS_ARRAY & & ( ppid = zend_hash_str_find ( Z_ARRVAL_P ( data ) , PS ( session_name ) , lensess ) ) ) {
ppid2sid ( ppid ) ;
PS ( send_cookie ) = 0 ;
}
2002-05-09 20:02:47 +00:00
}
2015-06-28 14:30:58 +00:00
if ( PS ( define_sid ) & & ! PS ( id ) & & ( data = zend_hash_str_find ( & EG ( symbol_table ) , " _GET " , sizeof ( " _GET " ) - 1 ) ) ) {
ZVAL_DEREF ( data ) ;
if ( Z_TYPE_P ( data ) = = IS_ARRAY & & ( ppid = zend_hash_str_find ( Z_ARRVAL_P ( data ) , PS ( session_name ) , lensess ) ) ) {
ppid2sid ( ppid ) ;
}
2002-05-09 20:02:47 +00:00
}
2015-06-28 14:30:58 +00:00
if ( PS ( define_sid ) & & ! PS ( id ) & & ( data = zend_hash_str_find ( & EG ( symbol_table ) , " _POST " , sizeof ( " _POST " ) - 1 ) ) ) {
ZVAL_DEREF ( data ) ;
if ( Z_TYPE_P ( data ) = = IS_ARRAY & & ( ppid = zend_hash_str_find ( Z_ARRVAL_P ( data ) , PS ( session_name ) , lensess ) ) ) {
ppid2sid ( ppid ) ;
}
2002-05-09 20:02:47 +00:00
}
1999-08-21 20:48:40 +00:00
2015-02-02 03:53:41 +00:00
/* Check the REQUEST_URI symbol for a string of the form
* ' < session - name > = < session - id > ' to allow URLs of the form
* http : //yoursite/<session-name>=<session-id>/script.php */
if ( PS ( define_sid ) & & ! PS ( id ) & &
2014-03-26 15:23:54 +00:00
( data = zend_hash_str_find ( Z_ARRVAL ( PG ( http_globals ) [ TRACK_VARS_SERVER ] ) , " REQUEST_URI " , sizeof ( " REQUEST_URI " ) - 1 ) ) & &
Z_TYPE_P ( data ) = = IS_STRING & &
( p = strstr ( Z_STRVAL_P ( data ) , PS ( session_name ) ) ) & &
2009-05-18 16:10:09 +00:00
p [ lensess ] = = ' = '
2015-02-02 03:53:41 +00:00
) {
char * q ;
p + = lensess + 1 ;
if ( ( q = strpbrk ( p , " /? \\ " ) ) ) {
PS ( id ) = zend_string_init ( p , q - p , 0 ) ;
}
2007-05-16 01:18:14 +00:00
}
2008-08-06 05:53:31 +00:00
2015-02-02 03:53:41 +00:00
/* Check whether the current request was referred to by
* an external site which invalidates the previously found id . */
if ( PS ( define_sid ) & & PS ( id ) & &
1999-08-21 20:48:40 +00:00
PS ( extern_referer_chk ) [ 0 ] ! = ' \0 ' & &
2014-05-03 08:06:27 +00:00
! Z_ISUNDEF ( PG ( http_globals ) [ TRACK_VARS_SERVER ] ) & &
2014-03-26 15:23:54 +00:00
( data = zend_hash_str_find ( Z_ARRVAL ( PG ( http_globals ) [ TRACK_VARS_SERVER ] ) , " HTTP_REFERER " , sizeof ( " HTTP_REFERER " ) - 1 ) ) & &
Z_TYPE_P ( data ) = = IS_STRING & &
2014-08-25 17:24:55 +00:00
Z_STRLEN_P ( data ) ! = 0 & &
2014-03-26 15:23:54 +00:00
strstr ( Z_STRVAL_P ( data ) , PS ( extern_referer_chk ) ) = = NULL
2015-02-02 03:53:41 +00:00
) {
zend_string_release ( PS ( id ) ) ;
PS ( id ) = NULL ;
2008-08-06 05:53:31 +00:00
}
1999-08-21 20:48:40 +00:00
}
2008-08-06 05:53:31 +00:00
2014-05-06 20:08:52 +00:00
/* Finally check session id for dangerous characters
2013-06-25 10:47:04 +00:00
* Security note : session id may be embedded in HTML pages . */
2015-06-30 01:05:24 +00:00
if ( PS ( id ) & & strpbrk ( ZSTR_VAL ( PS ( id ) ) , " \r \n \t <>' \" \\ " ) ) {
2014-08-25 17:24:55 +00:00
zend_string_release ( PS ( id ) ) ;
2013-06-25 10:47:04 +00:00
PS ( id ) = NULL ;
1999-10-22 08:10:08 +00:00
}
2001-07-11 13:46:11 +00:00
2015-12-16 00:34:41 +00:00
php_session_initialize ( ) ;
php_session_cache_limiter ( ) ;
1999-06-07 16:43:24 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-06-07 16:43:24 +00:00
2015-01-28 05:22:22 +00:00
static void php_session_flush ( int write ) /* { { { */
1999-06-07 16:43:24 +00:00
{
2008-08-06 05:53:31 +00:00
if ( PS ( session_status ) = = php_session_active ) {
PS ( session_status ) = php_session_none ;
2015-01-28 05:22:22 +00:00
php_session_save_current_state ( write ) ;
2002-05-09 20:02:47 +00:00
}
2008-08-06 05:53:31 +00:00
}
/* }}} */
2002-05-09 19:42:00 +00:00
2014-12-13 22:06:14 +00:00
static void php_session_abort ( void ) /* { { { */
2013-08-10 07:57:56 +00:00
{
if ( PS ( session_status ) = = php_session_active ) {
PS ( session_status ) = php_session_none ;
if ( PS ( mod_data ) | | PS ( mod_user_implemented ) ) {
2014-12-13 22:06:14 +00:00
PS ( mod ) - > s_close ( & PS ( mod_data ) ) ;
2013-08-10 07:57:56 +00:00
}
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
static void php_session_reset ( void ) /* { { { */
2013-08-10 07:57:56 +00:00
{
if ( PS ( session_status ) = = php_session_active ) {
2014-12-13 22:06:14 +00:00
php_session_initialize ( ) ;
2013-08-10 07:57:56 +00:00
}
}
/* }}} */
2015-02-02 03:53:41 +00:00
/* This API is not used by any PHP modules including session currently.
session_adapt_url ( ) may be used to set Session ID to target url without
starting " URL-Rewriter " output handler . */
2014-12-13 22:06:14 +00:00
PHPAPI void session_adapt_url ( const char * url , size_t urllen , char * * new , size_t * newlen ) /* { { { */
2008-08-06 05:53:31 +00:00
{
2015-02-02 03:53:41 +00:00
if ( APPLY_TRANS_SID & & ( PS ( session_status ) = = php_session_active ) ) {
2015-06-30 01:05:24 +00:00
* new = php_url_scanner_adapt_single_url ( url , urllen , PS ( session_name ) , ZSTR_VAL ( PS ( id ) ) , newlen , 1 ) ;
2002-05-09 20:02:47 +00:00
}
1999-06-05 22:15:49 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-06-05 22:15:49 +00:00
2008-08-06 05:53:31 +00:00
/* ********************************
* Userspace exported functions *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-09-11 10:16:01 +00:00
2006-08-10 21:10:03 +00:00
/* {{{ proto void session_set_cookie_params(int lifetime [, string path [, string domain [, bool secure[, bool httponly]]]])
2000-02-04 23:34:24 +00:00
Set session cookie parameters */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_set_cookie_params )
2000-02-04 23:34:24 +00:00
{
2014-03-26 15:23:54 +00:00
zval * lifetime ;
2014-09-01 16:57:33 +00:00
zend_string * path = NULL , * domain = NULL ;
2014-08-27 13:31:48 +00:00
int argc = ZEND_NUM_ARGS ( ) ;
2008-08-06 05:53:31 +00:00
zend_bool secure = 0 , httponly = 0 ;
2014-03-26 15:23:54 +00:00
zend_string * ini_name ;
2000-02-04 23:34:24 +00:00
2008-08-06 05:53:31 +00:00
if ( ! PS ( use_cookies ) | |
2014-12-13 22:06:14 +00:00
zend_parse_parameters ( argc , " z|SSbb " , & lifetime , & path , & domain , & secure , & httponly ) = = FAILURE ) {
2008-06-21 15:27:34 +00:00
return ;
}
2002-05-09 20:02:47 +00:00
2004-04-13 00:39:05 +00:00
convert_to_string_ex ( lifetime ) ;
2008-08-06 05:53:31 +00:00
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.cookie_lifetime " , sizeof ( " session.cookie_lifetime " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
zend_alter_ini_entry ( ini_name , Z_STR_P ( lifetime ) , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2002-05-09 20:02:47 +00:00
2008-08-06 05:53:31 +00:00
if ( path ) {
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.cookie_path " , sizeof ( " session.cookie_path " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
zend_alter_ini_entry ( ini_name , path , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2008-08-06 05:53:31 +00:00
}
if ( domain ) {
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.cookie_domain " , sizeof ( " session.cookie_domain " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
zend_alter_ini_entry ( ini_name , domain , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2008-08-06 05:53:31 +00:00
}
if ( argc > 3 ) {
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.cookie_secure " , sizeof ( " session.cookie_secure " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
zend_alter_ini_entry_chars ( ini_name , secure ? " 1 " : " 0 " , 1 , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2008-08-06 05:53:31 +00:00
}
if ( argc > 4 ) {
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.cookie_httponly " , sizeof ( " session.cookie_httponly " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
zend_alter_ini_entry_chars ( ini_name , httponly ? " 1 " : " 0 " , 1 , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2002-05-09 20:02:47 +00:00
}
2000-02-04 23:34:24 +00:00
}
/* }}} */
2000-06-23 17:37:49 +00:00
/* {{{ proto array session_get_cookie_params(void)
2009-05-18 16:10:09 +00:00
Return the session cookie parameters */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_get_cookie_params )
2000-03-30 20:02:21 +00:00
{
2008-03-10 22:15:36 +00:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
2002-05-09 20:02:47 +00:00
}
2003-01-18 19:28:10 +00:00
array_init ( return_value ) ;
2002-05-09 20:02:47 +00:00
2014-08-25 17:24:55 +00:00
add_assoc_long ( return_value , " lifetime " , PS ( cookie_lifetime ) ) ;
2014-04-15 11:40:40 +00:00
add_assoc_string ( return_value , " path " , PS ( cookie_path ) ) ;
add_assoc_string ( return_value , " domain " , PS ( cookie_domain ) ) ;
2002-05-09 20:02:47 +00:00
add_assoc_bool ( return_value , " secure " , PS ( cookie_secure ) ) ;
2006-08-10 13:50:56 +00:00
add_assoc_bool ( return_value , " httponly " , PS ( cookie_httponly ) ) ;
2000-03-30 18:50:09 +00:00
}
/* }}} */
2000-02-04 23:34:24 +00:00
1999-06-06 14:19:55 +00:00
/* {{{ proto string session_name([string newname])
2000-06-23 17:37:49 +00:00
Return the current session name . If newname is given , the session name is replaced with newname */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_name )
1999-06-05 19:52:58 +00:00
{
2014-09-01 16:57:33 +00:00
zend_string * name = NULL ;
2014-03-26 15:23:54 +00:00
zend_string * ini_name ;
1999-06-05 19:52:58 +00:00
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " |S " , & name ) = = FAILURE ) {
2008-06-21 15:27:34 +00:00
return ;
}
2002-05-09 19:42:00 +00:00
2014-03-26 15:23:54 +00:00
RETVAL_STRING ( PS ( session_name ) ) ;
2008-08-06 05:53:31 +00:00
if ( name ) {
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.name " , sizeof ( " session.name " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
zend_alter_ini_entry ( ini_name , name , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2002-05-09 20:02:47 +00:00
}
1999-06-05 19:52:58 +00:00
}
1999-06-06 14:19:55 +00:00
/* }}} */
1999-06-05 19:52:58 +00:00
1999-06-06 14:19:55 +00:00
/* {{{ proto string session_module_name([string newname])
2000-06-23 17:37:49 +00:00
Return the current module name used for accessing session data . If newname is given , the module name is replaced with newname */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_module_name )
1999-06-05 19:52:58 +00:00
{
2014-09-01 16:57:33 +00:00
zend_string * name = NULL ;
2014-03-26 15:23:54 +00:00
zend_string * ini_name ;
2002-05-09 20:02:47 +00:00
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " |S " , & name ) = = FAILURE ) {
2008-06-21 15:27:34 +00:00
return ;
2005-06-03 22:09:22 +00:00
}
2002-05-09 20:02:47 +00:00
2005-06-03 22:09:22 +00:00
/* Set return_value to current module name */
if ( PS ( mod ) & & PS ( mod ) - > s_name ) {
2014-03-26 15:23:54 +00:00
RETVAL_STRING ( PS ( mod ) - > s_name ) ;
2005-06-03 22:09:22 +00:00
} else {
RETVAL_EMPTY_STRING ( ) ;
}
2008-08-06 05:53:31 +00:00
if ( name ) {
2015-06-30 01:05:24 +00:00
if ( ! _php_find_ps_module ( ZSTR_VAL ( name ) ) ) {
php_error_docref ( NULL , E_WARNING , " Cannot find named PHP session module (%s) " , ZSTR_VAL ( name ) ) ;
2008-08-06 05:53:31 +00:00
2006-08-30 15:43:10 +00:00
zval_dtor ( return_value ) ;
2002-05-09 20:02:47 +00:00
RETURN_FALSE ;
}
2011-09-13 22:28:15 +00:00
if ( PS ( mod_data ) | | PS ( mod_user_implemented ) ) {
2014-12-13 22:06:14 +00:00
PS ( mod ) - > s_close ( & PS ( mod_data ) ) ;
2004-04-13 18:18:22 +00:00
}
PS ( mod_data ) = NULL ;
2002-05-09 20:02:47 +00:00
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.save_handler " , sizeof ( " session.save_handler " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
zend_alter_ini_entry ( ini_name , name , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2004-04-13 18:18:22 +00:00
}
1999-06-05 19:52:58 +00:00
}
1999-06-06 14:19:55 +00:00
/* }}} */
1999-06-05 19:52:58 +00:00
2012-06-15 14:06:47 +00:00
/* {{{ proto void session_set_save_handler(string open, string close, string read, string write, string destroy, string gc, string create_sid)
2000-02-24 15:11:09 +00:00
Sets user - level functions */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_set_save_handler )
1999-09-17 05:40:59 +00:00
{
2014-03-26 15:23:54 +00:00
zval * args = NULL ;
2008-06-21 15:27:34 +00:00
int i , num_args , argc = ZEND_NUM_ARGS ( ) ;
2014-03-26 15:23:54 +00:00
zend_string * name ;
2014-09-01 16:57:33 +00:00
zend_string * ini_name , * ini_val ;
2002-05-09 19:42:00 +00:00
2008-08-06 05:53:31 +00:00
if ( PS ( session_status ) ! = php_session_none ) {
RETURN_FALSE ;
}
2012-06-15 14:06:47 +00:00
if ( argc > 0 & & argc < = 2 ) {
2014-03-26 15:23:54 +00:00
zval * obj = NULL ;
zend_string * func_name ;
2014-08-26 22:25:48 +00:00
zend_function * current_mptr ;
2011-09-13 22:28:15 +00:00
zend_bool register_shutdown = 1 ;
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " O|b " , & obj , php_session_iface_entry , & register_shutdown ) = = FAILURE ) {
2012-01-04 01:16:45 +00:00
RETURN_FALSE ;
2011-09-13 22:28:15 +00:00
}
2015-01-21 10:13:59 +00:00
/* For compatibility reason, implemeted interface is not checked */
2013-06-27 11:33:56 +00:00
/* Find implemented methods - SessionHandlerInterface */
2011-09-13 22:28:15 +00:00
i = 0 ;
2014-08-26 22:25:48 +00:00
ZEND_HASH_FOREACH_STR_KEY ( & php_session_iface_entry - > function_table , func_name ) {
2014-03-26 15:23:54 +00:00
if ( ( current_mptr = zend_hash_find_ptr ( & Z_OBJCE_P ( obj ) - > function_table , func_name ) ) ) {
2014-05-03 08:06:27 +00:00
if ( ! Z_ISUNDEF ( PS ( mod_user_names ) . names [ i ] ) ) {
2011-09-13 22:28:15 +00:00
zval_ptr_dtor ( & PS ( mod_user_names ) . names [ i ] ) ;
}
2014-03-26 15:23:54 +00:00
array_init_size ( & PS ( mod_user_names ) . names [ i ] , 2 ) ;
2011-09-13 22:28:15 +00:00
Z_ADDREF_P ( obj ) ;
2014-03-26 15:23:54 +00:00
add_next_index_zval ( & PS ( mod_user_names ) . names [ i ] , obj ) ;
2014-08-26 22:25:48 +00:00
add_next_index_str ( & PS ( mod_user_names ) . names [ i ] , zend_string_copy ( func_name ) ) ;
2011-09-13 22:28:15 +00:00
} else {
2015-07-21 09:18:36 +00:00
php_error_docref ( NULL , E_ERROR , " Session handler's function table is corrupt " ) ;
2011-09-13 22:28:15 +00:00
RETURN_FALSE ;
}
2013-06-27 11:33:56 +00:00
+ + i ;
2014-08-26 22:25:48 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2013-06-27 11:33:56 +00:00
/* Find implemented methods - SessionIdInterface (optional) */
2014-08-26 22:25:48 +00:00
ZEND_HASH_FOREACH_STR_KEY ( & php_session_id_iface_entry - > function_table , func_name ) {
2014-03-26 15:23:54 +00:00
if ( ( current_mptr = zend_hash_find_ptr ( & Z_OBJCE_P ( obj ) - > function_table , func_name ) ) ) {
2014-05-03 08:06:27 +00:00
if ( ! Z_ISUNDEF ( PS ( mod_user_names ) . names [ i ] ) ) {
2013-06-27 11:33:56 +00:00
zval_ptr_dtor ( & PS ( mod_user_names ) . names [ i ] ) ;
}
2014-03-26 15:23:54 +00:00
array_init_size ( & PS ( mod_user_names ) . names [ i ] , 2 ) ;
2013-06-27 11:33:56 +00:00
Z_ADDREF_P ( obj ) ;
2014-03-26 15:23:54 +00:00
add_next_index_zval ( & PS ( mod_user_names ) . names [ i ] , obj ) ;
2014-08-26 22:25:48 +00:00
add_next_index_str ( & PS ( mod_user_names ) . names [ i ] , zend_string_copy ( func_name ) ) ;
2015-01-21 10:13:59 +00:00
} else {
if ( ! Z_ISUNDEF ( PS ( mod_user_names ) . names [ i ] ) ) {
zval_ptr_dtor ( & PS ( mod_user_names ) . names [ i ] ) ;
ZVAL_UNDEF ( & PS ( mod_user_names ) . names [ i ] ) ;
}
2013-06-27 11:33:56 +00:00
}
2011-09-13 22:28:15 +00:00
+ + i ;
2014-08-26 22:25:48 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2011-09-13 22:28:15 +00:00
2015-01-21 10:13:59 +00:00
/* Find implemented methods - SessionUpdateTimestampInterface (optional) */
ZEND_HASH_FOREACH_STR_KEY ( & php_session_update_timestamp_iface_entry - > function_table , func_name ) {
if ( ( current_mptr = zend_hash_find_ptr ( & Z_OBJCE_P ( obj ) - > function_table , func_name ) ) ) {
if ( ! Z_ISUNDEF ( PS ( mod_user_names ) . names [ i ] ) ) {
zval_ptr_dtor ( & PS ( mod_user_names ) . names [ i ] ) ;
}
array_init_size ( & PS ( mod_user_names ) . names [ i ] , 2 ) ;
Z_ADDREF_P ( obj ) ;
add_next_index_zval ( & PS ( mod_user_names ) . names [ i ] , obj ) ;
add_next_index_str ( & PS ( mod_user_names ) . names [ i ] , zend_string_copy ( func_name ) ) ;
} else {
if ( ! Z_ISUNDEF ( PS ( mod_user_names ) . names [ i ] ) ) {
zval_ptr_dtor ( & PS ( mod_user_names ) . names [ i ] ) ;
ZVAL_UNDEF ( & PS ( mod_user_names ) . names [ i ] ) ;
}
}
+ + i ;
} ZEND_HASH_FOREACH_END ( ) ;
2011-09-13 22:28:15 +00:00
if ( register_shutdown ) {
/* create shutdown function */
2014-08-26 22:25:48 +00:00
php_shutdown_function_entry shutdown_function_entry ;
2011-09-13 22:28:15 +00:00
shutdown_function_entry . arg_count = 1 ;
2014-03-26 15:23:54 +00:00
shutdown_function_entry . arguments = ( zval * ) safe_emalloc ( sizeof ( zval ) , 1 , 0 ) ;
2011-09-13 22:28:15 +00:00
2014-03-26 15:23:54 +00:00
ZVAL_STRING ( & shutdown_function_entry . arguments [ 0 ] , " session_register_shutdown " ) ;
2011-09-13 22:28:15 +00:00
/* add shutdown function, removing the old one if it exists */
2014-12-13 22:06:14 +00:00
if ( ! register_user_shutdown_function ( " session_shutdown " , sizeof ( " session_shutdown " ) - 1 , & shutdown_function_entry ) ) {
2014-03-26 15:23:54 +00:00
zval_ptr_dtor ( & shutdown_function_entry . arguments [ 0 ] ) ;
2011-09-13 22:28:15 +00:00
efree ( shutdown_function_entry . arguments ) ;
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Unable to register session shutdown function " ) ;
2011-09-13 22:28:15 +00:00
RETURN_FALSE ;
}
} else {
/* remove shutdown function */
2014-12-13 22:06:14 +00:00
remove_user_shutdown_function ( " session_shutdown " , sizeof ( " session_shutdown " ) - 1 ) ;
2011-09-13 22:28:15 +00:00
}
2015-01-21 10:13:59 +00:00
if ( PS ( mod ) & & PS ( session_status ) ! = php_session_active & & PS ( mod ) ! = & ps_mod_user ) {
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.save_handler " , sizeof ( " session.save_handler " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
ini_val = zend_string_init ( " user " , sizeof ( " user " ) - 1 , 0 ) ;
zend_alter_ini_entry ( ini_name , ini_val , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
zend_string_release ( ini_val ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2011-09-13 22:28:15 +00:00
}
RETURN_TRUE ;
}
2015-01-21 10:13:59 +00:00
/* Set procedural save handler functions */
if ( argc < 6 | | PS_NUM_APIS < argc ) {
2012-06-15 14:06:47 +00:00
WRONG_PARAM_COUNT ;
}
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( argc , " + " , & args , & num_args ) = = FAILURE ) {
2008-06-21 15:27:34 +00:00
return ;
}
2008-08-06 05:53:31 +00:00
2011-09-13 22:28:15 +00:00
/* remove shutdown function */
2014-12-13 22:06:14 +00:00
remove_user_shutdown_function ( " session_shutdown " , sizeof ( " session_shutdown " ) - 1 ) ;
2011-09-13 22:28:15 +00:00
2015-01-21 10:13:59 +00:00
/* At this point argc can only be between 6 and PS_NUM_APIS */
2012-06-15 14:06:47 +00:00
for ( i = 0 ; i < argc ; i + + ) {
2014-12-13 22:06:14 +00:00
if ( ! zend_is_callable ( & args [ i ] , 0 , & name ) ) {
php_error_docref ( NULL , E_WARNING , " Argument %d is not a valid callback " , i + 1 ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( name ) ;
2005-01-09 17:42:02 +00:00
RETURN_FALSE ;
2005-01-09 17:49:51 +00:00
}
2014-08-25 17:24:55 +00:00
zend_string_release ( name ) ;
2005-01-09 17:42:02 +00:00
}
2015-01-03 09:22:58 +00:00
2011-09-13 22:28:15 +00:00
if ( PS ( mod ) & & PS ( mod ) ! = & ps_mod_user ) {
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.save_handler " , sizeof ( " session.save_handler " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
ini_val = zend_string_init ( " user " , sizeof ( " user " ) - 1 , 0 ) ;
zend_alter_ini_entry ( ini_name , ini_val , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
zend_string_release ( ini_val ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2011-09-13 22:28:15 +00:00
}
2002-05-09 19:42:00 +00:00
2012-06-15 14:06:47 +00:00
for ( i = 0 ; i < argc ; i + + ) {
2014-05-03 08:06:27 +00:00
if ( ! Z_ISUNDEF ( PS ( mod_user_names ) . names [ i ] ) ) {
2008-03-07 23:20:32 +00:00
zval_ptr_dtor ( & PS ( mod_user_names ) . names [ i ] ) ;
}
2014-03-26 15:23:54 +00:00
ZVAL_COPY ( & PS ( mod_user_names ) . names [ i ] , & args [ i ] ) ;
2002-05-09 20:02:47 +00:00
}
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
RETURN_TRUE ;
1999-09-17 05:40:59 +00:00
}
/* }}} */
1999-06-06 14:19:55 +00:00
/* {{{ proto string session_save_path([string newname])
2000-06-23 17:37:49 +00:00
Return the current save path passed to module_name . If newname is given , the save path is replaced with newname */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_save_path )
1999-06-05 19:52:58 +00:00
{
2014-09-01 16:57:33 +00:00
zend_string * name = NULL ;
2014-03-26 15:23:54 +00:00
zend_string * ini_name ;
2008-08-06 05:53:31 +00:00
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " |S " , & name ) = = FAILURE ) {
2008-06-21 15:27:34 +00:00
return ;
}
2002-05-09 19:42:00 +00:00
2014-03-26 15:23:54 +00:00
RETVAL_STRING ( PS ( save_path ) ) ;
2008-08-06 05:53:31 +00:00
if ( name ) {
2015-06-30 01:05:24 +00:00
if ( memchr ( ZSTR_VAL ( name ) , ' \0 ' , ZSTR_LEN ( name ) ) ! = NULL ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " The save_path cannot contain NULL characters " ) ;
2008-08-06 05:53:31 +00:00
zval_dtor ( return_value ) ;
RETURN_FALSE ;
}
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.save_path " , sizeof ( " session.save_path " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
zend_alter_ini_entry ( ini_name , name , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2002-05-09 20:02:47 +00:00
}
1999-06-05 19:52:58 +00:00
}
1999-06-06 14:19:55 +00:00
/* }}} */
1999-06-05 19:52:58 +00:00
1999-06-06 14:19:55 +00:00
/* {{{ proto string session_id([string newid])
2000-06-23 17:37:49 +00:00
Return the current session id . If newid is given , the session id is replaced with newid */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_id )
1999-06-05 19:52:58 +00:00
{
2014-04-10 08:29:14 +00:00
zend_string * name = NULL ;
2014-04-25 20:32:51 +00:00
int argc = ZEND_NUM_ARGS ( ) ;
2002-03-06 09:02:31 +00:00
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( argc , " |S " , & name ) = = FAILURE ) {
2008-06-21 15:27:34 +00:00
return ;
}
2002-03-06 12:34:47 +00:00
2004-07-19 07:19:50 +00:00
if ( PS ( id ) ) {
2014-08-14 06:46:17 +00:00
/* keep compatibility for "\0" characters ???
* see : ext / session / tests / session_id_error3 . phpt */
2015-06-30 01:05:24 +00:00
size_t len = strlen ( ZSTR_VAL ( PS ( id ) ) ) ;
if ( UNEXPECTED ( len ! = ZSTR_LEN ( PS ( id ) ) ) ) {
RETVAL_NEW_STR ( zend_string_init ( ZSTR_VAL ( PS ( id ) ) , len , 0 ) ) ;
2014-04-10 08:29:14 +00:00
} else {
2015-03-12 13:53:51 +00:00
RETVAL_STR_COPY ( PS ( id ) ) ;
2014-04-10 08:29:14 +00:00
}
2004-07-19 07:19:50 +00:00
} else {
2008-08-06 05:53:31 +00:00
RETVAL_EMPTY_STRING ( ) ;
2004-07-19 07:19:50 +00:00
}
2002-05-09 19:42:00 +00:00
2008-08-06 05:53:31 +00:00
if ( name ) {
2008-06-21 15:27:34 +00:00
if ( PS ( id ) ) {
2014-08-25 17:24:55 +00:00
zend_string_release ( PS ( id ) ) ;
2008-06-21 15:27:34 +00:00
}
2014-08-25 17:24:55 +00:00
PS ( id ) = zend_string_copy ( name ) ;
2002-05-09 20:02:47 +00:00
}
1999-06-05 19:52:58 +00:00
}
1999-06-06 14:19:55 +00:00
/* }}} */
1999-06-05 19:52:58 +00:00
2005-05-29 16:51:25 +00:00
/* {{{ proto bool session_regenerate_id([bool delete_old_session])
Update the current session id with a newly generated one . If delete_old_session is set to true , remove the old session . */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_regenerate_id )
2003-02-18 18:50:44 +00:00
{
2005-05-29 16:51:25 +00:00
zend_bool del_ses = 0 ;
2015-09-06 08:14:34 +00:00
zend_string * data ;
2005-05-29 16:51:25 +00:00
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " |b " , & del_ses ) = = FAILURE ) {
2006-11-03 14:46:48 +00:00
return ;
2005-05-29 16:51:25 +00:00
}
2011-08-29 21:20:41 +00:00
if ( SG ( headers_sent ) & & PS ( use_cookies ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Cannot regenerate session id - headers already sent " ) ;
2006-05-18 22:12:26 +00:00
RETURN_FALSE ;
}
2015-02-03 03:23:00 +00:00
if ( PS ( session_status ) ! = php_session_active ) {
php_error_docref ( NULL , E_WARNING , " Cannot regenerate session id - session is not active " ) ;
RETURN_FALSE ;
}
2008-08-06 05:53:31 +00:00
2015-09-06 08:14:34 +00:00
/* Process old session data */
if ( del_ses ) {
if ( PS ( mod ) - > s_destroy ( & PS ( mod_data ) , PS ( id ) ) = = FAILURE ) {
PS ( mod ) - > s_close ( & PS ( mod_data ) ) ;
PS ( session_status ) = php_session_none ;
php_error_docref ( NULL , E_WARNING , " Session object destruction failed. ID: %s (path: %s) " , PS ( mod ) - > s_name , PS ( save_path ) ) ;
RETURN_FALSE ;
}
} else {
int ret ;
data = php_session_encode ( ) ;
if ( data ) {
ret = PS ( mod ) - > s_write ( & PS ( mod_data ) , PS ( id ) , data , PS ( gc_maxlifetime ) ) ;
zend_string_release ( data ) ;
} else {
ret = PS ( mod ) - > s_write ( & PS ( mod_data ) , PS ( id ) , ZSTR_EMPTY_ALLOC ( ) , PS ( gc_maxlifetime ) ) ;
}
if ( ret = = FAILURE ) {
2015-09-06 19:45:20 +00:00
PS ( mod ) - > s_close ( & PS ( mod_data ) ) ;
2015-09-06 08:14:34 +00:00
PS ( session_status ) = php_session_none ;
php_error_docref ( NULL , E_WARNING , " Session write failed. ID: %s (path: %s) " , PS ( mod ) - > s_name , PS ( save_path ) ) ;
RETURN_FALSE ;
}
2015-02-03 03:23:00 +00:00
}
2015-09-06 19:45:20 +00:00
PS ( mod ) - > s_close ( & PS ( mod_data ) ) ;
2015-02-03 03:23:00 +00:00
2015-09-06 08:14:34 +00:00
/* New session data */
if ( PS ( session_vars ) ) {
zend_string_release ( PS ( session_vars ) ) ;
PS ( session_vars ) = NULL ;
}
zend_string_release ( PS ( id ) ) ;
PS ( id ) = PS ( mod ) - > s_create_sid ( & PS ( mod_data ) ) ;
if ( ! PS ( id ) ) {
PS ( session_status ) = php_session_none ;
2015-11-13 12:22:59 +00:00
php_error_docref ( NULL , E_RECOVERABLE_ERROR , " Failed to create new session ID: %s (path: %s) " , PS ( mod ) - > s_name , PS ( save_path ) ) ;
2015-09-06 08:14:34 +00:00
RETURN_FALSE ;
}
2015-11-07 15:30:31 +00:00
if ( PS ( mod ) - > s_open ( & PS ( mod_data ) , PS ( save_path ) , PS ( session_name ) ) = = FAILURE ) {
PS ( session_status ) = php_session_none ;
2015-11-13 12:22:59 +00:00
php_error_docref ( NULL , E_RECOVERABLE_ERROR , " Failed to create(open) session ID: %s (path: %s) " , PS ( mod ) - > s_name , PS ( save_path ) ) ;
2015-11-07 15:30:31 +00:00
RETURN_FALSE ;
}
2015-09-06 08:14:34 +00:00
if ( PS ( use_strict_mode ) & & PS ( mod ) - > s_validate_sid & &
PS ( mod ) - > s_validate_sid ( & PS ( mod_data ) , PS ( id ) ) = = FAILURE ) {
zend_string_release ( PS ( id ) ) ;
PS ( id ) = PS ( mod ) - > s_create_sid ( & PS ( mod_data ) ) ;
if ( ! PS ( id ) ) {
PS ( session_status ) = php_session_none ;
2015-11-13 12:22:59 +00:00
php_error_docref ( NULL , E_RECOVERABLE_ERROR , " Failed to create session ID by collision: %s (path: %s) " , PS ( mod ) - > s_name , PS ( save_path ) ) ;
2015-09-06 08:14:34 +00:00
RETURN_FALSE ;
2013-06-25 10:47:04 +00:00
}
2015-09-06 08:14:34 +00:00
}
/* Read is required to make new session data at this point. */
if ( PS ( mod ) - > s_read ( & PS ( mod_data ) , PS ( id ) , & data , PS ( gc_maxlifetime ) ) = = FAILURE ) {
PS ( session_status ) = php_session_none ;
2015-11-13 12:22:59 +00:00
php_error_docref ( NULL , E_RECOVERABLE_ERROR , " Failed to create(read) session ID: %s (path: %s) " , PS ( mod ) - > s_name , PS ( save_path ) ) ;
2015-09-06 08:14:34 +00:00
RETURN_FALSE ;
}
if ( data ) {
2015-02-03 03:23:00 +00:00
zend_string_release ( data ) ;
2003-02-18 18:50:44 +00:00
}
2015-09-06 08:14:34 +00:00
2015-09-16 12:32:05 +00:00
if ( PS ( use_cookies ) ) {
PS ( send_cookie ) = 1 ;
}
2015-09-06 08:14:34 +00:00
php_session_reset_id ( ) ;
2015-02-03 03:23:00 +00:00
RETURN_TRUE ;
2003-02-18 18:50:44 +00:00
}
/* }}} */
2015-01-21 10:13:59 +00:00
/* {{{ proto void session_create_id([string prefix])
Generate new session ID . Intended for user save handlers . */
2015-09-15 15:54:14 +00:00
#if 0
/* This is not used yet */
2015-01-21 10:13:59 +00:00
static PHP_FUNCTION ( session_create_id )
{
zend_string * prefix = NULL , * new_id ;
smart_str id = { 0 } ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " |S " , & prefix ) = = FAILURE ) {
return ;
}
2015-06-30 01:05:24 +00:00
if ( prefix & & ZSTR_LEN ( prefix ) ) {
if ( php_session_valid_key ( ZSTR_VAL ( prefix ) ) = = FAILURE ) {
2015-01-21 10:13:59 +00:00
/* E_ERROR raised for security reason. */
php_error_docref ( NULL , E_WARNING , " Prefix cannot contain special characters. Only aphanumeric, ',', '-' are allowed " ) ;
RETURN_FALSE ;
} else {
smart_str_append ( & id , prefix ) ;
}
}
if ( PS ( session_status ) = = php_session_active ) {
new_id = PS ( mod ) - > s_create_sid ( & PS ( mod_data ) ) ;
} else {
new_id = php_session_create_id ( NULL ) ;
}
if ( new_id ) {
smart_str_append ( & id , new_id ) ;
zend_string_release ( new_id ) ;
} else {
smart_str_free ( & id ) ;
php_error_docref ( NULL , E_WARNING , " Failed to create new ID " ) ;
RETURN_FALSE ;
}
smart_str_0 ( & id ) ;
2015-03-12 13:53:51 +00:00
RETVAL_NEW_STR ( id . s ) ;
2015-01-21 10:13:59 +00:00
smart_str_free ( & id ) ;
}
2015-09-15 15:54:14 +00:00
# endif
2015-01-21 10:13:59 +00:00
/* }}} */
2000-09-01 15:56:26 +00:00
/* {{{ proto string session_cache_limiter([string new_cache_limiter])
Return the current cache limiter . If new_cache_limited is given , the current cache_limiter is replaced with new_cache_limiter */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_cache_limiter )
2000-09-01 15:56:26 +00:00
{
2014-09-01 16:57:33 +00:00
zend_string * limiter = NULL ;
2014-03-26 15:23:54 +00:00
zend_string * ini_name ;
2000-09-01 15:56:26 +00:00
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " |S " , & limiter ) = = FAILURE ) {
2008-06-21 15:27:34 +00:00
return ;
}
2002-05-09 19:42:00 +00:00
2014-03-26 15:23:54 +00:00
RETVAL_STRING ( PS ( cache_limiter ) ) ;
2008-08-06 05:53:31 +00:00
if ( limiter ) {
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.cache_limiter " , sizeof ( " session.cache_limiter " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
zend_alter_ini_entry ( ini_name , limiter , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2002-05-09 20:02:47 +00:00
}
2000-09-01 15:56:26 +00:00
}
/* }}} */
2001-10-22 15:18:06 +00:00
/* {{{ proto int session_cache_expire([int new_cache_expire])
Return the current cache expire . If new_cache_expire is given , the current cache_expire is replaced with new_cache_expire */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_cache_expire )
2001-10-22 15:18:06 +00:00
{
2014-03-26 15:23:54 +00:00
zval * expires = NULL ;
zend_string * ini_name ;
2001-10-22 15:18:06 +00:00
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " |z " , & expires ) = = FAILURE ) {
2008-06-21 15:27:34 +00:00
return ;
}
2001-10-22 15:18:06 +00:00
2014-08-25 17:24:55 +00:00
RETVAL_LONG ( PS ( cache_expire ) ) ;
2008-08-06 05:53:31 +00:00
2014-03-26 15:23:54 +00:00
if ( expires ) {
2008-08-06 05:53:31 +00:00
convert_to_string_ex ( expires ) ;
2014-08-25 17:24:55 +00:00
ini_name = zend_string_init ( " session.cache_expire " , sizeof ( " session.cache_expire " ) - 1 , 0 ) ;
2014-09-01 16:57:33 +00:00
zend_alter_ini_entry ( ini_name , Z_STR_P ( expires ) , ZEND_INI_USER , ZEND_INI_STAGE_RUNTIME ) ;
2014-08-25 17:24:55 +00:00
zend_string_release ( ini_name ) ;
2002-05-09 20:02:47 +00:00
}
2001-10-22 15:18:06 +00:00
}
/* }}} */
2008-08-06 05:53:31 +00:00
/* {{{ proto string session_encode(void)
Serializes the current setup and returns the serialized representation */
static PHP_FUNCTION ( session_encode )
{
2014-03-26 15:23:54 +00:00
zend_string * enc ;
2008-08-06 05:53:31 +00:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
}
2014-12-13 22:06:14 +00:00
enc = php_session_encode ( ) ;
2008-08-06 05:53:31 +00:00
if ( enc = = NULL ) {
RETURN_FALSE ;
}
2014-03-26 15:23:54 +00:00
RETURN_STR ( enc ) ;
2008-08-06 05:53:31 +00:00
}
/* }}} */
/* {{{ proto bool session_decode(string data)
Deserializes data and reinitializes the variables */
static PHP_FUNCTION ( session_decode )
{
2015-01-21 10:13:59 +00:00
zend_string * str = NULL ;
2008-08-06 05:53:31 +00:00
2015-01-21 10:13:59 +00:00
if ( PS ( session_status ) ! = php_session_active ) {
2015-01-25 06:26:00 +00:00
php_error_docref ( NULL , E_WARNING , " Session is not active. You cannot decode session data " ) ;
2008-08-06 05:53:31 +00:00
RETURN_FALSE ;
}
2015-01-21 10:13:59 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " S " , & str ) = = FAILURE ) {
2008-08-06 05:53:31 +00:00
return ;
}
2015-01-25 06:26:00 +00:00
if ( php_session_decode ( str ) = = FAILURE ) {
2015-09-01 19:40:10 +00:00
RETURN_FALSE ;
2015-01-25 06:26:00 +00:00
}
2008-08-06 05:53:31 +00:00
RETURN_TRUE ;
}
/* }}} */
2015-01-21 10:13:59 +00:00
static int php_session_start_set_ini ( zend_string * varname , zend_string * new_value ) {
int ret ;
smart_str buf = { 0 } ;
smart_str_appends ( & buf , " session " ) ;
smart_str_appendc ( & buf , ' . ' ) ;
smart_str_append ( & buf , varname ) ;
smart_str_0 ( & buf ) ;
ret = zend_alter_ini_entry_ex ( buf . s , new_value , PHP_INI_USER , PHP_INI_STAGE_RUNTIME , 0 ) ;
smart_str_free ( & buf ) ;
return ret ;
}
/* {{{ proto bool session_start([array options])
+ Begin session */
2008-08-06 05:53:31 +00:00
static PHP_FUNCTION ( session_start )
{
2015-01-21 10:13:59 +00:00
zval * options = NULL ;
zval * value ;
zend_ulong num_idx ;
zend_string * str_idx ;
2015-03-24 17:49:54 +00:00
zend_long read_and_close = 0 ;
2015-01-21 10:13:59 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " |a " , & options ) = = FAILURE ) {
RETURN_FALSE ;
}
2015-06-30 01:05:24 +00:00
if ( PS ( id ) & & ! ( ZSTR_LEN ( PS ( id ) ) ) ) {
2015-03-08 11:24:50 +00:00
php_error_docref ( NULL , E_WARNING , " Cannot start session with empty session ID " ) ;
2015-02-03 04:38:49 +00:00
RETURN_FALSE ;
}
2015-01-21 10:13:59 +00:00
/* set options */
if ( options ) {
ZEND_HASH_FOREACH_KEY_VAL ( Z_ARRVAL_P ( options ) , num_idx , str_idx , value ) {
2015-01-27 23:03:37 +00:00
if ( str_idx ) {
switch ( Z_TYPE_P ( value ) ) {
case IS_STRING :
case IS_TRUE :
case IS_FALSE :
case IS_LONG :
if ( zend_string_equals_literal ( str_idx , " read_and_close " ) ) {
2015-01-29 04:22:55 +00:00
read_and_close = zval_get_long ( value ) ;
2015-01-27 23:03:37 +00:00
} else {
2015-01-29 04:22:55 +00:00
zend_string * val = zval_get_string ( value ) ;
if ( php_session_start_set_ini ( str_idx , val ) = = FAILURE ) {
2015-06-30 01:05:24 +00:00
php_error_docref ( NULL , E_WARNING , " Setting option '%s' failed " , ZSTR_VAL ( str_idx ) ) ;
2015-01-27 23:03:37 +00:00
}
2015-01-29 04:22:55 +00:00
zend_string_release ( val ) ;
2015-01-21 10:13:59 +00:00
}
2015-01-27 23:03:37 +00:00
break ;
default :
2015-06-30 01:05:24 +00:00
php_error_docref ( NULL , E_WARNING , " Option(%s) value must be string, boolean or long " , ZSTR_VAL ( str_idx ) ) ;
2015-01-27 23:03:37 +00:00
break ;
}
2015-01-21 10:13:59 +00:00
}
2015-01-30 19:11:25 +00:00
( void ) num_idx ;
2015-01-21 10:13:59 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
}
2014-12-13 22:06:14 +00:00
php_session_start ( ) ;
2008-08-06 05:53:31 +00:00
if ( PS ( session_status ) ! = php_session_active ) {
RETURN_FALSE ;
}
2015-01-21 10:13:59 +00:00
if ( read_and_close ) {
2015-01-28 05:22:22 +00:00
php_session_flush ( 0 ) ;
2015-01-21 10:13:59 +00:00
}
2008-08-06 05:53:31 +00:00
RETURN_TRUE ;
}
/* }}} */
/* {{{ proto bool session_destroy(void)
Destroy the current session and all data associated with it */
static PHP_FUNCTION ( session_destroy )
{
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
}
2014-12-13 22:06:14 +00:00
RETURN_BOOL ( php_session_destroy ( ) = = SUCCESS ) ;
2008-08-06 05:53:31 +00:00
}
/* }}} */
/* {{{ proto void session_unset(void)
Unset all registered variables */
static PHP_FUNCTION ( session_unset )
{
2015-01-21 10:13:59 +00:00
if ( PS ( session_status ) ! = php_session_active ) {
2008-08-06 05:53:31 +00:00
RETURN_FALSE ;
}
IF_SESSION_VARS ( ) {
2014-10-09 10:51:05 +00:00
HashTable * ht_sess_var = Z_ARRVAL_P ( Z_REFVAL ( PS ( http_session_vars ) ) ) ;
2008-08-06 05:53:31 +00:00
/* Clean $_SESSION. */
2011-01-23 10:02:06 +00:00
zend_hash_clean ( ht_sess_var ) ;
2008-08-06 05:53:31 +00:00
}
}
/* }}} */
/* {{{ proto void session_write_close(void)
Write session data and end session */
static PHP_FUNCTION ( session_write_close )
{
2015-01-28 05:22:22 +00:00
php_session_flush ( 1 ) ;
2008-08-06 05:53:31 +00:00
}
/* }}} */
2013-08-10 07:57:56 +00:00
/* {{{ proto void session_abort(void)
Abort session and end session . Session data will not be written */
static PHP_FUNCTION ( session_abort )
{
2014-12-13 22:06:14 +00:00
php_session_abort ( ) ;
2013-08-10 07:57:56 +00:00
}
/* }}} */
/* {{{ proto void session_reset(void)
Reset session data from saved session data */
static PHP_FUNCTION ( session_reset )
{
2014-12-13 22:06:14 +00:00
php_session_reset ( ) ;
2013-08-10 07:57:56 +00:00
}
/* }}} */
2011-08-29 21:29:26 +00:00
/* {{{ proto int session_status(void)
Returns the current session status */
static PHP_FUNCTION ( session_status )
{
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
}
2014-08-25 17:24:55 +00:00
RETURN_LONG ( PS ( session_status ) ) ;
2011-08-29 21:29:26 +00:00
}
/* }}} */
2011-09-13 22:28:15 +00:00
/* {{{ proto void session_register_shutdown(void)
Registers session_write_close ( ) as a shutdown function */
static PHP_FUNCTION ( session_register_shutdown )
{
php_shutdown_function_entry shutdown_function_entry ;
/* This function is registered itself as a shutdown function by
* session_set_save_handler ( $ obj ) . The reason we now register another
* shutdown function is in case the user registered their own shutdown
* function after calling session_set_save_handler ( ) , which expects
* the session still to be available .
*/
shutdown_function_entry . arg_count = 1 ;
2014-03-26 15:23:54 +00:00
shutdown_function_entry . arguments = ( zval * ) safe_emalloc ( sizeof ( zval ) , 1 , 0 ) ;
2011-09-13 22:28:15 +00:00
2014-03-26 15:23:54 +00:00
ZVAL_STRING ( & shutdown_function_entry . arguments [ 0 ] , " session_write_close " ) ;
2011-09-13 22:28:15 +00:00
2014-12-13 22:06:14 +00:00
if ( ! append_user_shutdown_function ( shutdown_function_entry ) ) {
2014-03-26 15:23:54 +00:00
zval_ptr_dtor ( & shutdown_function_entry . arguments [ 0 ] ) ;
2011-09-13 22:28:15 +00:00
efree ( shutdown_function_entry . arguments ) ;
/* Unable to register shutdown function, presumably because of lack
* of memory , so flush the session now . It would be done in rshutdown
* anyway but the handler will have had it ' s dtor called by then .
* If the user does have a later shutdown function which needs the
* session then tough luck .
*/
2015-01-28 05:22:22 +00:00
php_session_flush ( 1 ) ;
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Unable to register session flush function " ) ;
2011-09-13 22:28:15 +00:00
}
}
/* }}} */
2008-08-06 05:53:31 +00:00
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX ( arginfo_session_name , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , name )
ZEND_END_ARG_INFO ( )
2001-08-13 06:43:47 +00:00
2008-08-06 05:53:31 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_session_module_name , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , module )
ZEND_END_ARG_INFO ( )
1999-06-05 19:52:58 +00:00
2008-08-06 05:53:31 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_session_save_path , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , path )
ZEND_END_ARG_INFO ( )
1999-06-05 19:52:58 +00:00
2008-08-06 05:53:31 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_session_id , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , id )
ZEND_END_ARG_INFO ( )
1999-06-05 19:52:58 +00:00
2008-08-06 05:53:31 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_session_regenerate_id , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , delete_old_session )
ZEND_END_ARG_INFO ( )
2002-10-03 15:33:00 +00:00
2008-08-06 05:53:31 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_session_decode , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , data )
ZEND_END_ARG_INFO ( )
1999-06-05 19:52:58 +00:00
2008-08-06 05:53:31 +00:00
ZEND_BEGIN_ARG_INFO ( arginfo_session_void , 0 )
ZEND_END_ARG_INFO ( )
2001-07-04 15:30:21 +00:00
2013-06-27 11:33:56 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_session_set_save_handler , 0 , 0 , 1 )
2008-08-06 05:53:31 +00:00
ZEND_ARG_INFO ( 0 , open )
ZEND_ARG_INFO ( 0 , close )
ZEND_ARG_INFO ( 0 , read )
ZEND_ARG_INFO ( 0 , write )
ZEND_ARG_INFO ( 0 , destroy )
ZEND_ARG_INFO ( 0 , gc )
2012-06-15 14:06:47 +00:00
ZEND_ARG_INFO ( 0 , create_sid )
2015-01-21 10:13:59 +00:00
ZEND_ARG_INFO ( 0 , validate_sid )
ZEND_ARG_INFO ( 0 , update_timestamp )
2008-08-06 05:53:31 +00:00
ZEND_END_ARG_INFO ( )
2002-05-09 20:02:47 +00:00
2008-08-06 05:53:31 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_session_cache_limiter , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , cache_limiter )
ZEND_END_ARG_INFO ( )
2002-10-03 03:23:02 +00:00
2008-08-06 05:53:31 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_session_cache_expire , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , new_cache_expire )
ZEND_END_ARG_INFO ( )
2002-10-03 03:23:02 +00:00
2008-08-06 05:53:31 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_session_set_cookie_params , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , lifetime )
ZEND_ARG_INFO ( 0 , path )
ZEND_ARG_INFO ( 0 , domain )
ZEND_ARG_INFO ( 0 , secure )
ZEND_ARG_INFO ( 0 , httponly )
ZEND_END_ARG_INFO ( )
2011-09-13 22:28:15 +00:00
ZEND_BEGIN_ARG_INFO ( arginfo_session_class_open , 0 )
ZEND_ARG_INFO ( 0 , save_path )
ZEND_ARG_INFO ( 0 , session_name )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_session_class_close , 0 )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_session_class_read , 0 )
ZEND_ARG_INFO ( 0 , key )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_session_class_write , 0 )
ZEND_ARG_INFO ( 0 , key )
ZEND_ARG_INFO ( 0 , val )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_session_class_destroy , 0 )
ZEND_ARG_INFO ( 0 , key )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_session_class_gc , 0 )
ZEND_ARG_INFO ( 0 , maxlifetime )
ZEND_END_ARG_INFO ( )
2012-06-15 14:06:47 +00:00
ZEND_BEGIN_ARG_INFO ( arginfo_session_class_create_sid , 0 )
ZEND_END_ARG_INFO ( )
2015-01-21 10:13:59 +00:00
ZEND_BEGIN_ARG_INFO ( arginfo_session_class_validateId , 0 )
ZEND_ARG_INFO ( 0 , key )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_session_class_updateTimestamp , 0 )
ZEND_ARG_INFO ( 0 , key )
ZEND_ARG_INFO ( 0 , val )
ZEND_END_ARG_INFO ( )
1999-09-11 22:31:04 +00:00
/* }}} */
2008-08-06 05:53:31 +00:00
/* {{{ session_functions[]
*/
static const zend_function_entry session_functions [ ] = {
PHP_FE ( session_name , arginfo_session_name )
PHP_FE ( session_module_name , arginfo_session_module_name )
PHP_FE ( session_save_path , arginfo_session_save_path )
PHP_FE ( session_id , arginfo_session_id )
PHP_FE ( session_regenerate_id , arginfo_session_regenerate_id )
PHP_FE ( session_decode , arginfo_session_decode )
PHP_FE ( session_encode , arginfo_session_void )
PHP_FE ( session_start , arginfo_session_void )
PHP_FE ( session_destroy , arginfo_session_void )
PHP_FE ( session_unset , arginfo_session_void )
PHP_FE ( session_set_save_handler , arginfo_session_set_save_handler )
PHP_FE ( session_cache_limiter , arginfo_session_cache_limiter )
PHP_FE ( session_cache_expire , arginfo_session_cache_expire )
PHP_FE ( session_set_cookie_params , arginfo_session_set_cookie_params )
PHP_FE ( session_get_cookie_params , arginfo_session_void )
PHP_FE ( session_write_close , arginfo_session_void )
2013-08-10 07:57:56 +00:00
PHP_FE ( session_abort , arginfo_session_void )
PHP_FE ( session_reset , arginfo_session_void )
2011-08-29 21:29:26 +00:00
PHP_FE ( session_status , arginfo_session_void )
2011-09-13 22:28:15 +00:00
PHP_FE ( session_register_shutdown , arginfo_session_void )
2008-08-06 05:53:31 +00:00
PHP_FALIAS ( session_commit , session_write_close , arginfo_session_void )
2011-07-25 11:35:02 +00:00
PHP_FE_END
2008-08-06 05:53:31 +00:00
} ;
/* }}} */
1999-06-05 19:52:58 +00:00
2012-01-04 01:16:45 +00:00
/* {{{ SessionHandlerInterface functions[]
*/
static const zend_function_entry php_session_iface_functions [ ] = {
PHP_ABSTRACT_ME ( SessionHandlerInterface , open , arginfo_session_class_open )
PHP_ABSTRACT_ME ( SessionHandlerInterface , close , arginfo_session_class_close )
PHP_ABSTRACT_ME ( SessionHandlerInterface , read , arginfo_session_class_read )
PHP_ABSTRACT_ME ( SessionHandlerInterface , write , arginfo_session_class_write )
PHP_ABSTRACT_ME ( SessionHandlerInterface , destroy , arginfo_session_class_destroy )
PHP_ABSTRACT_ME ( SessionHandlerInterface , gc , arginfo_session_class_gc )
2013-06-27 11:33:56 +00:00
{ NULL , NULL , NULL }
} ;
/* }}} */
/* {{{ SessionIdInterface functions[]
*/
static const zend_function_entry php_session_id_iface_functions [ ] = {
PHP_ABSTRACT_ME ( SessionIdInterface , create_sid , arginfo_session_class_create_sid )
2012-01-04 01:16:45 +00:00
{ NULL , NULL , NULL }
} ;
/* }}} */
2015-01-21 10:13:59 +00:00
/* {{{ SessionUpdateTimestampHandler functions[]
*/
static const zend_function_entry php_session_update_timestamp_iface_functions [ ] = {
PHP_ABSTRACT_ME ( SessionUpdateTimestampHandlerInterface , validateId , arginfo_session_class_validateId )
PHP_ABSTRACT_ME ( SessionUpdateTimestampHandlerInterface , updateTimestamp , arginfo_session_class_updateTimestamp )
{ NULL , NULL , NULL }
} ;
/* }}} */
2012-01-04 01:16:45 +00:00
/* {{{ SessionHandler functions[]
2011-09-13 22:28:15 +00:00
*/
static const zend_function_entry php_session_class_functions [ ] = {
PHP_ME ( SessionHandler , open , arginfo_session_class_open , ZEND_ACC_PUBLIC )
PHP_ME ( SessionHandler , close , arginfo_session_class_close , ZEND_ACC_PUBLIC )
PHP_ME ( SessionHandler , read , arginfo_session_class_read , ZEND_ACC_PUBLIC )
PHP_ME ( SessionHandler , write , arginfo_session_class_write , ZEND_ACC_PUBLIC )
PHP_ME ( SessionHandler , destroy , arginfo_session_class_destroy , ZEND_ACC_PUBLIC )
PHP_ME ( SessionHandler , gc , arginfo_session_class_gc , ZEND_ACC_PUBLIC )
2012-06-15 14:06:47 +00:00
PHP_ME ( SessionHandler , create_sid , arginfo_session_class_create_sid , ZEND_ACC_PUBLIC )
2011-09-13 22:28:15 +00:00
{ NULL , NULL , NULL }
} ;
/* }}} */
2008-08-06 05:53:31 +00:00
/* ********************************
* Module Setup and Destruction *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-11-17 22:59:27 +00:00
2014-12-13 22:06:14 +00:00
static int php_rinit_session ( zend_bool auto_start ) /* { { { */
1999-06-05 19:52:58 +00:00
{
2014-12-13 22:06:14 +00:00
php_rinit_session_globals ( ) ;
1999-06-06 18:22:17 +00:00
2002-05-09 20:02:47 +00:00
if ( PS ( mod ) = = NULL ) {
char * value ;
2001-05-23 23:18:51 +00:00
2014-03-26 15:23:54 +00:00
value = zend_ini_string ( " session.save_handler " , sizeof ( " session.save_handler " ) - 1 , 0 ) ;
2002-05-09 20:02:47 +00:00
if ( value ) {
2014-12-13 22:06:14 +00:00
PS ( mod ) = _php_find_ps_module ( value ) ;
2002-05-09 20:02:47 +00:00
}
2008-08-04 06:21:55 +00:00
}
if ( PS ( serializer ) = = NULL ) {
char * value ;
2001-05-23 23:18:51 +00:00
2014-03-26 15:23:54 +00:00
value = zend_ini_string ( " session.serialize_handler " , sizeof ( " session.serialize_handler " ) - 1 , 0 ) ;
2008-08-06 05:53:31 +00:00
if ( value ) {
2014-12-13 22:06:14 +00:00
PS ( serializer ) = _php_find_ps_serializer ( value ) ;
2002-05-09 20:02:47 +00:00
}
}
1999-08-27 21:03:22 +00:00
2008-08-04 06:21:55 +00:00
if ( PS ( mod ) = = NULL | | PS ( serializer ) = = NULL ) {
/* current status is unusable */
PS ( session_status ) = php_session_disabled ;
return SUCCESS ;
}
2010-05-10 16:09:00 +00:00
if ( auto_start ) {
2014-12-13 22:06:14 +00:00
php_session_start ( ) ;
2002-05-09 20:02:47 +00:00
}
1999-06-05 19:52:58 +00:00
2002-05-09 20:02:47 +00:00
return SUCCESS ;
2010-05-10 16:09:00 +00:00
} /* }}} */
static PHP_RINIT_FUNCTION ( session ) /* { { { */
{
2014-12-13 22:06:14 +00:00
return php_rinit_session ( PS ( auto_start ) ) ;
2000-01-16 21:03:49 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
2000-01-15 13:09:32 +00:00
2008-08-06 05:53:31 +00:00
static PHP_RSHUTDOWN_FUNCTION ( session ) /* { { { */
2000-10-11 19:47:15 +00:00
{
2008-03-07 23:20:32 +00:00
int i ;
2012-03-08 03:31:46 +00:00
zend_try {
2015-01-28 05:22:22 +00:00
php_session_flush ( 1 ) ;
2012-03-08 03:31:46 +00:00
} zend_end_try ( ) ;
2014-12-13 22:06:14 +00:00
php_rshutdown_session_globals ( ) ;
2008-08-06 05:53:31 +00:00
2008-03-07 23:20:32 +00:00
/* this should NOT be done in php_rshutdown_session_globals() */
2015-01-21 10:13:59 +00:00
for ( i = 0 ; i < PS_NUM_APIS ; i + + ) {
2014-05-03 08:06:27 +00:00
if ( ! Z_ISUNDEF ( PS ( mod_user_names ) . names [ i ] ) ) {
2008-03-07 23:20:32 +00:00
zval_ptr_dtor ( & PS ( mod_user_names ) . names [ i ] ) ;
2014-03-26 15:23:54 +00:00
ZVAL_UNDEF ( & PS ( mod_user_names ) . names [ i ] ) ;
2008-03-07 23:20:32 +00:00
}
}
2005-09-20 20:56:54 +00:00
1999-06-05 19:52:58 +00:00
return SUCCESS ;
}
2001-12-04 22:57:16 +00:00
/* }}} */
2000-01-16 21:03:49 +00:00
2008-08-06 05:53:31 +00:00
static PHP_GINIT_FUNCTION ( ps ) /* { { { */
2004-02-24 08:47:35 +00:00
{
2008-03-07 23:20:32 +00:00
int i ;
2014-10-17 12:16:40 +00:00
# if defined(COMPILE_DL_SESSION) && defined(ZTS)
2015-02-16 16:19:32 +00:00
ZEND_TSRMLS_CACHE_UPDATE ( ) ;
2014-10-17 12:16:40 +00:00
# endif
2004-02-24 08:47:35 +00:00
ps_globals - > save_path = NULL ;
ps_globals - > session_name = NULL ;
ps_globals - > id = NULL ;
ps_globals - > mod = NULL ;
2008-08-06 05:53:31 +00:00
ps_globals - > serializer = NULL ;
2004-02-24 08:47:35 +00:00
ps_globals - > mod_data = NULL ;
ps_globals - > session_status = php_session_none ;
2011-09-13 22:28:15 +00:00
ps_globals - > default_mod = NULL ;
ps_globals - > mod_user_implemented = 0 ;
ps_globals - > mod_user_is_open = 0 ;
2015-01-21 10:13:59 +00:00
ps_globals - > session_vars = NULL ;
for ( i = 0 ; i < PS_NUM_APIS ; i + + ) {
2014-03-26 15:23:54 +00:00
ZVAL_UNDEF ( & ps_globals - > mod_user_names . names [ i ] ) ;
2008-03-07 23:20:32 +00:00
}
2014-03-26 15:23:54 +00:00
ZVAL_UNDEF ( & ps_globals - > http_session_vars ) ;
2004-02-24 08:47:35 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
2000-01-16 21:03:49 +00:00
2008-08-06 05:53:31 +00:00
static PHP_MINIT_FUNCTION ( session ) /* { { { */
1999-06-05 19:52:58 +00:00
{
2011-09-13 22:28:15 +00:00
zend_class_entry ce ;
2014-12-13 22:06:14 +00:00
zend_register_auto_global ( zend_string_init ( " _SESSION " , sizeof ( " _SESSION " ) - 1 , 1 ) , 0 , NULL ) ;
2001-08-11 10:49:03 +00:00
2002-05-05 16:39:49 +00:00
PS ( module_number ) = module_number ; /* if we really need this var we need to init it in zts mode as well! */
2002-06-28 02:27:02 +00:00
2003-01-08 13:28:16 +00:00
PS ( session_status ) = php_session_none ;
1999-06-05 19:52:58 +00:00
REGISTER_INI_ENTRIES ( ) ;
2002-06-28 02:27:02 +00:00
# ifdef HAVE_LIBMM
PHP_MINIT ( ps_mm ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
# endif
2010-05-10 16:09:00 +00:00
php_session_rfc1867_orig_callback = php_rfc1867_callback ;
php_rfc1867_callback = php_session_rfc1867_callback ;
2011-08-29 21:29:26 +00:00
2013-06-27 11:33:56 +00:00
/* Register interfaces */
2012-01-04 01:16:45 +00:00
INIT_CLASS_ENTRY ( ce , PS_IFACE_NAME , php_session_iface_functions ) ;
2014-12-13 22:06:14 +00:00
php_session_iface_entry = zend_register_internal_class ( & ce ) ;
2012-01-04 01:16:45 +00:00
php_session_iface_entry - > ce_flags | = ZEND_ACC_INTERFACE ;
2013-06-27 11:33:56 +00:00
INIT_CLASS_ENTRY ( ce , PS_SID_IFACE_NAME , php_session_id_iface_functions ) ;
2014-12-13 22:06:14 +00:00
php_session_id_iface_entry = zend_register_internal_class ( & ce ) ;
2013-06-27 11:33:56 +00:00
php_session_id_iface_entry - > ce_flags | = ZEND_ACC_INTERFACE ;
2015-01-21 10:13:59 +00:00
INIT_CLASS_ENTRY ( ce , PS_UPDATE_TIMESTAMP_IFACE_NAME , php_session_update_timestamp_iface_functions ) ;
2015-03-08 11:24:50 +00:00
php_session_update_timestamp_iface_entry = zend_register_internal_class ( & ce ) ;
2015-01-21 10:13:59 +00:00
php_session_update_timestamp_iface_entry - > ce_flags | = ZEND_ACC_INTERFACE ;
2013-06-27 11:33:56 +00:00
2011-09-13 22:28:15 +00:00
/* Register base class */
INIT_CLASS_ENTRY ( ce , PS_CLASS_NAME , php_session_class_functions ) ;
2014-12-13 22:06:14 +00:00
php_session_class_entry = zend_register_internal_class ( & ce ) ;
zend_class_implements ( php_session_class_entry , 1 , php_session_iface_entry ) ;
zend_class_implements ( php_session_class_entry , 1 , php_session_id_iface_entry ) ;
2011-09-13 22:28:15 +00:00
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " PHP_SESSION_DISABLED " , php_session_disabled , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " PHP_SESSION_NONE " , php_session_none , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " PHP_SESSION_ACTIVE " , php_session_active , CONST_CS | CONST_PERSISTENT ) ;
2011-08-29 21:29:26 +00:00
1999-06-05 19:52:58 +00:00
return SUCCESS ;
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-06-05 19:52:58 +00:00
2008-08-06 05:53:31 +00:00
static PHP_MSHUTDOWN_FUNCTION ( session ) /* { { { */
1999-06-05 19:52:58 +00:00
{
2002-05-09 20:02:47 +00:00
UNREGISTER_INI_ENTRIES ( ) ;
2002-06-28 02:27:02 +00:00
# ifdef HAVE_LIBMM
PHP_MSHUTDOWN ( ps_mm ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
# endif
2013-07-17 10:02:48 +00:00
/* reset rfc1867 callbacks */
php_session_rfc1867_orig_callback = NULL ;
if ( php_rfc1867_callback = = php_session_rfc1867_callback ) {
php_rfc1867_callback = NULL ;
}
2013-06-10 08:32:53 +00:00
2004-12-07 18:02:25 +00:00
ps_serializers [ PREDEFINED_SERIALIZERS ] . name = NULL ;
2005-09-20 14:03:29 +00:00
memset ( & ps_modules [ PREDEFINED_MODULES ] , 0 , ( MAX_MODULES - PREDEFINED_MODULES ) * sizeof ( ps_module * ) ) ;
2004-12-07 18:02:25 +00:00
2002-05-09 20:02:47 +00:00
return SUCCESS ;
1999-06-05 19:52:58 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
1999-06-06 19:53:59 +00:00
2008-08-06 05:53:31 +00:00
static PHP_MINFO_FUNCTION ( session ) /* { { { */
1999-06-06 19:53:59 +00:00
{
2002-06-28 02:27:02 +00:00
ps_module * * mod ;
2003-08-26 02:03:41 +00:00
ps_serializer * ser ;
smart_str save_handlers = { 0 } ;
smart_str ser_handlers = { 0 } ;
2002-06-28 02:27:02 +00:00
int i ;
2008-08-06 05:53:31 +00:00
2003-08-26 02:03:41 +00:00
/* Get save handlers */
2002-06-28 02:27:02 +00:00
for ( i = 0 , mod = ps_modules ; i < MAX_MODULES ; i + + , mod + + ) {
2003-02-11 00:42:14 +00:00
if ( * mod & & ( * mod ) - > s_name ) {
2003-08-26 02:03:41 +00:00
smart_str_appends ( & save_handlers , ( * mod ) - > s_name ) ;
smart_str_appendc ( & save_handlers , ' ' ) ;
}
}
/* Get serializer handlers */
for ( i = 0 , ser = ps_serializers ; i < MAX_SERIALIZERS ; i + + , ser + + ) {
if ( ser & & ser - > name ) {
smart_str_appends ( & ser_handlers , ser - > name ) ;
smart_str_appendc ( & ser_handlers , ' ' ) ;
2002-06-28 02:27:02 +00:00
}
}
2008-08-06 05:53:31 +00:00
2002-05-09 20:02:47 +00:00
php_info_print_table_start ( ) ;
php_info_print_table_row ( 2 , " Session Support " , " enabled " ) ;
2002-06-28 02:27:02 +00:00
2014-03-26 15:23:54 +00:00
if ( save_handlers . s ) {
2003-08-26 02:03:41 +00:00
smart_str_0 ( & save_handlers ) ;
2015-06-30 01:05:24 +00:00
php_info_print_table_row ( 2 , " Registered save handlers " , ZSTR_VAL ( save_handlers . s ) ) ;
2003-08-26 02:03:41 +00:00
smart_str_free ( & save_handlers ) ;
2002-06-28 02:27:02 +00:00
} else {
php_info_print_table_row ( 2 , " Registered save handlers " , " none " ) ;
}
2003-08-26 02:03:41 +00:00
2014-03-26 15:23:54 +00:00
if ( ser_handlers . s ) {
2003-08-26 02:03:41 +00:00
smart_str_0 ( & ser_handlers ) ;
2015-06-30 01:05:24 +00:00
php_info_print_table_row ( 2 , " Registered serializer handlers " , ZSTR_VAL ( ser_handlers . s ) ) ;
2003-08-26 02:03:41 +00:00
smart_str_free ( & ser_handlers ) ;
} else {
php_info_print_table_row ( 2 , " Registered serializer handlers " , " none " ) ;
}
2002-05-09 20:02:47 +00:00
php_info_print_table_end ( ) ;
2000-04-06 21:07:44 +00:00
2002-05-09 20:02:47 +00:00
DISPLAY_INI_ENTRIES ( ) ;
1999-06-06 19:53:59 +00:00
}
2008-08-06 05:53:31 +00:00
/* }}} */
2009-07-28 08:54:23 +00:00
static const zend_module_dep session_deps [ ] = { /* {{{ */
ZEND_MOD_OPTIONAL ( " hash " )
2010-11-02 18:34:56 +00:00
ZEND_MOD_REQUIRED ( " spl " )
2011-08-06 14:47:44 +00:00
ZEND_MOD_END
2009-07-28 08:54:23 +00:00
} ;
/* }}} */
2010-05-10 16:09:00 +00:00
/* ************************
* Upload hook handling *
* * * * * * * * * * * * * * * * * * * * * * * * */
2014-12-13 22:06:14 +00:00
static zend_bool early_find_sid_in ( zval * dest , int where , php_session_rfc1867_progress * progress ) /* { { { */
2010-05-10 16:09:00 +00:00
{
2014-03-26 15:23:54 +00:00
zval * ppid ;
2010-05-10 16:09:00 +00:00
2014-05-03 08:06:27 +00:00
if ( Z_ISUNDEF ( PG ( http_globals ) [ where ] ) ) {
2010-05-11 16:39:07 +00:00
return 0 ;
}
2014-03-26 15:23:54 +00:00
if ( ( ppid = zend_hash_str_find ( Z_ARRVAL ( PG ( http_globals ) [ where ] ) , PS ( session_name ) , progress - > sname_len ) )
& & Z_TYPE_P ( ppid ) = = IS_STRING ) {
2010-05-11 16:39:07 +00:00
zval_dtor ( dest ) ;
2015-06-12 10:33:14 +00:00
ZVAL_DEREF ( ppid ) ;
ZVAL_COPY ( dest , ppid ) ;
2010-05-11 16:39:07 +00:00
return 1 ;
}
return 0 ;
} /* }}} */
2014-12-13 22:06:14 +00:00
static void php_session_rfc1867_early_find_sid ( php_session_rfc1867_progress * progress ) /* { { { */
2010-05-11 16:39:07 +00:00
{
2010-05-10 16:09:00 +00:00
if ( PS ( use_cookies ) ) {
2014-12-13 22:06:14 +00:00
sapi_module . treat_data ( PARSE_COOKIE , NULL , NULL ) ;
if ( early_find_sid_in ( & progress - > sid , TRACK_VARS_COOKIE , progress ) ) {
2010-05-10 16:09:00 +00:00
progress - > apply_trans_sid = 0 ;
return ;
}
}
if ( PS ( use_only_cookies ) ) {
return ;
}
2014-12-13 22:06:14 +00:00
sapi_module . treat_data ( PARSE_GET , NULL , NULL ) ;
early_find_sid_in ( & progress - > sid , TRACK_VARS_GET , progress ) ;
2010-05-10 16:09:00 +00:00
} /* }}} */
2014-12-13 22:06:14 +00:00
static zend_bool php_check_cancel_upload ( php_session_rfc1867_progress * progress ) /* { { { */
2010-05-10 16:09:00 +00:00
{
2014-03-26 15:23:54 +00:00
zval * progress_ary , * cancel_upload ;
2010-05-10 16:09:00 +00:00
2014-03-28 10:46:25 +00:00
if ( ( progress_ary = zend_symtable_find ( Z_ARRVAL_P ( Z_REFVAL ( PS ( http_session_vars ) ) ) , progress - > key . s ) ) = = NULL ) {
2010-05-10 16:09:00 +00:00
return 0 ;
}
2014-03-26 15:23:54 +00:00
if ( Z_TYPE_P ( progress_ary ) ! = IS_ARRAY ) {
2010-05-10 16:09:00 +00:00
return 0 ;
}
2014-03-26 15:23:54 +00:00
if ( ( cancel_upload = zend_hash_str_find ( Z_ARRVAL_P ( progress_ary ) , " cancel_upload " , sizeof ( " cancel_upload " ) - 1 ) ) = = NULL ) {
2010-05-10 16:09:00 +00:00
return 0 ;
}
2014-04-30 14:32:42 +00:00
return Z_TYPE_P ( cancel_upload ) = = IS_TRUE ;
2010-05-10 16:09:00 +00:00
} /* }}} */
2014-12-13 22:06:14 +00:00
static void php_session_rfc1867_update ( php_session_rfc1867_progress * progress , int force_update ) /* { { { */
2010-05-10 16:09:00 +00:00
{
if ( ! force_update ) {
2014-08-25 17:24:55 +00:00
if ( Z_LVAL_P ( progress - > post_bytes_processed ) < progress - > next_update ) {
2010-05-10 16:09:00 +00:00
return ;
}
# ifdef HAVE_GETTIMEOFDAY
if ( PS ( rfc1867_min_freq ) > 0.0 ) {
struct timeval tv = { 0 } ;
double dtv ;
gettimeofday ( & tv , NULL ) ;
dtv = ( double ) tv . tv_sec + tv . tv_usec / 1000000.0 ;
if ( dtv < progress - > next_update_time ) {
return ;
}
progress - > next_update_time = dtv + PS ( rfc1867_min_freq ) ;
}
# endif
2014-08-25 17:24:55 +00:00
progress - > next_update = Z_LVAL_P ( progress - > post_bytes_processed ) + progress - > update_step ;
2010-05-10 16:09:00 +00:00
}
2014-12-13 22:06:14 +00:00
php_session_initialize ( ) ;
2010-05-10 16:09:00 +00:00
PS ( session_status ) = php_session_active ;
IF_SESSION_VARS ( ) {
2014-12-13 22:06:14 +00:00
progress - > cancel_upload | = php_check_cancel_upload ( progress ) ;
2014-04-15 11:40:40 +00:00
if ( Z_REFCOUNTED ( progress - > data ) ) Z_ADDREF ( progress - > data ) ;
zend_hash_update ( Z_ARRVAL_P ( Z_REFVAL ( PS ( http_session_vars ) ) ) , progress - > key . s , & progress - > data ) ;
2010-05-10 16:09:00 +00:00
}
2015-01-28 05:22:22 +00:00
php_session_flush ( 1 ) ;
2010-05-10 16:09:00 +00:00
} /* }}} */
2014-12-13 22:06:14 +00:00
static void php_session_rfc1867_cleanup ( php_session_rfc1867_progress * progress ) /* { { { */
2010-05-11 16:39:07 +00:00
{
2014-12-13 22:06:14 +00:00
php_session_initialize ( ) ;
2010-05-11 16:39:07 +00:00
PS ( session_status ) = php_session_active ;
IF_SESSION_VARS ( ) {
2014-03-28 10:46:25 +00:00
zend_hash_del ( Z_ARRVAL_P ( Z_REFVAL ( PS ( http_session_vars ) ) ) , progress - > key . s ) ;
2010-05-11 16:39:07 +00:00
}
2015-01-28 05:22:22 +00:00
php_session_flush ( 1 ) ;
2010-05-11 16:39:07 +00:00
} /* }}} */
2014-12-13 22:06:14 +00:00
static int php_session_rfc1867_callback ( unsigned int event , void * event_data , void * * extra ) /* { { { */
2010-05-10 16:09:00 +00:00
{
php_session_rfc1867_progress * progress ;
int retval = SUCCESS ;
if ( php_session_rfc1867_orig_callback ) {
2014-12-13 22:06:14 +00:00
retval = php_session_rfc1867_orig_callback ( event , event_data , extra ) ;
2010-05-10 16:09:00 +00:00
}
if ( ! PS ( rfc1867_enabled ) ) {
return retval ;
}
progress = PS ( rfc1867_progress ) ;
switch ( event ) {
case MULTIPART_EVENT_START : {
multipart_event_start * data = ( multipart_event_start * ) event_data ;
progress = ecalloc ( 1 , sizeof ( php_session_rfc1867_progress ) ) ;
progress - > content_length = data - > content_length ;
progress - > sname_len = strlen ( PS ( session_name ) ) ;
PS ( rfc1867_progress ) = progress ;
}
break ;
case MULTIPART_EVENT_FORMDATA : {
multipart_event_formdata * data = ( multipart_event_formdata * ) event_data ;
size_t value_len ;
2014-03-26 15:23:54 +00:00
if ( Z_TYPE ( progress - > sid ) & & progress - > key . s ) {
2010-05-11 16:39:07 +00:00
break ;
}
2010-05-10 16:09:00 +00:00
/* orig callback may have modified *data->newlength */
if ( data - > newlength ) {
value_len = * data - > newlength ;
} else {
value_len = data - > length ;
}
if ( data - > name & & data - > value & & value_len ) {
size_t name_len = strlen ( data - > name ) ;
if ( name_len = = progress - > sname_len & & memcmp ( data - > name , PS ( session_name ) , name_len ) = = 0 ) {
zval_dtor ( & progress - > sid ) ;
2014-03-26 15:23:54 +00:00
ZVAL_STRINGL ( & progress - > sid , ( * data - > value ) , value_len ) ;
2014-03-29 09:39:26 +00:00
} else if ( memcmp ( data - > name , PS ( rfc1867_name ) , name_len + 1 ) = = 0 ) {
2010-05-10 16:09:00 +00:00
smart_str_free ( & progress - > key ) ;
2014-03-29 09:39:26 +00:00
smart_str_appends ( & progress - > key , PS ( rfc1867_prefix ) ) ;
2010-05-10 16:09:00 +00:00
smart_str_appendl ( & progress - > key , * data - > value , value_len ) ;
smart_str_0 ( & progress - > key ) ;
2015-02-02 03:53:41 +00:00
progress - > apply_trans_sid = APPLY_TRANS_SID ;
2014-12-13 22:06:14 +00:00
php_session_rfc1867_early_find_sid ( progress ) ;
2010-05-10 16:09:00 +00:00
}
}
}
break ;
case MULTIPART_EVENT_FILE_START : {
multipart_event_file_start * data = ( multipart_event_file_start * ) event_data ;
2015-01-03 09:22:58 +00:00
/* Do nothing when $_POST["PHP_SESSION_UPLOAD_PROGRESS"] is not set
2010-05-10 16:09:00 +00:00
* or when we have no session id */
2014-03-26 15:23:54 +00:00
if ( ! Z_TYPE ( progress - > sid ) | | ! progress - > key . s ) {
2010-05-10 16:09:00 +00:00
break ;
}
2015-01-03 09:22:58 +00:00
2010-05-10 16:09:00 +00:00
/* First FILE_START event, initializing data */
2014-05-03 08:06:27 +00:00
if ( Z_ISUNDEF ( progress - > data ) ) {
2010-05-10 16:09:00 +00:00
2010-05-11 16:39:07 +00:00
if ( PS ( rfc1867_freq ) > = 0 ) {
progress - > update_step = PS ( rfc1867_freq ) ;
2011-11-21 05:57:45 +00:00
} else if ( PS ( rfc1867_freq ) < 0 ) { /* % of total size */
2010-05-11 16:39:07 +00:00
progress - > update_step = progress - > content_length * - PS ( rfc1867_freq ) / 100 ;
2010-05-10 16:09:00 +00:00
}
progress - > next_update = 0 ;
progress - > next_update_time = 0.0 ;
2014-03-26 15:23:54 +00:00
array_init ( & progress - > data ) ;
array_init ( & progress - > files ) ;
2010-05-10 16:09:00 +00:00
2014-12-13 22:06:14 +00:00
add_assoc_long_ex ( & progress - > data , " start_time " , sizeof ( " start_time " ) - 1 , ( zend_long ) sapi_get_request_time ( ) ) ;
2014-08-25 17:24:55 +00:00
add_assoc_long_ex ( & progress - > data , " content_length " , sizeof ( " content_length " ) - 1 , progress - > content_length ) ;
add_assoc_long_ex ( & progress - > data , " bytes_processed " , sizeof ( " bytes_processed " ) - 1 , data - > post_bytes_processed ) ;
2014-03-26 15:23:54 +00:00
add_assoc_bool_ex ( & progress - > data , " done " , sizeof ( " done " ) - 1 , 0 ) ;
add_assoc_zval_ex ( & progress - > data , " files " , sizeof ( " files " ) - 1 , & progress - > files ) ;
2010-05-10 16:09:00 +00:00
2014-03-29 09:39:26 +00:00
progress - > post_bytes_processed = zend_hash_str_find ( Z_ARRVAL ( progress - > data ) , " bytes_processed " , sizeof ( " bytes_processed " ) - 1 ) ;
2014-12-13 22:06:14 +00:00
php_rinit_session ( 0 ) ;
2014-08-25 17:24:55 +00:00
PS ( id ) = zend_string_init ( Z_STRVAL ( progress - > sid ) , Z_STRLEN ( progress - > sid ) , 0 ) ;
2015-02-02 03:53:41 +00:00
if ( progress - > apply_trans_sid ) {
/* Enable trans sid by modifying flags */
PS ( use_trans_sid ) = 1 ;
PS ( use_only_cookies ) = 0 ;
}
2010-05-10 16:09:00 +00:00
PS ( send_cookie ) = 0 ;
}
2014-03-26 15:23:54 +00:00
array_init ( & progress - > current_file ) ;
2010-05-10 16:09:00 +00:00
/* Each uploaded file has its own array. Trying to make it close to $_FILES entries. */
2014-04-15 11:40:40 +00:00
add_assoc_string_ex ( & progress - > current_file , " field_name " , sizeof ( " field_name " ) - 1 , data - > name ) ;
add_assoc_string_ex ( & progress - > current_file , " name " , sizeof ( " name " ) - 1 , * data - > filename ) ;
2014-03-26 15:23:54 +00:00
add_assoc_null_ex ( & progress - > current_file , " tmp_name " , sizeof ( " tmp_name " ) - 1 ) ;
2014-08-25 17:24:55 +00:00
add_assoc_long_ex ( & progress - > current_file , " error " , sizeof ( " error " ) - 1 , 0 ) ;
2010-05-10 16:09:00 +00:00
2014-03-26 15:23:54 +00:00
add_assoc_bool_ex ( & progress - > current_file , " done " , sizeof ( " done " ) - 1 , 0 ) ;
2014-08-25 17:24:55 +00:00
add_assoc_long_ex ( & progress - > current_file , " start_time " , sizeof ( " start_time " ) - 1 , ( zend_long ) time ( NULL ) ) ;
add_assoc_long_ex ( & progress - > current_file , " bytes_processed " , sizeof ( " bytes_processed " ) - 1 , 0 ) ;
2010-05-10 16:09:00 +00:00
2014-03-26 15:23:54 +00:00
add_next_index_zval ( & progress - > files , & progress - > current_file ) ;
2015-01-03 09:22:58 +00:00
2014-03-29 09:39:26 +00:00
progress - > current_file_bytes_processed = zend_hash_str_find ( Z_ARRVAL ( progress - > current_file ) , " bytes_processed " , sizeof ( " bytes_processed " ) - 1 ) ;
2010-05-10 16:09:00 +00:00
2014-08-25 17:24:55 +00:00
Z_LVAL_P ( progress - > current_file_bytes_processed ) = data - > post_bytes_processed ;
2014-12-13 22:06:14 +00:00
php_session_rfc1867_update ( progress , 0 ) ;
2010-05-10 16:09:00 +00:00
}
break ;
case MULTIPART_EVENT_FILE_DATA : {
multipart_event_file_data * data = ( multipart_event_file_data * ) event_data ;
2014-03-26 15:23:54 +00:00
if ( ! Z_TYPE ( progress - > sid ) | | ! progress - > key . s ) {
2010-05-10 16:09:00 +00:00
break ;
}
2015-01-03 09:22:58 +00:00
2014-08-25 17:24:55 +00:00
Z_LVAL_P ( progress - > current_file_bytes_processed ) = data - > offset + data - > length ;
Z_LVAL_P ( progress - > post_bytes_processed ) = data - > post_bytes_processed ;
2010-05-10 16:09:00 +00:00
2014-12-13 22:06:14 +00:00
php_session_rfc1867_update ( progress , 0 ) ;
2010-05-10 16:09:00 +00:00
}
break ;
case MULTIPART_EVENT_FILE_END : {
multipart_event_file_end * data = ( multipart_event_file_end * ) event_data ;
2014-03-26 15:23:54 +00:00
if ( ! Z_TYPE ( progress - > sid ) | | ! progress - > key . s ) {
2010-05-10 16:09:00 +00:00
break ;
}
2015-01-03 09:22:58 +00:00
2010-05-10 16:09:00 +00:00
if ( data - > temp_filename ) {
2014-04-15 11:40:40 +00:00
add_assoc_string_ex ( & progress - > current_file , " tmp_name " , sizeof ( " tmp_name " ) - 1 , data - > temp_filename ) ;
2010-05-10 16:09:00 +00:00
}
2014-03-28 10:46:25 +00:00
2014-08-25 17:24:55 +00:00
add_assoc_long_ex ( & progress - > current_file , " error " , sizeof ( " error " ) - 1 , data - > cancel_upload ) ;
2014-03-26 15:23:54 +00:00
add_assoc_bool_ex ( & progress - > current_file , " done " , sizeof ( " done " ) - 1 , 1 ) ;
2010-05-10 16:09:00 +00:00
2014-08-25 17:24:55 +00:00
Z_LVAL_P ( progress - > post_bytes_processed ) = data - > post_bytes_processed ;
2010-05-10 16:09:00 +00:00
2014-12-13 22:06:14 +00:00
php_session_rfc1867_update ( progress , 0 ) ;
2010-05-10 16:09:00 +00:00
}
break ;
case MULTIPART_EVENT_END : {
multipart_event_end * data = ( multipart_event_end * ) event_data ;
2014-03-26 15:23:54 +00:00
if ( Z_TYPE ( progress - > sid ) & & progress - > key . s ) {
2010-05-11 16:39:07 +00:00
if ( PS ( rfc1867_cleanup ) ) {
2014-12-13 22:06:14 +00:00
php_session_rfc1867_cleanup ( progress ) ;
2010-05-11 16:39:07 +00:00
} else {
2014-03-26 15:23:54 +00:00
add_assoc_bool_ex ( & progress - > data , " done " , sizeof ( " done " ) - 1 , 1 ) ;
2014-08-25 17:24:55 +00:00
Z_LVAL_P ( progress - > post_bytes_processed ) = data - > post_bytes_processed ;
2014-12-13 22:06:14 +00:00
php_session_rfc1867_update ( progress , 1 ) ;
2010-05-11 16:39:07 +00:00
}
2014-12-13 22:06:14 +00:00
php_rshutdown_session_globals ( ) ;
2010-05-10 16:09:00 +00:00
}
2014-05-03 08:06:27 +00:00
if ( ! Z_ISUNDEF ( progress - > data ) ) {
2010-05-10 16:09:00 +00:00
zval_ptr_dtor ( & progress - > data ) ;
}
2014-03-26 15:23:54 +00:00
zval_ptr_dtor ( & progress - > sid ) ;
2010-05-10 16:09:00 +00:00
smart_str_free ( & progress - > key ) ;
efree ( progress ) ;
progress = NULL ;
PS ( rfc1867_progress ) = NULL ;
}
break ;
}
if ( progress & & progress - > cancel_upload ) {
return FAILURE ;
}
return retval ;
} /* }}} */
2008-08-06 05:53:31 +00:00
zend_module_entry session_module_entry = {
2009-07-28 08:54:23 +00:00
STANDARD_MODULE_HEADER_EX ,
NULL ,
session_deps ,
2008-08-06 05:53:31 +00:00
" session " ,
session_functions ,
PHP_MINIT ( session ) , PHP_MSHUTDOWN ( session ) ,
PHP_RINIT ( session ) , PHP_RSHUTDOWN ( session ) ,
PHP_MINFO ( session ) ,
2015-03-23 20:30:22 +00:00
PHP_SESSION_VERSION ,
2008-08-06 05:53:31 +00:00
PHP_MODULE_GLOBALS ( ps ) ,
PHP_GINIT ( ps ) ,
NULL ,
NULL ,
STANDARD_MODULE_PROPERTIES_EX
} ;
2001-06-06 14:32:27 +00:00
2008-08-06 05:53:31 +00:00
# ifdef COMPILE_DL_SESSION
2014-10-17 12:16:40 +00:00
# ifdef ZTS
2015-02-16 16:19:32 +00:00
ZEND_TSRMLS_CACHE_DEFINE ( ) ;
2014-10-17 12:16:40 +00:00
# endif
2008-08-06 05:53:31 +00:00
ZEND_GET_MODULE ( session )
# endif
2001-08-25 15:57:42 +00:00
2001-06-06 14:32:27 +00:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2006-05-18 22:12:26 +00:00
* vim600 : noet sw = 4 ts = 4 fdm = marker
2001-09-09 13:29:31 +00:00
* vim < 600 : sw = 4 ts = 4
2001-06-06 14:32:27 +00:00
*/