diff options
Diffstat (limited to 'ext/session')
-rw-r--r-- | ext/session/CREDITS | 2 | ||||
-rw-r--r-- | ext/session/Makefile.in | 7 | ||||
-rw-r--r-- | ext/session/config.m4 | 39 | ||||
-rw-r--r-- | ext/session/mod_files.c | 349 | ||||
-rw-r--r-- | ext/session/mod_files.h | 27 | ||||
-rw-r--r-- | ext/session/mod_files.sh | 16 | ||||
-rw-r--r-- | ext/session/mod_mm.c | 365 | ||||
-rw-r--r-- | ext/session/mod_mm.h | 41 | ||||
-rw-r--r-- | ext/session/mod_user.c | 185 | ||||
-rw-r--r-- | ext/session/mod_user.h | 39 | ||||
-rw-r--r-- | ext/session/php_session.h | 205 | ||||
-rw-r--r-- | ext/session/session.c | 1464 | ||||
-rw-r--r-- | ext/session/setup.stub | 6 | ||||
-rw-r--r-- | ext/session/tests/001.phpt | 27 | ||||
-rw-r--r-- | ext/session/tests/002.phpt | 10 | ||||
-rw-r--r-- | ext/session/tests/003.phpt | 36 | ||||
-rw-r--r-- | ext/session/tests/004.phpt | 103 | ||||
-rw-r--r-- | ext/session/tests/005.phpt | 138 | ||||
-rw-r--r-- | ext/session/tests/006.phpt | 62 |
19 files changed, 0 insertions, 3121 deletions
diff --git a/ext/session/CREDITS b/ext/session/CREDITS deleted file mode 100644 index 79659c7035..0000000000 --- a/ext/session/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Sessions -Sascha Schumann, Andrei Zmievski diff --git a/ext/session/Makefile.in b/ext/session/Makefile.in deleted file mode 100644 index 2e1d76edb0..0000000000 --- a/ext/session/Makefile.in +++ /dev/null @@ -1,7 +0,0 @@ - -LTLIBRARY_NAME = libsession.la -LTLIBRARY_SOURCES = session.c mod_files.c mod_mm.c mod_user.c -LTLIBRARY_SHARED_NAME = session.la -LTLIBRARY_SHARED_LIBADD = $(SESSION_SHARED_LIBADD) - -include $(top_srcdir)/build/dynlib.mk diff --git a/ext/session/config.m4 b/ext/session/config.m4 deleted file mode 100644 index 74c77414f7..0000000000 --- a/ext/session/config.m4 +++ /dev/null @@ -1,39 +0,0 @@ -dnl $Id$ - -PHP_ARG_WITH(mm,for mm support, -[ --with-mm[=DIR] Include mm support for session storage]) - -PHP_ARG_ENABLE(trans-sid,whether to enable transparent session id propagation, -[ --enable-trans-sid Enable transparent session id propagation]) - -PHP_ARG_ENABLE(session, whether to enable session support, -[ --disable-session Disable session support], yes) - -if test "$PHP_MM" != "no"; then - for i in /usr/local /usr $PHP_MM; 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 - - PHP_ADD_LIBRARY_WITH_PATH(mm, $MM_DIR/lib, SESSION_SHARED_LIBADD) - PHP_ADD_INCLUDE($MM_DIR/include) - AC_DEFINE(HAVE_LIBMM, 1, [Whether you have libmm]) - PHP_MODULE_PTR(phpext_ps_mm_ptr) -fi - -if test "$PHP_TRANS_SID" = "yes"; then - AC_DEFINE(TRANS_SID, 1, [Whether you want transparent session id propagation]) -fi - -if test "$PHP_SESSION" != "no"; then - AC_CHECK_FUNCS(pread pwrite) - PHP_MISSING_PWRITE_DECL - PHP_MISSING_PREAD_DECL - PHP_EXTENSION(session,$ext_shared) - PHP_SUBST(SESSION_SHARED_LIBADD) -fi diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c deleted file mode 100644 index 5ed3e0aa4d..0000000000 --- a/ext/session/mod_files.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" - -#include <sys/stat.h> -#include <sys/types.h> - -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif - -#if HAVE_DIRENT_H -#include <dirent.h> -#endif - -#ifdef PHP_WIN32 -#include "win32/readdir.h" -#endif -#include <time.h> - -#include <fcntl.h> -#include <errno.h> - -#include "php_session.h" -#include "mod_files.h" -#include "ext/standard/flock_compat.h" - -#define FILE_PREFIX "sess_" - -typedef struct { - int fd; - char *lastkey; - char *basedir; - size_t basedir_len; - size_t dirdepth; - size_t st_size; -} ps_files; - -ps_module ps_mod_files = { - PS_MOD(files) -}; - -static int ps_files_valid_key(const char *key) -{ - size_t len; - const char *p; - char c; - int ret = 1; - - for (p = key; (c = *p); p++) { - /* valid characters are a..z,A..Z,0..9 */ - if (!((c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9'))) { - ret = 0; - break; - } - } - - len = p - key; - - if (len == 0) - ret = 0; - - return ret; -} - -static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, const char *key) -{ - size_t key_len; - const char *p; - int i; - int n; - - key_len = strlen(key); - if (key_len <= data->dirdepth || buflen < - (strlen(data->basedir) + 2 * data->dirdepth + key_len + 5 + sizeof(FILE_PREFIX))) - return NULL; - p = key; - memcpy(buf, data->basedir, data->basedir_len); - n = data->basedir_len; - buf[n++] = PHP_DIR_SEPARATOR; - for (i = 0; i < (int)data->dirdepth; i++) { - buf[n++] = *p++; - buf[n++] = PHP_DIR_SEPARATOR; - } - memcpy(buf + n, FILE_PREFIX, sizeof(FILE_PREFIX) - 1); - n += sizeof(FILE_PREFIX) - 1; - memcpy(buf + n, key, key_len); - n += key_len; - buf[n] = '\0'; - - return buf; -} - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -static void ps_files_close(ps_files *data) -{ - if (data->fd != -1) { - close(data->fd); - data->fd = -1; - } -} - -static void ps_files_open(ps_files *data, const char *key) -{ - char buf[MAXPATHLEN]; - - if (data->fd < 0 || !data->lastkey || strcmp(key, data->lastkey)) { - if (data->lastkey) { - efree(data->lastkey); - data->lastkey = NULL; - } - - ps_files_close(data); - - if (!ps_files_valid_key(key) || - !ps_files_path_create(buf, sizeof(buf), data, key)) - return; - - data->lastkey = estrdup(key); - -#ifdef O_EXCL - data->fd = VCWD_OPEN((buf, O_RDWR | O_BINARY)); - - if (data->fd == -1 && errno == ENOENT) - data->fd = VCWD_OPEN((buf, O_EXCL | O_RDWR | O_CREAT | O_BINARY, 0600)); -#else - data->fd = VCWD_OPEN((buf, O_CREAT | O_RDWR | O_BINARY, 0600)); -#endif - if (data->fd != -1) - flock(data->fd, LOCK_EX); - - if (data->fd == -1) - php_error(E_WARNING, "open(%s, O_RDWR) failed: %s (%d)", buf, - strerror(errno), errno); - } -} - -static int ps_files_cleanup_dir(const char *dirname, int maxlifetime) -{ - DIR *dir; - char dentry[sizeof(struct dirent) + MAXPATHLEN]; - struct dirent *entry = (struct dirent *) &dentry; - struct stat sbuf; - char buf[MAXPATHLEN]; - time_t now; - int nrdels = 0; - size_t dirname_len; - - dir = opendir(dirname); - if (!dir) { - php_error(E_NOTICE, "ps_files_cleanup_dir: opendir(%s) failed: %s (%d)\n", dirname, strerror(errno), errno); - return (0); - } - - time(&now); - - dirname_len = strlen(dirname); - - /* Prepare buffer (dirname never changes) */ - memcpy(buf, dirname, dirname_len); - buf[dirname_len] = PHP_DIR_SEPARATOR; - - while (php_readdir_r(dir, (struct dirent *) dentry, &entry) == 0 && entry) { - /* does the file start with our prefix? */ - if (!strncmp(entry->d_name, FILE_PREFIX, sizeof(FILE_PREFIX) - 1)) { - size_t entry_len; - - entry_len = strlen(entry->d_name); - /* does it fit into our buffer? */ - if (entry_len + dirname_len + 2 < MAXPATHLEN) { - /* create the full path.. */ - memcpy(buf + dirname_len + 1, entry->d_name, entry_len); - /* NUL terminate it and */ - buf[dirname_len + entry_len + 1] = '\0'; - /* check whether its last access was more than maxlifet ago */ - if (VCWD_STAT(buf, &sbuf) == 0 && - (now - sbuf.st_atime) > maxlifetime) { - VCWD_UNLINK(buf); - nrdels++; - } - } - } - } - - closedir(dir); - - return (nrdels); -} - -#define PS_FILES_DATA ps_files *data = PS_GET_MOD_DATA() - -PS_OPEN_FUNC(files) -{ - ps_files *data; - char *p; - - data = ecalloc(sizeof(*data), 1); - PS_SET_MOD_DATA(data); - - data->fd = -1; - if ((p = strchr(save_path, ';'))) { - data->dirdepth = (size_t) strtol(save_path, NULL, 10); - save_path = p + 1; - } - data->basedir_len = strlen(save_path); - data->basedir = estrndup(save_path, data->basedir_len); - - return SUCCESS; -} - -PS_CLOSE_FUNC(files) -{ - PS_FILES_DATA; - - ps_files_close(data); - - if (data->lastkey) - efree(data->lastkey); - efree(data->basedir); - efree(data); - *mod_data = NULL; - - return SUCCESS; -} - -PS_READ_FUNC(files) -{ - long n; - struct stat sbuf; - PS_FILES_DATA; - - ps_files_open(data, key); - if (data->fd < 0) - return FAILURE; - - if (fstat(data->fd, &sbuf)) - return FAILURE; - - data->st_size = *vallen = sbuf.st_size; - *val = emalloc(sbuf.st_size); - -#ifdef HAVE_PREAD - n = pread(data->fd, *val, sbuf.st_size, 0); -#else - lseek(data->fd, 0, SEEK_SET); - n = read(data->fd, *val, sbuf.st_size); -#endif - if (n != sbuf.st_size) { - efree(*val); - return FAILURE; - } - - return SUCCESS; -} - -PS_WRITE_FUNC(files) -{ - long n; - PS_FILES_DATA; - - ps_files_open(data, key); - if (data->fd < 0) - return FAILURE; - - /* - * truncate file, if the amount of new data is smaller than - * the existing data set. - */ - - if (vallen < (int)data->st_size) - ftruncate(data->fd, 0); - -#ifdef HAVE_PWRITE - n = pwrite(data->fd, val, vallen, 0); -#else - lseek(data->fd, 0, SEEK_SET); - n = write(data->fd, val, vallen); -#endif - - if (n != vallen) { - php_error(E_WARNING, "write failed: %s (%d)", strerror(errno), errno); - return FAILURE; - } - - return SUCCESS; -} - -PS_DESTROY_FUNC(files) -{ - char buf[MAXPATHLEN]; - PS_FILES_DATA; - - if (!ps_files_path_create(buf, sizeof(buf), data, key)) - return FAILURE; - - ps_files_close(data); - - if (VCWD_UNLINK(buf) == -1) { - return FAILURE; - } - - return SUCCESS; -} - -PS_GC_FUNC(files) -{ - PS_FILES_DATA; - - /* we don't perform any cleanup, if dirdepth is larger than 0. - we return SUCCESS, since all cleanup should be handled by - an external entity (i.e. find -ctime x | xargs rm) */ - - if (data->dirdepth == 0) - *nrdels = ps_files_cleanup_dir(data->basedir, maxlifetime); - - return SUCCESS; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 tw=78 fdm=marker - * vim<600: sw=4 ts=4 tw=78 - */ diff --git a/ext/session/mod_files.h b/ext/session/mod_files.h deleted file mode 100644 index bab104e9c8..0000000000 --- a/ext/session/mod_files.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -#ifndef MOD_FILES_H -#define MOD_FILES_H - -extern ps_module ps_mod_files; -#define ps_files_ptr &ps_mod_files - -PS_FUNCS(files); - -#endif diff --git a/ext/session/mod_files.sh b/ext/session/mod_files.sh deleted file mode 100644 index 4d6a681d9c..0000000000 --- a/ext/session/mod_files.sh +++ /dev/null @@ -1,16 +0,0 @@ -#! /bin/sh - -if test "$2" = ""; then - echo "usage: $0 basedir depth" - exit 1 -fi - -if test "$2" = "0"; then - exit 0 -fi - -for i in a b c d e f 0 1 2 3 4 5 6 7 8 9; do - newpath="$1/$i" - mkdir $newpath || exit 1 - sh $0 $newpath `expr $2 - 1` -done diff --git a/ext/session/mod_mm.c b/ext/session/mod_mm.c deleted file mode 100644 index b6f4b52465..0000000000 --- a/ext/session/mod_mm.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" - -#ifdef HAVE_LIBMM - -#include <mm.h> -#include <time.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <fcntl.h> - -#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; -} ps_sd; - -typedef struct { - MM *mm; - ps_sd **hash; -} ps_mm; - -static ps_mm *ps_mm_instance = NULL; - -/* should be a prime */ -#define HASH_SIZE 577 - -#if 0 -#define ps_mm_debug(a...) fprintf(stderr, a) -#else -#define ps_mm_debug -#endif - -#define BITS_IN_int (sizeof(int) * CHAR_BIT) -#define THREE_QUARTERS ((int) ((BITS_IN_int * 3) / 4)) -#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; - - for (val = 0; *data; data++) { - val = (val << ONE_EIGTH) + *data; - if ((i = val & HIGH_BITS) != 0) - val = (val ^ (i >> THREE_QUARTERS)) & ~HIGH_BITS; - } - - return val; -} - - -static ps_sd *ps_sd_new(ps_mm *data, const char *key, const void *sdata, size_t sdatalen) -{ - unsigned int h; - ps_sd *sd; - - 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); - 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; - - ps_mm_debug("inserting %s(%p) into %d\n", key, sd, h); - - data->hash[h] = sd; - - return sd; -} - -static void ps_sd_destroy(ps_mm *data, ps_sd *sd) -{ - unsigned int h; - - h = ps_sd_hash(sd->key) % HASH_SIZE; - - if (sd->next) - sd->next->prev = sd->prev; - if (sd->prev) - sd->prev->next = sd->next; - - if (data->hash[h] == sd) - data->hash[h] = sd->next; - - mm_free(data->mm, sd->key); - if (sd->data) - mm_free(data->mm, sd->data); - mm_free(data->mm, sd); -} - -static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw) -{ - unsigned int h; - ps_sd *ret; - - h = ps_sd_hash(key) % HASH_SIZE; - - for (ret = data->hash[h]; ret; ret = ret->next) - if (!strcmp(ret->key, key)) - break; - - if (ret && rw && ret != data->hash[h]) { - data->hash[h]->prev = ret; - ret->next = data->hash[h]; - data->hash[h] = ret; - ps_mm_debug("optimizing\n"); - } - - ps_mm_debug("lookup(%s): ret=%p,h=%d\n", key, ret, h); - - return ret; -} - -ps_module ps_mod_mm = { - PS_MOD(mm) -}; - -#define PS_MM_DATA ps_mm *data = PS_GET_MOD_DATA() - -static int ps_mm_initialize(ps_mm *data, const char *path) -{ - data->mm = mm_create(0, path); - if (!data->mm) { - return FAILURE; - } - - data->hash = mm_calloc(data->mm, HASH_SIZE, sizeof(*data->hash)); - if (!data->hash) { - mm_destroy(data->mm); - return FAILURE; - } - - return SUCCESS; -} - -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); -} - -PHP_MINIT_FUNCTION(ps_mm) -{ - ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1); - if (ps_mm_initialize(ps_mm_instance, PS_MM_PATH) != SUCCESS) { - ps_mm_instance = NULL; - return FAILURE; - } - php_session_register_module(&ps_mod_mm); - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(ps_mm) -{ - if (ps_mm_instance) { - ps_mm_destroy(ps_mm_instance); - free(ps_mm_instance); - return SUCCESS; - } - return FAILURE; -} - -PS_OPEN_FUNC(mm) -{ - ps_mm_debug("open: ps_mm_instance=%p\n", ps_mm_instance); - - if (!ps_mm_instance) - return FAILURE; - - PS_SET_MOD_DATA(ps_mm_instance); - - return SUCCESS; -} - -PS_CLOSE_FUNC(mm) -{ - PS_SET_MOD_DATA(NULL); - - return SUCCESS; -} - -PS_READ_FUNC(mm) -{ - PS_MM_DATA; - ps_sd *sd; - int ret = FAILURE; - - mm_lock(data->mm, MM_LOCK_RD); - - sd = ps_sd_lookup(data, key, 0); - if (sd) { - *vallen = sd->datalen; - *val = emalloc(sd->datalen); - memcpy(*val, sd->data, sd->datalen); - ret = SUCCESS; - } - - mm_unlock(data->mm); - - return ret; -} - -PS_WRITE_FUNC(mm) -{ - PS_MM_DATA; - ps_sd *sd; - - if (vallen == 0) return SUCCESS; - - mm_lock(data->mm, MM_LOCK_RW); - - sd = ps_sd_lookup(data, key, 1); - if (!sd) { - sd = ps_sd_new(data, key, val, vallen); - ps_mm_debug("new one for %s\n", key); - } else { - ps_mm_debug("found existing one for %s\n", key); - mm_free(data->mm, sd->data); - sd->datalen = vallen; - sd->data = mm_malloc(data->mm, vallen); - if (!sd->data) { - ps_sd_destroy(data, sd); - sd = NULL; - } else - memcpy(sd->data, val, vallen); - } - - if (sd) - time(&sd->ctime); - - mm_unlock(data->mm); - - return sd ? SUCCESS : FAILURE; -} - -PS_DESTROY_FUNC(mm) -{ - PS_MM_DATA; - ps_sd *sd; - - mm_lock(data->mm, MM_LOCK_RW); - - sd = ps_sd_lookup(data, key, 0); - if (sd) - ps_sd_destroy(data, sd); - - mm_unlock(data->mm); - - return SUCCESS; -} - -PS_GC_FUNC(mm) -{ - PS_MM_DATA; - int h; - time_t now; - ps_sd *sd, *next; - - *nrdels = 0; - ps_mm_debug("gc\n"); - - mm_lock(data->mm, MM_LOCK_RW); - - time(&now); - - for (h = 0; h < HASH_SIZE; h++) - for (sd = data->hash[h]; sd; sd = next) { - next = sd->next; - ps_mm_debug("looking at %s\n", sd->key); - if ((now - sd->ctime) > maxlifetime) { - ps_sd_destroy(data, sd); - *nrdels++; - } - } - - mm_unlock(data->mm); - - return SUCCESS; -} - -zend_module_entry php_session_mm_module = { - "Session MM", - NULL, - PHP_MINIT(ps_mm), PHP_MSHUTDOWN(ps_mm), - NULL, NULL, - NULL, - STANDARD_MODULE_PROPERTIES -}; - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 tw=78 fdm=marker - * vim<600: sw=4 ts=4 tw=78 - */ diff --git a/ext/session/mod_mm.h b/ext/session/mod_mm.h deleted file mode 100644 index 01b390c0f8..0000000000 --- a/ext/session/mod_mm.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -#ifndef MOD_MM_H -#define MOD_MM_H - -#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 - -#endif diff --git a/ext/session/mod_user.c b/ext/session/mod_user.c deleted file mode 100644 index be4e89d50e..0000000000 --- a/ext/session/mod_user.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "php_session.h" -#include "mod_user.h" - -ps_module ps_mod_user = { - PS_MOD(user) -}; - -#define SESS_ZVAL_LONG(val, a) \ -{ \ - MAKE_STD_ZVAL(a); \ - a->type = IS_LONG; \ - a->value.lval = val; \ -} - -#define SESS_ZVAL_STRING(vl, a) \ -{ \ - int len = strlen(vl); \ - MAKE_STD_ZVAL(a); \ - a->type = IS_STRING; \ - a->value.str.len = len; \ - a->value.str.val = estrndup(vl, len); \ -} - -#define SESS_ZVAL_STRINGN(vl, ln, a) \ -{ \ - MAKE_STD_ZVAL(a); \ - a->type = IS_STRING; \ - a->value.str.len = ln; \ - a->value.str.val = estrndup(vl, ln); \ -} - - -static zval *ps_call_handler(zval *func, int argc, zval **argv) -{ - int i; - zval *retval = NULL; - ELS_FETCH(); - - MAKE_STD_ZVAL(retval); - if (call_user_function(EG(function_table), NULL, func, retval, - argc, argv) == FAILURE) { - zval_ptr_dtor(&retval); - retval = NULL; - } - - for (i = 0; i < argc; i++) { - zval_ptr_dtor(&argv[i]); - } - - return retval; -} - -#define STDVARS \ - zval *retval; \ - int ret = FAILURE; \ - ps_user *mdata = PS_GET_MOD_DATA(); \ - if (!mdata) \ - return FAILURE - -#define PSF(a) mdata->name.ps_##a - -#define FINISH \ - if (retval) { \ - convert_to_long(retval); \ - ret = retval->value.lval; \ - zval_ptr_dtor(&retval); \ - } \ - return ret - -PS_OPEN_FUNC(user) -{ - zval *args[2]; - STDVARS; - - SESS_ZVAL_STRING(save_path, args[0]); - SESS_ZVAL_STRING(session_name, args[1]); - - retval = ps_call_handler(PSF(open), 2, args); - - FINISH; -} - -PS_CLOSE_FUNC(user) -{ - int i; - STDVARS; - - retval = ps_call_handler(PSF(close), 0, NULL); - - for (i = 0; i < 6; i++) - zval_ptr_dtor(&mdata->names[i]); - efree(mdata); - - PS_SET_MOD_DATA(NULL); - - FINISH; -} - -PS_READ_FUNC(user) -{ - zval *args[1]; - STDVARS; - - SESS_ZVAL_STRING(key, args[0]); - - retval = ps_call_handler(PSF(read), 1, args); - - if (retval) { - if (retval->type == IS_STRING) { - *val = estrndup(retval->value.str.val, retval->value.str.len); - *vallen = retval->value.str.len; - ret = SUCCESS; - } - zval_ptr_dtor(&retval); - } - - return ret; -} - -PS_WRITE_FUNC(user) -{ - zval *args[2]; - STDVARS; - - SESS_ZVAL_STRING(key, args[0]); - SESS_ZVAL_STRINGN(val, vallen, args[1]); - - retval = ps_call_handler(PSF(write), 2, args); - - FINISH; -} - -PS_DESTROY_FUNC(user) -{ - zval *args[1]; - STDVARS; - - SESS_ZVAL_STRING(key, args[0]); - - retval = ps_call_handler(PSF(destroy), 1, args); - - FINISH; -} - -PS_GC_FUNC(user) -{ - zval *args[1]; - STDVARS; - - SESS_ZVAL_LONG(maxlifetime, args[0]); - - retval = ps_call_handler(PSF(gc), 1, args); - - FINISH; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 tw=78 fdm=marker - * vim<600: sw=4 ts=4 tw=78 - */ diff --git a/ext/session/mod_user.h b/ext/session/mod_user.h deleted file mode 100644 index c2123a8c15..0000000000 --- a/ext/session/mod_user.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -#ifndef MOD_USER_H -#define MOD_USER_H - -typedef union { - zval *names[6]; - struct { - zval *ps_open; - zval *ps_close; - zval *ps_read; - zval *ps_write; - zval *ps_destroy; - zval *ps_gc; - } name; -} ps_user; - -extern ps_module ps_mod_user; -#define ps_user_ptr &ps_mod_user - -PS_FUNCS(user); - -#endif diff --git a/ext/session/php_session.h b/ext/session/php_session.h deleted file mode 100644 index 97623915b5..0000000000 --- a/ext/session/php_session.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_SESSION_H -#define PHP_SESSION_H - -#define PS_OPEN_ARGS void **mod_data, const char *save_path, const char *session_name -#define PS_CLOSE_ARGS void **mod_data -#define PS_READ_ARGS void **mod_data, const char *key, char **val, int *vallen -#define PS_WRITE_ARGS void **mod_data, const char *key, const char *val, const int vallen -#define PS_DESTROY_ARGS void **mod_data, const char *key -#define PS_GC_ARGS void **mod_data, int maxlifetime, int *nrdels - -typedef struct ps_module_struct { - const char *name; - int (*open)(PS_OPEN_ARGS); - int (*close)(PS_CLOSE_ARGS); - int (*read)(PS_READ_ARGS); - int (*write)(PS_WRITE_ARGS); - int (*destroy)(PS_DESTROY_ARGS); - 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) -#define PS_READ_FUNC(x) int ps_read_##x(PS_READ_ARGS) -#define PS_WRITE_FUNC(x) int ps_write_##x(PS_WRITE_ARGS) -#define PS_DESTROY_FUNC(x) int ps_delete_##x(PS_DESTROY_ARGS) -#define PS_GC_FUNC(x) int ps_gc_##x(PS_GC_ARGS) - -#define PS_FUNCS(x) \ - PS_OPEN_FUNC(x); \ - PS_CLOSE_FUNC(x); \ - PS_READ_FUNC(x); \ - PS_WRITE_FUNC(x); \ - PS_DESTROY_FUNC(x); \ - PS_GC_FUNC(x) - - -#define PS_MOD(x) \ - #x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \ - ps_delete_##x, ps_gc_##x - -typedef struct { - char *save_path; - char *session_name; - char *id; - char *extern_referer_chk; - char *entropy_file; - char *cache_limiter; - long entropy_length; - long cookie_lifetime; - char *cookie_path; - char *cookie_domain; - zend_bool cookie_secure; - ps_module *mod; - void *mod_data; - HashTable vars; - int nr_open_sessions; - long gc_probability; - long gc_maxlifetime; - int module_number; - long cache_expire; - const struct ps_serializer_struct *serializer; - zval *http_session_vars; - zend_bool auto_start; - zend_bool define_sid; - zend_bool use_cookies; -} php_ps_globals; - -extern zend_module_entry session_module_entry; -#define phpext_session_ptr &session_module_entry - -PHP_FUNCTION(session_name); -PHP_FUNCTION(session_module_name); -PHP_FUNCTION(session_save_path); -PHP_FUNCTION(session_id); -PHP_FUNCTION(session_decode); -PHP_FUNCTION(session_register); -PHP_FUNCTION(session_unregister); -PHP_FUNCTION(session_is_registered); -PHP_FUNCTION(session_encode); -PHP_FUNCTION(session_start); -PHP_FUNCTION(session_destroy); -PHP_FUNCTION(session_unset); -PHP_FUNCTION(session_set_save_handler); -PHP_FUNCTION(session_cache_limiter); -PHP_FUNCTION(session_set_cookie_params); -PHP_FUNCTION(session_get_cookie_params); -PHP_FUNCTION(session_write_close); - -#ifdef ZTS -#define PSLS_D php_ps_globals *ps_globals -#define PSLS_DC , PSLS_D -#define PSLS_C ps_globals -#define PSLS_CC , PSLS_C -#define PS(v) (ps_globals->v) -#define PSLS_FETCH() php_ps_globals *ps_globals = ts_resource(ps_globals_id) -#else -#define PSLS_D void -#define PSLS_DC -#define PSLS_C -#define PSLS_CC -#define PS(v) (ps_globals.v) -#define PSLS_FETCH() -#endif - -#define PS_SERIALIZER_ENCODE_ARGS char **newstr, int *newlen PSLS_DC -#define PS_SERIALIZER_DECODE_ARGS const char *val, int vallen PSLS_DC - -typedef struct ps_serializer_struct { - const char *name; - int (*encode)(PS_SERIALIZER_ENCODE_ARGS); - int (*decode)(PS_SERIALIZER_DECODE_ARGS); -} ps_serializer; - -#define PS_SERIALIZER_ENCODE_NAME(x) ps_srlzr_encode_##x -#define PS_SERIALIZER_DECODE_NAME(x) ps_srlzr_decode_##x - -#define PS_SERIALIZER_ENCODE_FUNC(x) \ - int PS_SERIALIZER_ENCODE_NAME(x)(PS_SERIALIZER_ENCODE_ARGS) -#define PS_SERIALIZER_DECODE_FUNC(x) \ - int PS_SERIALIZER_DECODE_NAME(x)(PS_SERIALIZER_DECODE_ARGS) - -#define PS_SERIALIZER_FUNCS(x) \ - PS_SERIALIZER_ENCODE_FUNC(x); \ - PS_SERIALIZER_DECODE_FUNC(x) - -#define PS_SERIALIZER_ENTRY(x) \ - { #x, PS_SERIALIZER_ENCODE_NAME(x), PS_SERIALIZER_DECODE_NAME(x) } - -#ifdef TRANS_SID -void session_adapt_uris(const char *, size_t, char **, size_t *); -void session_adapt_url(const char *, size_t, char **, size_t *); -#else -#define session_adapt_uris(a,b,c,d) -#define session_adapt_url(a,b,c,d) -#endif - -void php_set_session_var(char *name, size_t namelen, zval *state_val,HashTable *var_hash PSLS_DC); -int php_get_session_var(char *name, size_t namelen, zval ***state_var PLS_DC PSLS_DC ELS_DC); - -int php_session_register_module(ps_module *); - -int php_session_register_serializer(const char *name, - int (*encode)(PS_SERIALIZER_ENCODE_ARGS), - int (*decode)(PS_SERIALIZER_DECODE_ARGS)); - -#define PS_ADD_VARL(name,namelen) \ - zend_hash_add_empty_element(&PS(vars), name, namelen + 1) - -#define PS_ADD_VAR(name) PS_ADD_VARL(name, strlen(name)) - -#define PS_DEL_VARL(name,namelen) \ - zend_hash_del(&PS(vars), name, namelen + 1); - -#define PS_DEL_VAR(name) PS_DEL_VARL(name, strlen(name)) - -#define PS_ENCODE_VARS \ - char *key; \ - ulong key_length; \ - ulong num_key; \ - zval **struc; \ - ELS_FETCH(); \ - PLS_FETCH() - -#define PS_ENCODE_LOOP(code) \ - for (zend_hash_internal_pointer_reset(&PS(vars)); \ - zend_hash_get_current_key_ex(&PS(vars), &key, &key_length, &num_key, 0, NULL) == HASH_KEY_IS_STRING; \ - zend_hash_move_forward(&PS(vars))) { \ - key_length--; \ - if (php_get_session_var(key, key_length, &struc PLS_CC PSLS_CC ELS_CC) == SUCCESS) { \ - code; \ - } \ - } - -#ifdef ZTS -extern int ps_globals_id; -#else -extern php_ps_globals ps_globals; -#endif - - -void php_session_auto_start(void *data); -void php_session_shutdown(void *data); - -#endif diff --git a/ext/session/session.c b/ext/session/session.c deleted file mode 100644 index d373b5a757..0000000000 --- a/ext/session/session.c +++ /dev/null @@ -1,1464 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - | Andrei Zmievski <andrei@ispi.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#ifdef PHP_WIN32 -#include "win32/time.h" -#else -#include <sys/time.h> -#endif - -#include <sys/stat.h> -#include <fcntl.h> - -#include "php_ini.h" -#include "SAPI.h" -#include "php_session.h" -#include "ext/standard/md5.h" -#include "ext/standard/php_var.h" -#include "ext/standard/datetime.h" -#include "ext/standard/php_lcg.h" -#include "ext/standard/url_scanner_ex.h" -#include "ext/standard/php_output.h" -#include "ext/standard/php_rand.h" /* for RAND_MAX */ -#include "ext/standard/info.h" - -#include "ext/standard/php_smart_str.h" - -#include "mod_files.h" -#include "mod_user.h" - -/* {{{ session_functions[] - */ -function_entry session_functions[] = { - PHP_FE(session_name, NULL) - PHP_FE(session_module_name, NULL) - PHP_FE(session_save_path, NULL) - PHP_FE(session_id, NULL) - PHP_FE(session_decode, NULL) - PHP_FE(session_register, NULL) - PHP_FE(session_unregister, NULL) - PHP_FE(session_is_registered, NULL) - PHP_FE(session_encode, NULL) - PHP_FE(session_start, NULL) - PHP_FE(session_destroy, NULL) - PHP_FE(session_unset, NULL) - PHP_FE(session_set_save_handler, NULL) - PHP_FE(session_cache_limiter, NULL) - PHP_FE(session_set_cookie_params, NULL) - PHP_FE(session_get_cookie_params, NULL) - PHP_FE(session_write_close, NULL) - {0} -}; -/* }}} */ - -#ifdef ZTS -int ps_globals_id; -#else -php_ps_globals ps_globals; -#endif - -static ps_module *_php_find_ps_module(char *name PSLS_DC); -static const ps_serializer *_php_find_ps_serializer(char *name PSLS_DC); - -static PHP_INI_MH(OnUpdateSaveHandler) -{ - PSLS_FETCH(); - - PS(mod) = _php_find_ps_module(new_value PSLS_CC); - if(!PS(mod)) { - php_error(E_ERROR,"Cannot find save handler %s",new_value); - } - return SUCCESS; -} - - -static PHP_INI_MH(OnUpdateSerializer) -{ - PSLS_FETCH(); - - PS(serializer) = _php_find_ps_serializer(new_value PSLS_CC); - if(!PS(serializer)) { - php_error(E_ERROR,"Cannot find serialization handler %s",new_value); - } - return SUCCESS; -} - - -/* {{{ PHP_INI - */ -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("session.save_path", "/tmp", PHP_INI_ALL, OnUpdateString, save_path, php_ps_globals, ps_globals) - STD_PHP_INI_ENTRY("session.name", "PHPSESSID", PHP_INI_ALL, OnUpdateString, session_name, php_ps_globals, ps_globals) - PHP_INI_ENTRY("session.save_handler", "files", PHP_INI_ALL, OnUpdateSaveHandler) - STD_PHP_INI_BOOLEAN("session.auto_start", "0", PHP_INI_ALL, OnUpdateBool, auto_start, php_ps_globals, ps_globals) - STD_PHP_INI_ENTRY("session.gc_probability", "1", PHP_INI_ALL, OnUpdateInt, gc_probability, php_ps_globals, ps_globals) - STD_PHP_INI_ENTRY("session.gc_maxlifetime", "1440", PHP_INI_ALL, OnUpdateInt, gc_maxlifetime, php_ps_globals, ps_globals) - PHP_INI_ENTRY("session.serialize_handler", "php", PHP_INI_ALL, OnUpdateSerializer) - STD_PHP_INI_ENTRY("session.cookie_lifetime", "0", PHP_INI_ALL, OnUpdateInt, cookie_lifetime, php_ps_globals, ps_globals) - STD_PHP_INI_ENTRY("session.cookie_path", "/", PHP_INI_ALL, OnUpdateString, cookie_path, php_ps_globals, ps_globals) - STD_PHP_INI_ENTRY("session.cookie_domain", "", PHP_INI_ALL, OnUpdateString, cookie_domain, php_ps_globals, ps_globals) - STD_PHP_INI_BOOLEAN("session.cookie_secure", "", PHP_INI_ALL, OnUpdateBool, cookie_secure, php_ps_globals, ps_globals) - STD_PHP_INI_BOOLEAN("session.use_cookies", "1", PHP_INI_ALL, OnUpdateBool, use_cookies, php_ps_globals, ps_globals) - STD_PHP_INI_ENTRY("session.referer_check", "", PHP_INI_ALL, OnUpdateString, extern_referer_chk, php_ps_globals, ps_globals) - STD_PHP_INI_ENTRY("session.entropy_file", "", PHP_INI_ALL, OnUpdateString, entropy_file, php_ps_globals, ps_globals) - STD_PHP_INI_ENTRY("session.entropy_length", "0", PHP_INI_ALL, OnUpdateInt, entropy_length, php_ps_globals, ps_globals) - STD_PHP_INI_ENTRY("session.cache_limiter", "nocache", PHP_INI_ALL, OnUpdateString, cache_limiter, php_ps_globals, ps_globals) - STD_PHP_INI_ENTRY("session.cache_expire", "180", PHP_INI_ALL, OnUpdateInt, cache_expire, php_ps_globals, ps_globals) - /* Commented out until future discussion */ - /* PHP_INI_ENTRY("session.encode_sources", "globals,track", PHP_INI_ALL, NULL) */ -PHP_INI_END() -/* }}} */ - -PS_SERIALIZER_FUNCS(php); -PS_SERIALIZER_FUNCS(php_binary); - -#define MAX_SERIALIZERS 10 - -static ps_serializer ps_serializers[MAX_SERIALIZERS + 1] = { - PS_SERIALIZER_ENTRY(php), - PS_SERIALIZER_ENTRY(php_binary) -}; - -#define MAX_MODULES 10 - -static ps_module *ps_modules[MAX_MODULES + 1] = { - ps_files_ptr, - ps_user_ptr -}; - -int php_session_register_serializer(const char *name, - int (*encode)(PS_SERIALIZER_ENCODE_ARGS), - int (*decode)(PS_SERIALIZER_DECODE_ARGS)) -{ - int ret = -1; - int i; - - for (i = 0; i < MAX_SERIALIZERS; i++) { - if (ps_serializers[i].name == NULL) { - ps_serializers[i].name = name; - ps_serializers[i].encode = encode; - ps_serializers[i].decode = decode; - ps_serializers[i + 1].name = NULL; - ret = 0; - break; - } - } - - return ret; -} - -int php_session_register_module(ps_module *ptr) -{ - int ret = -1; - int i; - - for (i = 0; i < MAX_MODULES; i++) { - if (!ps_modules[i]) { - ps_modules[i] = ptr; - ret = 0; - break; - } - } - - return ret; -} - -PHP_MINIT_FUNCTION(session); -PHP_RINIT_FUNCTION(session); -PHP_MSHUTDOWN_FUNCTION(session); -PHP_RSHUTDOWN_FUNCTION(session); -PHP_MINFO_FUNCTION(session); - -static void php_rinit_session_globals(PSLS_D); -static void php_rshutdown_session_globals(PSLS_D); -static zend_bool php_session_destroy(PSLS_D); - -zend_module_entry session_module_entry = { - "session", - session_functions, - PHP_MINIT(session), PHP_MSHUTDOWN(session), - PHP_RINIT(session), PHP_RSHUTDOWN(session), - PHP_MINFO(session), - STANDARD_MODULE_PROPERTIES -}; - -#ifdef COMPILE_DL_SESSION -ZEND_GET_MODULE(session) -#endif - -typedef struct { - char *name; - void (*func)(PSLS_D); -} php_session_cache_limiter_t; - -#define CACHE_LIMITER_FUNC(name) static void _php_cache_limiter_##name(PSLS_D) -#define CACHE_LIMITER(name) { #name, _php_cache_limiter_##name }, - -#define ADD_COOKIE(a) sapi_add_header(a, strlen(a), 1); - -#define STR_CAT(P,S,I) {\ - pval *__p = (P);\ - size_t __l = (I);\ - ulong __i = Z_STRLEN_P(__p);\ - Z_STRLEN_P(__p) += __l;\ - Z_STRVAL_P(__p) = (char *)erealloc(Z_STRVAL_P(__p), Z_STRLEN_P(__p) + 1);\ - memcpy(Z_STRVAL_P(__p) + __i, (S), __l); \ - Z_STRVAL_P(__p)[Z_STRLEN_P(__p)] = '\0'; \ -} - -#define MAX_STR 512 - -void php_set_session_var(char *name, size_t namelen, zval *state_val,HashTable *var_hash PSLS_DC) -{ - PLS_FETCH(); - ELS_FETCH(); - - if (PG(register_globals)) { - zval **old_symbol; - if (zend_hash_find(&EG(symbol_table),name,namelen+1,(void *)&old_symbol) == SUCCESS) { - /* - There where old one, we need to replace it accurately. - hash_update in zend_set_hash_symbol is not good, because - it will leave referenced variables (such as local instances - of a global variable) dangling. - - BTW: if you use register_globals references between - session-vars won't work because of this very reason! - */ - - - REPLACE_ZVAL_VALUE(old_symbol,state_val,1); - - /* the following line will muck with the reference-table used for - * unserialisation - */ - - PHP_VAR_UNSERIALIZE_ZVAL_CHANGED(var_hash,state_val,*old_symbol); - - zend_set_hash_symbol(*old_symbol, name, namelen, 1, 1, Z_ARRVAL_P(PS(http_session_vars))); - } else { - zend_set_hash_symbol(state_val, name, namelen, 1, 2, Z_ARRVAL_P(PS(http_session_vars)), &EG(symbol_table)); - } - } else { - zend_set_hash_symbol(state_val, name, namelen, 0, 1, Z_ARRVAL_P(PS(http_session_vars))); - } -} - -int php_get_session_var(char *name, size_t namelen, zval ***state_var PLS_DC PSLS_DC ELS_DC) -{ - HashTable *ht = &EG(symbol_table); - - if (!PG(register_globals)) - ht = PS(http_session_vars) ? Z_ARRVAL_P(PS(http_session_vars)) : NULL; - - if (!ht) return HASH_KEY_NON_EXISTANT; - - return zend_hash_find(ht, name, namelen + 1, (void **)state_var); -} - -#define PS_BIN_NR_OF_BITS 8 -#define PS_BIN_UNDEF (1<<(PS_BIN_NR_OF_BITS-1)) -#define PS_BIN_MAX (PS_BIN_UNDEF-1) - -PS_SERIALIZER_ENCODE_FUNC(php_binary) -{ - zval *buf; - unsigned char strbuf[MAX_STR + 1]; - php_serialize_data_t var_hash; - PS_ENCODE_VARS; - - buf = ecalloc(sizeof(*buf), 1); - Z_TYPE_P(buf) = IS_STRING; - buf->refcount++; - - PHP_VAR_SERIALIZE_INIT(var_hash); - - PS_ENCODE_LOOP( - if (key_length > PS_BIN_MAX) continue; - strbuf[0] = (unsigned char) key_length; - memcpy(strbuf + 1, key, key_length); - - STR_CAT(buf, strbuf, key_length + 1); - php_var_serialize(buf, struc, &var_hash); - } else { - if (key_length > PS_BIN_MAX) continue; - strbuf[0] = (unsigned char) (key_length & PS_BIN_UNDEF); - memcpy(strbuf + 1, key, key_length); - - STR_CAT(buf, strbuf, key_length + 1); - ); - - if (newlen) *newlen = Z_STRLEN_P(buf); - *newstr = Z_STRVAL_P(buf); - efree(buf); - PHP_VAR_SERIALIZE_DESTROY(var_hash); - - return SUCCESS; -} - -PS_SERIALIZER_DECODE_FUNC(php_binary) -{ - const char *p; - char *name; - const char *endptr = val + vallen; - zval *current; - int namelen; - int has_value; - php_serialize_data_t var_hash; - - PHP_VAR_UNSERIALIZE_INIT(var_hash); - - for (p = val; p < endptr; ) { - namelen = *p & (~PS_BIN_UNDEF); - has_value = *p & PS_BIN_UNDEF ? 0 : 1; - - name = estrndup(p + 1, namelen); - - p += namelen + 1; - - if (has_value) { - MAKE_STD_ZVAL(current); - if (php_var_unserialize(¤t, &p, endptr, &var_hash)) { - php_set_session_var(name, namelen, current, &var_hash PSLS_CC); - } - zval_ptr_dtor(¤t); - } - PS_ADD_VARL(name, namelen); - efree(name); - } - - PHP_VAR_UNSERIALIZE_DESTROY(var_hash); - - return SUCCESS; -} - -#define PS_DELIMITER '|' -#define PS_UNDEF_MARKER '!' - -PS_SERIALIZER_ENCODE_FUNC(php) -{ - zval *buf; - char strbuf[MAX_STR + 1]; - php_serialize_data_t var_hash; - PS_ENCODE_VARS; - - buf = ecalloc(sizeof(*buf), 1); - Z_TYPE_P(buf) = IS_STRING; - buf->refcount++; - - PHP_VAR_SERIALIZE_INIT(var_hash); - - PS_ENCODE_LOOP( - if (key_length + 1 > MAX_STR) continue; - memcpy(strbuf, key, key_length); - strbuf[key_length] = PS_DELIMITER; - STR_CAT(buf, strbuf, key_length + 1); - - php_var_serialize(buf, struc, &var_hash); - } else { - if (key_length + 2 > MAX_STR) continue; - strbuf[0] = PS_UNDEF_MARKER; - memcpy(strbuf + 1, key, key_length); - strbuf[key_length + 1] = PS_DELIMITER; - - STR_CAT(buf, strbuf, key_length + 2); - ); - - if (newlen) *newlen = Z_STRLEN_P(buf); - *newstr = Z_STRVAL_P(buf); - efree(buf); - - PHP_VAR_SERIALIZE_DESTROY(var_hash); - return SUCCESS; -} - -PS_SERIALIZER_DECODE_FUNC(php) -{ - const char *p, *q; - char *name; - const char *endptr = val + vallen; - zval *current; - int namelen; - int has_value; - php_serialize_data_t var_hash; - - PHP_VAR_UNSERIALIZE_INIT(var_hash); - - for (p = q = val; (p < endptr) && (q = memchr(p, PS_DELIMITER, endptr - p)); p = q) { - if (p[0] == PS_UNDEF_MARKER) { - p++; - has_value = 0; - } else { - has_value = 1; - } - - namelen = q - p; - name = estrndup(p, namelen); - q++; - - if (has_value) { - MAKE_STD_ZVAL(current); - if (php_var_unserialize(¤t, &q, endptr, &var_hash)) { - php_set_session_var(name, namelen, current, &var_hash PSLS_CC); - } - zval_ptr_dtor(¤t); - } - PS_ADD_VARL(name, namelen); - efree(name); - } - - PHP_VAR_UNSERIALIZE_DESTROY(var_hash); - - return SUCCESS; -} - -static void php_session_track_init(void) -{ - zval **old_vars = NULL; - PSLS_FETCH(); - ELS_FETCH(); - - if (zend_hash_find(&EG(symbol_table), "HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS"), (void **)&old_vars) == SUCCESS && Z_TYPE_PP(old_vars) == IS_ARRAY) { - PS(http_session_vars) = *old_vars; - zend_hash_clean(Z_ARRVAL_P(PS(http_session_vars))); - } else { - if(old_vars) { - zend_hash_del(&EG(symbol_table), "HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS")); - } - MAKE_STD_ZVAL(PS(http_session_vars)); - array_init(PS(http_session_vars)); - ZEND_SET_GLOBAL_VAR_WITH_LENGTH("HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS"), PS(http_session_vars), 1, 0); - } -} - -static char *php_session_encode(int *newlen PSLS_DC) -{ - char *ret = NULL; - - if (PS(serializer)->encode(&ret, newlen PSLS_CC) == FAILURE) - ret = NULL; - - return ret; -} - -static void php_session_decode(const char *val, int vallen PSLS_DC) -{ - php_session_track_init(); - if (PS(serializer)->decode(val, vallen PSLS_CC) == FAILURE) { - php_session_destroy(PSLS_C); - php_error(E_WARNING, "Failed to decode session object. Session has been destroyed."); - } -} - -static char hexconvtab[] = "0123456789abcdef"; - -static char *_php_create_id(int *newlen PSLS_DC) -{ - PHP_MD5_CTX context; - unsigned char digest[16]; - char buf[256]; - struct timeval tv; - int i; - int j = 0; - unsigned char c; - - gettimeofday(&tv, NULL); - PHP_MD5Init(&context); - - sprintf(buf, "%ld%ld%0.8f", tv.tv_sec, tv.tv_usec, php_combined_lcg() * 10); - PHP_MD5Update(&context, buf, strlen(buf)); - - if (PS(entropy_length) > 0) { - int fd; - - fd = VCWD_OPEN((PS(entropy_file), O_RDONLY)); - if (fd >= 0) { - char buf[2048]; - int n; - int to_read = PS(entropy_length); - - while (to_read > 0) { - n = read(fd, buf, MIN(to_read, sizeof(buf))); - if (n <= 0) break; - PHP_MD5Update(&context, buf, n); - to_read -= n; - } - close(fd); - } - } - - PHP_MD5Final(digest, &context); - - for (i = 0; i < 16; i++) { - c = digest[i]; - buf[j++] = hexconvtab[c >> 4]; - buf[j++] = hexconvtab[c & 15]; - } - buf[j] = '\0'; - - if (newlen) - *newlen = j; - return estrdup(buf); -} - -static void php_session_initialize(PSLS_D) -{ - char *val; - int vallen; - - if (PS(mod)->open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) { - php_error(E_ERROR, "Failed to initialize session module"); - return; - } - if (PS(mod)->read(&PS(mod_data), PS(id), &val, &vallen) == SUCCESS) { - php_session_decode(val, vallen PSLS_CC); - efree(val); - } -} - -static void php_session_save_current_state(PSLS_D) -{ - char *val; - int vallen; - int ret = FAILURE; - char *variable; - ulong variable_len; - ulong num_key; - HashPosition pos; - PLS_FETCH(); - - if (!PG(register_globals)) { - if (!PS(http_session_vars)) { - return; - } - - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(PS(http_session_vars)), &pos); - zend_hash_get_current_key_ex(Z_ARRVAL_P(PS(http_session_vars)), &variable, &variable_len, &num_key, 0, &pos) == HASH_KEY_IS_STRING; - zend_hash_move_forward_ex(Z_ARRVAL_P(PS(http_session_vars)),&pos)) { - PS_ADD_VARL(variable,variable_len-1); - } - } - - if (PS(mod_data)) { - val = php_session_encode(&vallen PSLS_CC); - if (val) { - ret = PS(mod)->write(&PS(mod_data), PS(id), val, vallen); - efree(val); - } else { - ret = PS(mod)->write(&PS(mod_data), PS(id), "", 0); - } - } - - if (ret == FAILURE) - php_error(E_WARNING, "Failed to write session data (%s). Please " - "verify that the current setting of session.save_path " - "is correct (%s)", - PS(mod)->name, - PS(save_path)); - - - if (PS(mod_data)) - PS(mod)->close(&PS(mod_data)); -} - -static char *month_names[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" -}; - -static char *week_days[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" -}; - -static void strcpy_gmt(char *ubuf, time_t *when) -{ - char buf[MAX_STR]; - struct tm tm; - int n; - - php_gmtime_r(when, &tm); - - /* we know all components, thus it is safe to use sprintf */ - n = sprintf(buf, "%s, %d %s %d %02d:%02d:%02d GMT", week_days[tm.tm_wday], tm.tm_mday, month_names[tm.tm_mon], tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec); - memcpy(ubuf, buf, n); - ubuf[n] = '\0'; -} - -static void last_modified(void) -{ - const char *path; - struct stat sb; - char buf[MAX_STR + 1]; - SLS_FETCH(); - - path = SG(request_info).path_translated; - if (path) { - if (VCWD_STAT(path, &sb) == -1) { - return; - } - -#define LAST_MODIFIED "Last-Modified: " - memcpy(buf, LAST_MODIFIED, sizeof(LAST_MODIFIED) - 1); - strcpy_gmt(buf + sizeof(LAST_MODIFIED) - 1, &sb.st_mtime); - ADD_COOKIE(buf); - } -} - -CACHE_LIMITER_FUNC(public) -{ - char buf[MAX_STR + 1]; - time_t now; - - time(&now); - now += PS(cache_expire) * 60; -#define EXPIRES "Expires: " - memcpy(buf, EXPIRES, sizeof(EXPIRES) - 1); - strcpy_gmt(buf + sizeof(EXPIRES) - 1, &now); - ADD_COOKIE(buf); - - sprintf(buf, "Cache-Control: public, max-age=%ld", PS(cache_expire) * 60); - ADD_COOKIE(buf); - - last_modified(); -} - -CACHE_LIMITER_FUNC(private) -{ - char buf[MAX_STR + 1]; - - ADD_COOKIE("Expires: Thu, 19 Nov 1981 08:52:00 GMT"); - sprintf(buf, "Cache-Control: private, max-age=%ld, pre-check=%ld", PS(cache_expire) * 60, PS(cache_expire) * 60); - ADD_COOKIE(buf); - - last_modified(); -} - -CACHE_LIMITER_FUNC(nocache) -{ - ADD_COOKIE("Expires: Thu, 19 Nov 1981 08:52:00 GMT"); - /* For HTTP/1.1 conforming clients and the rest (MSIE 5) */ - ADD_COOKIE("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); - /* For HTTP/1.0 conforming clients */ - ADD_COOKIE("Pragma: no-cache"); -} - -static php_session_cache_limiter_t php_session_cache_limiters[] = { - CACHE_LIMITER(public) - CACHE_LIMITER(private) - CACHE_LIMITER(nocache) - {0} -}; - -static int php_session_cache_limiter(PSLS_D) -{ - php_session_cache_limiter_t *lim; - SLS_FETCH(); - - if (SG(headers_sent)) { - char *output_start_filename = php_get_output_start_filename(); - int output_start_lineno = php_get_output_start_lineno(); - - if (output_start_filename) { - php_error(E_WARNING, "Cannot send session cache limiter - headers already sent (output started at %s:%d)", - output_start_filename, output_start_lineno); - } else { - php_error(E_WARNING, "Cannot send session cache limiter - headers already sent"); - } - return (-2); - } - - for (lim = php_session_cache_limiters; lim->name; lim++) { - if (!strcasecmp(lim->name, PS(cache_limiter))) { - lim->func(PSLS_C); - return (0); - } - } - - return (-1); -} - -#define COOKIE_SET_COOKIE "Set-Cookie: " -#define COOKIE_EXPIRES "; expires=" -#define COOKIE_PATH "; path=" -#define COOKIE_DOMAIN "; domain=" -#define COOKIE_SECURE "; secure" - -static void php_session_send_cookie(PSLS_D) -{ - smart_str ncookie = {0}; - char *date_fmt = NULL; - SLS_FETCH(); - - if (SG(headers_sent)) { - char *output_start_filename = php_get_output_start_filename(); - int output_start_lineno = php_get_output_start_lineno(); - - if (output_start_filename) { - php_error(E_WARNING, "Cannot send session cookie - headers already sent by (output started at %s:%d)", - output_start_filename, output_start_lineno); - } else { - php_error(E_WARNING, "Cannot send session cookie - headers already sent"); - } - return; - } - - smart_str_appends(&ncookie, COOKIE_SET_COOKIE); - smart_str_appends(&ncookie, PS(session_name)); - smart_str_appendc(&ncookie, '='); - smart_str_appends(&ncookie, PS(id)); - - if (PS(cookie_lifetime) > 0) { - date_fmt = php_std_date(time(NULL) + PS(cookie_lifetime)); - - smart_str_appends(&ncookie, COOKIE_EXPIRES); - smart_str_appends(&ncookie, date_fmt); - efree(date_fmt); - } - - if (PS(cookie_path)[0]) { - smart_str_appends(&ncookie, COOKIE_PATH); - smart_str_appends(&ncookie, PS(cookie_path)); - } - - if (PS(cookie_domain)[0]) { - smart_str_appends(&ncookie, COOKIE_DOMAIN); - smart_str_appends(&ncookie, PS(cookie_domain)); - } - - if (PS(cookie_secure)) { - smart_str_appends(&ncookie, COOKIE_SECURE); - } - - smart_str_0(&ncookie); - - sapi_add_header(ncookie.c, ncookie.len, 0); -} - -static ps_module *_php_find_ps_module(char *name PSLS_DC) -{ - ps_module *ret = NULL; - ps_module **mod; - int i; - - for (i = 0, mod = ps_modules; i < MAX_MODULES; i++, mod++) - if (*mod && !strcasecmp(name, (*mod)->name)) { - ret = *mod; - break; - } - - return ret; -} - -static const ps_serializer *_php_find_ps_serializer(char *name PSLS_DC) -{ - const ps_serializer *ret = NULL; - const ps_serializer *mod; - - for (mod = ps_serializers; mod->name; mod++) - if (!strcasecmp(name, mod->name)) { - ret = mod; - break; - } - - return ret; -} - -#define PPID2SID \ - convert_to_string((*ppid)); \ - PS(id) = estrndup(Z_STRVAL_PP(ppid), Z_STRLEN_PP(ppid)) - -static void php_session_start(PSLS_D) -{ - pval **ppid; - pval **data; - char *p; - int send_cookie = 1; - int define_sid = 1; - int module_number = PS(module_number); - int nrand; - int lensess; - ELS_FETCH(); - - if (PS(nr_open_sessions) != 0) - return; - - lensess = strlen(PS(session_name)); - - - /* - * Cookies are preferred, because initially - * cookie and get variables will be available. - */ - - if (!PS(id)) { - if (zend_hash_find(&EG(symbol_table), "HTTP_COOKIE_VARS", - sizeof("HTTP_COOKIE_VARS"), (void **) &data) == SUCCESS && - Z_TYPE_PP(data) == IS_ARRAY && - zend_hash_find(Z_ARRVAL_PP(data), PS(session_name), - lensess + 1, (void **) &ppid) == SUCCESS) { - PPID2SID; - define_sid = 0; - send_cookie = 0; - } - - if (!PS(id) && - zend_hash_find(&EG(symbol_table), "HTTP_GET_VARS", - sizeof("HTTP_GET_VARS"), (void **) &data) == SUCCESS && - Z_TYPE_PP(data) == IS_ARRAY && - zend_hash_find(Z_ARRVAL_PP(data), PS(session_name), - lensess + 1, (void **) &ppid) == SUCCESS) { - PPID2SID; - } - - if (!PS(id) && - zend_hash_find(&EG(symbol_table), "HTTP_POST_VARS", - sizeof("HTTP_POST_VARS"), (void **) &data) == SUCCESS && - Z_TYPE_PP(data) == IS_ARRAY && - zend_hash_find(Z_ARRVAL_PP(data), PS(session_name), - lensess + 1, (void **) &ppid) == SUCCESS) { - PPID2SID; - } - } - - /* check the REQUEST_URI symbol for a string of the form - '<session-name>=<session-id>' to allow URLs of the form - http://yoursite/<session-name>=<session-id>/script.php */ - - if (!PS(id) && - zend_hash_find(&EG(symbol_table), "REQUEST_URI", - sizeof("REQUEST_URI"), (void **) &data) == SUCCESS && - Z_TYPE_PP(data) == IS_STRING && - (p = strstr(Z_STRVAL_PP(data), PS(session_name))) && - p[lensess] == '=') { - char *q; - - p += lensess + 1; - if ((q = strpbrk(p, "/?\\"))) - PS(id) = estrndup(p, q - p); - } - - /* check whether the current request was referred to by - an external site which invalidates the previously found id */ - - if (PS(id) && - PS(extern_referer_chk)[0] != '\0' && - zend_hash_find(&EG(symbol_table), "HTTP_REFERER", - sizeof("HTTP_REFERER"), (void **) &data) == SUCCESS && - Z_TYPE_PP(data) == IS_STRING && - Z_STRLEN_PP(data) != 0 && - strstr(Z_STRVAL_PP(data), PS(extern_referer_chk)) == NULL) { - efree(PS(id)); - PS(id) = NULL; - send_cookie = 1; - define_sid = 1; - } - - if (!PS(id)) - PS(id) = _php_create_id(NULL PSLS_CC); - - if (!PS(use_cookies) && send_cookie) { - define_sid = 1; - send_cookie = 0; - } - - if (send_cookie) - php_session_send_cookie(PSLS_C); - - if (define_sid) { - smart_str var = {0}; - - smart_str_appends(&var, PS(session_name)); - smart_str_appendc(&var, '='); - smart_str_appends(&var, PS(id)); - smart_str_0(&var); - REGISTER_STRING_CONSTANT("SID", var.c, 0); - } else - REGISTER_STRING_CONSTANT("SID", empty_string, 0); - PS(define_sid) = define_sid; - - PS(nr_open_sessions)++; - - php_session_cache_limiter(PSLS_C); - php_session_initialize(PSLS_C); - - if (PS(mod_data) && PS(gc_probability) > 0) { - int nrdels = -1; - - srand(time(NULL)); - nrand = (int) (100.0*rand()/RAND_MAX); - if (nrand < PS(gc_probability)) { - PS(mod)->gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels); -#if 0 - if (nrdels != -1) - php_error(E_NOTICE, "purged %d expired session objects\n", nrdels); -#endif - } - } -} - -static zend_bool php_session_destroy(PSLS_D) -{ - zend_bool retval = SUCCESS; - - if (PS(nr_open_sessions) == 0) { - php_error(E_WARNING, "Trying to destroy uninitialized session"); - return FAILURE; - } - - if (PS(mod)->destroy(&PS(mod_data), PS(id)) == FAILURE) { - retval = FAILURE; - php_error(E_WARNING, "Session object destruction failed"); - } - - php_rshutdown_session_globals(PSLS_C); - php_rinit_session_globals(PSLS_C); - - return retval; -} - - -/* {{{ proto void session_set_cookie_params(int lifetime [, string path [, string domain [, bool secure]]]) - Set session cookie parameters */ -PHP_FUNCTION(session_set_cookie_params) -{ - zval **lifetime, **path, **domain, **secure; - PSLS_FETCH(); - - if (!PS(use_cookies)) - return; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 4 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &lifetime, &path, &domain, &secure) == FAILURE) - WRONG_PARAM_COUNT; - - convert_to_long_ex(lifetime); - PS(cookie_lifetime) = Z_LVAL_PP(lifetime); - - if (ZEND_NUM_ARGS() > 1) { - convert_to_string_ex(path); - zend_alter_ini_entry("session.cookie_path", sizeof("session.cookie_path"), Z_STRVAL_PP(path), Z_STRLEN_PP(path), PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - - if (ZEND_NUM_ARGS() > 2) { - convert_to_string_ex(domain); - zend_alter_ini_entry("session.cookie_domain", sizeof("session.cookie_domain"), Z_STRVAL_PP(domain), Z_STRLEN_PP(domain), PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - if (ZEND_NUM_ARGS() > 3) { - convert_to_long_ex(secure); - zend_alter_ini_entry("session.cookie_secure", sizeof("session.cookie_secure"), Z_BVAL_PP(secure)?"1":"0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - } - } - } -} -/* }}} */ - -/* {{{ proto array session_get_cookie_params(void) - Return the session cookie parameters */ -PHP_FUNCTION(session_get_cookie_params) -{ - PSLS_FETCH(); - - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - if (array_init(return_value) == FAILURE) { - php_error(E_ERROR, "Cannot initialize return value from session_get_cookie_parameters"); - RETURN_FALSE; - } - - add_assoc_long(return_value, "lifetime", PS(cookie_lifetime)); - add_assoc_string(return_value, "path", PS(cookie_path), 1); - add_assoc_string(return_value, "domain", PS(cookie_domain), 1); - add_assoc_bool(return_value, "secure", PS(cookie_secure)); -} -/* }}} */ - -/* {{{ proto string session_name([string newname]) - Return the current session name. If newname is given, the session name is replaced with newname */ -PHP_FUNCTION(session_name) -{ - pval **p_name; - int ac = ZEND_NUM_ARGS(); - char *old; - PSLS_FETCH(); - - old = estrdup(PS(session_name)); - - if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE) - WRONG_PARAM_COUNT; - - if (ac == 1) { - convert_to_string_ex(p_name); - zend_alter_ini_entry("session.name", sizeof("session.name"), Z_STRVAL_PP(p_name), Z_STRLEN_PP(p_name), PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - } - - RETVAL_STRING(old, 0); -} -/* }}} */ - -/* {{{ proto string session_module_name([string newname]) - Return the current module name used for accessing session data. If newname is given, the module name is replaced with newname */ -PHP_FUNCTION(session_module_name) -{ - pval **p_name; - int ac = ZEND_NUM_ARGS(); - char *old; - PSLS_FETCH(); - - old = estrdup(PS(mod)->name); - - if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE) - WRONG_PARAM_COUNT; - - if (ac == 1) { - ps_module *tempmod; - - convert_to_string_ex(p_name); - tempmod = _php_find_ps_module(Z_STRVAL_PP(p_name) PSLS_CC); - if (tempmod) { - if (PS(mod_data)) - PS(mod)->close(&PS(mod_data)); - PS(mod) = tempmod; - PS(mod_data) = NULL; - } else { - efree(old); - php_error(E_ERROR, "Cannot find named PHP session module (%s)", - Z_STRVAL_PP(p_name)); - RETURN_FALSE; - } - } - - RETVAL_STRING(old, 0); -} -/* }}} */ - -/* {{{ proto void session_set_save_handler(string open, string close, string read, string write, string destroy, string gc) - Sets user-level functions */ -PHP_FUNCTION(session_set_save_handler) -{ - zval **args[6]; - int i; - ps_user *mdata; - PSLS_FETCH(); - - if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_array_ex(6, args) == FAILURE) - WRONG_PARAM_COUNT; - - if (PS(nr_open_sessions) > 0) - RETURN_FALSE; - - zend_alter_ini_entry("session.save_handler", sizeof("session.save_handler"), "user", sizeof("user")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - - mdata = emalloc(sizeof(*mdata)); - - for (i = 0; i < 6; i++) { - ZVAL_ADDREF(*args[i]); - mdata->names[i] = *args[i]; - } - - PS(mod_data) = (void *) mdata; - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string session_save_path([string newname]) - Return the current save path passed to module_name. If newname is given, the save path is replaced with newname */ -PHP_FUNCTION(session_save_path) -{ - pval **p_name; - int ac = ZEND_NUM_ARGS(); - char *old; - PSLS_FETCH(); - - old = estrdup(PS(save_path)); - - if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE) - WRONG_PARAM_COUNT; - - if (ac == 1) { - convert_to_string_ex(p_name); - zend_alter_ini_entry("session.save_path", sizeof("session.save_path"), Z_STRVAL_PP(p_name), Z_STRLEN_PP(p_name), PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - } - - RETVAL_STRING(old, 0); -} -/* }}} */ - -/* {{{ proto string session_id([string newid]) - Return the current session id. If newid is given, the session id is replaced with newid */ -PHP_FUNCTION(session_id) -{ - pval **p_name; - int ac = ZEND_NUM_ARGS(); - char *old = empty_string; - PSLS_FETCH(); - - if (PS(id)) - old = estrdup(PS(id)); - - if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE) - WRONG_PARAM_COUNT; - - if (ac == 1) { - convert_to_string_ex(p_name); - if (PS(id)) efree(PS(id)); - PS(id) = estrndup(Z_STRVAL_PP(p_name), Z_STRLEN_PP(p_name)); - } - - RETVAL_STRING(old, 0); -} -/* }}} */ - -/* {{{ proto string session_cache_limiter([string new_cache_limiter]) - Return the current cache limiter. If new_cache_limited is given, the current cache_limiter is replaced with new_cache_limiter */ -PHP_FUNCTION(session_cache_limiter) -{ - pval **p_cache_limiter; - int ac = ZEND_NUM_ARGS(); - char *old; - PSLS_FETCH(); - - old = estrdup(PS(cache_limiter)); - - if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_cache_limiter) == FAILURE) - WRONG_PARAM_COUNT; - - if (ac == 1) { - convert_to_string_ex(p_cache_limiter); - zend_alter_ini_entry("session.cache_limiter", sizeof("session.cache_limiter"), Z_STRVAL_PP(p_cache_limiter), Z_STRLEN_PP(p_cache_limiter), PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - } - - RETVAL_STRING(old, 0); -} -/* }}} */ - -/* {{{ static void php_register_var(zval** entry PSLS_DC PLS_DC) */ -static void php_register_var(zval** entry PSLS_DC PLS_DC) -{ - zval **value; - - if (Z_TYPE_PP(entry) == IS_ARRAY) { - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(entry)); - - while (zend_hash_get_current_data(Z_ARRVAL_PP(entry), (void**)&value) == SUCCESS) { - php_register_var(value PSLS_CC PLS_CC); - zend_hash_move_forward(Z_ARRVAL_PP(entry)); - } - } else { - convert_to_string_ex(entry); - - if (strcmp(Z_STRVAL_PP(entry), "HTTP_SESSION_VARS") != 0) - PS_ADD_VARL(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry)); - } -} -/* }}} */ - -/* {{{ proto bool session_register(mixed var_names [, mixed ...]) - Adds varname(s) to the list of variables which are freezed at the session end */ -PHP_FUNCTION(session_register) -{ - zval ***args; - int argc = ZEND_NUM_ARGS(); - int i; - PSLS_FETCH(); - PLS_FETCH(); - - if (argc <= 0) - RETURN_FALSE - else - args = (zval ***)emalloc(argc * sizeof(zval **)); - - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - if (PS(nr_open_sessions) == 0) - php_session_start(PSLS_C); - - for (i = 0; i < argc; i++) { - if (Z_TYPE_PP(args[i]) == IS_ARRAY) - SEPARATE_ZVAL(args[i]); - php_register_var(args[i] PSLS_CC PLS_CC); - } - - efree(args); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool session_unregister(string varname) - Removes varname from the list of variables which are freezed at the session end */ -PHP_FUNCTION(session_unregister) -{ - pval **p_name; - int ac = ZEND_NUM_ARGS(); - PSLS_FETCH(); - - if (ac != 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE) - WRONG_PARAM_COUNT; - - convert_to_string_ex(p_name); - - PS_DEL_VAR(Z_STRVAL_PP(p_name)); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool session_is_registered(string varname) - Checks if a variable is registered in session */ -PHP_FUNCTION(session_is_registered) -{ - pval **p_name; - pval *p_var; - int ac = ZEND_NUM_ARGS(); - PSLS_FETCH(); - - if (ac != 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE) - WRONG_PARAM_COUNT; - - convert_to_string_ex(p_name); - - if (zend_hash_find(&PS(vars), Z_STRVAL_PP(p_name), - Z_STRLEN_PP(p_name)+1, (void **)&p_var) == SUCCESS) - RETURN_TRUE - else - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto string session_encode(void) - Serializes the current setup and returns the serialized representation */ -PHP_FUNCTION(session_encode) -{ - int len; - char *enc; - PSLS_FETCH(); - - enc = php_session_encode(&len PSLS_CC); - RETVAL_STRINGL(enc, len, 0); -} -/* }}} */ - -/* {{{ proto bool session_decode(string data) - Deserializes data and reinitializes the variables */ -PHP_FUNCTION(session_decode) -{ - pval **str; - PSLS_FETCH(); - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) - WRONG_PARAM_COUNT; - - convert_to_string_ex(str); - - php_session_decode(Z_STRVAL_PP(str), Z_STRLEN_PP(str) PSLS_CC); -} -/* }}} */ - -/* {{{ proto bool session_start(void) - Begin session - reinitializes freezed variables, registers browsers etc */ -PHP_FUNCTION(session_start) -{ - PSLS_FETCH(); - - php_session_start(PSLS_C); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool session_destroy(void) - Destroy the current session and all data associated with it */ -PHP_FUNCTION(session_destroy) -{ - PSLS_FETCH(); - - if (php_session_destroy(PSLS_C) == SUCCESS) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -#ifdef TRANS_SID -void session_adapt_uris(const char *src, size_t srclen, char **new, size_t *newlen) -{ - PSLS_FETCH(); - - if (PS(define_sid) && PS(nr_open_sessions) > 0) - *new = url_adapt_ext_ex(src, srclen, PS(session_name), PS(id), newlen); -} - -void session_adapt_url(const char *url, size_t urllen, char **new, size_t *newlen) -{ - PSLS_FETCH(); - - if (PS(define_sid) && PS(nr_open_sessions) > 0) - *new = url_adapt_single_url(url, urllen, PS(session_name), PS(id), newlen); -} -#endif - -/* {{{ proto void session_unset(void) - Unset all registered variables */ -PHP_FUNCTION(session_unset) -{ - zval **tmp; - char *variable; - ulong num_key; - PSLS_FETCH(); - - if (PS(nr_open_sessions) == 0) - RETURN_FALSE; - - for (zend_hash_internal_pointer_reset(&PS(vars)); - zend_hash_get_current_key(&PS(vars), &variable, &num_key, 0) == HASH_KEY_IS_STRING; - zend_hash_move_forward(&PS(vars))) { - if (zend_hash_find(&EG(symbol_table), variable, strlen(variable) + 1, (void **) &tmp) - == SUCCESS) - zend_hash_del(&EG(symbol_table), variable, strlen(variable) + 1); - } - - /* Clean $HTTP_SESSION_VARS. */ - zend_hash_clean(Z_ARRVAL_P(PS(http_session_vars))); -} -/* }}} */ - -static void php_rinit_session_globals(PSLS_D) -{ - zend_hash_init(&PS(vars), 0, NULL, NULL, 0); - PS(define_sid) = 0; - PS(id) = NULL; - PS(nr_open_sessions) = 0; - PS(mod_data) = NULL; -} - -static void php_rshutdown_session_globals(PSLS_D) -{ - if (PS(mod_data)) - PS(mod)->close(&PS(mod_data)); - if (PS(id)) - efree(PS(id)); - zend_hash_destroy(&PS(vars)); -} - - -PHP_RINIT_FUNCTION(session) -{ - PSLS_FETCH(); - - php_rinit_session_globals(PSLS_C); - - if (PS(mod) == NULL) { - char *value; - - value = zend_ini_string("session.save_handler", sizeof("session.save_handler"), 0); - if (value) { - PS(mod) = _php_find_ps_module(value PSLS_CC); - } - - if (!PS(mod)) { - /* current status is unusable */ - PS(nr_open_sessions) = -1; - return SUCCESS; - } - } - - if (PS(auto_start)) { - php_session_start(PSLS_C); - } - - return SUCCESS; -} - -static void php_session_flush(PSLS_D) -{ - if (PS(nr_open_sessions) > 0) { - php_session_save_current_state(PSLS_C); - PS(nr_open_sessions)--; - } -} - -PHP_FUNCTION(session_write_close) -{ - PSLS_FETCH(); - php_session_flush(PSLS_C); -} - -PHP_RSHUTDOWN_FUNCTION(session) -{ - PSLS_FETCH(); - - php_session_flush(PSLS_C); - php_rshutdown_session_globals(PSLS_C); - return SUCCESS; -} - - - -PHP_MINIT_FUNCTION(session) -{ -#ifdef ZTS - php_ps_globals *ps_globals; - - ps_globals_id = ts_allocate_id(sizeof(php_ps_globals), NULL, NULL); - ps_globals = ts_resource(ps_globals_id); -#endif - - PS(module_number) = module_number; - REGISTER_INI_ENTRIES(); - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(session) -{ - UNREGISTER_INI_ENTRIES(); - return SUCCESS; -} - - -PHP_MINFO_FUNCTION(session) -{ - - php_info_print_table_start(); - php_info_print_table_row(2, "Session Support", "enabled" ); - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 tw=78 fdm=marker - * vim<600: sw=4 ts=4 tw=78 - */ diff --git a/ext/session/setup.stub b/ext/session/setup.stub deleted file mode 100644 index 33ca6e8664..0000000000 --- a/ext/session/setup.stub +++ /dev/null @@ -1,6 +0,0 @@ -# $Source$ -# $Id$ - -define_option with-session 'session support?' yesnodir no \ -' Whether to build the session extension.' - diff --git a/ext/session/tests/001.phpt b/ext/session/tests/001.phpt deleted file mode 100644 index aac17cb3d5..0000000000 --- a/ext/session/tests/001.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Session Object Serialization ---FILE-- -<? - -class foo { - var $bar = "ok"; - - function method() { $this->yes = "done"; } -} - -$baz = new foo; -$baz->method(); - -$arr[3] = new foo; -$arr[3]->method(); - -session_register("baz"); -session_register("arr"); - -print session_encode()."\n"; - -session_destroy(); ---GET-- ---POST-- ---EXPECT-- -baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";s:4:"done";}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";s:4:"done";}} diff --git a/ext/session/tests/002.phpt b/ext/session/tests/002.phpt deleted file mode 100644 index 60ece0dc96..0000000000 --- a/ext/session/tests/002.phpt +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -session_unset() without any session ---FILE-- -<? -session_unset(); -print "ok\n"; ---GET-- ---POST-- ---EXPECT-- -ok diff --git a/ext/session/tests/003.phpt b/ext/session/tests/003.phpt deleted file mode 100644 index 5401a2d0ba..0000000000 --- a/ext/session/tests/003.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -Session Object Deserialization ---FILE-- -<? - -class foo { - var $bar = "ok"; - function method() { $this->yes++; } -} - -session_id("test"); -session_start(); -session_decode('baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}}'); - -$baz->method(); -$arr[3]->method(); - -var_dump($baz); -var_dump($arr); -session_destroy(); ---EXPECT-- -object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(2) -} -array(1) { - [3]=> - &object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(2) - } -} diff --git a/ext/session/tests/004.phpt b/ext/session/tests/004.phpt deleted file mode 100644 index 8e6ec4e8d3..0000000000 --- a/ext/session/tests/004.phpt +++ /dev/null @@ -1,103 +0,0 @@ ---TEST-- -session_set_save_handler test ---FILE-- -<? - -class handler { - var $data = 'baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}}'; - function open($save_path, $session_name) - { - print "OPEN: $save_path, $session_name\n"; - return true; - } - function close() - { - return true; - } - function read($key) - { - print "READ: $key\n"; - return $GLOBALS["hnd"]->data; - } - - function write($key, $val) - { - print "WRITE: $key, $val\n"; - $GLOBALS["hnd"]->data = $val; - return true; - } - - function destroy($key) - { - print "DESTROY: $key\n"; - return true; - } - - function gc() { return true; } -} - -$hnd = new handler; - -class foo { - var $bar = "ok"; - function method() { $this->yes++; } -} - -ob_start(); - -session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); - -session_id("test"); -session_start(); -$baz->method(); -$arr[3]->method(); - -var_dump($baz); -var_dump($arr); - -session_write_close(); - -session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); -session_start(); - -var_dump($baz); -var_dump($arr); - -session_destroy(); ---EXPECT-- -OPEN: /tmp, PHPSESSID -READ: test -object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(2) -} -array(1) { - [3]=> - &object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(2) - } -} -WRITE: test, baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}} -OPEN: /tmp, PHPSESSID -READ: test -object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(2) -} -array(1) { - [3]=> - object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(2) - } -} -DESTROY: test diff --git a/ext/session/tests/005.phpt b/ext/session/tests/005.phpt deleted file mode 100644 index 38e660b100..0000000000 --- a/ext/session/tests/005.phpt +++ /dev/null @@ -1,138 +0,0 @@ ---TEST-- -Custom save handler, multiple session_start()s, complex data structure test. ---FILE-- -<?php - -class handler { - var $data = 'baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}}'; - function open($save_path, $session_name) - { - print "OPEN: $save_path, $session_name\n"; - return true; - } - function close() - { - print "CLOSE\n"; - return true; - } - function read($key) - { - print "READ: $key\n"; - return $GLOBALS["hnd"]->data; - } - - function write($key, $val) - { - print "WRITE: $key, $val\n"; - $GLOBALS["hnd"]->data = $val; - return true; - } - - function destroy($key) - { - print "DESTROY: $key\n"; - return true; - } - - function gc() { return true; } -} - -$hnd = new handler; - -class foo { - var $bar = "ok"; - function method() { $this->yes++; } -} - -ob_start(); - -session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); - -session_id("test"); -session_start(); -$baz->method(); -$arr[3]->method(); - -var_dump($baz); -var_dump($arr); - -session_write_close(); - -session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); -session_start(); -$baz->method(); -$arr[3]->method(); - - -$c = 123; -session_register("c"); -var_dump($baz); var_dump($arr); var_dump($c); - -session_write_close(); - -session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); -session_start(); -var_dump($baz); var_dump($arr); var_dump($c); - -session_destroy(); -?> ---EXPECT-- -OPEN: /tmp, PHPSESSID -READ: test -object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(2) -} -array(1) { - [3]=> - &object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(2) - } -} -WRITE: test, baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}} -CLOSE -OPEN: /tmp, PHPSESSID -READ: test -object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(3) -} -array(1) { - [3]=> - &object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(3) - } -} -int(123) -WRITE: test, baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:3;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:3;}}c|i:123; -CLOSE -OPEN: /tmp, PHPSESSID -READ: test -object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(3) -} -array(1) { - [3]=> - object(foo)(2) { - ["bar"]=> - string(2) "ok" - ["yes"]=> - int(3) - } -} -int(123) -DESTROY: test -CLOSE diff --git a/ext/session/tests/006.phpt b/ext/session/tests/006.phpt deleted file mode 100644 index 91f1cb949d..0000000000 --- a/ext/session/tests/006.phpt +++ /dev/null @@ -1,62 +0,0 @@ ---TEST-- -References between variables in sessions ---FILE-- -<?php -ob_start(); -session_id("test"); -session_start(); - -class a { - var $test = "hallo"; -} - -class b { - var $a; - function b(&$a) { - $this->a = &$a; - } -} - -$a = new a(); -$b = new b($a); - -echo "original values:\n"; -var_dump($a,$b); - -session_register("a"); -session_register("b"); -session_write_close(); - -session_unregister("a"); -session_unregister("b"); - -session_start(); - -echo "values after session:\n"; -var_dump($a,$b); -?> ---EXPECT-- -original values: -object(a)(1) { - ["test"]=> - string(5) "hallo" -} -object(b)(1) { - ["a"]=> - &object(a)(1) { - ["test"]=> - string(5) "hallo" - } -} -values after session: -object(a)(1) { - ["test"]=> - string(5) "hallo" -} -object(b)(1) { - ["a"]=> - &object(a)(1) { - ["test"]=> - string(5) "hallo" - } -} |