1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2010 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: Sascha Schumann <sascha@schumann.cx> |
+----------------------------------------------------------------------+
*/
/* $Id: mod_user.c 293036 2010-01-03 09:23:27Z sebastian $ */
#include "php.h"
#include "php_session.h"
#include "mod_user.h"
ps_module ps_mod_user = {
PS_MOD(user)
};
#define SESS_ZVAL_LONG(val, a) \
{ \
MAKE_STD_ZVAL(a); \
ZVAL_LONG(a, val); \
}
#define SESS_ZVAL_STRING(vl, a) \
{ \
char *__vl = vl; \
SESS_ZVAL_STRINGN(__vl, strlen(__vl), a); \
}
#define SESS_ZVAL_STRINGN(vl, ln, a) \
{ \
MAKE_STD_ZVAL(a); \
ZVAL_STRINGL(a, vl, ln, 1); \
}
static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC)
{
int i;
zval *retval = NULL;
MAKE_STD_ZVAL(retval);
if (call_user_function(EG(function_table), NULL, func, retval, argc, argv TSRMLS_CC) == FAILURE) {
zval_ptr_dtor(&retval);
retval = NULL;
}
for (i = 0; i < argc; i++) {
zval_ptr_dtor(&argv[i]);
}
return retval;
}
#define STDVARS1 \
zval *retval; \
int ret = FAILURE
#define STDVARS \
STDVARS1; \
char *mdata = PS_GET_MOD_DATA(); \
if (!mdata) { return FAILURE; }
#define PSF(a) PS(mod_user_names).name.ps_##a
#define FINISH \
if (retval) { \
convert_to_long(retval); \
ret = Z_LVAL_P(retval); \
zval_ptr_dtor(&retval); \
} \
return ret
PS_OPEN_FUNC(user)
{
zval *args[2];
static char dummy = 0;
STDVARS1;
SESS_ZVAL_STRING((char*)save_path, args[0]);
SESS_ZVAL_STRING((char*)session_name, args[1]);
retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC);
if (retval) {
/* This is necessary to fool the session module. Yes, it's safe to
* use a static. Neither mod_user nor the session module itself will
* ever touch this pointer. It could be set to 0xDEADBEEF for all the
* difference it makes, but for the sake of paranoia it's set to some
* valid value. */
PS_SET_MOD_DATA(&dummy);
}
FINISH;
}
PS_CLOSE_FUNC(user)
{
STDVARS1;
retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC);
PS_SET_MOD_DATA(NULL);
FINISH;
}
PS_READ_FUNC(user)
{
zval *args[1];
STDVARS;
SESS_ZVAL_STRING((char*)key, args[0]);
retval = ps_call_handler(PSF(read), 1, args TSRMLS_CC);
if (retval) {
if (Z_TYPE_P(retval) == IS_STRING) {
*val = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
*vallen = Z_STRLEN_P(retval);
ret = SUCCESS;
}
zval_ptr_dtor(&retval);
}
return ret;
}
PS_WRITE_FUNC(user)
{
zval *args[2];
STDVARS;
SESS_ZVAL_STRING((char*)key, args[0]);
SESS_ZVAL_STRINGN((char*)val, vallen, args[1]);
retval = ps_call_handler(PSF(write), 2, args TSRMLS_CC);
FINISH;
}
PS_DESTROY_FUNC(user)
{
zval *args[1];
STDVARS;
SESS_ZVAL_STRING((char*)key, args[0]);
retval = ps_call_handler(PSF(destroy), 1, args TSRMLS_CC);
FINISH;
}
PS_GC_FUNC(user)
{
zval *args[1];
STDVARS;
SESS_ZVAL_LONG(maxlifetime, args[0]);
retval = ps_call_handler(PSF(gc), 1, args TSRMLS_CC);
FINISH;
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/
|