cvs: /php4 ChangeLog SAPI.c acinclude.m4 genif.sh internal_functions.c.in main.c php.h /php4/ext/session config.m4 mod_mm.c mod_mm.h session.c
| From: | Sascha Schumann | Date: | Fri, 03 Sep 1999 17:46:39 +0000 |
| Subject: | cvs: /php4 ChangeLog SAPI.c acinclude.m4 genif.sh internal_functions.c.in main.c php.h /php4/ext/session config.m4 mod_mm.c mod_mm.h session.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-4054@lists.php.net to get a copy of this message | ||
sas Fri Sep 3 13:46:39 1999 EDT
Modified files:
/php4 ChangeLog SAPI.c acinclude.m4 genif.sh
internal_functions.c.in main.c php.h
/php4/ext/session config.m4 mod_mm.c mod_mm.h session.c
Log:
- add global startup/shutdown handlers
- improve genif.sh to also consider all header files for inclusion
(checks for phpext_)
- use vsnprintf in main.c to avoid buffer overflows
- improve sessions's mm module to cope better with OOM situations
within the shared memory segment
- fix typo wrt session.auto_start
Index: php4/ChangeLog
diff -u php4/ChangeLog:1.78 php4/ChangeLog:1.79
--- php4/ChangeLog:1.78 Thu Sep 2 22:39:35 1999
+++ php4/ChangeLog Fri Sep 3 13:46:38 1999
@@ -2,6 +2,8 @@
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ?? 1999, Version 4.0 Beta 3
+- Added shared memory module for session data storage (Sascha)
+- Fixed session.auto_start (Sascha)
- Fixed several problems with output buffering and HEAD requests (Zeev)
- Fixed HTTP Status code issue with ISAPI module (Zeev)
- Fixed a problem that prevented $GLOBALS from working properly (Zeev, Zend
Index: php4/SAPI.c
diff -u php4/SAPI.c:1.27 php4/SAPI.c:1.28
--- php4/SAPI.c:1.27 Mon Aug 9 13:40:28 1999
+++ php4/SAPI.c Fri Sep 3 13:46:39 1999
@@ -75,11 +75,13 @@
#ifdef ZTS
sapi_globals_id = ts_allocate_id(sizeof(sapi_globals_struct), NULL, NULL);
#endif
-}
+ module_global_startup_modules();
+}
SAPI_API void sapi_shutdown()
{
+ module_global_shutdown_modules();
zend_hash_destroy(&known_post_content_types);
}
Index: php4/acinclude.m4
diff -u php4/acinclude.m4:1.24 php4/acinclude.m4:1.25
--- php4/acinclude.m4:1.24 Sun Aug 22 14:47:27 1999
+++ php4/acinclude.m4 Fri Sep 3 13:46:39 1999
@@ -1,4 +1,4 @@
-dnl $Id: acinclude.m4,v 1.24 1999/08/22 18:47:27 sas Exp $
+dnl $Id: acinclude.m4,v 1.25 1999/09/03 17:46:39 sas Exp $
dnl
dnl This file contains local autoconf functions.
@@ -141,6 +141,7 @@
dnl to make dynamic libraries as well.
dnl
AC_DEFUN(PHP_EXTENSION,[
+ if test -d "$cwd/$srcdir/ext/$1" ; then
EXT_SUBDIRS="$EXT_SUBDIRS $1"
if test "$2" != "shared" -a "$2" != "yes"; then
_extlib="libphpext_$1.a"
@@ -153,6 +154,7 @@
dnl EXT_INCLUDE_CODE="\#include \"ext/$1/php3_$1.h\"\\n$EXT_INCLUDE_CODE"
dnl EXT_MODULE_PTRS="phpext_$1_ptr, $EXT_MODULE_PTRS"
dnl "
+ fi
])
AC_SUBST(EXT_SUBDIRS)
Index: php4/genif.sh
diff -u php4/genif.sh:1.6 php4/genif.sh:1.7
--- php4/genif.sh:1.6 Fri May 21 06:05:41 1999
+++ php4/genif.sh Fri Sep 3 13:46:39 1999
@@ -1,6 +1,6 @@
#! /bin/sh
-# $Id: genif.sh,v 1.6 1999/05/21 10:05:41 sas Exp $
+# $Id: genif.sh,v 1.7 1999/09/03 17:46:39 sas Exp $
# replacement for genif.pl
infile="$1"
@@ -16,15 +16,19 @@
module_ptrs=""
includes=""
+olddir=
pwd
+cd $srcdir
+
for ext in ${1+"$@"} ; do
module_ptrs=" phpext_${ext}_ptr,\\\n$module_ptrs"
- for pre in php3_ php_ php4_ zend_ "" ; do
- hdrfile="ext/$ext/${pre}${ext}.h"
- if test -f "$srcdir/$hdrfile" ; then
- includes="#include \"$hdrfile\"\\\n$includes"
+ for header in ext/$ext/*.h ; do
+ if grep phpext_ $header >/dev/null 2>&1 ; then
+ includes="#include \"$header\"\\\n$includes"
fi
done
done
+
+cd $olddir
cat $infile | \
sed \
Index: php4/internal_functions.c.in
diff -u php4/internal_functions.c.in:1.4 php4/internal_functions.c.in:1.5
--- php4/internal_functions.c.in:1.4 Sun Aug 29 16:12:12 1999
+++ php4/internal_functions.c.in Fri Sep 3 13:46:39 1999
@@ -29,7 +29,7 @@
*/
-/* $Id: internal_functions.c.in,v 1.4 1999/08/29 20:12:12 ssb Exp $ */
+/* $Id: internal_functions.c.in,v 1.5 1999/09/03 17:46:39 sas Exp $ */
#include "php.h"
@@ -80,7 +80,7 @@
@EXT_MODULE_PTRS@
};
-
+
int module_startup_modules(void)
{
zend_module_entry **ptr = php3_builtin_modules, **end =
ptr+(sizeof(php3_builtin_modules)/sizeof(zend_module_entry *));
@@ -96,6 +96,37 @@
return SUCCESS;
}
+int module_global_startup_modules(void)
+{
+ zend_module_entry **ptr = php3_builtin_modules, **end =
ptr+(sizeof(php3_builtin_modules)/sizeof(zend_module_entry *));
+
+ while (ptr < end) {
+ if (*ptr) {
+ if ((*ptr)->global_startup_func &&
+ (*ptr)->global_startup_func()==FAILURE) {
+ return FAILURE;
+ }
+ }
+ ptr++;
+ }
+ return SUCCESS;
+}
+
+int module_global_shutdown_modules(void)
+{
+ zend_module_entry **ptr = php3_builtin_modules, **end =
ptr+(sizeof(php3_builtin_modules)/sizeof(zend_module_entry *));
+
+ while (ptr < end) {
+ if (*ptr) {
+ if ((*ptr)->global_shutdown_func &&
+ (*ptr)->global_shutdown_func()==FAILURE) {
+ return FAILURE;
+ }
+ }
+ ptr++;
+ }
+ return SUCCESS;
+}
/*
* Local variables:
Index: php4/main.c
diff -u php4/main.c:1.107 php4/main.c:1.108
--- php4/main.c:1.107 Thu Sep 2 22:39:35 1999
+++ php4/main.c Fri Sep 3 13:46:39 1999
@@ -19,7 +19,7 @@
*/
-/* $Id: main.c,v 1.107 1999/09/03 02:39:35 zeev Exp $ */
+/* $Id: main.c,v 1.108 1999/09/03 17:46:39 sas Exp $ */
#include <stdio.h>
@@ -325,7 +325,7 @@
int size;
va_start(args, format);
- size = vsprintf(buffer, format, args);
+ size = vsnprintf(buffer, sizeof(buffer), format, args);
ret = PHPWRITE(buffer, size);
va_end(args);
Index: php4/php.h
diff -u php4/php.h:1.25 php4/php.h:1.26
--- php4/php.h:1.25 Sat Aug 14 12:52:28 1999
+++ php4/php.h Fri Sep 3 13:46:39 1999
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php.h,v 1.25 1999/08/14 16:52:28 zeev Exp $ */
+/* $Id: php.h,v 1.26 1999/09/03 17:46:39 sas Exp $ */
#ifndef _PHP_H
#define _PHP_H
@@ -259,12 +259,16 @@
#define PHP_RINIT(module) php3_rinit_##module
#define PHP_RSHUTDOWN(module) php3_rshutdown_##module
#define PHP_MINFO(module) php3_info_##module
+#define PHP_GINIT(module) php3_ginit_##module
+#define PHP_GSHUTDOWN(module) php3_gshutdown_##module
-#define PHP_MINIT_FUNCTION(module) int php3_minit_##module(INIT_FUNC_ARGS)
-#define PHP_MSHUTDOWN_FUNCTION(module) int php3_mshutdown_##module(SHUTDOWN_FUNC_ARGS)
-#define PHP_RINIT_FUNCTION(module) int php3_rinit_##module(INIT_FUNC_ARGS)
-#define PHP_RSHUTDOWN_FUNCTION(module) int php3_rshutdown_##module(SHUTDOWN_FUNC_ARGS)
-#define PHP_MINFO_FUNCTION(module) void php3_info_##module(ZEND_MODULE_INFO_FUNC_ARGS)
+#define PHP_MINIT_FUNCTION(module) int PHP_MINIT(module)(INIT_FUNC_ARGS)
+#define PHP_MSHUTDOWN_FUNCTION(module) int PHP_MSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS)
+#define PHP_RINIT_FUNCTION(module) int PHP_RINIT(module)(INIT_FUNC_ARGS)
+#define PHP_RSHUTDOWN_FUNCTION(module) int PHP_RSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS)
+#define PHP_MINFO_FUNCTION(module) void PHP_MINFO(module)(ZEND_MODULE_INFO_FUNC_ARGS)
+#define PHP_GINIT_FUNCTION(module) static int PHP_GINIT(module)(void)
+#define PHP_GSHUTDOWN_FUNCTION(module) static int PHP_GSHUTDOWN(module)(void)
/* global variables */
Index: php4/ext/session/config.m4
diff -u php4/ext/session/config.m4:1.2 php4/ext/session/config.m4:1.3
--- php4/ext/session/config.m4:1.2 Fri Aug 27 17:03:22 1999
+++ php4/ext/session/config.m4 Fri Sep 3 13:46:39 1999
@@ -1,4 +1,4 @@
-dnl $Id: config.m4,v 1.2 1999/08/27 21:03:22 sas Exp $
+dnl $Id: config.m4,v 1.3 1999/09/03 17:46:39 sas Exp $
dnl config.m4 for extension session
dnl don't forget to call PHP_EXTENSION(session)
@@ -23,6 +23,7 @@
AC_ADD_INCLUDE($MM_DIR/include)
AC_DEFINE(HAVE_LIBMM, 1)
MM_RESULT=yes
+ PHP_EXTENSION(ps_mm)
fi
])
AC_MSG_RESULT($MM_RESULT)
Index: php4/ext/session/mod_mm.c
diff -u php4/ext/session/mod_mm.c:1.1 php4/ext/session/mod_mm.c:1.2
--- php4/ext/session/mod_mm.c:1.1 Fri Aug 27 17:03:22 1999
+++ php4/ext/session/mod_mm.c Fri Sep 3 13:46:39 1999
@@ -30,12 +30,18 @@
#include "php_session.h"
#include "mod_mm.h"
+#define PS_MM_PATH "/tmp/session_mm"
+
+/*
+ * this list holds all data associated with one session
+ */
+
typedef struct ps_sd {
+ struct ps_sd *next, *prev;
time_t ctime;
char *key;
void *data;
size_t datalen;
- struct ps_sd *next, *prev;
} ps_sd;
typedef struct {
@@ -46,7 +52,7 @@
static ps_mm *ps_mm_instance = NULL;
/* should be a prime */
-#define HASH_SIZE 11
+#define HASH_SIZE 577
#if 0
#define ps_mm_debug(a...) fprintf(stderr, a)
@@ -59,6 +65,11 @@
#define ONE_EIGTH ((int) (BITS_IN_int / 8))
#define HIGH_BITS (~((unsigned int)(~0) >> ONE_EIGTH))
+/*
+ * Weinberger's generic hash algorithm, adapted by Holub
+ * (published in [Holub 1990])
+ */
+
static unsigned int ps_sd_hash(const char *data)
{
unsigned int val, i;
@@ -82,14 +93,28 @@
h = ps_sd_hash(key) % HASH_SIZE;
sd = mm_malloc(data->mm, sizeof(*sd));
+ if(!sd) {
+ return NULL;
+ }
sd->ctime = 0;
sd->data = mm_malloc(data->mm, sdatalen);
- memcpy(sd->data, sdata, sdatalen);
+ if(!sd->data) {
+ mm_free(data->mm, sd);
+ return NULL;
+ }
+
sd->datalen = sdatalen;
sd->key = mm_strdup(data->mm, key);
+ if(!sd->key) {
+ mm_free(data->mm, sd->data);
+ mm_free(data->mm, sd);
+ return NULL;
+ }
+ memcpy(sd->data, sdata, sdatalen);
+
if((sd->next = data->hash[h]))
sd->next->prev = sd;
sd->prev = NULL;
@@ -116,7 +141,7 @@
data->hash[h] = sd->next;
mm_free(data->mm, sd->key);
- mm_free(data->mm, sd->data);
+ if(sd->data) mm_free(data->mm, sd->data);
mm_free(data->mm, sd);
}
@@ -159,17 +184,38 @@
static void ps_mm_destroy(ps_mm *data)
{
+ int h;
+ ps_sd *sd, *next;
+
+ for(h = 0; h < HASH_SIZE; h++) {
+ for(sd = data->hash[h]; sd; sd = next) {
+ next = sd->next;
+ ps_sd_destroy(data, sd);
+ }
+ }
+
mm_free(data->mm, data->hash);
mm_destroy(data->mm);
}
-PS_OPEN_FUNC(mm)
+PHP_GINIT_FUNCTION(ps_mm)
{
- if(!ps_mm_instance) {
- ps_mm_instance = calloc(sizeof(*data), 1);
- ps_mm_initialize(ps_mm_instance, save_path);
- }
+ ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1);
+ ps_mm_initialize(ps_mm_instance, PS_MM_PATH);
+ return SUCCESS;
+}
+PHP_GSHUTDOWN_FUNCTION(ps_mm)
+{
+ ps_mm_destroy(ps_mm_instance);
+ free(ps_mm_instance);
+ return SUCCESS;
+}
+
+PS_OPEN_FUNC(mm)
+{
+ ps_mm_debug("open: ps_mm_instance=%x\n", ps_mm_instance);
+
PS_SET_MOD_DATA(ps_mm_instance);
return SUCCESS;
@@ -219,14 +265,19 @@
mm_free(data->mm, sd->data);
sd->datalen = vallen;
sd->data = mm_malloc(data->mm, vallen);
- memcpy(sd->data, val, vallen);
+ if(!sd->data) {
+ ps_sd_destroy(data, sd);
+ sd = NULL;
+ } else {
+ memcpy(sd->data, val, vallen);
+ }
}
- time(&sd->ctime);
+ if(sd) time(&sd->ctime);
mm_unlock(data->mm);
- return SUCCESS;
+ return sd ? SUCCESS : FAILURE;
}
PS_DESTROY_FUNC(mm)
@@ -273,5 +324,15 @@
return SUCCESS;
}
+
+zend_module_entry php_session_mm_module = {
+ "Session MM",
+ NULL,
+ NULL, NULL,
+ NULL, NULL,
+ NULL,
+ PHP_GINIT(ps_mm), PHP_GSHUTDOWN(ps_mm),
+ STANDARD_MODULE_PROPERTIES_EX
+};
#endif
Index: php4/ext/session/mod_mm.h
diff -u php4/ext/session/mod_mm.h:1.1 php4/ext/session/mod_mm.h:1.2
--- php4/ext/session/mod_mm.h:1.1 Fri Aug 27 17:03:22 1999
+++ php4/ext/session/mod_mm.h Fri Sep 3 13:46:39 1999
@@ -32,14 +32,20 @@
#ifdef HAVE_LIBMM
+#include "php_session.h"
+
extern ps_module ps_mod_mm;
#define ps_mm_ptr &ps_mod_mm
+extern zend_module_entry php_session_mm_module;
+#define phpext_ps_mm_ptr &php_session_mm_module
+
PS_FUNCS(mm);
#else
#define ps_mm_ptr NULL
+#define phpext_ps_mm_ptr NULL
#endif
Index: php4/ext/session/session.c
diff -u php4/ext/session/session.c:1.38 php4/ext/session/session.c:1.39
--- php4/ext/session/session.c:1.38 Wed Sep 1 10:20:15 1999
+++ php4/ext/session/session.c Fri Sep 3 13:46:39 1999
@@ -281,7 +281,6 @@
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);
@@ -701,7 +700,7 @@
return FAILURE;
}
- if(INI_INT("session_auto_start")) {
+ if(INI_INT("session.auto_start")) {
_php_session_start(PSLS_C);
}