diff options
author | Leigh <leight@gmail.com> | 2012-06-15 15:06:47 +0100 |
---|---|---|
committer | Leigh <leight@gmail.com> | 2012-06-15 15:06:47 +0100 |
commit | 59cf3a2404dc5d678ee16249764b7effd6ecd485 (patch) | |
tree | 70368491ab340681ca7f87a944cd4a960b38956b /ext/session/mod_user.c | |
parent | 74916d8ec86f10cf5efd91559e956da191dfe3e7 (diff) | |
download | php-git-59cf3a2404dc5d678ee16249764b7effd6ecd485.tar.gz |
Add create_sid to session_set_save_handler and SessionHandler
A lot of code already existed to allow a custom create_sid handler, but
lacked a specific implementation.
Therefore I have added a 7th (optional) argument
session_set_save_handler, to allow a user function to be supplied for
session id generation.
If a create_sid function is not supplied, the default function is
called in its absence to preserve backwards compatibility.
Likewise create_sid only added to SessionHandler class, and not the
interface to maintain backwards compatibility. If the result is not
overridden, the default is called.
Diffstat (limited to 'ext/session/mod_user.c')
-rw-r--r-- | ext/session/mod_user.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/ext/session/mod_user.c b/ext/session/mod_user.c index 2ff5302f78..02b7621885 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 |