diff --git a/ext/session/mod_user.c b/ext/session/mod_user.c index 2ff5302f78204..02b7621885436 100644 --- a/ext/session/mod_user.c +++ b/ext/session/mod_user.c @@ -23,7 +23,7 @@ #include "mod_user.h" ps_module ps_mod_user = { - PS_MOD(user) + PS_MOD_SID(user) }; #define SESS_ZVAL_LONG(val, a) \ @@ -170,6 +170,39 @@ PS_GC_FUNC(user) FINISH; } +PS_CREATE_SID_FUNC(user) +{ + /* maintain backwards compatibility */ + if (PSF(create_sid) != NULL) { + zval *args[1]; + char *id = NULL; + STDVARS; + + retval = ps_call_handler(PSF(create_sid), 0, NULL TSRMLS_CC); + + if (retval) { + if (Z_TYPE_P(retval) == IS_STRING) { + id = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + } + zval_ptr_dtor(&retval); + } + else { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "No session id returned by function"); + return NULL; + } + + if (!id) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Session id must be a string"); + return NULL; + } + + return id; + } + + /* function as defined by PS_MOD */ + return php_session_create_id(mod_data, newlen TSRMLS_CC); +} + /* * Local variables: * tab-width: 4 diff --git a/ext/session/mod_user.h b/ext/session/mod_user.h index ea1980ab4890e..a25fa6d767344 100644 --- a/ext/session/mod_user.h +++ b/ext/session/mod_user.h @@ -24,6 +24,6 @@ extern ps_module ps_mod_user; #define ps_user_ptr &ps_mod_user -PS_FUNCS(user); +PS_FUNCS_SID(user); #endif diff --git a/ext/session/mod_user_class.c b/ext/session/mod_user_class.c index 70d2f40df18b9..4387bddadfc8b 100644 --- a/ext/session/mod_user_class.c +++ b/ext/session/mod_user_class.c @@ -142,3 +142,19 @@ PHP_METHOD(SessionHandler, gc) RETVAL_BOOL(SUCCESS == PS(default_mod)->s_gc(&PS(mod_data), maxlifetime, &nrdels TSRMLS_CC)); } /* }}} */ + +/* {{{ proto char SessionHandler::create_sid() + Wraps the old create_sid handler */ +PHP_METHOD(SessionHandler, create_sid) +{ + char *id; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + id = PS(default_mod)->s_create_sid(&PS(mod_data), NULL TSRMLS_CC); + + RETURN_STRING(id, 0); +} +/* }}} */ diff --git a/ext/session/php_session.h b/ext/session/php_session.h index ba0195bec46f4..2a6ecf1cc87f8 100644 --- a/ext/session/php_session.h +++ b/ext/session/php_session.h @@ -138,7 +138,7 @@ typedef struct _php_ps_globals { int module_number; long cache_expire; union { - zval *names[6]; + zval *names[7]; struct { zval *ps_open; zval *ps_close; @@ -146,6 +146,7 @@ typedef struct _php_ps_globals { zval *ps_write; zval *ps_destroy; zval *ps_gc; + zval *ps_create_sid; } name; } mod_user_names; int mod_user_implemented; @@ -283,5 +284,6 @@ extern PHP_METHOD(SessionHandler, read); extern PHP_METHOD(SessionHandler, write); extern PHP_METHOD(SessionHandler, destroy); extern PHP_METHOD(SessionHandler, gc); +extern PHP_METHOD(SessionHandler, create_sid); #endif diff --git a/ext/session/session.c b/ext/session/session.c index 7a8199d810600..d6ae64fbd2e32 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1573,7 +1573,7 @@ static PHP_FUNCTION(session_module_name) } /* }}} */ -/* {{{ proto void session_set_save_handler(string open, string close, string read, string write, string destroy, string gc) +/* {{{ proto void session_set_save_handler(string open, string close, string read, string write, string destroy, string gc, string create_sid) Sets user-level functions */ static PHP_FUNCTION(session_set_save_handler) { @@ -1585,11 +1585,7 @@ static PHP_FUNCTION(session_set_save_handler) RETURN_FALSE; } - if (argc != 1 && argc != 2 && argc != 6) { - WRONG_PARAM_COUNT; - } - - if (argc <= 2) { + if (argc > 0 && argc <= 2) { zval *obj = NULL, *callback = NULL; zend_uint func_name_len; char *func_name; @@ -1657,6 +1653,10 @@ static PHP_FUNCTION(session_set_save_handler) RETURN_TRUE; } + if (argc != 6 && argc != 7) { + WRONG_PARAM_COUNT; + } + if (zend_parse_parameters(argc TSRMLS_CC, "+", &args, &num_args) == FAILURE) { return; } @@ -1664,7 +1664,8 @@ static PHP_FUNCTION(session_set_save_handler) /* remove shutdown function */ remove_user_shutdown_function("session_shutdown", sizeof("session_shutdown") TSRMLS_CC); - for (i = 0; i < 6; i++) { + /* at this point argc can only be 6 or 7 */ + for (i = 0; i < argc; i++) { if (!zend_is_callable(*args[i], 0, &name TSRMLS_CC)) { efree(args); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument %d is not a valid callback", i+1); @@ -1678,7 +1679,7 @@ static PHP_FUNCTION(session_set_save_handler) zend_alter_ini_entry("session.save_handler", sizeof("session.save_handler"), "user", sizeof("user")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); } - for (i = 0; i < 6; i++) { + for (i = 0; i < argc; i++) { if (PS(mod_user_names).names[i] != NULL) { zval_ptr_dtor(&PS(mod_user_names).names[i]); } @@ -1988,13 +1989,14 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_session_void, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_session_set_save_handler, 0, 0, 6) +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_set_save_handler, 0, 0, 7) 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) + ZEND_ARG_INFO(0, create_sid) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_session_cache_limiter, 0, 0, 0) @@ -2037,6 +2039,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_session_class_gc, 0) ZEND_ARG_INFO(0, maxlifetime) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_session_class_create_sid, 0) +ZEND_END_ARG_INFO() /* }}} */ /* {{{ session_functions[] @@ -2074,6 +2079,7 @@ static const zend_function_entry php_session_iface_functions[] = { 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) + PHP_ABSTRACT_ME(SessionHandlerInterface, create_sid, arginfo_session_class_create_sid) { NULL, NULL, NULL } }; /* }}} */ @@ -2087,6 +2093,7 @@ static const zend_function_entry php_session_class_functions[] = { 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) + PHP_ME(SessionHandler, create_sid, arginfo_session_class_create_sid, ZEND_ACC_PUBLIC) { NULL, NULL, NULL } }; /* }}} */ @@ -2146,7 +2153,7 @@ static PHP_RSHUTDOWN_FUNCTION(session) /* {{{ */ php_rshutdown_session_globals(TSRMLS_C); /* this should NOT be done in php_rshutdown_session_globals() */ - for (i = 0; i < 6; i++) { + for (i = 0; i < 7; i++) { if (PS(mod_user_names).names[i] != NULL) { zval_ptr_dtor(&PS(mod_user_names).names[i]); PS(mod_user_names).names[i] = NULL; @@ -2171,7 +2178,7 @@ static PHP_GINIT_FUNCTION(ps) /* {{{ */ ps_globals->default_mod = NULL; ps_globals->mod_user_implemented = 0; ps_globals->mod_user_is_open = 0; - for (i = 0; i < 6; i++) { + for (i = 0; i < 7; i++) { ps_globals->mod_user_names.names[i] = NULL; } ps_globals->http_session_vars = NULL; diff --git a/ext/session/tests/session_set_save_handler_class_002.phpt b/ext/session/tests/session_set_save_handler_class_002.phpt index 6fb831f6957a1..4195a163a73c8 100644 --- a/ext/session/tests/session_set_save_handler_class_002.phpt +++ b/ext/session/tests/session_set_save_handler_class_002.phpt @@ -53,6 +53,10 @@ class MySession2 extends SessionHandler { } return true; } + + public function create_sid() { + return parent::create_sid(); + } } $handler = new MySession2; diff --git a/ext/session/tests/session_set_save_handler_iface_001.phpt b/ext/session/tests/session_set_save_handler_iface_001.phpt index 39a4b9975b589..0576341a109f7 100644 --- a/ext/session/tests/session_set_save_handler_iface_001.phpt +++ b/ext/session/tests/session_set_save_handler_iface_001.phpt @@ -53,6 +53,10 @@ class MySession2 implements SessionHandlerInterface { } return true; } + + public function create_sid() { + return md5(mt_rand()); + } } $handler = new MySession2;