1999-09-17 13:40:59 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
| PHP Version 5 |
|
1999-09-17 13:40:59 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2012-01-01 21:15:04 +08:00
|
|
|
| Copyright (c) 1997-2012 The PHP Group |
|
1999-09-17 13:40:59 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
1999-09-17 13:40:59 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
1999-09-17 13:40:59 +08: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. |
|
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 16:29:35 +08:00
|
|
|
| Author: Sascha Schumann <sascha@schumann.cx> |
|
1999-09-17 13:40:59 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2001-06-06 22:32:27 +08:00
|
|
|
/* $Id$ */
|
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
#include "php.h"
|
|
|
|
#include "php_session.h"
|
|
|
|
#include "mod_user.h"
|
|
|
|
|
|
|
|
ps_module ps_mod_user = {
|
|
|
|
PS_MOD(user)
|
|
|
|
};
|
|
|
|
|
2009-05-19 00:10:09 +08:00
|
|
|
#define SESS_ZVAL_LONG(val, a) \
|
|
|
|
{ \
|
|
|
|
MAKE_STD_ZVAL(a); \
|
|
|
|
ZVAL_LONG(a, val); \
|
1999-09-17 13:40:59 +08:00
|
|
|
}
|
|
|
|
|
2009-05-19 00:10:09 +08:00
|
|
|
#define SESS_ZVAL_STRING(vl, a) \
|
|
|
|
{ \
|
|
|
|
char *__vl = vl; \
|
|
|
|
SESS_ZVAL_STRINGN(__vl, strlen(__vl), a); \
|
1999-09-17 13:40:59 +08:00
|
|
|
}
|
|
|
|
|
2009-05-19 00:10:09 +08:00
|
|
|
#define SESS_ZVAL_STRINGN(vl, ln, a) \
|
|
|
|
{ \
|
|
|
|
MAKE_STD_ZVAL(a); \
|
|
|
|
ZVAL_STRINGL(a, vl, ln, 1); \
|
1999-09-17 13:40:59 +08:00
|
|
|
}
|
|
|
|
|
2002-03-06 19:49:51 +08:00
|
|
|
static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC)
|
1999-09-17 13:40:59 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
zval *retval = NULL;
|
2009-05-19 00:10:09 +08:00
|
|
|
|
2000-10-12 03:47:15 +08:00
|
|
|
MAKE_STD_ZVAL(retval);
|
2009-05-19 00:10:09 +08:00
|
|
|
if (call_user_function(EG(function_table), NULL, func, retval, argc, argv TSRMLS_CC) == FAILURE) {
|
2001-01-07 18:32:06 +08:00
|
|
|
zval_ptr_dtor(&retval);
|
2000-10-12 03:47:15 +08:00
|
|
|
retval = NULL;
|
1999-09-17 13:40:59 +08:00
|
|
|
}
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
for (i = 0; i < argc; i++) {
|
2001-01-07 18:32:06 +08:00
|
|
|
zval_ptr_dtor(&argv[i]);
|
1999-09-17 13:40:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-09-14 06:28:15 +08:00
|
|
|
#define STDVARS \
|
2009-05-19 00:10:09 +08:00
|
|
|
zval *retval; \
|
2008-03-08 07:20:32 +08:00
|
|
|
int ret = FAILURE
|
|
|
|
|
|
|
|
#define PSF(a) PS(mod_user_names).name.ps_##a
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2009-05-19 00:10:09 +08:00
|
|
|
#define FINISH \
|
2000-02-11 21:41:30 +08:00
|
|
|
if (retval) { \
|
1999-09-17 13:40:59 +08:00
|
|
|
convert_to_long(retval); \
|
2009-05-19 00:10:09 +08:00
|
|
|
ret = Z_LVAL_P(retval); \
|
2001-01-07 18:32:06 +08:00
|
|
|
zval_ptr_dtor(&retval); \
|
2009-05-19 00:10:09 +08:00
|
|
|
} \
|
1999-09-17 13:40:59 +08:00
|
|
|
return ret
|
|
|
|
|
|
|
|
PS_OPEN_FUNC(user)
|
|
|
|
{
|
|
|
|
zval *args[2];
|
2011-09-14 06:28:15 +08:00
|
|
|
STDVARS;
|
2012-01-29 05:02:09 +08:00
|
|
|
|
|
|
|
if (PSF(open) == NULL) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING,
|
|
|
|
"user session functions not defined");
|
|
|
|
|
|
|
|
return FAILURE;
|
|
|
|
}
|
2009-05-19 00:10:09 +08:00
|
|
|
|
|
|
|
SESS_ZVAL_STRING((char*)save_path, args[0]);
|
|
|
|
SESS_ZVAL_STRING((char*)session_name, args[1]);
|
|
|
|
|
2002-03-06 19:49:51 +08:00
|
|
|
retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC);
|
2011-09-14 06:28:15 +08:00
|
|
|
PS(mod_user_implemented) = 1;
|
2009-05-19 00:10:09 +08:00
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_CLOSE_FUNC(user)
|
|
|
|
{
|
2012-08-15 00:15:34 +08:00
|
|
|
zend_bool bailout = 0;
|
2011-09-14 06:28:15 +08:00
|
|
|
STDVARS;
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2011-09-14 06:28:15 +08:00
|
|
|
if (!PS(mod_user_implemented)) {
|
|
|
|
/* already closed */
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2012-08-15 00:15:34 +08:00
|
|
|
zend_try {
|
|
|
|
retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC);
|
|
|
|
} zend_catch {
|
|
|
|
bailout = 1;
|
|
|
|
PS(mod_user_implemented) = 0;
|
|
|
|
} zend_end_try();
|
|
|
|
|
|
|
|
if (bailout) {
|
|
|
|
if (retval) {
|
|
|
|
zval_ptr_dtor(&retval);
|
|
|
|
}
|
|
|
|
zend_bailout();
|
|
|
|
}
|
|
|
|
|
2012-08-15 00:25:06 +08:00
|
|
|
PS(mod_user_implemented) = 0;
|
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_READ_FUNC(user)
|
|
|
|
{
|
|
|
|
zval *args[1];
|
|
|
|
STDVARS;
|
|
|
|
|
2009-05-19 00:10:09 +08:00
|
|
|
SESS_ZVAL_STRING((char*)key, args[0]);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2002-03-06 19:49:51 +08:00
|
|
|
retval = ps_call_handler(PSF(read), 1, args TSRMLS_CC);
|
2009-05-19 00:10:09 +08:00
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (retval) {
|
2001-09-26 05:58:48 +08:00
|
|
|
if (Z_TYPE_P(retval) == IS_STRING) {
|
|
|
|
*val = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
|
|
|
|
*vallen = Z_STRLEN_P(retval);
|
1999-09-17 13:40:59 +08:00
|
|
|
ret = SUCCESS;
|
|
|
|
}
|
2001-01-07 18:32:06 +08:00
|
|
|
zval_ptr_dtor(&retval);
|
1999-09-17 13:40:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_WRITE_FUNC(user)
|
|
|
|
{
|
|
|
|
zval *args[2];
|
|
|
|
STDVARS;
|
2009-05-19 00:10:09 +08:00
|
|
|
|
|
|
|
SESS_ZVAL_STRING((char*)key, args[0]);
|
|
|
|
SESS_ZVAL_STRINGN((char*)val, vallen, args[1]);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2002-03-06 19:49:51 +08:00
|
|
|
retval = ps_call_handler(PSF(write), 2, args TSRMLS_CC);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_DESTROY_FUNC(user)
|
|
|
|
{
|
|
|
|
zval *args[1];
|
|
|
|
STDVARS;
|
|
|
|
|
2009-05-19 00:10:09 +08:00
|
|
|
SESS_ZVAL_STRING((char*)key, args[0]);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2002-03-06 19:49:51 +08:00
|
|
|
retval = ps_call_handler(PSF(destroy), 1, args TSRMLS_CC);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_GC_FUNC(user)
|
|
|
|
{
|
|
|
|
zval *args[1];
|
|
|
|
STDVARS;
|
|
|
|
|
2000-01-06 03:37:13 +08:00
|
|
|
SESS_ZVAL_LONG(maxlifetime, args[0]);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2002-03-06 19:49:51 +08:00
|
|
|
retval = ps_call_handler(PSF(gc), 1, args TSRMLS_CC);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
2001-06-06 22:32:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
2001-06-06 22:32:27 +08:00
|
|
|
*/
|