summaryrefslogtreecommitdiff
path: root/ext/session
diff options
context:
space:
mode:
Diffstat (limited to 'ext/session')
-rw-r--r--ext/session/CREDITS2
-rw-r--r--ext/session/config.m433
-rw-r--r--ext/session/mod_files.c406
-rw-r--r--ext/session/mod_files.h27
-rw-r--r--ext/session/mod_files.sh16
-rw-r--r--ext/session/mod_mm.c437
-rw-r--r--ext/session/mod_mm.h35
-rw-r--r--ext/session/mod_user.c184
-rw-r--r--ext/session/mod_user.h39
-rw-r--r--ext/session/php_session.h236
-rw-r--r--ext/session/session.c1778
-rw-r--r--ext/session/tests/001.phpt35
-rw-r--r--ext/session/tests/002.phpt13
-rw-r--r--ext/session/tests/003.phpt44
-rw-r--r--ext/session/tests/004.phpt111
-rw-r--r--ext/session/tests/005.phpt146
-rw-r--r--ext/session/tests/006.phpt70
-rw-r--r--ext/session/tests/007.phpt59
-rw-r--r--ext/session/tests/008-php4.2.3.phpt68
-rw-r--r--ext/session/tests/008.phpt61
-rw-r--r--ext/session/tests/009.phpt57
-rw-r--r--ext/session/tests/010.phpt19
-rw-r--r--ext/session/tests/011.phpt20
-rw-r--r--ext/session/tests/012.phpt34
-rw-r--r--ext/session/tests/013.phpt26
-rw-r--r--ext/session/tests/014.phpt37
-rw-r--r--ext/session/tests/015.phpt24
-rw-r--r--ext/session/tests/016.phpt20
-rw-r--r--ext/session/tests/017.phpt25
-rw-r--r--ext/session/tests/018.phpt24
-rw-r--r--ext/session/tests/019.phpt72
-rw-r--r--ext/session/tests/020.phpt25
-rw-r--r--ext/session/tests/021.phpt61
-rw-r--r--ext/session/tests/skipif.inc10
34 files changed, 0 insertions, 4254 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/config.m4 b/ext/session/config.m4
deleted file mode 100644
index 4e5a4ddd2c..0000000000
--- a/ext/session/config.m4
+++ /dev/null
@@ -1,33 +0,0 @@
-dnl
-dnl $Id$
-dnl
-
-PHP_ARG_ENABLE(session, whether to enable PHP sessions,
-[ --disable-session Disable session support], yes)
-
-PHP_ARG_WITH(mm,for mm support,
-[ --with-mm[=DIR] Include mm support for session storage], no, no)
-
-if test "$PHP_SESSION" != "no"; then
- PHP_PWRITE_TEST
- PHP_PREAD_TEST
- PHP_NEW_EXTENSION(session, session.c mod_files.c mod_mm.c mod_user.c, $ext_shared)
- PHP_SUBST(SESSION_SHARED_LIBADD)
- AC_DEFINE(HAVE_PHP_SESSION,1,[ ])
-fi
-
-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])
-fi
diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c
deleted file mode 100644
index f276201a85..0000000000
--- a/ext/session/mod_files.c
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 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. |
- +----------------------------------------------------------------------+
- | Author: 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>
-
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#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;
- int filemode;
-} ps_files;
-
-ps_module ps_mod_files = {
- PS_MOD(files)
-};
-
-/* If you change the logic here, please also update the error message in
- * ps_files_open() appropriately */
-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')
- || c == ','
- || c == '-')) {
- 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 TSRMLS_DC)
-{
- 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)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,'");
- return;
- }
- if (!ps_files_path_create(buf, sizeof(buf), data, key))
- return;
-
- data->lastkey = estrdup(key);
-
- data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY,
- data->filemode);
-
- if (data->fd != -1) {
- flock(data->fd, LOCK_EX);
-
-#ifdef F_SETFD
- if (fcntl(data->fd, F_SETFD, 1)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "fcntl(%d, F_SETFD, 1) failed: %s (%d)", data->fd, strerror(errno), errno);
- }
-#endif
- } else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "open(%s, O_RDWR) failed: %s (%d)", buf,
- strerror(errno), errno);
- }
- }
-}
-
-static int ps_files_cleanup_dir(const char *dirname, int maxlifetime TSRMLS_DC)
-{
- 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_docref(NULL TSRMLS_CC, 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_mtime) > 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;
- const char *p, *last;
- const char *argv[3];
- int argc = 0;
- size_t dirdepth = 0;
- int filemode = 0600;
-
- /* split up input parameter */
- last = save_path;
- p = strchr(save_path, ';');
- while (p) {
- argv[argc++] = last;
- last = ++p;
- p = strchr(p, ';');
- if (argc > 1) break;
- }
- argv[argc++] = last;
-
- if (argc > 1) {
- errno = 0;
- dirdepth = (size_t) strtol(argv[0], NULL, 10);
- if (errno == ERANGE) {
- php_error(E_WARNING,
- "The first parameter in session.save_path is invalid");
- return FAILURE;
- }
- }
-
- if (argc > 2) {
- errno = 0;
- filemode = strtol(argv[1], NULL, 8);
- if (errno == ERANGE || filemode < 0 || filemode > 07777) {
- php_error(E_WARNING,
- "The second parameter in session.save_path is invalid");
- return FAILURE;
- }
- }
- save_path = argv[argc - 1];
-
- data = emalloc(sizeof(*data));
- memset(data, 0, sizeof(*data));
-
- data->fd = -1;
- data->dirdepth = dirdepth;
- data->filemode = filemode;
- data->basedir_len = strlen(save_path);
- data->basedir = estrndup(save_path, data->basedir_len);
-
- PS_SET_MOD_DATA(data);
-
- 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 TSRMLS_CC);
- 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);
-
-#if defined(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) {
- if (n == -1)
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "read failed: %s (%d)", strerror(errno), errno);
- else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "read returned less bytes than requested");
- efree(*val);
- return FAILURE;
- }
-
- return SUCCESS;
-}
-
-PS_WRITE_FUNC(files)
-{
- long n;
- PS_FILES_DATA;
-
- ps_files_open(data, key TSRMLS_CC);
- 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);
-
-#if defined(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) {
- if (n == -1)
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "write failed: %s (%d)", strerror(errno), errno);
- else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "write wrote less bytes than requested");
- 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 TSRMLS_CC);
-
- return SUCCESS;
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/ext/session/mod_files.h b/ext/session/mod_files.h
deleted file mode 100644
index 652920a17c..0000000000
--- a/ext/session/mod_files.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 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. |
- +----------------------------------------------------------------------+
- | Author: 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 df18659278..0000000000
--- a/ext/session/mod_mm.c
+++ /dev/null
@@ -1,437 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 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. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-
-#ifdef HAVE_LIBMM
-
-#include <unistd.h>
-#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"
-#include "SAPI.h"
-
-#ifdef ZTS
-# error mm is not thread-safe
-#endif
-
-#define PS_MM_FILE "session_mm_"
-
-/* For php_uint32 */
-#include "ext/standard/basic_functions.h"
-
-/*
- * this list holds all data associated with one session
- */
-
-typedef struct ps_sd {
- struct ps_sd *next;
- php_uint32 hv; /* hash value of key */
- time_t ctime; /* time of last change */
- void *data;
- size_t datalen; /* amount of valid data */
- size_t alloclen; /* amount of allocated memory for data */
- char key[1]; /* inline key */
-} ps_sd;
-
-typedef struct {
- MM *mm;
- ps_sd **hash;
- php_uint32 hash_max;
- php_uint32 hash_cnt;
- pid_t owner;
-} ps_mm;
-
-static ps_mm *ps_mm_instance = NULL;
-
-#if 0
-#define ps_mm_debug(a) printf a
-#else
-#define ps_mm_debug(a)
-#endif
-
-static inline php_uint32 ps_sd_hash(const char *data, int len)
-{
- php_uint32 h;
- const char *e = data + len;
-
- for (h = 2166136261U; data < e; ) {
- h *= 16777619;
- h ^= *data++;
- }
-
- return h;
-}
-
-static void hash_split(ps_mm *data)
-{
- php_uint32 nmax;
- ps_sd **nhash;
- ps_sd **ohash, **ehash;
- ps_sd *ps, *next;
-
- nmax = ((data->hash_max + 1) << 1) - 1;
- nhash = mm_calloc(data->mm, nmax + 1, sizeof(*data->hash));
-
- if (!nhash) {
- /* no further memory to expand hash table */
- return;
- }
-
- ehash = data->hash + data->hash_max + 1;
- for (ohash = data->hash; ohash < ehash; ohash++) {
- for (ps = *ohash; ps; ps = next) {
- next = ps->next;
- ps->next = nhash[ps->hv & nmax];
- nhash[ps->hv & nmax] = ps;
- }
- }
- mm_free(data->mm, data->hash);
-
- data->hash = nhash;
- data->hash_max = nmax;
-}
-
-static ps_sd *ps_sd_new(ps_mm *data, const char *key)
-{
- php_uint32 hv, slot;
- ps_sd *sd;
- int keylen;
-
- keylen = strlen(key);
-
- sd = mm_malloc(data->mm, sizeof(ps_sd) + keylen);
- if (!sd) {
- TSRMLS_FETCH();
-
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "mm_malloc failed, avail %d, err %s", mm_available(data->mm), mm_error());
- return NULL;
- }
-
- hv = ps_sd_hash(key, keylen);
- slot = hv & data->hash_max;
-
- sd->ctime = 0;
- sd->hv = hv;
- sd->data = NULL;
- sd->alloclen = sd->datalen = 0;
-
- memcpy(sd->key, key, keylen + 1);
-
- sd->next = data->hash[slot];
- data->hash[slot] = sd;
-
- data->hash_cnt++;
-
- if (!sd->next) {
- if (data->hash_cnt >= data->hash_max)
- hash_split(data);
- }
-
- ps_mm_debug(("inserting %s(%p) into slot %d\n", key, sd, slot));
-
- return sd;
-}
-
-static void ps_sd_destroy(ps_mm *data, ps_sd *sd)
-{
- php_uint32 slot;
-
- slot = ps_sd_hash(sd->key, strlen(sd->key)) & data->hash_max;
-
- if (data->hash[slot] == sd)
- data->hash[slot] = sd->next;
- else {
- ps_sd *prev;
-
- /* There must be some entry before the one we want to delete */
- for (prev = data->hash[slot]; prev->next != sd; prev = prev->next);
- prev->next = sd->next;
- }
-
- data->hash_cnt--;
- 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)
-{
- php_uint32 hv, slot;
- ps_sd *ret, *prev;
-
- hv = ps_sd_hash(key, strlen(key));
- slot = hv & data->hash_max;
-
- for (prev = NULL, ret = data->hash[slot]; ret; prev = ret, ret = ret->next)
- if (ret->hv == hv && !strcmp(ret->key, key))
- break;
-
- if (ret && rw && ret != data->hash[slot]) {
- /* Move the entry to the top of the linked list */
-
- if (prev)
- prev->next = ret->next;
- ret->next = data->hash[slot];
- data->hash[slot] = ret;
- }
-
- ps_mm_debug(("lookup(%s): ret=%p,hv=%u,slot=%d\n", key, ret, hv, slot));
-
- 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->owner = getpid();
- data->mm = mm_create(0, path);
- if (!data->mm) {
- return FAILURE;
- }
-
- data->hash_cnt = 0;
- data->hash_max = 511;
- data->hash = mm_calloc(data->mm, data->hash_max + 1, sizeof(ps_sd *));
- 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;
-
- /* This function is called during each module shutdown,
- but we must not release the shared memory pool, when
- an Apache child dies! */
- if (data->owner != getpid()) return;
-
- for (h = 0; h < data->hash_max + 1; 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);
- free(data);
-}
-
-PHP_MINIT_FUNCTION(ps_mm)
-{
- int save_path_len = strlen(PS(save_path));
- int mod_name_len = strlen(sapi_module.name);
- char *ps_mm_path, euid[30];
- int ret;
-
- ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1);
- if (!ps_mm_instance)
- return FAILURE;
-
- if (!sprintf(euid,"%d", geteuid()))
- return FAILURE;
-
- /* Directory + '/' + File + Module Name + Effective UID + \0 */
- ps_mm_path = do_alloca(save_path_len+1+sizeof(PS_MM_FILE)+mod_name_len+strlen(euid)+1);
-
- memcpy(ps_mm_path, PS(save_path), save_path_len + 1);
- if (save_path_len > 0 && ps_mm_path[save_path_len - 1] != DEFAULT_SLASH) {
- ps_mm_path[save_path_len] = DEFAULT_SLASH;
- ps_mm_path[save_path_len+1] = '\0';
- }
- strcat(ps_mm_path, PS_MM_FILE);
- strcat(ps_mm_path, sapi_module.name);
- strcat(ps_mm_path, euid);
-
- ret = ps_mm_initialize(ps_mm_instance, ps_mm_path);
-
- free_alloca(ps_mm_path);
-
- if (ret != SUCCESS) {
- free(ps_mm_instance);
- 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);
- 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 + 1);
- memcpy(*val, sd->data, sd->datalen);
- (*val)[sd->datalen] = '\0';
- ret = SUCCESS;
- }
-
- mm_unlock(data->mm);
-
- return ret;
-}
-
-PS_WRITE_FUNC(mm)
-{
- PS_MM_DATA;
- ps_sd *sd;
-
- mm_lock(data->mm, MM_LOCK_RW);
-
- sd = ps_sd_lookup(data, key, 1);
- if (!sd) {
- sd = ps_sd_new(data, key);
- ps_mm_debug(("new entry for %s\n", key));
- }
-
- if (sd) {
- if (vallen >= sd->alloclen) {
- if (data->mm)
- mm_free(data->mm, sd->data);
- sd->alloclen = vallen + 1;
- sd->data = mm_malloc(data->mm, sd->alloclen);
-
- if (!sd->data) {
- ps_sd_destroy(data, sd);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot allocate new data segment");
- sd = NULL;
- }
- }
- if (sd) {
- sd->datalen = vallen;
- memcpy(sd->data, val, vallen);
- 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;
- time_t limit;
- ps_sd **ohash, **ehash;
- ps_sd *sd, *next;
-
- *nrdels = 0;
- ps_mm_debug(("gc\n"));
-
- time(&limit);
-
- limit -= maxlifetime;
-
- mm_lock(data->mm, MM_LOCK_RW);
-
- ehash = data->hash + data->hash_max + 1;
- for (ohash = data->hash; ohash < ehash; ohash++)
- for (sd = *ohash; sd; sd = next) {
- next = sd->next;
- if (sd->ctime < limit) {
- ps_mm_debug(("purging %s\n", sd->key));
- ps_sd_destroy(data, sd);
- (*nrdels)++;
- }
- }
-
- mm_unlock(data->mm);
-
- return SUCCESS;
-}
-
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/ext/session/mod_mm.h b/ext/session/mod_mm.h
deleted file mode 100644
index 2fa85531a7..0000000000
--- a/ext/session/mod_mm.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 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. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-#ifndef MOD_MM_H
-#define MOD_MM_H
-
-#ifdef HAVE_LIBMM
-
-#include "php_session.h"
-
-PHP_MINIT_FUNCTION(ps_mm);
-PHP_MSHUTDOWN_FUNCTION(ps_mm);
-
-extern ps_module ps_mod_mm;
-#define ps_mm_ptr &ps_mod_mm
-
-PS_FUNCS(mm);
-
-#endif
-#endif
diff --git a/ext/session/mod_user.c b/ext/session/mod_user.c
deleted file mode 100644
index eeaf404bc4..0000000000
--- a/ext/session/mod_user.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 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. |
- +----------------------------------------------------------------------+
- | Author: 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); \
- Z_TYPE_P(a) = IS_LONG; \
- Z_LVAL_P(a) = val; \
-}
-
-#define SESS_ZVAL_STRING(vl, a) \
-{ \
- int len = strlen(vl); \
- MAKE_STD_ZVAL(a); \
- Z_TYPE_P(a) = IS_STRING; \
- Z_STRLEN_P(a) = len; \
- Z_STRVAL_P(a) = estrndup(vl, len); \
-}
-
-#define SESS_ZVAL_STRINGN(vl, ln, a) \
-{ \
- MAKE_STD_ZVAL(a); \
- Z_TYPE_P(a) = IS_STRING; \
- Z_STRLEN_P(a) = ln; \
- Z_STRVAL_P(a) = estrndup(vl, ln); \
-}
-
-
-static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC)
-{
- int i;
- zval *retval = NULL;
-
- MAKE_STD_ZVAL(retval);
- if (call_user_function(EG(function_table), NULL, func, retval,
- argc, argv TSRMLS_CC) == 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 = Z_LVAL_P(retval); \
- 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 TSRMLS_CC);
-
- FINISH;
-}
-
-PS_CLOSE_FUNC(user)
-{
- int i;
- STDVARS;
-
- retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC);
-
- 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 TSRMLS_CC);
-
- if (retval) {
- if (Z_TYPE_P(retval) == IS_STRING) {
- *val = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
- *vallen = Z_STRLEN_P(retval);
- 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 TSRMLS_CC);
-
- FINISH;
-}
-
-PS_DESTROY_FUNC(user)
-{
- zval *args[1];
- STDVARS;
-
- SESS_ZVAL_STRING(key, args[0]);
-
- retval = ps_call_handler(PSF(destroy), 1, args TSRMLS_CC);
-
- FINISH;
-}
-
-PS_GC_FUNC(user)
-{
- zval *args[1];
- STDVARS;
-
- SESS_ZVAL_LONG(maxlifetime, args[0]);
-
- retval = ps_call_handler(PSF(gc), 1, args TSRMLS_CC);
-
- FINISH;
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/ext/session/mod_user.h b/ext/session/mod_user.h
deleted file mode 100644
index c146fd4d37..0000000000
--- a/ext/session/mod_user.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 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. |
- +----------------------------------------------------------------------+
- | Author: 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 13f17d73a6..0000000000
--- a/ext/session/php_session.h
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 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. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-#ifndef PHP_SESSION_H
-#define PHP_SESSION_H
-
-#include "ext/standard/php_var.h"
-
-#define PHP_SESSION_API 20020330
-
-#define PS_OPEN_ARGS void **mod_data, const char *save_path, const char *session_name TSRMLS_DC
-#define PS_CLOSE_ARGS void **mod_data TSRMLS_DC
-#define PS_READ_ARGS void **mod_data, const char *key, char **val, int *vallen TSRMLS_DC
-#define PS_WRITE_ARGS void **mod_data, const char *key, const char *val, const int vallen TSRMLS_DC
-#define PS_DESTROY_ARGS void **mod_data, const char *key TSRMLS_DC
-#define PS_GC_ARGS void **mod_data, int maxlifetime, int *nrdels TSRMLS_DC
-#define PS_CREATE_SID_ARGS void **mod_data, int *newlen TSRMLS_DC
-
-/* default create id function */
-char *php_session_create_id(PS_CREATE_SID_ARGS);
-
-typedef struct ps_module_struct {
- const char *s_name;
- int (*s_open)(PS_OPEN_ARGS);
- int (*s_close)(PS_CLOSE_ARGS);
- int (*s_read)(PS_READ_ARGS);
- int (*s_write)(PS_WRITE_ARGS);
- int (*s_destroy)(PS_DESTROY_ARGS);
- int (*s_gc)(PS_GC_ARGS);
- char *(*s_create_sid)(PS_CREATE_SID_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_CREATE_SID_FUNC(x) char *ps_create_sid_##x(PS_CREATE_SID_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); \
- PS_CREATE_SID_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, php_session_create_id
-
-/* SID enabled module handler definitions */
-#define PS_FUNCS_SID(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); \
- PS_CREATE_SID_FUNC(x)
-
-#define PS_MOD_SID(x) \
- #x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
- ps_delete_##x, ps_gc_##x, ps_create_sid_##x
-
-typedef enum {
- php_session_disabled,
- php_session_none,
- php_session_active
-} php_session_status;
-
-typedef struct _php_ps_globals {
- 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;
- php_session_status session_status;
- long gc_probability;
- long gc_divisor;
- long gc_maxlifetime;
- int module_number;
- long cache_expire;
- zend_bool bug_compat; /* Whether to behave like PHP 4.2 and earlier */
- zend_bool bug_compat_warn; /* Whether to warn about it */
- const struct ps_serializer_struct *serializer;
- zval *http_session_vars;
- zend_bool auto_start;
- zend_bool use_cookies;
- zend_bool use_only_cookies;
- zend_bool use_trans_sid; /* contains the INI value of whether to use trans-sid */
- zend_bool apply_trans_sid; /* whether or not to enable trans-sid for the current request */
-
- long hash_func;
- long hash_bits_per_character;
- int send_cookie;
- int define_sid;
-} php_ps_globals;
-
-typedef php_ps_globals zend_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_regenerate_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_expire);
-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 PS(v) TSRMG(ps_globals_id, php_ps_globals *, v)
-#else
-#define PS(v) (ps_globals.v)
-#endif
-
-#define PS_SERIALIZER_ENCODE_ARGS char **newstr, int *newlen TSRMLS_DC
-#define PS_SERIALIZER_DECODE_ARGS const char *val, int vallen TSRMLS_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) }
-
-PHPAPI void session_adapt_url(const char *, size_t, char **, size_t * TSRMLS_DC);
-
-void php_add_session_var(char *name, size_t namelen TSRMLS_DC);
-void php_set_session_var(char *name, size_t namelen, zval *state_val, php_unserialize_data_t *var_hash TSRMLS_DC);
-int php_get_session_var(char *name, size_t namelen, zval ***state_var TSRMLS_DC);
-
-PHPAPI int php_session_register_module(ps_module *);
-
-PHPAPI int php_session_register_serializer(const char *name,
- int (*encode)(PS_SERIALIZER_ENCODE_ARGS),
- int (*decode)(PS_SERIALIZER_DECODE_ARGS));
-
-PHPAPI void php_session_set_id(char *id TSRMLS_DC);
-PHPAPI void php_session_start(TSRMLS_D);
-
-#define PS_ADD_VARL(name,namelen) do { \
- php_add_session_var(name, namelen TSRMLS_CC); \
-} while (0)
-
-#define PS_ADD_VAR(name) PS_ADD_VARL(name, strlen(name))
-
-#define PS_DEL_VARL(name,namelen) do { \
- if (PS(http_session_vars)) { \
- zend_hash_del(Z_ARRVAL_P(PS(http_session_vars)), name, namelen+1); \
- } \
-} while (0)
-
-
-#define PS_ENCODE_VARS \
- char *key; \
- uint key_length; \
- ulong num_key; \
- zval **struc;
-
-#define PS_ENCODE_LOOP(code) \
- { \
- HashTable *_ht = Z_ARRVAL_P(PS(http_session_vars)); \
- \
- for (zend_hash_internal_pointer_reset(_ht); \
- zend_hash_get_current_key_ex(_ht, &key, &key_length, &num_key, 0, NULL) == HASH_KEY_IS_STRING; \
- zend_hash_move_forward(_ht)) { \
- key_length--; \
- if (php_get_session_var(key, key_length, &struc TSRMLS_CC) == SUCCESS) { \
- code; \
- } \
- } \
- }
-
-ZEND_EXTERN_MODULE_GLOBALS(ps);
-
-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 04fa63a916..0000000000
--- a/ext/session/session.c
+++ /dev/null
@@ -1,1778 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 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@php.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/sha1.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_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"
-
-#ifdef HAVE_LIBMM
-#include "mod_mm.h"
-#endif
-
-/* {{{ 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_regenerate_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_cache_expire, NULL)
- PHP_FE(session_set_cookie_params, NULL)
- PHP_FE(session_get_cookie_params, NULL)
- PHP_FE(session_write_close, NULL)
- {NULL, NULL, NULL}
-};
-/* }}} */
-
-ZEND_DECLARE_MODULE_GLOBALS(ps);
-
-static ps_module *_php_find_ps_module(char *name TSRMLS_DC);
-static const ps_serializer *_php_find_ps_serializer(char *name TSRMLS_DC);
-
-static PHP_INI_MH(OnUpdateSaveHandler)
-{
- if (PS(session_status) == php_session_active) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "A session is active. You cannot change the session module's ini settings at this time.");
- return FAILURE;
- }
- PS(mod) = _php_find_ps_module(new_value TSRMLS_CC);
-/*
- * Following lines are commented out to prevent bogus error message at
- * start up. i.e. Save handler modules are not initilzied before Session
- * module.
- */
-
-#if 0
- if(!PS(mod)) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot find save handler %s", new_value);
- }
-#endif
- return SUCCESS;
-}
-
-static PHP_INI_MH(OnUpdateSerializer)
-{
- if (PS(session_status) == php_session_active) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "A session is active. You cannot change the session module's ini settings at this time.");
- return FAILURE;
- }
- PS(serializer) = _php_find_ps_serializer(new_value TSRMLS_CC);
-/*
- * Following lines are commented out to prevent bogus error message at
- * start up. i.e. Serializer modules are not initilzied before Session
- * module.
- */
-
-#if 0
- if(!PS(serializer)) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot find serialization handler %s", new_value);
- }
-#endif
- return SUCCESS;
-}
-
-
-/* {{{ PHP_INI
- */
-PHP_INI_BEGIN()
- STD_PHP_INI_BOOLEAN("session.bug_compat_42", "1", PHP_INI_ALL, OnUpdateBool, bug_compat, php_ps_globals, ps_globals)
- STD_PHP_INI_BOOLEAN("session.bug_compat_warn", "1", PHP_INI_ALL, OnUpdateBool, bug_compat_warn, php_ps_globals, ps_globals)
- 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, OnUpdateLong, gc_probability, php_ps_globals, ps_globals)
- STD_PHP_INI_ENTRY("session.gc_divisor", "100", PHP_INI_ALL, OnUpdateLong, gc_divisor, php_ps_globals, ps_globals)
- STD_PHP_INI_ENTRY("session.gc_maxlifetime", "1440", PHP_INI_ALL, OnUpdateLong, 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, OnUpdateLong, 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_BOOLEAN("session.use_only_cookies", "0", PHP_INI_ALL, OnUpdateBool, use_only_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, OnUpdateLong, 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, OnUpdateLong, cache_expire, php_ps_globals, ps_globals)
- STD_PHP_INI_BOOLEAN("session.use_trans_sid", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, use_trans_sid, php_ps_globals, ps_globals)
- STD_PHP_INI_ENTRY("session.hash_function", "0", PHP_INI_ALL, OnUpdateLong, hash_func, php_ps_globals, ps_globals)
- STD_PHP_INI_ENTRY("session.hash_bits_per_character", "4", PHP_INI_ALL, OnUpdateLong, hash_bits_per_character, 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
-};
-
-#define IF_SESSION_VARS() \
- if (PS(http_session_vars) && PS(http_session_vars)->type == IS_ARRAY)
-
-PHPAPI 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;
-}
-
-PHPAPI 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(TSRMLS_D);
-static void php_rshutdown_session_globals(TSRMLS_D);
-static zend_bool php_session_destroy(TSRMLS_D);
-
-zend_module_entry session_module_entry = {
- STANDARD_MODULE_HEADER,
- "session",
- session_functions,
- PHP_MINIT(session), PHP_MSHUTDOWN(session),
- PHP_RINIT(session), PHP_RSHUTDOWN(session),
- PHP_MINFO(session),
- NO_VERSION_YET,
- STANDARD_MODULE_PROPERTIES
-};
-
-#ifdef COMPILE_DL_SESSION
-ZEND_GET_MODULE(session)
-#endif
-
-typedef struct {
- char *name;
- void (*func)(TSRMLS_D);
-} php_session_cache_limiter_t;
-
-#define CACHE_LIMITER(name) _php_cache_limiter_##name
-#define CACHE_LIMITER_FUNC(name) static void CACHE_LIMITER(name)(TSRMLS_D)
-#define CACHE_LIMITER_ENTRY(name) { #name, CACHE_LIMITER(name) },
-
-#define ADD_HEADER(a) sapi_add_header(a, strlen(a), 1);
-
-#define MAX_STR 512
-
-void php_add_session_var(char *name, size_t namelen TSRMLS_DC)
-{
- zval **sym_track = NULL;
-
- zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, namelen + 1,
- (void *) &sym_track);
-
- /*
- * Set up a proper reference between $_SESSION["x"] and $x.
- */
-
- if (PG(register_globals)) {
- zval **sym_global = NULL;
-
- zend_hash_find(&EG(symbol_table), name, namelen + 1,
- (void *) &sym_global);
-
- if (sym_global == NULL && sym_track == NULL) {
- zval *empty_var;
-
- ALLOC_INIT_ZVAL(empty_var); /* this sets refcount to 1 */
- ZVAL_DELREF(empty_var); /* our module does not maintain a ref */
- /* The next call will increase refcount by NR_OF_SYM_TABLES==2 */
- zend_set_hash_symbol(empty_var, name, namelen, 1, 2, Z_ARRVAL_P(PS(http_session_vars)), &EG(symbol_table));
- } else if (sym_global == NULL) {
- zend_set_hash_symbol(*sym_track, name, namelen, 1, 1, &EG(symbol_table));
- } else if (sym_track == NULL) {
- zend_set_hash_symbol(*sym_global, name, namelen, 1, 1, Z_ARRVAL_P(PS(http_session_vars)));
- }
- } else {
- if (sym_track == NULL) {
- zval *empty_var;
-
- ALLOC_INIT_ZVAL(empty_var);
- ZEND_SET_SYMBOL_WITH_LENGTH(Z_ARRVAL_P(PS(http_session_vars)), name, namelen+1, empty_var, 1, 0);
- }
- }
-}
-
-void php_set_session_var(char *name, size_t namelen, zval *state_val, php_unserialize_data_t *var_hash TSRMLS_DC)
-{
- if (PG(register_globals)) {
- zval **old_symbol;
- if (zend_hash_find(&EG(symbol_table),name,namelen+1,(void *)&old_symbol) == SUCCESS) {
- /*
- There was an 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 IF_SESSION_VARS() {
- 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 TSRMLS_DC)
-{
- int ret = FAILURE;
-
- IF_SESSION_VARS() {
- ret = zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name,
- namelen+1, (void **) state_var);
-
- /*
- * If register_globals is enabled, and
- * if there is an entry for the slot in $_SESSION, and
- * if that entry is still set to NULL, and
- * if the global var exists, then
- * we prefer the same key in the global sym table
- */
-
- if (PG(register_globals) && ret == SUCCESS
- && Z_TYPE_PP(*state_var) == IS_NULL) {
- zval **tmp;
-
- if (zend_hash_find(&EG(symbol_table), name, namelen + 1,
- (void **) &tmp) == SUCCESS) {
- *state_var = tmp;
- }
- }
- }
-
- return ret;
-}
-
-#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)
-{
- smart_str buf = {0};
- php_serialize_data_t var_hash;
- PS_ENCODE_VARS;
-
- PHP_VAR_SERIALIZE_INIT(var_hash);
-
- PS_ENCODE_LOOP(
- if (key_length > PS_BIN_MAX) continue;
- smart_str_appendc(&buf, (unsigned char) key_length);
- smart_str_appendl(&buf, key, key_length);
-
- php_var_serialize(&buf, struc, &var_hash TSRMLS_CC);
- } else {
- if (key_length > PS_BIN_MAX) continue;
- smart_str_appendc(&buf, (unsigned char) (key_length & PS_BIN_UNDEF));
- smart_str_appendl(&buf, key, key_length);
- );
-
- if (newlen) *newlen = buf.len;
- *newstr = buf.c;
- 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_unserialize_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(&current, &p, endptr, &var_hash TSRMLS_CC)) {
- php_set_session_var(name, namelen, current, &var_hash TSRMLS_CC);
- }
- zval_ptr_dtor(&current);
- }
- 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)
-{
- smart_str buf = {0};
- php_serialize_data_t var_hash;
- PS_ENCODE_VARS;
-
- PHP_VAR_SERIALIZE_INIT(var_hash);
-
- PS_ENCODE_LOOP(
- smart_str_appendl(&buf, key, (unsigned char) key_length);
- smart_str_appendc(&buf, PS_DELIMITER);
-
- php_var_serialize(&buf, struc, &var_hash TSRMLS_CC);
- } else {
- smart_str_appendc(&buf, PS_UNDEF_MARKER);
- smart_str_appendl(&buf, key, key_length);
- smart_str_appendc(&buf, PS_DELIMITER);
- );
-
- if (newlen) *newlen = buf.len;
- *newstr = buf.c;
-
- 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_unserialize_data_t var_hash;
-
- PHP_VAR_UNSERIALIZE_INIT(var_hash);
-
- p = val;
-
- while (p < endptr) {
- q = p;
- while (*q != PS_DELIMITER)
- if (++q >= endptr) goto break_outer_loop;
-
- 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(&current, &q, endptr, &var_hash TSRMLS_CC)) {
- php_set_session_var(name, namelen, current, &var_hash TSRMLS_CC);
- }
- zval_ptr_dtor(&current);
- }
- PS_ADD_VARL(name, namelen);
- efree(name);
-
- p = q;
- }
-break_outer_loop:
-
- PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
-
- return SUCCESS;
-}
-
-static void php_session_track_init(TSRMLS_D)
-{
- /* Unconditionally destroy existing arrays -- possible dirty data */
- zend_hash_del(&EG(symbol_table), "HTTP_SESSION_VARS",
- sizeof("HTTP_SESSION_VARS"));
- zend_hash_del(&EG(symbol_table), "_SESSION", sizeof("_SESSION"));
-
- 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), 2, 1);
- ZEND_SET_GLOBAL_VAR_WITH_LENGTH("_SESSION", sizeof("_SESSION"), PS(http_session_vars), 2, 1);
-}
-
-static char *php_session_encode(int *newlen TSRMLS_DC)
-{
- char *ret = NULL;
-
- IF_SESSION_VARS() {
- if (PS(serializer)->encode(&ret, newlen TSRMLS_CC) == FAILURE)
- ret = NULL;
- } else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot encode non-existent session.");
- }
-
- return ret;
-}
-
-static void php_session_decode(const char *val, int vallen TSRMLS_DC)
-{
- if (PS(serializer)->decode(val, vallen TSRMLS_CC) == FAILURE) {
- php_session_destroy(TSRMLS_C);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to decode session object. Session has been destroyed.");
- }
-}
-
-
-/*
- * Note that we cannot use the BASE64 alphabet here, because
- * it contains "/" and "+": both are unacceptable for simple inclusion
- * into URLs.
- */
-
-static char hexconvtab[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,-";
-
-enum {
- PS_HASH_FUNC_MD5,
- PS_HASH_FUNC_SHA1
-};
-
-/* returns a pointer to the byte after the last valid character in out */
-static char *bin_to_readable(char *in, size_t inlen, char *out, char nbits)
-{
- unsigned char *p, *q;
- unsigned short w;
- int mask;
- int have;
-
- p = in;
- q = in + inlen;
-
- w = 0;
- have = 0;
- mask = (1 << nbits) - 1;
-
- while (1) {
- if (have < nbits) {
- if (p < q) {
- w |= *p++ << have;
- have += 8;
- } else {
- /* consumed everything? */
- if (have == 0) break;
- /* No? We need a final round */
- have = nbits;
- }
- }
-
- /* consume nbits */
- *out++ = hexconvtab[w & mask];
- w >>= nbits;
- have -= nbits;
- }
-
- *out = '\0';
- return out;
-}
-
-char *php_session_create_id(PS_CREATE_SID_ARGS)
-{
- PHP_MD5_CTX md5_context;
- PHP_SHA1_CTX sha1_context;
- unsigned char digest[21];
- int digest_len;
- int j;
- char *buf;
- struct timeval tv;
- zval **array;
- zval **token;
- char *remote_addr = NULL;
-
- gettimeofday(&tv, NULL);
-
- if (zend_hash_find(&EG(symbol_table), "_SERVER",
- sizeof("_SERVER"), (void **) &array) == SUCCESS &&
- Z_TYPE_PP(array) == IS_ARRAY &&
- zend_hash_find(Z_ARRVAL_PP(array), "REMOTE_ADDR",
- sizeof("REMOTE_ADDR"), (void **) &token) == SUCCESS) {
- remote_addr = Z_STRVAL_PP(token);
- }
-
- buf = emalloc(100);
-
- /* maximum 15+19+19+10 bytes */
- sprintf(buf, "%.15s%ld%ld%0.8f", remote_addr ? remote_addr : "",
- tv.tv_sec, tv.tv_usec, php_combined_lcg(TSRMLS_C) * 10);
-
- switch (PS(hash_func)) {
- case PS_HASH_FUNC_MD5:
- PHP_MD5Init(&md5_context);
- PHP_MD5Update(&md5_context, buf, strlen(buf));
- digest_len = 16;
- break;
- case PS_HASH_FUNC_SHA1:
- PHP_SHA1Init(&sha1_context);
- PHP_SHA1Update(&sha1_context, buf, strlen(buf));
- digest_len = 20;
- break;
- default:
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid session hash function");
- efree(buf);
- return NULL;
- }
-
- if (PS(entropy_length) > 0) {
- int fd;
-
- fd = VCWD_OPEN(PS(entropy_file), O_RDONLY);
- if (fd >= 0) {
- unsigned char rbuf[2048];
- int n;
- int to_read = PS(entropy_length);
-
- while (to_read > 0) {
- n = read(fd, rbuf, MIN(to_read, sizeof(rbuf)));
- if (n <= 0) break;
-
- switch (PS(hash_func)) {
- case PS_HASH_FUNC_MD5:
- PHP_MD5Update(&md5_context, rbuf, n);
- break;
- case PS_HASH_FUNC_SHA1:
- PHP_SHA1Update(&sha1_context, rbuf, n);
- break;
- }
- to_read -= n;
- }
- close(fd);
- }
- }
-
- switch (PS(hash_func)) {
- case PS_HASH_FUNC_MD5:
- PHP_MD5Final(digest, &md5_context);
- break;
- case PS_HASH_FUNC_SHA1:
- PHP_SHA1Final(digest, &sha1_context);
- break;
- }
-
- if (PS(hash_bits_per_character) < 4
- || PS(hash_bits_per_character) > 6) {
- PS(hash_bits_per_character) = 4;
-
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "The ini setting hash_bits_per_character is out of range (should be 4, 5, or 6) - using 4 for now");
- }
- j = (int) (bin_to_readable(digest, digest_len, buf, PS(hash_bits_per_character)) - buf);
-
- if (newlen)
- *newlen = j;
- return buf;
-}
-
-static void php_session_initialize(TSRMLS_D)
-{
- char *val;
- int vallen;
-
- if (!PS(mod)) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Failed to initialize session module.");
- return;
- }
-
- /* Open session handler first */
- if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name) TSRMLS_CC) == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Failed to initialize session module");
- return;
- }
-
- /* If there is no ID, use session module to create one */
- if (!PS(id))
- PS(id) = PS(mod)->s_create_sid(&PS(mod_data), NULL TSRMLS_CC);
-
- /* Read data */
- /* Question: if you create a SID here, should you also try to read data?
- * I'm not sure, but while not doing so will remove one session operation
- * it could prove usefull for those sites which wish to have "default"
- * session information
- */
- php_session_track_init(TSRMLS_C);
- if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == SUCCESS) {
- php_session_decode(val, vallen TSRMLS_CC);
- efree(val);
- }
-}
-
-static int migrate_global(HashTable *ht, HashPosition *pos TSRMLS_DC)
-{
- char *str;
- uint str_len;
- ulong num_key;
- int n;
- zval **val = NULL;
- int ret = 0;
-
- n = zend_hash_get_current_key_ex(ht, &str, &str_len, &num_key, 0, pos);
-
- switch (n) {
- case HASH_KEY_IS_STRING:
- zend_hash_find(&EG(symbol_table), str, str_len, (void **) &val);
- if (val) {
- ZEND_SET_SYMBOL_WITH_LENGTH(ht, str, str_len, *val, (*val)->refcount + 1 , 1);
- ret = 1;
- }
- break;
- case HASH_KEY_IS_LONG:
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "The session bug compatibility code will not "
- "try to locate the global variable $%d due to its "
- "numeric nature.", num_key);
- break;
- }
-
- return ret;
-}
-
-static void php_session_save_current_state(TSRMLS_D)
-{
- int ret = FAILURE;
-
- IF_SESSION_VARS() {
- if (PS(bug_compat) && !PG(register_globals)) {
- HashTable *ht = Z_ARRVAL_P(PS(http_session_vars));
- HashPosition pos;
- zval **val;
- int do_warn = 0;
-
- zend_hash_internal_pointer_reset_ex(ht, &pos);
-
- while (zend_hash_get_current_data_ex(ht,
- (void **) &val, &pos) != FAILURE) {
- if (Z_TYPE_PP(val) == IS_NULL) {
- if (migrate_global(ht, &pos TSRMLS_CC))
- do_warn = 1;
- }
- zend_hash_move_forward_ex(ht, &pos);
- }
-
- if (do_warn && PS(bug_compat_warn)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively.");
- }
- }
-
- if (PS(mod_data)) {
- char *val;
- int vallen;
-
- val = php_session_encode(&vallen TSRMLS_CC);
- if (val) {
- ret = PS(mod)->s_write(&PS(mod_data), PS(id), val, vallen TSRMLS_CC);
- efree(val);
- } else {
- ret = PS(mod)->s_write(&PS(mod_data), PS(id), "", 0 TSRMLS_CC);
- }
- }
-
- if (ret == FAILURE)
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write session data (%s). Please "
- "verify that the current setting of session.save_path "
- "is correct (%s)",
- PS(mod)->s_name,
- PS(save_path));
- }
-
- if (PS(mod_data))
- PS(mod)->s_close(&PS(mod_data) TSRMLS_CC);
-}
-
-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);
-
- n = sprintf(buf, "%s, %d %s %d %02d:%02d:%02d GMT", /* SAFE */
- 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(TSRMLS_D)
-{
- const char *path;
- struct stat sb;
- char buf[MAX_STR + 1];
-
- 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_HEADER(buf);
- }
-}
-
-CACHE_LIMITER_FUNC(public)
-{
- char buf[MAX_STR + 1];
- struct timeval tv;
- time_t now;
-
- gettimeofday(&tv, NULL);
- now = tv.tv_sec + PS(cache_expire) * 60;
-#define EXPIRES "Expires: "
- memcpy(buf, EXPIRES, sizeof(EXPIRES) - 1);
- strcpy_gmt(buf + sizeof(EXPIRES) - 1, &now);
- ADD_HEADER(buf);
-
- sprintf(buf, "Cache-Control: public, max-age=%ld", PS(cache_expire) * 60); /* SAFE */
- ADD_HEADER(buf);
-
- last_modified(TSRMLS_C);
-}
-
-CACHE_LIMITER_FUNC(private_no_expire)
-{
- char buf[MAX_STR + 1];
-
- sprintf(buf, "Cache-Control: private, max-age=%ld, pre-check=%ld", PS(cache_expire) * 60, PS(cache_expire) * 60); /* SAFE */
- ADD_HEADER(buf);
-
- last_modified(TSRMLS_C);
-}
-
-CACHE_LIMITER_FUNC(private)
-{
- ADD_HEADER("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
- CACHE_LIMITER(private_no_expire)(TSRMLS_C);
-}
-
-CACHE_LIMITER_FUNC(nocache)
-{
- ADD_HEADER("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
- /* For HTTP/1.1 conforming clients and the rest (MSIE 5) */
- ADD_HEADER("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
- /* For HTTP/1.0 conforming clients */
- ADD_HEADER("Pragma: no-cache");
-}
-
-static php_session_cache_limiter_t php_session_cache_limiters[] = {
- CACHE_LIMITER_ENTRY(public)
- CACHE_LIMITER_ENTRY(private)
- CACHE_LIMITER_ENTRY(private_no_expire)
- CACHE_LIMITER_ENTRY(nocache)
- {0}
-};
-
-static int php_session_cache_limiter(TSRMLS_D)
-{
- php_session_cache_limiter_t *lim;
-
- if (PS(cache_limiter)[0] == '\0') return 0;
-
- if (SG(headers_sent)) {
- char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
- int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
-
- if (output_start_filename) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cache limiter - headers already sent (output started at %s:%d)",
- output_start_filename, output_start_lineno);
- } else {
- php_error_docref(NULL TSRMLS_CC, 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(TSRMLS_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(TSRMLS_D)
-{
- smart_str ncookie = {0};
- char *date_fmt = NULL;
-
- if (SG(headers_sent)) {
- char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
- int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
-
- if (output_start_filename) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cookie - headers already sent by (output started at %s:%d)",
- output_start_filename, output_start_lineno);
- } else {
- php_error_docref(NULL TSRMLS_CC, 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) {
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
- date_fmt = php_std_date(tv.tv_sec + PS(cookie_lifetime) TSRMLS_CC);
-
- 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_ex(ncookie.c, ncookie.len, 0, 0 TSRMLS_CC);
-}
-
-static ps_module *_php_find_ps_module(char *name TSRMLS_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)->s_name)) {
- ret = *mod;
- break;
- }
-
- return ret;
-}
-
-static const ps_serializer *_php_find_ps_serializer(char *name TSRMLS_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_reset_id(TSRMLS_D)
-{
- int module_number = PS(module_number);
-
- if (PS(send_cookie)) {
- php_session_send_cookie(TSRMLS_C);
- }
-
- /* if the SID constant exists, destroy it. */
- zend_hash_del(EG(zend_constants), "sid", sizeof("sid"));
-
- if (PS(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_STRINGL_CONSTANT("SID", var.c, var.len, 0);
- } else {
- REGISTER_STRINGL_CONSTANT("SID", empty_string, 0, 0);
- }
-
- if (PS(apply_trans_sid)) {
- php_url_scanner_reset_vars(TSRMLS_C);
- php_url_scanner_add_var(PS(session_name), strlen(PS(session_name)), PS(id), strlen(PS(id)), 1 TSRMLS_CC);
- }
-}
-
-PHPAPI void php_session_start(TSRMLS_D)
-{
- zval **ppid;
- zval **data;
- char *p;
- int nrand;
- int lensess;
-
- PS(apply_trans_sid) = PS(use_trans_sid);
-
- PS(define_sid) = 1;
- PS(send_cookie) = 1;
- if (PS(session_status) != php_session_none)
- 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), "_COOKIE",
- sizeof("_COOKIE"), (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;
- PS(apply_trans_sid) = 0;
- PS(send_cookie) = 0;
- PS(define_sid) = 0;
- }
-
- if (!PS(use_only_cookies) && !PS(id) &&
- zend_hash_find(&EG(symbol_table), "_GET",
- sizeof("_GET"), (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;
- PS(send_cookie) = 0;
- }
-
- if (!PS(use_only_cookies) && !PS(id) &&
- zend_hash_find(&EG(symbol_table), "_POST",
- sizeof("_POST"), (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;
- PS(send_cookie) = 0;
- }
- }
-
- /* 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(use_only_cookies) && !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;
- PS(send_cookie) = 1;
- if (PS(use_trans_sid))
- PS(apply_trans_sid) = 1;
- }
-
- php_session_initialize(TSRMLS_C);
-
- if (!PS(use_cookies) && PS(send_cookie)) {
- if (PS(use_trans_sid))
- PS(apply_trans_sid) = 1;
- PS(send_cookie) = 0;
- }
-
- php_session_reset_id(TSRMLS_C);
-
- PS(session_status) = php_session_active;
-
- php_session_cache_limiter(TSRMLS_C);
-
- if (PS(mod_data) && PS(gc_probability) > 0) {
- int nrdels = -1;
-
- nrand = (int) ((float) PS(gc_divisor) * php_combined_lcg(TSRMLS_C));
- if (nrand < PS(gc_probability)) {
- PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels TSRMLS_CC);
-#if 0
- if (nrdels != -1)
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "purged %d expired session objects\n", nrdels);
-#endif
- }
- }
-}
-
-static zend_bool php_session_destroy(TSRMLS_D)
-{
- zend_bool retval = SUCCESS;
-
- if (PS(session_status) != php_session_active) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Trying to destroy uninitialized session");
- return FAILURE;
- }
-
- if (PS(mod)->s_destroy(&PS(mod_data), PS(id) TSRMLS_CC) == FAILURE) {
- retval = FAILURE;
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session object destruction failed");
- }
-
- php_rshutdown_session_globals(TSRMLS_C);
- php_rinit_session_globals(TSRMLS_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;
-
- 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)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- array_init(return_value);
-
- 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)
-{
- zval **p_name;
- int ac = ZEND_NUM_ARGS();
- char *old;
-
- if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
- WRONG_PARAM_COUNT;
-
- old = estrdup(PS(session_name));
-
- 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)
-{
- zval **p_name;
- int ac = ZEND_NUM_ARGS();
- char *old;
-
- if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
- WRONG_PARAM_COUNT;
-
- old = safe_estrdup(PS(mod)->s_name);
-
- if (ac == 1) {
- ps_module *tempmod;
-
- convert_to_string_ex(p_name);
- tempmod = _php_find_ps_module(Z_STRVAL_PP(p_name) TSRMLS_CC);
- if (tempmod) {
- if (PS(mod_data))
- PS(mod)->s_close(&PS(mod_data) TSRMLS_CC);
- PS(mod) = tempmod;
- PS(mod_data) = NULL;
- } else {
- efree(old);
- php_error_docref(NULL TSRMLS_CC, 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;
-
- if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_array_ex(6, args) == FAILURE)
- WRONG_PARAM_COUNT;
-
- if (PS(session_status) != php_session_none)
- 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)
-{
- zval **p_name;
- int ac = ZEND_NUM_ARGS();
- char *old;
-
- if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
- WRONG_PARAM_COUNT;
-
- old = estrdup(PS(save_path));
-
- 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)
-{
- zval **p_name;
- int ac = ZEND_NUM_ARGS();
- char *old = empty_string;
-
- if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
- WRONG_PARAM_COUNT;
-
- if (PS(id))
- old = estrdup(PS(id));
-
- 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_regenerate_id()
- Update the current session id with a newly generated one. */
-PHP_FUNCTION(session_regenerate_id)
-{
- if (PS(session_status) == php_session_active) {
- if (PS(id)) efree(PS(id));
-
- PS(id) = PS(mod)->s_create_sid(&PS(mod_data), NULL TSRMLS_CC);
-
- php_session_reset_id(TSRMLS_C);
-
- RETURN_TRUE;
- }
- RETURN_FALSE;
-}
-/* }}} */
-
-/* {{{ 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)
-{
- zval **p_cache_limiter;
- int ac = ZEND_NUM_ARGS();
- char *old;
-
- if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_cache_limiter) == FAILURE)
- WRONG_PARAM_COUNT;
-
- old = estrdup(PS(cache_limiter));
-
- 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);
-}
-/* }}} */
-
-/* {{{ proto int session_cache_expire([int new_cache_expire])
- Return the current cache expire. If new_cache_expire is given, the current cache_expire is replaced with new_cache_expire */
-PHP_FUNCTION(session_cache_expire)
-{
- zval **p_cache_expire;
- int ac = ZEND_NUM_ARGS();
- long old;
-
- old = PS(cache_expire);
-
- if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_cache_expire) == FAILURE)
- WRONG_PARAM_COUNT;
-
- if (ac == 1) {
- convert_to_long_ex(p_cache_expire);
- PS(cache_expire) = Z_LVAL_PP(p_cache_expire);
- }
-
- RETVAL_LONG(old);
-}
-/* }}} */
-
-/* {{{ static void php_register_var(zval** entry TSRMLS_DC) */
-static void php_register_var(zval** entry TSRMLS_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 TSRMLS_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) ||
- (strcmp(Z_STRVAL_PP(entry), "_SESSION") != 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;
-
- 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(session_status) == php_session_none)
- php_session_start(TSRMLS_C);
-
- for (i = 0; i < argc; i++) {
- if (Z_TYPE_PP(args[i]) == IS_ARRAY)
- SEPARATE_ZVAL(args[i]);
- php_register_var(args[i] TSRMLS_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)
-{
- zval **p_name;
- int ac = ZEND_NUM_ARGS();
-
- if (ac != 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
- WRONG_PARAM_COUNT;
-
- convert_to_string_ex(p_name);
-
- PS_DEL_VARL(Z_STRVAL_PP(p_name), Z_STRLEN_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)
-{
- zval **p_name;
- zval *p_var;
- int ac = ZEND_NUM_ARGS();
-
- if (ac != 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
- WRONG_PARAM_COUNT;
-
- convert_to_string_ex(p_name);
-
- if (PS(session_status) == php_session_none)
- RETURN_FALSE;
-
- IF_SESSION_VARS() {
- if (zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)),
- Z_STRVAL_PP(p_name), Z_STRLEN_PP(p_name)+1,
- (void **)&p_var) == SUCCESS) {
- RETURN_TRUE;
- }
- }
- RETURN_FALSE;
-}
-/* }}} */
-
-/* {{{ proto string session_encode(void)
- Serializes the current setup and returns the serialized representation */
-PHP_FUNCTION(session_encode)
-{
- int len;
- char *enc;
-
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- enc = php_session_encode(&len TSRMLS_CC);
- if (enc == NULL) {
- RETURN_FALSE;
- }
-
- RETVAL_STRINGL(enc, len, 0);
-}
-/* }}} */
-
-/* {{{ proto bool session_decode(string data)
- Deserializes data and reinitializes the variables */
-PHP_FUNCTION(session_decode)
-{
- zval **str;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (PS(session_status) == php_session_none) {
- RETURN_FALSE;
- }
-
- convert_to_string_ex(str);
-
- php_session_decode(Z_STRVAL_PP(str), Z_STRLEN_PP(str) TSRMLS_CC);
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto bool session_start(void)
- Begin session - reinitializes freezed variables, registers browsers etc */
-PHP_FUNCTION(session_start)
-{
- /* skipping check for non-zero args for performance reasons here ?*/
- php_session_start(TSRMLS_C);
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto bool session_destroy(void)
- Destroy the current session and all data associated with it */
-PHP_FUNCTION(session_destroy)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- if (php_session_destroy(TSRMLS_C) == SUCCESS) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-
-/* {{{ proto void session_unset(void)
- Unset all registered variables */
-PHP_FUNCTION(session_unset)
-{
- if (PS(session_status) == php_session_none)
- RETURN_FALSE;
-
- IF_SESSION_VARS() {
- HashTable *ht = Z_ARRVAL_P(PS(http_session_vars));
-
- if (PG(register_globals)) {
- uint str_len;
- char *str;
- ulong num_key;
- HashPosition pos;
-
- zend_hash_internal_pointer_reset_ex(ht, &pos);
-
- while (zend_hash_get_current_key_ex(ht, &str, &str_len, &num_key,
- 0, &pos) == HASH_KEY_IS_STRING) {
- zend_hash_del(&EG(symbol_table), str, str_len);
- zend_hash_move_forward_ex(ht, &pos);
- }
- }
-
- /* Clean $_SESSION. */
- zend_hash_clean(ht);
- }
-}
-/* }}} */
-
-PHPAPI void session_adapt_url(const char *url, size_t urllen, char **new, size_t *newlen TSRMLS_DC)
-{
- if (PS(apply_trans_sid) && (PS(session_status) == php_session_active)) {
- *new = php_url_scanner_adapt_single_url(url, urllen, PS(session_name), PS(id), newlen TSRMLS_CC);
- }
-}
-
-static void php_rinit_session_globals(TSRMLS_D)
-{
- PS(id) = NULL;
- PS(session_status) = php_session_none;
- PS(mod_data) = NULL;
- PS(http_session_vars) = NULL;
-}
-
-static void php_rshutdown_session_globals(TSRMLS_D)
-{
- if (PS(mod_data)) {
- PS(mod)->s_close(&PS(mod_data) TSRMLS_CC);
- }
- if (PS(id)) {
- efree(PS(id));
- }
-}
-
-
-PHP_RINIT_FUNCTION(session)
-{
- php_rinit_session_globals(TSRMLS_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 TSRMLS_CC);
- }
-
- if (!PS(mod)) {
- /* current status is unusable */
- PS(session_status) = php_session_disabled;
- return SUCCESS;
- }
- }
-
- if (PS(auto_start)) {
- php_session_start(TSRMLS_C);
- }
-
- return SUCCESS;
-}
-
-static void php_session_flush(TSRMLS_D)
-{
- if(PS(session_status)==php_session_active) {
- php_session_save_current_state(TSRMLS_C);
- PS(session_status)=php_session_none;
- }
-}
-
-/* {{{ proto void session_write_close(void)
- Write session data and end session */
-PHP_FUNCTION(session_write_close)
-{
- php_session_flush(TSRMLS_C);
-}
-
-PHP_RSHUTDOWN_FUNCTION(session)
-{
- php_session_flush(TSRMLS_C);
- php_rshutdown_session_globals(TSRMLS_C);
- return SUCCESS;
-}
-/* }}} */
-
-
-PHP_MINIT_FUNCTION(session)
-{
-#ifdef ZTS
- php_ps_globals *ps_globals;
-
- ts_allocate_id(&ps_globals_id, sizeof(php_ps_globals), NULL, NULL);
- ps_globals = ts_resource(ps_globals_id);
-#endif
-
- zend_register_auto_global("_SESSION", sizeof("_SESSION")-1, NULL TSRMLS_CC);
-
- PS(module_number) = module_number; /* if we really need this var we need to init it in zts mode as well! */
-
- PS(session_status) = php_session_none;
- REGISTER_INI_ENTRIES();
-
-#ifdef HAVE_LIBMM
- PHP_MINIT(ps_mm) (INIT_FUNC_ARGS_PASSTHRU);
-#endif
- return SUCCESS;
-}
-
-PHP_MSHUTDOWN_FUNCTION(session)
-{
- UNREGISTER_INI_ENTRIES();
-
-#ifdef HAVE_LIBMM
- PHP_MSHUTDOWN(ps_mm) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
-#endif
-
- return SUCCESS;
-}
-
-
-PHP_MINFO_FUNCTION(session)
-{
- ps_module **mod;
- smart_str handlers = {0};
- int i;
-
- for (i = 0, mod = ps_modules; i < MAX_MODULES; i++, mod++) {
- if (*mod && (*mod)->s_name) {
- smart_str_appends(&handlers, (*mod)->s_name);
- smart_str_appendc(&handlers, ' ');
- }
- }
-
- php_info_print_table_start();
- php_info_print_table_row(2, "Session Support", "enabled" );
-
- if (handlers.c) {
- smart_str_0(&handlers);
- php_info_print_table_row(2, "Registered save handlers", handlers.c);
- smart_str_free(&handlers);
- } else {
- php_info_print_table_row(2, "Registered save handlers", "none");
- }
- php_info_print_table_end();
-
- DISPLAY_INI_ENTRIES();
-}
-
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/ext/session/tests/001.phpt b/ext/session/tests/001.phpt
deleted file mode 100644
index f499029a73..0000000000
--- a/ext/session/tests/001.phpt
+++ /dev/null
@@ -1,35 +0,0 @@
---TEST--
-session object serialization
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=1
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-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 7c77fdcf94..0000000000
--- a/ext/session/tests/002.phpt
+++ /dev/null
@@ -1,13 +0,0 @@
---TEST--
-session_unset() without a initialized session
---SKIPIF--
-<?php include('skipif.inc'); ?>
---FILE--
-<?php
-error_reporting(E_ALL);
-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 638506e31e..0000000000
--- a/ext/session/tests/003.phpt
+++ /dev/null
@@ -1,44 +0,0 @@
---TEST--
-session object deserialization
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=1
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-class foo {
- var $bar = "ok";
- function method() { $this->yes++; }
-}
-
-session_id("abtest");
-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 0d930c5307..0000000000
--- a/ext/session/tests/004.phpt
+++ /dev/null
@@ -1,111 +0,0 @@
---TEST--
-session_set_save_handler test
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=1
-session.name=PHPSESSID
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-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: $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++; }
-}
-
-session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
-
-session_id("abtest");
-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: PHPSESSID
-READ: abtest
-object(foo)(2) {
- ["bar"]=>
- string(2) "ok"
- ["yes"]=>
- int(2)
-}
-array(1) {
- [3]=>
- &object(foo)(2) {
- ["bar"]=>
- string(2) "ok"
- ["yes"]=>
- int(2)
- }
-}
-WRITE: abtest, 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: PHPSESSID
-READ: abtest
-object(foo)(2) {
- ["bar"]=>
- string(2) "ok"
- ["yes"]=>
- int(2)
-}
-array(1) {
- [3]=>
- object(foo)(2) {
- ["bar"]=>
- string(2) "ok"
- ["yes"]=>
- int(2)
- }
-}
-DESTROY: abtest
diff --git a/ext/session/tests/005.phpt b/ext/session/tests/005.phpt
deleted file mode 100644
index 3c9205277f..0000000000
--- a/ext/session/tests/005.phpt
+++ /dev/null
@@ -1,146 +0,0 @@
---TEST--
-custom save handler, multiple session_start()s, complex data structure test.
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=1
-session.name=PHPSESSID
-session.serialize_handler=php
---FILE--
-<?php
-
-error_reporting(E_ALL);
-
-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: $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++; }
-}
-
-session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
-
-session_id("abtest");
-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: PHPSESSID
-READ: abtest
-object(foo)(2) {
- ["bar"]=>
- string(2) "ok"
- ["yes"]=>
- int(2)
-}
-array(1) {
- [3]=>
- &object(foo)(2) {
- ["bar"]=>
- string(2) "ok"
- ["yes"]=>
- int(2)
- }
-}
-WRITE: abtest, 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: PHPSESSID
-READ: abtest
-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: abtest, 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: PHPSESSID
-READ: abtest
-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: abtest
-CLOSE
diff --git a/ext/session/tests/006.phpt b/ext/session/tests/006.phpt
deleted file mode 100644
index 2cdeace074..0000000000
--- a/ext/session/tests/006.phpt
+++ /dev/null
@@ -1,70 +0,0 @@
---TEST--
-correct instantiation of references between variables in sessions
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=1
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-session_id("abtest");
-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"
- }
-}
diff --git a/ext/session/tests/007.phpt b/ext/session/tests/007.phpt
deleted file mode 100644
index 7e13ab27e3..0000000000
--- a/ext/session/tests/007.phpt
+++ /dev/null
@@ -1,59 +0,0 @@
---TEST--
-bug compatibility: unset($c) with enabled register_globals
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=1
-session.bug_compat_42=1
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-session_id("abtest");
-
-### Phase 1 cleanup
-session_start();
-session_destroy();
-
-### Phase 2 $HTTP_SESSION_VARS["c"] does not contain any value
-session_id("abtest");
-session_register("c");
-unset($c);
-$c = 3.14;
-session_write_close();
-unset($HTTP_SESSION_VARS);
-unset($c);
-
-### Phase 3 $HTTP_SESSION_VARS["c"] is set
-session_start();
-var_dump($c);
-var_dump($HTTP_SESSION_VARS);
-unset($c);
-$c = 2.78;
-
-session_write_close();
-unset($HTTP_SESSION_VARS);
-unset($c);
-
-### Phase 4 final
-
-session_start();
-var_dump($c);
-var_dump($HTTP_SESSION_VARS);
-
-session_destroy();
-?>
---EXPECT--
-float(3.14)
-array(1) {
- ["c"]=>
- &float(3.14)
-}
-float(3.14)
-array(1) {
- ["c"]=>
- &float(3.14)
-}
diff --git a/ext/session/tests/008-php4.2.3.phpt b/ext/session/tests/008-php4.2.3.phpt
deleted file mode 100644
index 2785ddc2e8..0000000000
--- a/ext/session/tests/008-php4.2.3.phpt
+++ /dev/null
@@ -1,68 +0,0 @@
---TEST--
-bug compatibility: global is used albeit register_globals=0
---SKIPIF--
-<?php include('skipif.inc');
- if (version_compare(PHP_VERSION,"4.2.3-dev", "<")) die("skip this is for PHP >= 4.2.3");
-?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=0
-session.bug_compat_42=1
-session.bug_compat_warn=1
-track_errors=1
-log_errors=0
-html_errors=0
-display_errors=1
-error_reporting=2039;
-session.serialize_handler=php
---FILE--
-<?php
-session_id("abtest");
-
-### Phase 1 cleanup
-session_start();
-session_destroy();
-
-### Phase 2 $HTTP_SESSION_VARS["c"] does not contain any value
-session_id("abtest");
-session_register("c");
-var_dump($c);
-unset($c);
-$c = 3.14;
-@session_write_close(); // this generates an E_WARNING which will be printed
-// by $php_errormsg so we can use "@" here. ANY further message IS an error.
-echo $php_errormsg."\n";
-unset($HTTP_SESSION_VARS);
-unset($c);
-
-### Phase 3 $HTTP_SESSION_VARS["c"] is set
-session_start();
-var_dump($HTTP_SESSION_VARS);
-unset($c);
-$c = 2.78;
-
-session_write_close();
-unset($HTTP_SESSION_VARS);
-unset($c);
-
-### Phase 4 final
-
-session_start();
-var_dump($c);
-var_dump($HTTP_SESSION_VARS);
-
-session_destroy();
-?>
---EXPECTF--
-NULL
-Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively.
-array(1) {
- ["c"]=>
- float(3.14)
-}
-NULL
-array(1) {
- ["c"]=>
- float(3.14)
-}
diff --git a/ext/session/tests/008.phpt b/ext/session/tests/008.phpt
deleted file mode 100644
index 044a6f2536..0000000000
--- a/ext/session/tests/008.phpt
+++ /dev/null
@@ -1,61 +0,0 @@
---TEST--
-bug compatibility: global is used albeit register_globals=0
---SKIPIF--
-<?php include('skipif.inc');
- if (version_compare(PHP_VERSION,"4.2.3-dev", ">=")) die("skip this is for PHP < 4.2.3");
-?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=0
-session.bug_compat_42=1
-session.bug_compat_warn=0
---FILE--
-<?php
-error_reporting(E_ALL & ~E_NOTICE);
-
-session_id("abtest");
-
-### Phase 1 cleanup
-session_start();
-session_destroy();
-
-### Phase 2 $HTTP_SESSION_VARS["c"] does not contain any value
-session_id("abtest");
-session_register("c");
-var_dump($c);
-unset($c);
-$c = 3.14;
-session_write_close();
-unset($HTTP_SESSION_VARS);
-unset($c);
-
-### Phase 3 $HTTP_SESSION_VARS["c"] is set
-session_start();
-var_dump($HTTP_SESSION_VARS);
-unset($c);
-$c = 2.78;
-
-session_write_close();
-unset($HTTP_SESSION_VARS);
-unset($c);
-
-### Phase 4 final
-
-session_start();
-var_dump($c);
-var_dump($HTTP_SESSION_VARS);
-
-session_destroy();
-?>
---EXPECT--
-NULL
-array(1) {
- ["c"]=>
- float(3.14)
-}
-NULL
-array(1) {
- ["c"]=>
- float(3.14)
-}
diff --git a/ext/session/tests/009.phpt b/ext/session/tests/009.phpt
deleted file mode 100644
index a79cb931aa..0000000000
--- a/ext/session/tests/009.phpt
+++ /dev/null
@@ -1,57 +0,0 @@
---TEST--
-unset($_SESSION["name"]); should work with register_globals=off
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=0
-session.bug_compat_42=1
-session.bug_compat_warn=0
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-session_id("abtest");
-
-### Phase 1 cleanup
-session_start();
-session_destroy();
-
-### Phase 2 $HTTP_SESSION_VARS["c"] does not contain any value
-session_id("abtest");
-session_start();
-var_dump($HTTP_SESSION_VARS);
-$HTTP_SESSION_VARS["name"] = "foo";
-var_dump($HTTP_SESSION_VARS);
-session_write_close();
-
-### Phase 3 $HTTP_SESSION_VARS["c"] is set
-session_start();
-var_dump($HTTP_SESSION_VARS);
-unset($HTTP_SESSION_VARS["name"]);
-var_dump($HTTP_SESSION_VARS);
-session_write_close();
-
-### Phase 4 final
-
-session_start();
-var_dump($HTTP_SESSION_VARS);
-session_destroy();
-?>
---EXPECT--
-array(0) {
-}
-array(1) {
- ["name"]=>
- string(3) "foo"
-}
-array(1) {
- ["name"]=>
- string(3) "foo"
-}
-array(0) {
-}
-array(0) {
-}
diff --git a/ext/session/tests/010.phpt b/ext/session/tests/010.phpt
deleted file mode 100644
index e1af8ce87f..0000000000
--- a/ext/session/tests/010.phpt
+++ /dev/null
@@ -1,19 +0,0 @@
---TEST--
-$session_array = explode(";", session_encode()); should not segfault
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=0
-session.bug_compat_42=1
-session.bug_compat_warn=0
---FILE--
-<?php
-error_reporting(E_ALL);
-
-$session_array = explode(";", @session_encode());
-print "I live\n";
-?>
---EXPECT--
-I live
diff --git a/ext/session/tests/011.phpt b/ext/session/tests/011.phpt
deleted file mode 100644
index 6aaa6bd797..0000000000
--- a/ext/session/tests/011.phpt
+++ /dev/null
@@ -1,20 +0,0 @@
---TEST--
-session_decode(); should not segfault
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=0
-session.bug_compat_42=1
-session.bug_compat_warn=0
---FILE--
-<?php
-error_reporting(E_ALL);
-
-@session_decode("garbage data and no session started");
-@session_decode("userid|s:5:\"mazen\";chatRoom|s:1:\"1\";");
-print "I live\n";
-?>
---EXPECT--
-I live
diff --git a/ext/session/tests/012.phpt b/ext/session/tests/012.phpt
deleted file mode 100644
index 2bfee9b3de..0000000000
--- a/ext/session/tests/012.phpt
+++ /dev/null
@@ -1,34 +0,0 @@
---TEST--
-registering $_SESSION should not segfault
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=1
-session.bug_compat_42=1
-session.bug_compat_warn=0
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-### Absurd example, value of $_SESSION does not matter
-
-session_id("abtest");
-session_start();
-session_register("_SESSION");
-$_SESSION = "kk";
-
-session_write_close();
-
-### Restart to test for $_SESSION brokenness
-
-session_start();
-$_SESSION = "kk";
-session_destroy();
-
-print "I live\n";
-?>
---EXPECT--
-I live
diff --git a/ext/session/tests/013.phpt b/ext/session/tests/013.phpt
deleted file mode 100644
index 77c1353054..0000000000
--- a/ext/session/tests/013.phpt
+++ /dev/null
@@ -1,26 +0,0 @@
---TEST--
-redefining SID should not cause warnings
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=1
-session.bug_compat_42=1
-session.bug_compat_warn=0
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-session_id("abtest");
-session_start();
-session_destroy();
-session_id("abtest2");
-session_start();
-session_destroy();
-
-print "I live\n";
-?>
---EXPECT--
-I live
diff --git a/ext/session/tests/014.phpt b/ext/session/tests/014.phpt
deleted file mode 100644
index 593cfb957d..0000000000
--- a/ext/session/tests/014.phpt
+++ /dev/null
@@ -1,37 +0,0 @@
---TEST--
-a script should not be able to modify session.use_trans_sid
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_trans_sid=1
-session.use_cookies=0
-session.cache_limiter=
-register_globals=1
-session.bug_compat_42=1
-session.bug_compat_warn=0
-session.name=PHPSESSID
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-session_id("abtest");
-session_start();
-
-?>
-<a href="/link">
-<?php
-ini_set("session.use_trans_sid","0");
-?>
-<a href="/link">
-<?php
-ini_set("session.use_trans_sid","1");
-?>
-<a href="/link">
-<?php
-session_destroy();
-?>
---EXPECT--
-<a href="/link?PHPSESSID=abtest">
-<a href="/link?PHPSESSID=abtest">
-<a href="/link?PHPSESSID=abtest">
diff --git a/ext/session/tests/015.phpt b/ext/session/tests/015.phpt
deleted file mode 100644
index 53929b1672..0000000000
--- a/ext/session/tests/015.phpt
+++ /dev/null
@@ -1,24 +0,0 @@
---TEST--
-use_trans_sid should not affect SID
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_trans_sid=1
-session.use_cookies=0
-session.cache_limiter=
-arg_separator.output=&
-session.name=PHPSESSID
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-session_id("abtest");
-session_start();
-?>
-<a href="/link?<?php echo SID; ?>">
-<?php
-session_destroy();
-?>
---EXPECT--
-<a href="/link?PHPSESSID=abtest&PHPSESSID=abtest">
diff --git a/ext/session/tests/016.phpt b/ext/session/tests/016.phpt
deleted file mode 100644
index fde3a915a7..0000000000
--- a/ext/session/tests/016.phpt
+++ /dev/null
@@ -1,20 +0,0 @@
---TEST--
-invalid session.save_path should not cause a segfault
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.save_path="123;:/really\\completely:::/invalid;;,23123;213"
-session.use_cookies=0
-session.cache_limiter=
-session.serialize_handler=php
---FILE--
-<?php
-error_reporting(E_ALL);
-
-@session_start();
-$HTTP_SESSION_VARS["test"] = 1;
-@session_write_close();
-print "I live\n";
-?>
---EXPECT--
-I live
diff --git a/ext/session/tests/017.phpt b/ext/session/tests/017.phpt
deleted file mode 100644
index 2a11fed85b..0000000000
--- a/ext/session/tests/017.phpt
+++ /dev/null
@@ -1,25 +0,0 @@
---TEST--
-setting $_SESSION before session_start() should not cause segfault
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-session.serialize_handler=php
---FILE--
-<?php
-
-error_reporting(E_ALL);
-
-class Kill {
- function Kill() {
- global $HTTP_SESSION_VARS;
- session_start();
- }
-}
-$k = new Kill();
-
-print "I live\n";
-?>
---EXPECT--
-I live
diff --git a/ext/session/tests/018.phpt b/ext/session/tests/018.phpt
deleted file mode 100644
index 0b84978ed2..0000000000
--- a/ext/session/tests/018.phpt
+++ /dev/null
@@ -1,24 +0,0 @@
---TEST--
-rewriter correctly handles attribute names which contain dashes
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-session.use_trans_sid=1
-session.name=PHPSESSID
-session.serialize_handler=php
---FILE--
-<?php
-
-error_reporting(E_ALL);
-
-session_id("abtest");
-session_start();
-?>
-<form accept-charset="ISO-8859-15, ISO-8859-1" action=url.php>
-<?php
-session_destroy();
-?>
---EXPECT--
-<form accept-charset="ISO-8859-15, ISO-8859-1" action=url.php><input type="hidden" name="PHPSESSID" value="abtest" />
diff --git a/ext/session/tests/019.phpt b/ext/session/tests/019.phpt
deleted file mode 100644
index c8b969e44f..0000000000
--- a/ext/session/tests/019.phpt
+++ /dev/null
@@ -1,72 +0,0 @@
---TEST--
-serializing references test case using globals
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-register_globals=1
-session.serialize_handler=php
---FILE--
-<?php
-
-error_reporting(E_ALL);
-
-class TFoo {
- var $c;
- function TFoo($c) {
- $this->c = $c;
- }
- function inc() {
- $this->c++;
- }
-}
-
-session_id("abtest");
-session_register('o1', 'o2' );
-session_start();
-
-$o1 =& new TFoo(42);
-$o2 =& $o1;
-
-session_write_close();
-
-unset($o1);
-unset($o2);
-
-session_start();
-
-var_dump($_SESSION);
-
-$o1->inc();
-$o2->inc();
-
-var_dump($_SESSION);
-
-session_destroy();
-?>
---EXPECT--
-array(2) {
- ["o1"]=>
- &object(tfoo)(1) {
- ["c"]=>
- int(42)
- }
- ["o2"]=>
- &object(tfoo)(1) {
- ["c"]=>
- int(42)
- }
-}
-array(2) {
- ["o1"]=>
- &object(tfoo)(1) {
- ["c"]=>
- int(44)
- }
- ["o2"]=>
- &object(tfoo)(1) {
- ["c"]=>
- int(44)
- }
-}
diff --git a/ext/session/tests/020.phpt b/ext/session/tests/020.phpt
deleted file mode 100644
index c9571ef20d..0000000000
--- a/ext/session/tests/020.phpt
+++ /dev/null
@@ -1,25 +0,0 @@
---TEST--
-rewriter uses arg_seperator.output for modifying URLs
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-session.use_trans_sid=1
-arg_separator.output=&amp;
-session.name=PHPSESSID
-session.serialize_handler=php
---FILE--
-<?php
-
-error_reporting(E_ALL);
-
-session_id("abtest");
-session_start();
-?>
-<a href="link.php?a=b">
-<?php
-session_destroy();
-?>
---EXPECT--
-<a href="link.php?a=b&amp;PHPSESSID=abtest">
diff --git a/ext/session/tests/021.phpt b/ext/session/tests/021.phpt
deleted file mode 100644
index b45406438e..0000000000
--- a/ext/session/tests/021.phpt
+++ /dev/null
@@ -1,61 +0,0 @@
---TEST--
-rewriter handles form and fieldset tags correctly
---SKIPIF--
-<?php include('skipif.inc'); ?>
---INI--
-session.use_cookies=0
-session.cache_limiter=
-session.use_trans_sid=1
-url_rewriter.tags="a=href,area=href,frame=src,input=src,form=,fieldset="
-session.name=PHPSESSID
-session.serialize_handler=php
---FILE--
-<?php
-
-error_reporting(E_ALL);
-
-session_id("abtest");
-session_start();
-?>
-<form>
-<fieldset>
-<?php
-
-ob_flush();
-
-ini_set("url_rewriter.tags", "a=href,area=href,frame=src,input=src,form=");
-
-?>
-<form>
-<fieldset>
-<?php
-
-ob_flush();
-
-ini_set("url_rewriter.tags", "a=href,area=href,frame=src,input=src,form=fakeentry");
-
-?>
-<form>
-<fieldset>
-<?php
-
-ob_flush();
-
-ini_set("url_rewriter.tags", "a=href,fieldset=,area=href,frame=src,input=src");
-
-?>
-<form>
-<fieldset>
-<?php
-
-session_destroy();
-?>
---EXPECT--
-<form><input type="hidden" name="PHPSESSID" value="abtest" />
-<fieldset><input type="hidden" name="PHPSESSID" value="abtest" />
-<form><input type="hidden" name="PHPSESSID" value="abtest" />
-<fieldset>
-<form><input type="hidden" name="PHPSESSID" value="abtest" />
-<fieldset>
-<form>
-<fieldset><input type="hidden" name="PHPSESSID" value="abtest" />
diff --git a/ext/session/tests/skipif.inc b/ext/session/tests/skipif.inc
deleted file mode 100644
index 8336e75bd0..0000000000
--- a/ext/session/tests/skipif.inc
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-// This script prints "skip" if condition does not meet.
-if (!extension_loaded("session") && ini_get("enable_dl")) {
- $dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so";
- @dl("session$dlext");
-}
-if (!extension_loaded("session")) {
- die("skip\n");
-}
-?>