cvs: /php4/ext/session mod_mm.c mod_mm.h /php4/ext/session Makefile.am config.h.stub config.m4 mod_files.c modules.c php_session.h session.c

From: Date: Fri, 27 Aug 1999 21:03:22 +0000
Subject: cvs: /php4/ext/session mod_mm.c mod_mm.h /php4/ext/session Makefile.am config.h.stub config.m4 mod_files.c modules.c php_session.h session.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-3789@lists.php.net to get a copy of this message
sas Fri Aug 27 17:03:22 1999 EDT Added files: /php4/ext/session mod_mm.c mod_mm.h Modified files: /php4/ext/session Makefile.am config.h.stub config.m4 mod_files.c modules.c php_session.h session.c Log: - fix potential buffer problem in send_cookie - fix gc probability algorithm - don't access mod_data directly - initial version of mm support for session data storage This works pretty good, but we need to create the initial mm pool from the parent process/thread. Still looking for a clean way to do that. Index: php4/ext/session/Makefile.am diff -u php4/ext/session/Makefile.am:1.1 php4/ext/session/Makefile.am:1.2 --- php4/ext/session/Makefile.am:1.1 Sat Jun 5 15:52:58 1999 +++ php4/ext/session/Makefile.am Fri Aug 27 17:03:21 1999 @@ -1,6 +1,6 @@ -# $Id: Makefile.am,v 1.1 1999/06/05 19:52:58 sas Exp $ +# $Id: Makefile.am,v 1.2 1999/08/27 21:03:21 sas Exp $ INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend noinst_LIBRARIES=libphpext_session.a -libphpext_session_a_SOURCES=session.c mod_files.c +libphpext_session_a_SOURCES=session.c mod_files.c mod_mm.c Index: php4/ext/session/config.h.stub diff -u php4/ext/session/config.h.stub:1.1 php4/ext/session/config.h.stub:1.2 --- php4/ext/session/config.h.stub:1.1 Sat Jun 5 15:52:58 1999 +++ php4/ext/session/config.h.stub Fri Aug 27 17:03:22 1999 @@ -1,2 +1,3 @@ /* define if you want to use the session extension */ -/* #undef HAVE_LIBSESSION */ + +#undef HAVE_LIBMM Index: php4/ext/session/config.m4 diff -u php4/ext/session/config.m4:1.1 php4/ext/session/config.m4:1.2 --- php4/ext/session/config.m4:1.1 Sat Jun 5 15:52:58 1999 +++ php4/ext/session/config.m4 Fri Aug 27 17:03:22 1999 @@ -1,5 +1,30 @@ -dnl $Id: config.m4,v 1.1 1999/06/05 19:52:58 sas Exp $ +dnl $Id: config.m4,v 1.2 1999/08/27 21:03:22 sas Exp $ dnl config.m4 for extension session dnl don't forget to call PHP_EXTENSION(session) + + +MM_RESULT=no +AC_MSG_CHECKING(for mm support) +AC_ARG_WITH(mm, +[ --with-mm[=DIR] Include mm support], +[ + if test "$withval" != "no"; then + for i in /usr/local /usr $withval; do + if test -f "$i/include/mm.h"; then + MM_DIR="$i" + fi + done + + if test -z "$MM_DIR" ; then + AC_MSG_ERROR(cannot find mm library) + fi + + AC_ADD_LIBRARY_WITH_PATH(mm, $MM_DIR/lib) + AC_ADD_INCLUDE($MM_DIR/include) + AC_DEFINE(HAVE_LIBMM, 1) + MM_RESULT=yes + fi +]) +AC_MSG_RESULT($MM_RESULT) PHP_EXTENSION(session) Index: php4/ext/session/mod_files.c diff -u php4/ext/session/mod_files.c:1.11 php4/ext/session/mod_files.c:1.12 --- php4/ext/session/mod_files.c:1.11 Sun Aug 22 10:14:46 1999 +++ php4/ext/session/mod_files.c Fri Aug 27 17:03:22 1999 @@ -43,7 +43,7 @@ PS_MOD(files) }; -#define PS_FILES_DATA ps_files *data = *mod_data +#define PS_FILES_DATA ps_files *data = PS_GET_MOD_DATA() PS_OPEN_FUNC(files) { @@ -51,7 +51,7 @@ char *p; data = ecalloc(sizeof(*data), 1); - *mod_data = data; + PS_SET_MOD_DATA(data); data->fd = -1; if((p = strchr(save_path, ':'))) { Index: php4/ext/session/modules.c diff -u php4/ext/session/modules.c:1.1 php4/ext/session/modules.c:1.2 --- php4/ext/session/modules.c:1.1 Sat Jun 5 15:52:58 1999 +++ php4/ext/session/modules.c Fri Aug 27 17:03:22 1999 @@ -4,9 +4,10 @@ */ #include "mod_files.h" +#include "mod_mm.h" static ps_module *ps_modules[] = { ps_files_ptr, - 0, + ps_mm_ptr, }; Index: php4/ext/session/php_session.h diff -u php4/ext/session/php_session.h:1.10 php4/ext/session/php_session.h:1.11 --- php4/ext/session/php_session.h:1.10 Sat Aug 21 16:48:40 1999 +++ php4/ext/session/php_session.h Fri Aug 27 17:03:22 1999 @@ -57,6 +57,8 @@ int (*gc)(PS_GC_ARGS); } ps_module; +#define PS_GET_MOD_DATA() *mod_data +#define PS_SET_MOD_DATA(a) *mod_data = (a) #define PS_OPEN_FUNC(x) int _ps_open_##x(PS_OPEN_ARGS) #define PS_CLOSE_FUNC(x) int _ps_close_##x(PS_CLOSE_ARGS) Index: php4/ext/session/session.c diff -u php4/ext/session/session.c:1.35 php4/ext/session/session.c:1.36 --- php4/ext/session/session.c:1.35 Mon Aug 23 11:37:11 1999 +++ php4/ext/session/session.c Fri Aug 27 17:03:22 1999 @@ -21,7 +21,6 @@ * TODO: * - add complete support for objects (partially implemented) * - userland callback functions for ps_module - * - write ps_module utilizing shared memory (mm) */ #if !(WIN32|WINNT) #include <sys/time.h> @@ -279,9 +278,10 @@ date_fmt = php3_std_date(time(NULL) + PS(lifetime)); len += sizeof(COOKIE_EXPIRES) + strlen(date_fmt); } - cookie = emalloc(len + 1); + cookie = ecalloc(len + 1, 1); snprintf(cookie, len, COOKIE_FMT, PS(session_name), PS(id)); + cookie[len] = '\0'; if (PS(lifetime) > 0) { strcat(cookie, COOKIE_EXPIRES); strcat(cookie, date_fmt); @@ -295,8 +295,9 @@ { ps_module *ret = NULL; ps_module **mod; + ps_module **end = ps_modules + (sizeof(ps_modules)/sizeof(ps_module*)); - for(mod = ps_modules; ((*mod && (*mod)->name) || !*mod); mod++) { + for(mod = ps_modules; mod < end; mod++) { if(*mod && !strcasecmp(name, (*mod)->name)) { ret = *mod; break; @@ -333,7 +334,7 @@ int lensess; ELS_FETCH(); - if (PS(nr_open_sessions) > 0) return; + if (PS(nr_open_sessions) != 0) return; lensess = strlen(PS(session_name)); @@ -419,7 +420,7 @@ if(PS(mod_data) && PS(gc_probability) > 0) { srand(time(NULL)); nrand = (int) (100.0*rand()/RAND_MAX); - if(nrand >= PS(gc_probability)) + if(nrand < PS(gc_probability)) PS(mod)->gc(&PS(mod_data), PS(gc_maxlifetime)); } } @@ -694,11 +695,15 @@ php_rinit_session_globals(PSLS_C); + if(PS(mod) == NULL) { + /* current status is unusable */ + PS(nr_open_sessions) = -1; + return FAILURE; + } + if(INI_INT("session_auto_start")) { _php_session_start(PSLS_C); } - if(PS(mod) == NULL) - return FAILURE; return SUCCESS; }

« previous php.version4 (#3789) next »