File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / session / mod_user.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:34:42 2012 UTC (12 years, 2 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_17p0, HEAD
php 5.4.3+patches

    1: /* 
    2:    +----------------------------------------------------------------------+
    3:    | PHP Version 5                                                        |
    4:    +----------------------------------------------------------------------+
    5:    | Copyright (c) 1997-2012 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,v 1.1.1.2 2012/05/29 12:34:42 misho Exp $ */
   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: {
   49: 	int i;
   50: 	zval *retval = NULL;
   51: 
   52: 	MAKE_STD_ZVAL(retval);
   53: 	if (call_user_function(EG(function_table), NULL, func, retval, argc, argv TSRMLS_CC) == FAILURE) {
   54: 		zval_ptr_dtor(&retval);
   55: 		retval = NULL;
   56: 	}
   57: 
   58: 	for (i = 0; i < argc; i++) {
   59: 		zval_ptr_dtor(&argv[i]);
   60: 	}
   61: 
   62: 	return retval;
   63: }
   64: 
   65: #define STDVARS								\
   66: 	zval *retval;							\
   67: 	int ret = FAILURE
   68: 
   69: #define PSF(a) PS(mod_user_names).name.ps_##a
   70: 
   71: #define FINISH								\
   72: 	if (retval) {							\
   73: 		convert_to_long(retval);			\
   74: 		ret = Z_LVAL_P(retval);				\
   75: 		zval_ptr_dtor(&retval);				\
   76: 	}										\
   77: 	return ret
   78: 
   79: PS_OPEN_FUNC(user)
   80: {
   81: 	zval *args[2];
   82: 	STDVARS;
   83: 	
   84: 	if (PSF(open) == NULL) {
   85: 		php_error_docref(NULL TSRMLS_CC, E_WARNING,
   86: 			"user session functions not defined");
   87: 			
   88: 		return FAILURE;
   89: 	}
   90: 
   91: 	SESS_ZVAL_STRING((char*)save_path, args[0]);
   92: 	SESS_ZVAL_STRING((char*)session_name, args[1]);
   93: 
   94: 	retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC);
   95: 	PS(mod_user_implemented) = 1;
   96: 
   97: 	FINISH;
   98: }
   99: 
  100: PS_CLOSE_FUNC(user)
  101: {
  102: 	STDVARS;
  103: 
  104: 	if (!PS(mod_user_implemented)) {
  105: 		/* already closed */
  106: 		return SUCCESS;
  107: 	}
  108: 
  109: 	retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC);
  110: 	PS(mod_user_implemented) = 0;
  111: 
  112: 	FINISH;
  113: }
  114: 
  115: PS_READ_FUNC(user)
  116: {
  117: 	zval *args[1];
  118: 	STDVARS;
  119: 
  120: 	SESS_ZVAL_STRING((char*)key, args[0]);
  121: 
  122: 	retval = ps_call_handler(PSF(read), 1, args TSRMLS_CC);
  123: 
  124: 	if (retval) {
  125: 		if (Z_TYPE_P(retval) == IS_STRING) {
  126: 			*val = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
  127: 			*vallen = Z_STRLEN_P(retval);
  128: 			ret = SUCCESS;
  129: 		}
  130: 		zval_ptr_dtor(&retval);
  131: 	}
  132: 
  133: 	return ret;
  134: }
  135: 
  136: PS_WRITE_FUNC(user)
  137: {
  138: 	zval *args[2];
  139: 	STDVARS;
  140: 
  141: 	SESS_ZVAL_STRING((char*)key, args[0]);
  142: 	SESS_ZVAL_STRINGN((char*)val, vallen, args[1]);
  143: 
  144: 	retval = ps_call_handler(PSF(write), 2, args TSRMLS_CC);
  145: 
  146: 	FINISH;
  147: }
  148: 
  149: PS_DESTROY_FUNC(user)
  150: {
  151: 	zval *args[1];
  152: 	STDVARS;
  153: 
  154: 	SESS_ZVAL_STRING((char*)key, args[0]);
  155: 
  156: 	retval = ps_call_handler(PSF(destroy), 1, args TSRMLS_CC);
  157: 
  158: 	FINISH;
  159: }
  160: 
  161: PS_GC_FUNC(user)
  162: {
  163: 	zval *args[1];
  164: 	STDVARS;
  165: 
  166: 	SESS_ZVAL_LONG(maxlifetime, args[0]);
  167: 
  168: 	retval = ps_call_handler(PSF(gc), 1, args TSRMLS_CC);
  169: 
  170: 	FINISH;
  171: }
  172: 
  173: /*
  174:  * Local variables:
  175:  * tab-width: 4
  176:  * c-basic-offset: 4
  177:  * End:
  178:  * vim600: sw=4 ts=4 fdm=marker
  179:  * vim<600: sw=4 ts=4
  180:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>