1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.txt |
11 : | If you did not receive a copy of the PHP license and are unable to |
12 : | obtain it through the world-wide-web, please send a note to |
13 : | license@php.net so we can mail you a copy immediately. |
14 : +----------------------------------------------------------------------+
15 : | Author: Sascha Schumann <sascha@schumann.cx> |
16 : +----------------------------------------------------------------------+
17 : */
18 :
19 : /* $Id: mod_user.c 280733 2009-05-18 17:23:42Z jani $ */
20 :
21 : #include "php.h"
22 : #include "php_session.h"
23 : #include "mod_user.h"
24 :
25 : ps_module ps_mod_user = {
26 : PS_MOD(user)
27 : };
28 :
29 : #define SESS_ZVAL_LONG(val, a) \
30 : { \
31 : MAKE_STD_ZVAL(a); \
32 : ZVAL_LONG(a, val); \
33 : }
34 :
35 : #define SESS_ZVAL_STRING(vl, a) \
36 : { \
37 : char *__vl = vl; \
38 : SESS_ZVAL_STRINGN(__vl, strlen(__vl), a); \
39 : }
40 :
41 : #define SESS_ZVAL_STRINGN(vl, ln, a) \
42 : { \
43 : MAKE_STD_ZVAL(a); \
44 : ZVAL_STRINGL(a, vl, ln, 1); \
45 : }
46 :
47 : static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC)
48 79 : {
49 : int i;
50 79 : zval *retval = NULL;
51 :
52 79 : MAKE_STD_ZVAL(retval);
53 79 : if (call_user_function(EG(function_table), NULL, func, retval, argc, argv TSRMLS_CC) == FAILURE) {
54 2 : zval_ptr_dtor(&retval);
55 2 : retval = NULL;
56 : }
57 :
58 170 : for (i = 0; i < argc; i++) {
59 91 : zval_ptr_dtor(&argv[i]);
60 : }
61 :
62 79 : return retval;
63 : }
64 :
65 : #define STDVARS \
66 : zval *retval; \
67 : int ret = FAILURE; \
68 : ps_user *mdata = PS_GET_MOD_DATA(); \
69 : if (!mdata) \
70 : return FAILURE
71 :
72 : #define PSF(a) mdata->name.ps_##a
73 :
74 : #define FINISH \
75 : if (retval) { \
76 : convert_to_long(retval); \
77 : ret = Z_LVAL_P(retval); \
78 : zval_ptr_dtor(&retval); \
79 : } \
80 : return ret
81 :
82 : PS_OPEN_FUNC(user)
83 19 : {
84 : zval *args[2];
85 19 : STDVARS;
86 :
87 19 : SESS_ZVAL_STRING((char*)save_path, args[0]);
88 19 : SESS_ZVAL_STRING((char*)session_name, args[1]);
89 :
90 19 : retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC);
91 :
92 19 : FINISH;
93 : }
94 :
95 : PS_CLOSE_FUNC(user)
96 20 : {
97 : int i;
98 20 : STDVARS;
99 :
100 20 : retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC);
101 :
102 140 : for (i = 0; i < 6; i++) {
103 120 : zval_ptr_dtor(&mdata->names[i]);
104 : }
105 20 : efree(mdata);
106 :
107 20 : PS_SET_MOD_DATA(NULL);
108 :
109 20 : FINISH;
110 : }
111 :
112 : PS_READ_FUNC(user)
113 19 : {
114 : zval *args[1];
115 19 : STDVARS;
116 :
117 19 : SESS_ZVAL_STRING((char*)key, args[0]);
118 :
119 19 : retval = ps_call_handler(PSF(read), 1, args TSRMLS_CC);
120 :
121 19 : if (retval) {
122 17 : if (Z_TYPE_P(retval) == IS_STRING) {
123 14 : *val = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
124 14 : *vallen = Z_STRLEN_P(retval);
125 14 : ret = SUCCESS;
126 : }
127 17 : zval_ptr_dtor(&retval);
128 : }
129 :
130 19 : return ret;
131 : }
132 :
133 : PS_WRITE_FUNC(user)
134 13 : {
135 : zval *args[2];
136 13 : STDVARS;
137 :
138 13 : SESS_ZVAL_STRING((char*)key, args[0]);
139 13 : SESS_ZVAL_STRINGN((char*)val, vallen, args[1]);
140 :
141 13 : retval = ps_call_handler(PSF(write), 2, args TSRMLS_CC);
142 :
143 13 : FINISH;
144 : }
145 :
146 : PS_DESTROY_FUNC(user)
147 6 : {
148 : zval *args[1];
149 6 : STDVARS;
150 :
151 6 : SESS_ZVAL_STRING((char*)key, args[0]);
152 :
153 6 : retval = ps_call_handler(PSF(destroy), 1, args TSRMLS_CC);
154 :
155 6 : FINISH;
156 : }
157 :
158 : PS_GC_FUNC(user)
159 2 : {
160 : zval *args[1];
161 2 : STDVARS;
162 :
163 2 : SESS_ZVAL_LONG(maxlifetime, args[0]);
164 :
165 2 : retval = ps_call_handler(PSF(gc), 1, args TSRMLS_CC);
166 :
167 2 : FINISH;
168 : }
169 :
170 : /*
171 : * Local variables:
172 : * tab-width: 4
173 : * c-basic-offset: 4
174 : * End:
175 : * vim600: sw=4 ts=4 fdm=marker
176 : * vim<600: sw=4 ts=4
177 : */
|