Back to index

php5  5.3.10
mod_user.c
Go to the documentation of this file.
00001 /* 
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author: Sascha Schumann <sascha@schumann.cx>                         |
00016    +----------------------------------------------------------------------+
00017  */
00018 
00019 /* $Id: mod_user.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #include "php.h"
00022 #include "php_session.h"
00023 #include "mod_user.h"
00024 
00025 ps_module ps_mod_user = {
00026        PS_MOD(user)
00027 };
00028 
00029 #define SESS_ZVAL_LONG(val, a)                                        \
00030 {                                                                                          \
00031        MAKE_STD_ZVAL(a);                                                     \
00032        ZVAL_LONG(a, val);                                                    \
00033 }
00034 
00035 #define SESS_ZVAL_STRING(vl, a)                                       \
00036 {                                                                                          \
00037        char *__vl = vl;                                                      \
00038        SESS_ZVAL_STRINGN(__vl, strlen(__vl), a);        \
00039 }
00040 
00041 #define SESS_ZVAL_STRINGN(vl, ln, a)                           \
00042 {                                                                                          \
00043        MAKE_STD_ZVAL(a);                                                     \
00044        ZVAL_STRINGL(a, vl, ln, 1);                                    \
00045 }
00046 
00047 static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC)
00048 {
00049        int i;
00050        zval *retval = NULL;
00051 
00052        MAKE_STD_ZVAL(retval);
00053        if (call_user_function(EG(function_table), NULL, func, retval, argc, argv TSRMLS_CC) == FAILURE) {
00054               zval_ptr_dtor(&retval);
00055               retval = NULL;
00056        }
00057 
00058        for (i = 0; i < argc; i++) {
00059               zval_ptr_dtor(&argv[i]);
00060        }
00061 
00062        return retval;
00063 }
00064 
00065 #define STDVARS1                                               \
00066        zval *retval;                                           \
00067        int ret = FAILURE
00068 
00069 #define STDVARS                                                       \
00070        STDVARS1;                                                      \
00071        char *mdata = PS_GET_MOD_DATA();          \
00072        if (!mdata) { return FAILURE; }
00073 
00074 #define PSF(a) PS(mod_user_names).name.ps_##a
00075 
00076 #define FINISH                                                        \
00077        if (retval) {                                           \
00078               convert_to_long(retval);                  \
00079               ret = Z_LVAL_P(retval);                          \
00080               zval_ptr_dtor(&retval);                          \
00081        }                                                                     \
00082        return ret
00083 
00084 PS_OPEN_FUNC(user)
00085 {
00086        zval *args[2];
00087        static char dummy = 0;
00088        STDVARS1;
00089 
00090        SESS_ZVAL_STRING((char*)save_path, args[0]);
00091        SESS_ZVAL_STRING((char*)session_name, args[1]);
00092 
00093        retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC);
00094        if (retval) {
00095               /* This is necessary to fool the session module. Yes, it's safe to
00096                * use a static. Neither mod_user nor the session module itself will
00097                * ever touch this pointer. It could be set to 0xDEADBEEF for all the
00098                * difference it makes, but for the sake of paranoia it's set to some
00099                * valid value. */
00100               PS_SET_MOD_DATA(&dummy);
00101        }
00102 
00103        FINISH;
00104 }
00105 
00106 PS_CLOSE_FUNC(user)
00107 {
00108        STDVARS1;
00109 
00110        retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC);
00111 
00112        PS_SET_MOD_DATA(NULL);
00113 
00114        FINISH;
00115 }
00116 
00117 PS_READ_FUNC(user)
00118 {
00119        zval *args[1];
00120        STDVARS;
00121 
00122        SESS_ZVAL_STRING((char*)key, args[0]);
00123 
00124        retval = ps_call_handler(PSF(read), 1, args TSRMLS_CC);
00125 
00126        if (retval) {
00127               if (Z_TYPE_P(retval) == IS_STRING) {
00128                      *val = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
00129                      *vallen = Z_STRLEN_P(retval);
00130                      ret = SUCCESS;
00131               }
00132               zval_ptr_dtor(&retval);
00133        }
00134 
00135        return ret;
00136 }
00137 
00138 PS_WRITE_FUNC(user)
00139 {
00140        zval *args[2];
00141        STDVARS;
00142 
00143        SESS_ZVAL_STRING((char*)key, args[0]);
00144        SESS_ZVAL_STRINGN((char*)val, vallen, args[1]);
00145 
00146        retval = ps_call_handler(PSF(write), 2, args TSRMLS_CC);
00147 
00148        FINISH;
00149 }
00150 
00151 PS_DESTROY_FUNC(user)
00152 {
00153        zval *args[1];
00154        STDVARS;
00155 
00156        SESS_ZVAL_STRING((char*)key, args[0]);
00157 
00158        retval = ps_call_handler(PSF(destroy), 1, args TSRMLS_CC);
00159 
00160        FINISH;
00161 }
00162 
00163 PS_GC_FUNC(user)
00164 {
00165        zval *args[1];
00166        STDVARS;
00167 
00168        SESS_ZVAL_LONG(maxlifetime, args[0]);
00169 
00170        retval = ps_call_handler(PSF(gc), 1, args TSRMLS_CC);
00171 
00172        FINISH;
00173 }
00174 
00175 /*
00176  * Local variables:
00177  * tab-width: 4
00178  * c-basic-offset: 4
00179  * End:
00180  * vim600: sw=4 ts=4 fdm=marker
00181  * vim<600: sw=4 ts=4
00182  */