1999-09-17 13:40:59 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP version 4.0 |
|
|
|
|
+----------------------------------------------------------------------+
|
2001-02-26 14:11:02 +08:00
|
|
|
| Copyright (c) 1997-2001 The PHP Group |
|
1999-09-17 13:40:59 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 23:34:45 +08:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-09-17 13:40:59 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 23:34:45 +08:00
|
|
|
| http://www.php.net/license/2_02.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. |
|
|
|
|
+----------------------------------------------------------------------+
|
2000-07-10 18:09:15 +08:00
|
|
|
| Authors: 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)
|
|
|
|
};
|
|
|
|
|
2000-01-06 03:37:13 +08:00
|
|
|
#define SESS_ZVAL_LONG(val, a) \
|
1999-09-17 13:40:59 +08:00
|
|
|
{ \
|
|
|
|
MAKE_STD_ZVAL(a); \
|
|
|
|
a->type = IS_LONG; \
|
|
|
|
a->value.lval = val; \
|
|
|
|
}
|
|
|
|
|
2000-01-06 03:37:13 +08:00
|
|
|
#define SESS_ZVAL_STRING(vl, a) \
|
1999-09-17 13:40:59 +08:00
|
|
|
{ \
|
|
|
|
int len = strlen(vl); \
|
|
|
|
MAKE_STD_ZVAL(a); \
|
|
|
|
a->type = IS_STRING; \
|
|
|
|
a->value.str.len = len; \
|
|
|
|
a->value.str.val = estrndup(vl, len); \
|
|
|
|
}
|
|
|
|
|
2000-01-06 03:37:13 +08:00
|
|
|
#define SESS_ZVAL_STRINGN(vl, ln, a) \
|
1999-09-17 13:40:59 +08:00
|
|
|
{ \
|
|
|
|
MAKE_STD_ZVAL(a); \
|
|
|
|
a->type = IS_STRING; \
|
|
|
|
a->value.str.len = ln; \
|
|
|
|
a->value.str.val = estrndup(vl, ln); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-12 03:47:15 +08:00
|
|
|
static zval *ps_call_handler(zval *func, int argc, zval **argv)
|
1999-09-17 13:40:59 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
zval *retval = NULL;
|
|
|
|
ELS_FETCH();
|
|
|
|
|
2000-10-12 03:47:15 +08:00
|
|
|
MAKE_STD_ZVAL(retval);
|
|
|
|
if (call_user_function(EG(function_table), NULL, func, retval,
|
|
|
|
argc, argv) == 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define STDVARS \
|
|
|
|
zval *retval; \
|
|
|
|
int ret = FAILURE; \
|
|
|
|
ps_user *mdata = PS_GET_MOD_DATA(); \
|
2000-02-11 21:41:30 +08:00
|
|
|
if (!mdata) \
|
|
|
|
return FAILURE
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
#define PSF(a) mdata->name.ps_##a
|
|
|
|
|
|
|
|
#define FINISH \
|
2000-02-11 21:41:30 +08:00
|
|
|
if (retval) { \
|
1999-09-17 13:40:59 +08:00
|
|
|
convert_to_long(retval); \
|
|
|
|
ret = retval->value.lval; \
|
2001-01-07 18:32:06 +08:00
|
|
|
zval_ptr_dtor(&retval); \
|
1999-09-17 13:40:59 +08:00
|
|
|
} \
|
|
|
|
return ret
|
|
|
|
|
|
|
|
PS_OPEN_FUNC(user)
|
|
|
|
{
|
|
|
|
zval *args[2];
|
|
|
|
STDVARS;
|
|
|
|
|
2000-01-06 03:37:13 +08:00
|
|
|
SESS_ZVAL_STRING(save_path, args[0]);
|
|
|
|
SESS_ZVAL_STRING(session_name, args[1]);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
retval = ps_call_handler(PSF(open), 2, args);
|
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_CLOSE_FUNC(user)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
STDVARS;
|
|
|
|
|
|
|
|
retval = ps_call_handler(PSF(close), 0, NULL);
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
for (i = 0; i < 6; i++)
|
2001-02-28 04:16:35 +08:00
|
|
|
zval_ptr_dtor(&mdata->names[i]);
|
1999-09-17 13:40:59 +08:00
|
|
|
efree(mdata);
|
|
|
|
|
|
|
|
PS_SET_MOD_DATA(NULL);
|
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_READ_FUNC(user)
|
|
|
|
{
|
|
|
|
zval *args[1];
|
|
|
|
STDVARS;
|
|
|
|
|
2000-01-06 03:37:13 +08:00
|
|
|
SESS_ZVAL_STRING(key, args[0]);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
retval = ps_call_handler(PSF(read), 1, args);
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (retval) {
|
|
|
|
if (retval->type == IS_STRING) {
|
1999-09-17 13:40:59 +08:00
|
|
|
*val = estrndup(retval->value.str.val, retval->value.str.len);
|
|
|
|
*vallen = retval->value.str.len;
|
|
|
|
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;
|
|
|
|
|
2000-01-06 03:37:13 +08:00
|
|
|
SESS_ZVAL_STRING(key, args[0]);
|
|
|
|
SESS_ZVAL_STRINGN(val, vallen, args[1]);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
retval = ps_call_handler(PSF(write), 2, args);
|
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_DESTROY_FUNC(user)
|
|
|
|
{
|
|
|
|
zval *args[1];
|
|
|
|
STDVARS;
|
|
|
|
|
2000-01-06 03:37:13 +08:00
|
|
|
SESS_ZVAL_STRING(key, args[0]);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
retval = ps_call_handler(PSF(destroy), 1, args);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
retval = ps_call_handler(PSF(gc), 1, args);
|
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
2001-06-06 22:32:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: sw=4 ts=4 tw=78 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4 tw=78
|
|
|
|
*/
|