summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArpad Ray <arraypad@gmail.com>2013-06-27 11:27:49 +0100
committerArpad Ray <arraypad@gmail.com>2013-06-27 12:29:44 +0100
commitb66c14b0c82ad0ed4ea117f7b789eef6e3a95ef4 (patch)
tree3717bcbf6d8632c480bd1f059ee235db1b55090d
parent60bbc78bde18d2d21cd4c0eaf86d348368c8aca9 (diff)
parent6809c388b5d8bb03515f7b4ba391724f9a8df8e0 (diff)
downloadphp-git-b66c14b0c82ad0ed4ea117f7b789eef6e3a95ef4.tar.gz
Merge PR 109 - Add create_sid to session_set_save_handler and SessionHandler
Allows user session handlers to create session IDs by adding an optional 7th argument to session_set_save_handler() and a create_sid() method to SessionHandler.
-rw-r--r--ext/session/mod_user.c35
-rw-r--r--ext/session/mod_user.h2
-rw-r--r--ext/session/mod_user_class.c16
-rw-r--r--ext/session/php_session.h4
-rw-r--r--ext/session/session.c29
-rw-r--r--ext/session/tests/session_set_save_handler_class_002.phpt4
-rw-r--r--ext/session/tests/session_set_save_handler_iface_001.phpt4
7 files changed, 80 insertions, 14 deletions
diff --git a/ext/session/mod_user.c b/ext/session/mod_user.c
index 57d7bd0edc..e4261df294 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) \
@@ -183,6 +183,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 fd149ccff4..6b2998c426 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 1ed1e7bbd5..ea53af9ebe 100644
--- a/ext/session/mod_user_class.c
+++ b/ext/session/mod_user_class.c
@@ -141,3 +141,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 adc5e70402..210043582d 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 5e0565253f..d8de5769fc 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -1577,7 +1577,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)
{
@@ -1589,11 +1589,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;
@@ -1661,6 +1657,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;
}
@@ -1668,7 +1668,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);
@@ -1682,7 +1683,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]);
}
@@ -1992,13 +1993,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)
@@ -2041,6 +2043,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[]
@@ -2078,6 +2083,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 }
};
/* }}} */
@@ -2091,6 +2097,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 }
};
/* }}} */
@@ -2150,7 +2157,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;
@@ -2175,7 +2182,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 6fb831f695..4195a163a7 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 39a4b9975b..0576341a10 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;