Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/session/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ PHP_ARG_WITH(mm,for mm support,
if test "$PHP_SESSION" != "no"; then
PHP_PWRITE_TEST
PHP_PREAD_TEST
PHP_NEW_EXTENSION(session, mod_user_class.c session.c mod_files.c mod_mm.c mod_user.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
PHP_NEW_EXTENSION(session, serializer_user.c mod_user_class.c session.c mod_files.c mod_mm.c mod_user.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
PHP_ADD_EXTENSION_DEP(session, hash, true)
PHP_ADD_EXTENSION_DEP(session, spl)
PHP_SUBST(SESSION_SHARED_LIBADD)
PHP_INSTALL_HEADERS(ext/session, [php_session.h mod_files.h mod_user.h])
PHP_INSTALL_HEADERS(ext/session, [php_session.h mod_serializer.h mod_files.h mod_user.h])
AC_DEFINE(HAVE_PHP_SESSION,1,[ ])
fi

Expand Down
12 changes: 12 additions & 0 deletions ext/session/php_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ typedef struct _php_ps_globals {
int mod_user_implemented;
int mod_user_is_open;
const struct ps_serializer_struct *serializer;
union {
zval names[2];
struct {
zval ps_encode;
zval ps_decode;
} name;
} serializer_user_names;
zval http_session_vars;
zend_bool auto_start;
zend_bool use_cookies;
Expand Down Expand Up @@ -325,6 +332,10 @@ extern zend_class_entry *php_session_id_iface_entry;
#define PS_UPDATE_TIMESTAMP_IFACE_NAME "SessionUpdateTimestampHandlerInterface"
extern zend_class_entry *php_session_update_timestamp_iface_entry;

#define PS_SERIALIZER_IFACE_NAME "SessionSerializerInterface"
extern zend_class_entry *php_session_serializer_iface_entry;


extern PHP_METHOD(SessionHandler, open);
extern PHP_METHOD(SessionHandler, close);
extern PHP_METHOD(SessionHandler, read);
Expand All @@ -335,4 +346,5 @@ extern PHP_METHOD(SessionHandler, create_sid);
extern PHP_METHOD(SessionHandler, validateId);
extern PHP_METHOD(SessionHandler, updateTimestamp);


#endif
129 changes: 129 additions & 0 deletions ext/session/serializer_user.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| 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. |
+----------------------------------------------------------------------+
| Author: Yasuo Ohgaki <yohgaki@ohgaki.net/php.net> |
+----------------------------------------------------------------------+
*/


#include "php.h"
#include "php_session.h"

PS_SERIALIZER_ENCODE_FUNC(user);
PS_SERIALIZER_DECODE_FUNC(user);

ps_serializer ps_serializer_user = PS_SERIALIZER_ENTRY(user);


static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval)
{
int i;
if (call_user_function(EG(function_table), NULL, func, retval, argc, argv) == FAILURE) {
zval_ptr_dtor(retval);
ZVAL_UNDEF(retval);
} else if (Z_ISUNDEF_P(retval)) {
ZVAL_NULL(retval);
}
for (i = 0; i < argc; i++) {
zval_ptr_dtor(&argv[i]);
}
}


#define PSF(a) PS(serializer_user_names).name.ps_##a


/* {{{ PS_SERIALIZER_ENCODE_FUNC
*/
PS_SERIALIZER_ENCODE_FUNC(user)
{
zval args[1], retval;

if (Z_ISUNDEF(PSF(encode))) {
php_error_docref(NULL, E_RECOVERABLE_ERROR,
"User session encode function is not defined");
return NULL;
}

ZVAL_UNDEF(&retval);
args[0] = PS(http_session_vars);
Z_ADDREF(args[0]);
ps_call_handler(&PSF(encode), 1, args, &retval);

if (Z_TYPE(retval) == IS_STRING) {
zend_string *tmp;
tmp = zend_string_copy(Z_STR(retval));
zval_ptr_dtor(&retval);
return tmp;
} else if (Z_TYPE(retval) == IS_FALSE) {
return NULL;
} else {
if (!EG(exception)) {
php_error_docref(NULL, E_RECOVERABLE_ERROR,
"Session decode callback expects string or FALSE return value");
}
}
return NULL;
}
/* }}} */


/* {{{ PS_SERIALIZER_DECODE_FUNC
*/
PS_SERIALIZER_DECODE_FUNC(user)
{
zval args[1], retval;
zend_string *data;
zend_string *var_name = zend_string_init("_SESSION", sizeof("_SESSION") - 1, 0);

if (Z_ISUNDEF(PSF(encode))) {
php_error_docref(NULL, E_RECOVERABLE_ERROR,
"User session decode function is not defined");
return FAILURE;
}

data = zend_string_init(val, vallen, 0);
ZVAL_STR(&args[0], data);
ZVAL_UNDEF(&retval);
ps_call_handler(&PSF(decode), 1, args, &retval);

if (Z_TYPE(retval) != IS_ARRAY) {
if (!Z_ISUNDEF(retval)) {
zval_ptr_dtor(&retval);
}
php_error_docref(NULL, E_RECOVERABLE_ERROR,
"User session decode function must return array");
return FAILURE;
}

if (!Z_ISUNDEF(PS(http_session_vars))) {
zval_ptr_dtor(&PS(http_session_vars));
}
ZVAL_NEW_REF(&PS(http_session_vars), &retval);
Z_ADDREF_P(&PS(http_session_vars));
zend_hash_update_ind(&EG(symbol_table), var_name, &PS(http_session_vars));
zend_string_release(var_name);
return SUCCESS;
}
/* }}} */

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/

27 changes: 27 additions & 0 deletions ext/session/serializer_user.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| 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. |
+----------------------------------------------------------------------+
| Author: Yasuo Ohgaki <yohgaki@ohgaki.net/php.net> |
+----------------------------------------------------------------------+
*/

#ifndef MOD_SERIALIZER_USER_H
#define MOD_SERIALIZER_USER_H

extern ps_serializer ps_serializer_user;
#define ps_serializer_user_ptr &ps_serializer_user

PS_SERIALIZER_FUNCS(user);

#endif
Loading