diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/session | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/session')
209 files changed, 18271 insertions, 0 deletions
diff --git a/ext/session/CREDITS b/ext/session/CREDITS new file mode 100644 index 0000000..79659c7 --- /dev/null +++ b/ext/session/CREDITS @@ -0,0 +1,2 @@ +Sessions +Sascha Schumann, Andrei Zmievski diff --git a/ext/session/config.m4 b/ext/session/config.m4 new file mode 100644 index 0000000..1c3ba78 --- /dev/null +++ b/ext/session/config.m4 @@ -0,0 +1,35 @@ +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] SESSION: Include mm support for session storage], no, no) + +if test "$PHP_SESSION" != "no"; then + PHP_PWRITE_TEST + PHP_PREAD_TEST + PHP_NEW_EXTENSION(session, mod_user_class.c session.c mod_files.c mod_mm.c mod_user.c, $ext_shared) + PHP_ADD_EXTENSION_DEP(session, hash, true) + PHP_ADD_EXTENSION_DEP(session, spl) + PHP_SUBST(SESSION_SHARED_LIBADD) + PHP_INSTALL_HEADERS(ext/session, [php_session.h mod_files.h mod_user.h]) + AC_DEFINE(HAVE_PHP_SESSION,1,[ ]) +fi + +if test "$PHP_MM" != "no"; then + for i in $PHP_MM /usr/local /usr; do + test -f "$i/include/mm.h" && MM_DIR=$i && break + done + + if test -z "$MM_DIR" ; then + AC_MSG_ERROR(cannot find mm library) + fi + + PHP_ADD_LIBRARY_WITH_PATH(mm, $MM_DIR/$PHP_LIBDIR, SESSION_SHARED_LIBADD) + PHP_ADD_INCLUDE($MM_DIR/include) + PHP_INSTALL_HEADERS([ext/session/mod_mm.h]) + AC_DEFINE(HAVE_LIBMM, 1, [Whether you have libmm]) +fi diff --git a/ext/session/config.w32 b/ext/session/config.w32 new file mode 100644 index 0000000..c8b217a --- /dev/null +++ b/ext/session/config.w32 @@ -0,0 +1,10 @@ +// $Id$ +// vim:ft=javascript + +ARG_ENABLE("session", "session support", "yes"); + +if (PHP_SESSION == "yes") { + EXTENSION("session", "mod_user_class.c session.c mod_files.c mod_mm.c mod_user.c", false /* never shared */); + AC_DEFINE("HAVE_PHP_SESSION", 1, "Session support"); + PHP_INSTALL_HEADERS("ext/session/", "mod_mm.h php_session.h mod_files.h mod_user.h"); +} diff --git a/ext/session/mod_files.bat b/ext/session/mod_files.bat new file mode 100644 index 0000000..4ec9a49 --- /dev/null +++ b/ext/session/mod_files.bat @@ -0,0 +1,57 @@ +@ECHO OFF
+SETLOCAL ENABLEDELAYEDEXPANSION
+
+IF _%1_==_AUTO_ (
+ GOTO MakeDirs
+)
+
+IF _%2_==__ (
+ ECHO Usage %0 ^<basedir^> ^<depth^> ^[^hash_bits^]
+ ECHO.
+ ECHO Where ^<basedir^> is the session directory
+ ECHO ^<depth^> is the number of levels defined in session.save_path
+ ECHO ^[hash_bits^] is the number of bits defined in session.hash_bits_per_character
+ EXIT /B 1
+)
+
+SET /A Depth=%2 + 0 2>NUL
+IF /I %ERRORLEVEL% EQU 9167 GOTO DepthError
+IF _%Depth%_==__ GOTO DepthError
+IF /I %Depth% LEQ 0 GOTO DepthError
+
+IF _%3_==__ GOTO DefaultBits
+
+SET /A Bits=%3 + 0 2>NUL
+IF /I %ERRORLEVEL% EQU 9167 GOTO BitsError
+IF _%Bits%_==__ GOTO BitsError
+IF /I %Bits% LSS 4 GOTO BitsError
+IF /I %Bits% GTR 6 GOTO BitsError
+GOTO BitsSet
+
+:DefaultBits
+SET Bits=4
+:BitsSet
+
+SET HashChars=0 1 2 3 4 5 6 7 8 9 A B C D E F
+IF /I %Bits% GEQ 5 SET HashChars=!HashChars! G H I J K L M N O P Q R S T U V
+IF /I %Bits% GEQ 6 SET HashChars=!HashChars! W X Y Z - ,
+
+FOR %%A IN (%HashChars%) DO (
+ ECHO Making %%A
+ CALL "%~0" AUTO "%~1\%%~A" %Depth%
+)
+GOTO :EOF
+
+:MakeDirs
+MKDIR "%~2"
+SET /A ThisDepth=%3 - 1
+IF /I %ThisDepth% GTR 0 FOR %%A IN (%HashChars%) DO CALL "%~0" AUTO "%~2\%%~A" %ThisDepth%
+GOTO :EOF
+
+:DepthError
+ECHO ERROR: Invalid depth : %2
+EXIT /B 0
+
+:BitsError
+ECHO ERROR: Invalid hash_bits : %3
+EXIT /B 0
diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c new file mode 100644 index 0000000..1665ba5 --- /dev/null +++ b/ext/session/mod_files.c @@ -0,0 +1,464 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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" +#include "php_open_temporary_file.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; + + /* Somewhat arbitrary length limit here, but should be way more than + anyone needs and avoids file-level warnings later on if we exceed MAX_PATH */ + if (len == 0 || len > 128) { + 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) { +#ifdef PHP_WIN32 + /* On Win32 locked files that are closed without being explicitly unlocked + will be unlocked only when "system resources become available". */ + flock(data->fd, LOCK_UN); +#endif + 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 is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,'"); + PS(invalid_session_id) = 1; + 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) { +#ifndef PHP_WIN32 + /* check to make sure that the opened file is not a symlink, linking to data outside of allowable dirs */ + if (PG(open_basedir)) { + struct stat sbuf; + + if (fstat(data->fd, &sbuf)) { + close(data->fd); + return; + } + if (S_ISLNK(sbuf.st_mode) && php_check_open_basedir(buf TSRMLS_CC)) { + close(data->fd); + return; + } + } +#endif + flock(data->fd, LOCK_EX); + +#ifdef F_SETFD +# ifndef FD_CLOEXEC +# define FD_CLOEXEC 1 +# endif + if (fcntl(data->fd, F_SETFD, FD_CLOEXEC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "fcntl(%d, F_SETFD, FD_CLOEXEC) 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)", 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 = 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; + + if (*save_path == '\0') { + /* if save path is an empty string, determine the temporary dir */ + save_path = php_get_temporary_directory(); + + if (php_check_open_basedir(save_path TSRMLS_CC)) { + return FAILURE; + } + } + + /* 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 = ecalloc(1, 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); + + if (PS_GET_MOD_DATA()) { + ps_close_files(mod_data TSRMLS_CC); + } + 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; + + if (sbuf.st_size == 0) { + *val = STR_EMPTY_ALLOC(); + return SUCCESS; + } + + *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) { + php_ignore_value(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; + } + + if (data->fd != -1) { + ps_files_close(data); + + if (VCWD_UNLINK(buf) == -1) { + /* This is a little safety check for instances when we are dealing with a regenerated session + * that was not yet written to disk. */ + if (!VCWD_ACCESS(buf, F_OK)) { + 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 new file mode 100644 index 0000000..c97d168 --- /dev/null +++ b/ext/session/mod_files.h @@ -0,0 +1,29 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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$ */ + +#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 new file mode 100644 index 0000000..1d26728 --- /dev/null +++ b/ext/session/mod_files.sh @@ -0,0 +1,24 @@ +#! /bin/sh + +if test "$2" = ""; then + echo "usage: $0 basedir depth" + exit 1 +fi + +if test "$2" = "0"; then + exit 0 +fi + +hash_chars="0 1 2 3 4 5 6 7 8 9 a b c d e f" +if test "$3" -a "$3" -ge "5"; then + hash_chars="$hash_chars g h i j k l m n o p q r s t u v" + if test "$3" -eq "6"; then + hash_chars="$hash_chars w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - ," + fi +fi + +for i in $hash_chars; do + newpath="$1/$i" + mkdir $newpath || exit 1 + sh $0 $newpath `expr $2 - 1` $3 +done diff --git a/ext/session/mod_mm.c b/ext/session/mod_mm.c new file mode 100644 index 0000000..e5406d0 --- /dev/null +++ b/ext/session/mod_mm.c @@ -0,0 +1,454 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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); + int euid_len; + char *ps_mm_path, euid[30]; + int ret; + + ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1); + if (!ps_mm_instance) { + return FAILURE; + } + + if (!(euid_len = slprintf(euid, sizeof(euid), "%d", geteuid()))) { + return FAILURE; + } + + /* Directory + '/' + File + Module Name + Effective UID + \0 */ + ps_mm_path = emalloc(save_path_len + 1 + (sizeof(PS_MM_FILE) - 1) + mod_name_len + euid_len + 1); + + memcpy(ps_mm_path, PS(save_path), save_path_len); + if (save_path_len && PS(save_path)[save_path_len - 1] != DEFAULT_SLASH) { + ps_mm_path[save_path_len] = DEFAULT_SLASH; + save_path_len++; + } + memcpy(ps_mm_path + save_path_len, PS_MM_FILE, sizeof(PS_MM_FILE) - 1); + save_path_len += sizeof(PS_MM_FILE) - 1; + memcpy(ps_mm_path + save_path_len, sapi_module.name, mod_name_len); + save_path_len += mod_name_len; + memcpy(ps_mm_path + save_path_len, euid, euid_len); + ps_mm_path[save_path_len + euid_len] = '\0'; + + ret = ps_mm_initialize(ps_mm_instance, ps_mm_path); + + efree(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 new file mode 100644 index 0000000..3ddadce --- /dev/null +++ b/ext/session/mod_mm.h @@ -0,0 +1,37 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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$ */ + +#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 new file mode 100644 index 0000000..57d7bd0 --- /dev/null +++ b/ext/session/mod_user.c @@ -0,0 +1,193 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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); \ + ZVAL_LONG(a, val); \ +} + +#define SESS_ZVAL_STRING(vl, a) \ +{ \ + char *__vl = vl; \ + SESS_ZVAL_STRINGN(__vl, strlen(__vl), a); \ +} + +#define SESS_ZVAL_STRINGN(vl, ln, a) \ +{ \ + MAKE_STD_ZVAL(a); \ + ZVAL_STRINGL(a, vl, ln, 1); \ +} + +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 = NULL; \ + int ret = FAILURE + +#define PSF(a) PS(mod_user_names).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; + + if (PSF(open) == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "user session functions not defined"); + + return FAILURE; + } + + SESS_ZVAL_STRING((char*)save_path, args[0]); + SESS_ZVAL_STRING((char*)session_name, args[1]); + + retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC); + PS(mod_user_implemented) = 1; + + FINISH; +} + +PS_CLOSE_FUNC(user) +{ + zend_bool bailout = 0; + STDVARS; + + if (!PS(mod_user_implemented)) { + /* already closed */ + return SUCCESS; + } + + zend_try { + retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC); + } zend_catch { + bailout = 1; + } zend_end_try(); + + PS(mod_user_implemented) = 0; + + if (bailout) { + if (retval) { + zval_ptr_dtor(&retval); + } + zend_bailout(); + } + + FINISH; +} + +PS_READ_FUNC(user) +{ + zval *args[1]; + STDVARS; + + SESS_ZVAL_STRING((char*)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((char*)key, args[0]); + SESS_ZVAL_STRINGN((char*)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((char*)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 new file mode 100644 index 0000000..fd149cc --- /dev/null +++ b/ext/session/mod_user.h @@ -0,0 +1,29 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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$ */ + +#ifndef MOD_USER_H +#define MOD_USER_H + +extern ps_module ps_mod_user; +#define ps_user_ptr &ps_mod_user + +PS_FUNCS(user); + +#endif diff --git a/ext/session/mod_user_class.c b/ext/session/mod_user_class.c new file mode 100644 index 0000000..1ed1e7b --- /dev/null +++ b/ext/session/mod_user_class.c @@ -0,0 +1,143 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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: Arpad Ray <arpad@php.net> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +#include "php.h" +#include "php_session.h" + +#define PS_SANITY_CHECK \ + if (PS(default_mod) == NULL) { \ + php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Cannot call default session handler"); \ + RETURN_FALSE; \ + } + +#define PS_SANITY_CHECK_IS_OPEN \ + PS_SANITY_CHECK; \ + if (!PS(mod_user_is_open)) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parent session handler is not open"); \ + RETURN_FALSE; \ + } + +/* {{{ proto bool SessionHandler::open(string save_path, string session_name) + Wraps the old open handler */ +PHP_METHOD(SessionHandler, open) +{ + char *save_path = NULL, *session_name = NULL; + int save_path_len, session_name_len; + + PS_SANITY_CHECK; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &save_path, &save_path_len, &session_name, &session_name_len) == FAILURE) { + return; + } + + PS(mod_user_is_open) = 1; + RETVAL_BOOL(SUCCESS == PS(default_mod)->s_open(&PS(mod_data), save_path, session_name TSRMLS_CC)); +} +/* }}} */ + +/* {{{ proto bool SessionHandler::close() + Wraps the old close handler */ +PHP_METHOD(SessionHandler, close) +{ + PS_SANITY_CHECK_IS_OPEN; + + // don't return on failure, since not closing the default handler + // could result in memory leaks or other nasties + zend_parse_parameters_none(); + + PS(mod_user_is_open) = 0; + RETVAL_BOOL(SUCCESS == PS(default_mod)->s_close(&PS(mod_data) TSRMLS_CC)); +} +/* }}} */ + +/* {{{ proto bool SessionHandler::read(string id) + Wraps the old read handler */ +PHP_METHOD(SessionHandler, read) +{ + char *key, *val; + int key_len, val_len; + + PS_SANITY_CHECK_IS_OPEN; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + return; + } + + if (PS(default_mod)->s_read(&PS(mod_data), key, &val, &val_len TSRMLS_CC) == FAILURE) { + RETVAL_FALSE; + return; + } + + RETVAL_STRINGL(val, val_len, 1); + efree(val); + return; +} +/* }}} */ + +/* {{{ proto bool SessionHandler::write(string id, string data) + Wraps the old write handler */ +PHP_METHOD(SessionHandler, write) +{ + char *key, *val; + int key_len, val_len; + + PS_SANITY_CHECK_IS_OPEN; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &key, &key_len, &val, &val_len) == FAILURE) { + return; + } + + RETVAL_BOOL(SUCCESS == PS(default_mod)->s_write(&PS(mod_data), key, val, val_len TSRMLS_CC)); +} +/* }}} */ + +/* {{{ proto bool SessionHandler::destroy(string id) + Wraps the old destroy handler */ +PHP_METHOD(SessionHandler, destroy) +{ + char *key; + int key_len; + + PS_SANITY_CHECK_IS_OPEN; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + return; + } + + RETVAL_BOOL(SUCCESS == PS(default_mod)->s_destroy(&PS(mod_data), key TSRMLS_CC)); +} +/* }}} */ + +/* {{{ proto bool SessionHandler::gc(int maxlifetime) + Wraps the old gc handler */ +PHP_METHOD(SessionHandler, gc) +{ + long maxlifetime; + int nrdels; + + PS_SANITY_CHECK_IS_OPEN; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &maxlifetime) == FAILURE) { + return; + } + + RETVAL_BOOL(SUCCESS == PS(default_mod)->s_gc(&PS(mod_data), maxlifetime, &nrdels TSRMLS_CC)); +} +/* }}} */ diff --git a/ext/session/package.xml b/ext/session/package.xml new file mode 100644 index 0000000..03fcbf6 --- /dev/null +++ b/ext/session/package.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!DOCTYPE package SYSTEM "../pear/package.dtd"> +<package> + <name>session</name> + <summary>Session handling functions</summary> + <maintainers> + <maintainer> + <user>sascha</user> + <name>Sascha Schumann</name> + <email>sas@php.net</email> + <role>lead</role> + </maintainer> + <maintainer> + <user>andrei</user> + <name>Andrei Zmievski</name> + <email>andrei@php.net</email> + <role>lead</role> + </maintainer> + </maintainers> + <description> +Session support in PHP consists of a way to preserve certain data +across subsequent accesses. This enables you to build more customized +applications and increase the appeal of your web site. + </description> + <license>PHP</license> + <release> + <state>beta</state> + <version>5.0.0rc1</version> + <date>2004-03-19</date> + <notes> +package.xml added to support installation using pear installer + </notes> + <filelist> + <file role="doc" name="CREDITS"/> + <file role="src" name="config.m4"/> + <file role="src" name="config.w32"/> + <file role="src" name="mod_files.c"/> + <file role="src" name="mod_files.h"/> + <file role="src" name="mod_files.sh"/> + <file role="src" name="mod_mm.c"/> + <file role="src" name="mod_mm.h"/> + <file role="src" name="mod_user.c"/> + <file role="src" name="mod_user_class.c"/> + <file role="src" name="mod_user.h"/> + <file role="src" name="php_session.h"/> + <file role="src" name="session.c"/> + <file role="test" name="tests/001.phpt"/> + <file role="test" name="tests/002.phpt"/> + <file role="test" name="tests/bug25745.phpt"/> + <file role="test" name="tests/001.phpt"/> + <file role="test" name="tests/002.phpt"/> + <file role="test" name="tests/003.phpt"/> + <file role="test" name="tests/004.phpt"/> + <file role="test" name="tests/005.phpt"/> + <file role="test" name="tests/006.phpt"/> + <file role="test" name="tests/007.phpt"/> + <file role="test" name="tests/008-php4.2.3.phpt"/> + <file role="test" name="tests/008.phpt"/> + <file role="test" name="tests/009.phpt"/> + <file role="test" name="tests/010.phpt"/> + <file role="test" name="tests/011.phpt"/> + <file role="test" name="tests/012.phpt"/> + <file role="test" name="tests/013.phpt"/> + <file role="test" name="tests/014.phpt"/> + <file role="test" name="tests/015.phpt"/> + <file role="test" name="tests/016.phpt"/> + <file role="test" name="tests/017.phpt"/> + <file role="test" name="tests/018.phpt"/> + <file role="test" name="tests/019.phpt"/> + <file role="test" name="tests/020.phpt"/> + <file role="test" name="tests/021.phpt"/> + <file role="test" name="tests/skipif.inc"/> + <file role="test" name="tests/bug26862.phpt"/> + <file role="test" name="tests/bug24592.phpt"/> + </filelist> + <deps> + <dep type="php" rel="ge" version="5" /> + </deps> + </release> +</package> +<!-- +vim:et:ts=1:sw=1 +--> diff --git a/ext/session/php_session.h b/ext/session/php_session.h new file mode 100644 index 0000000..adc5e70 --- /dev/null +++ b/ext/session/php_session.h @@ -0,0 +1,287 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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$ */ + +#ifndef PHP_SESSION_H +#define PHP_SESSION_H + +#include "ext/standard/php_var.h" + +#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) +# include "ext/hash/php_hash.h" +#endif + +#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 */ +PHPAPI 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_session_rfc1867_progress { + + size_t sname_len; + zval sid; + smart_str key; + + long update_step; + long next_update; + double next_update_time; + zend_bool cancel_upload; + zend_bool apply_trans_sid; + size_t content_length; + + zval *data; /* the array exported to session data */ + zval *post_bytes_processed; /* data["bytes_processed"] */ + zval *files; /* data["files"] array */ + zval *current_file; /* array of currently uploading file */ + zval *current_file_bytes_processed; +} php_session_rfc1867_progress; + +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; + zend_bool cookie_httponly; + ps_module *mod; + ps_module *default_mod; + void *mod_data; + php_session_status session_status; + long gc_probability; + long gc_divisor; + long gc_maxlifetime; + int module_number; + long cache_expire; + union { + zval *names[6]; + struct { + zval *ps_open; + zval *ps_close; + zval *ps_read; + zval *ps_write; + zval *ps_destroy; + zval *ps_gc; + } name; + } mod_user_names; + int mod_user_implemented; + int mod_user_is_open; + 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; +#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) + php_hash_ops *hash_ops; +#endif + long hash_bits_per_character; + int send_cookie; + int define_sid; + zend_bool invalid_session_id; /* allows the driver to report about an invalid session id and request id regeneration */ + + php_session_rfc1867_progress *rfc1867_progress; + zend_bool rfc1867_enabled; /* session.upload_progress.enabled */ + zend_bool rfc1867_cleanup; /* session.upload_progress.cleanup */ + smart_str rfc1867_prefix; /* session.upload_progress.prefix */ + smart_str rfc1867_name; /* session.upload_progress.name */ + long rfc1867_freq; /* session.upload_progress.freq */ + double rfc1867_min_freq; /* session.upload_progress.min_freq */ +} php_ps_globals; + +typedef php_ps_globals zend_ps_globals; + +extern zend_module_entry session_module_entry; +#define phpext_session_ptr &session_module_entry + +#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); + +PHPAPI void php_add_session_var(char *name, size_t namelen TSRMLS_DC); +PHPAPI void php_set_session_var(char *name, size_t namelen, zval *state_val, php_unserialize_data_t *var_hash TSRMLS_DC); +PHPAPI 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); + +PHPAPI ps_module *_php_find_ps_module(char *name TSRMLS_DC); +PHPAPI const ps_serializer *_php_find_ps_serializer(char *name TSRMLS_DC); + +#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) do { \ + HashTable *_ht = Z_ARRVAL_P(PS(http_session_vars)); \ + int key_type; \ + \ + for (zend_hash_internal_pointer_reset(_ht); \ + (key_type = zend_hash_get_current_key_ex(_ht, &key, &key_length, &num_key, 0, NULL)) != HASH_KEY_NON_EXISTANT; \ + zend_hash_move_forward(_ht)) { \ + if (key_type == HASH_KEY_IS_LONG) { \ + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Skipping numeric key %ld", num_key); \ + continue; \ + } \ + key_length--; \ + if (php_get_session_var(key, key_length, &struc TSRMLS_CC) == SUCCESS) { \ + code; \ + } \ + } \ + } while(0) + +PHPAPI ZEND_EXTERN_MODULE_GLOBALS(ps) + +void php_session_auto_start(void *data); +void php_session_shutdown(void *data); + +#define PS_CLASS_NAME "SessionHandler" +extern zend_class_entry *php_session_class_entry; + +#define PS_IFACE_NAME "SessionHandlerInterface" +extern zend_class_entry *php_session_iface_entry; + +extern PHP_METHOD(SessionHandler, open); +extern PHP_METHOD(SessionHandler, close); +extern PHP_METHOD(SessionHandler, read); +extern PHP_METHOD(SessionHandler, write); +extern PHP_METHOD(SessionHandler, destroy); +extern PHP_METHOD(SessionHandler, gc); + +#endif diff --git a/ext/session/session.c b/ext/session/session.c new file mode 100644 index 0000000..a3be9a7 --- /dev/null +++ b/ext/session/session.c @@ -0,0 +1,2595 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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/winutil.h" +# 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 "rfc1867.h" +#include "php_variables.h" +#include "php_session.h" +#include "ext/standard/md5.h" +#include "ext/standard/sha1.h" +#include "ext/standard/php_var.h" +#include "ext/date/php_date.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 "ext/standard/url.h" +#include "ext/standard/basic_functions.h" + +#include "mod_files.h" +#include "mod_user.h" + +#ifdef HAVE_LIBMM +#include "mod_mm.h" +#endif + +PHPAPI ZEND_DECLARE_MODULE_GLOBALS(ps) + +static int php_session_rfc1867_callback(unsigned int event, void *event_data, void **extra TSRMLS_DC); +static int (*php_session_rfc1867_orig_callback)(unsigned int event, void *event_data, void **extra TSRMLS_DC); + +/* SessionHandler class */ +zend_class_entry *php_session_class_entry; + +/* SessionHandlerInterface */ +zend_class_entry *php_session_iface_entry; + +/* *********** + * Helpers * + *********** */ + +#define IF_SESSION_VARS() \ + if (PS(http_session_vars) && PS(http_session_vars)->type == IS_ARRAY) + +#define SESSION_CHECK_ACTIVE_STATE \ + 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; \ + } + +/* Dispatched by RINIT and by php_session_destroy */ +static inline void php_rinit_session_globals(TSRMLS_D) /* {{{ */ +{ + PS(id) = NULL; + PS(session_status) = php_session_none; + PS(mod_data) = NULL; + PS(mod_user_is_open) = 0; + /* Do NOT init PS(mod_user_names) here! */ + PS(http_session_vars) = NULL; +} +/* }}} */ + +/* Dispatched by RSHUTDOWN and by php_session_destroy */ +static inline void php_rshutdown_session_globals(TSRMLS_D) /* {{{ */ +{ + if (PS(http_session_vars)) { + zval_ptr_dtor(&PS(http_session_vars)); + PS(http_session_vars) = NULL; + } + /* Do NOT destroy PS(mod_user_names) here! */ + if (PS(mod_data) || PS(mod_user_implemented)) { + zend_try { + PS(mod)->s_close(&PS(mod_data) TSRMLS_CC); + } zend_end_try(); + } + if (PS(id)) { + efree(PS(id)); + } +} +/* }}} */ + +static int php_session_destroy(TSRMLS_D) /* {{{ */ +{ + int 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; +} +/* }}} */ + +PHPAPI void php_add_session_var(char *name, size_t namelen TSRMLS_DC) /* {{{ */ +{ + zval **sym_track = NULL; + + IF_SESSION_VARS() { + zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, namelen + 1, (void *) &sym_track); + } else { + return; + } + + 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); + } +} +/* }}} */ + +PHPAPI void php_set_session_var(char *name, size_t namelen, zval *state_val, php_unserialize_data_t *var_hash TSRMLS_DC) /* {{{ */ +{ + IF_SESSION_VARS() { + zend_set_hash_symbol(state_val, name, namelen, PZVAL_IS_REF(state_val), 1, Z_ARRVAL_P(PS(http_session_vars))); + } +} +/* }}} */ + +PHPAPI 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); + } + return ret; +} +/* }}} */ + +static void php_session_track_init(TSRMLS_D) /* {{{ */ +{ + zval *session_vars = NULL; + + /* Unconditionally destroy existing array -- possible dirty data */ + zend_delete_global_variable("_SESSION", sizeof("_SESSION")-1 TSRMLS_CC); + + if (PS(http_session_vars)) { + zval_ptr_dtor(&PS(http_session_vars)); + } + + MAKE_STD_ZVAL(session_vars); + array_init(session_vars); + PS(http_session_vars) = session_vars; + + 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)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown session.serialize_handler. Failed to encode session object"); + ret = NULL; + } else 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)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown session.serialize_handler. Failed to decode session object"); + return; + } + 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, + PS_HASH_FUNC_OTHER +}; + +/* 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 = (unsigned char *) in; + q = (unsigned char *)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; +} +/* }}} */ + +PHPAPI char *php_session_create_id(PS_CREATE_SID_ARGS) /* {{{ */ +{ + PHP_MD5_CTX md5_context; + PHP_SHA1_CTX sha1_context; +#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) + void *hash_context; +#endif + unsigned char *digest; + int digest_len; + int j; + char *buf, *outid; + 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); + } + + /* maximum 15+19+19+10 bytes */ + spprintf(&buf, 0, "%.15s%ld%ld%0.8F", remote_addr ? remote_addr : "", tv.tv_sec, (long int)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, (unsigned char *) buf, strlen(buf)); + digest_len = 16; + break; + case PS_HASH_FUNC_SHA1: + PHP_SHA1Init(&sha1_context); + PHP_SHA1Update(&sha1_context, (unsigned char *) buf, strlen(buf)); + digest_len = 20; + break; +#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) + case PS_HASH_FUNC_OTHER: + if (!PS(hash_ops)) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid session hash function"); + efree(buf); + return NULL; + } + + hash_context = emalloc(PS(hash_ops)->context_size); + PS(hash_ops)->hash_init(hash_context); + PS(hash_ops)->hash_update(hash_context, (unsigned char *) buf, strlen(buf)); + digest_len = PS(hash_ops)->digest_size; + break; +#endif /* HAVE_HASH_EXT */ + default: + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid session hash function"); + efree(buf); + return NULL; + } + efree(buf); + + if (PS(entropy_length) > 0) { +#ifdef PHP_WIN32 + unsigned char rbuf[2048]; + size_t toread = PS(entropy_length); + + if (php_win32_get_random_bytes(rbuf, (size_t) toread) == SUCCESS){ + + switch (PS(hash_func)) { + case PS_HASH_FUNC_MD5: + PHP_MD5Update(&md5_context, rbuf, toread); + break; + case PS_HASH_FUNC_SHA1: + PHP_SHA1Update(&sha1_context, rbuf, toread); + break; +# if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) + case PS_HASH_FUNC_OTHER: + PS(hash_ops)->hash_update(hash_context, rbuf, toread); + break; +# endif /* HAVE_HASH_EXT */ + } + } +#else + 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; +#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) + case PS_HASH_FUNC_OTHER: + PS(hash_ops)->hash_update(hash_context, rbuf, n); + break; +#endif /* HAVE_HASH_EXT */ + } + to_read -= n; + } + close(fd); + } +#endif + } + + digest = emalloc(digest_len + 1); + 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 defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) + case PS_HASH_FUNC_OTHER: + PS(hash_ops)->hash_final(digest, hash_context); + efree(hash_context); + break; +#endif /* HAVE_HASH_EXT */ + } + + 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"); + } + + outid = emalloc((size_t)((digest_len + 2) * ((8.0f / PS(hash_bits_per_character)) + 0.5))); + j = (int) (bin_to_readable((char *)digest, digest_len, outid, (char)PS(hash_bits_per_character)) - outid); + efree(digest); + + if (newlen) { + *newlen = j; + } + + return outid; +} +/* }}} */ + +static void php_session_initialize(TSRMLS_D) /* {{{ */ +{ + char *val; + int vallen; + + /* check session name for invalid characters */ + if (PS(id) && strpbrk(PS(id), "\r\n\t <>'\"\\")) { + efree(PS(id)); + PS(id) = NULL; + } + + if (!PS(mod)) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "No storage module chosen - failed to initialize session"); + 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 storage module: %s (path: %s)", PS(mod)->s_name, PS(save_path)); + return; + } + + /* If there is no ID, use session module to create one */ + if (!PS(id)) { +new_session: + PS(id) = PS(mod)->s_create_sid(&PS(mod_data), NULL TSRMLS_CC); + if (PS(use_cookies)) { + PS(send_cookie) = 1; + } + } + + /* 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); + PS(invalid_session_id) = 0; + if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == SUCCESS) { + php_session_decode(val, vallen TSRMLS_CC); + efree(val); + } else if (PS(invalid_session_id)) { /* address instances where the session read fails due to an invalid id */ + PS(invalid_session_id) = 0; + efree(PS(id)); + PS(id) = NULL; + goto new_session; + } +} +/* }}} */ + +static void php_session_save_current_state(TSRMLS_D) /* {{{ */ +{ + int ret = FAILURE; + + IF_SESSION_VARS() { + if (PS(mod_data) || PS(mod_user_implemented)) { + 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_user_implemented)) { + PS(mod)->s_close(&PS(mod_data) TSRMLS_CC); + } +} +/* }}} */ + +/* ************************* + * INI Settings/Handlers * + ************************* */ + +static PHP_INI_MH(OnUpdateSaveHandler) /* {{{ */ +{ + ps_module *tmp; + SESSION_CHECK_ACTIVE_STATE; + + tmp = _php_find_ps_module(new_value TSRMLS_CC); + + if (PG(modules_activated) && !tmp) { + int err_type; + + if (stage == ZEND_INI_STAGE_RUNTIME) { + err_type = E_WARNING; + } else { + err_type = E_ERROR; + } + + /* Do not output error when restoring ini options. */ + if (stage != ZEND_INI_STAGE_DEACTIVATE) { + php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find save handler '%s'", new_value); + } + return FAILURE; + } + + PS(default_mod) = PS(mod); + PS(mod) = tmp; + + return SUCCESS; +} +/* }}} */ + +static PHP_INI_MH(OnUpdateSerializer) /* {{{ */ +{ + const ps_serializer *tmp; + SESSION_CHECK_ACTIVE_STATE; + + tmp = _php_find_ps_serializer(new_value TSRMLS_CC); + + if (PG(modules_activated) && !tmp) { + int err_type; + + if (stage == ZEND_INI_STAGE_RUNTIME) { + err_type = E_WARNING; + } else { + err_type = E_ERROR; + } + + /* Do not output error when restoring ini options. */ + if (stage != ZEND_INI_STAGE_DEACTIVATE) { + php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find serialization handler '%s'", new_value); + } + return FAILURE; + } + PS(serializer) = tmp; + + return SUCCESS; +} +/* }}} */ + +static PHP_INI_MH(OnUpdateTransSid) /* {{{ */ +{ + SESSION_CHECK_ACTIVE_STATE; + + if (!strncasecmp(new_value, "on", sizeof("on"))) { + PS(use_trans_sid) = (zend_bool) 1; + } else { + PS(use_trans_sid) = (zend_bool) atoi(new_value); + } + + return SUCCESS; +} +/* }}} */ + +static PHP_INI_MH(OnUpdateSaveDir) /* {{{ */ +{ + /* Only do the safemode/open_basedir check at runtime */ + if (stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) { + char *p; + + if (memchr(new_value, '\0', new_value_length) != NULL) { + return FAILURE; + } + + /* we do not use zend_memrchr() since path can contain ; itself */ + if ((p = strchr(new_value, ';'))) { + char *p2; + p++; + if ((p2 = strchr(p, ';'))) { + p = p2 + 1; + } + } else { + p = new_value; + } + + if (PG(open_basedir) && *p && php_check_open_basedir(p TSRMLS_CC)) { + return FAILURE; + } + } + + OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + return SUCCESS; +} +/* }}} */ + +static PHP_INI_MH(OnUpdateHashFunc) /* {{{ */ +{ + long val; + char *endptr = NULL; + +#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) + PS(hash_ops) = NULL; +#endif + + val = strtol(new_value, &endptr, 10); + if (endptr && (*endptr == '\0')) { + /* Numeric value */ + PS(hash_func) = val ? 1 : 0; + + return SUCCESS; + } + + if (new_value_length == (sizeof("md5") - 1) && + strncasecmp(new_value, "md5", sizeof("md5") - 1) == 0) { + PS(hash_func) = PS_HASH_FUNC_MD5; + + return SUCCESS; + } + + if (new_value_length == (sizeof("sha1") - 1) && + strncasecmp(new_value, "sha1", sizeof("sha1") - 1) == 0) { + PS(hash_func) = PS_HASH_FUNC_SHA1; + + return SUCCESS; + } + +#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) /* {{{ */ +{ + php_hash_ops *ops = (php_hash_ops*)php_hash_fetch_ops(new_value, new_value_length); + + if (ops) { + PS(hash_func) = PS_HASH_FUNC_OTHER; + PS(hash_ops) = ops; + + return SUCCESS; + } +} +#endif /* HAVE_HASH_EXT }}} */ + + return FAILURE; +} +/* }}} */ + +static PHP_INI_MH(OnUpdateRfc1867Freq) /* {{{ */ +{ + int tmp; + tmp = zend_atoi(new_value, new_value_length); + if(tmp < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "session.upload_progress.freq must be greater than or equal to zero"); + return FAILURE; + } + if(new_value_length > 0 && new_value[new_value_length-1] == '%') { + if(tmp > 100) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "session.upload_progress.freq cannot be over 100%%"); + return FAILURE; + } + PS(rfc1867_freq) = -tmp; + } else { + PS(rfc1867_freq) = tmp; + } + return SUCCESS; +} /* }}} */ + +static ZEND_INI_MH(OnUpdateSmartStr) /* {{{ */ +{ + smart_str *p; +#ifndef ZTS + char *base = (char *) mh_arg2; +#else + char *base; + + base = (char *) ts_resource(*((int *) mh_arg2)); +#endif + + p = (smart_str *) (base+(size_t) mh_arg1); + + smart_str_sets(p, new_value); + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_INI + */ +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY("session.save_path", "", PHP_INI_ALL, OnUpdateSaveDir,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.cookie_httponly", "", PHP_INI_ALL, OnUpdateBool, cookie_httponly, 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", "1", 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) +#if HAVE_DEV_URANDOM + STD_PHP_INI_ENTRY("session.entropy_file", "/dev/urandom", PHP_INI_ALL, OnUpdateString, entropy_file, php_ps_globals, ps_globals) + STD_PHP_INI_ENTRY("session.entropy_length", "32", PHP_INI_ALL, OnUpdateLong, entropy_length, php_ps_globals, ps_globals) +#elif HAVE_DEV_ARANDOM + STD_PHP_INI_ENTRY("session.entropy_file", "/dev/arandom", PHP_INI_ALL, OnUpdateString, entropy_file, php_ps_globals, ps_globals) + STD_PHP_INI_ENTRY("session.entropy_length", "32", PHP_INI_ALL, OnUpdateLong, entropy_length, php_ps_globals, ps_globals) +#else + 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) +#endif + 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) + PHP_INI_ENTRY("session.use_trans_sid", "0", PHP_INI_ALL, OnUpdateTransSid) + PHP_INI_ENTRY("session.hash_function", "0", PHP_INI_ALL, OnUpdateHashFunc) + STD_PHP_INI_ENTRY("session.hash_bits_per_character", "4", PHP_INI_ALL, OnUpdateLong, hash_bits_per_character, php_ps_globals, ps_globals) + + /* Upload progress */ + STD_PHP_INI_BOOLEAN("session.upload_progress.enabled", + "1", ZEND_INI_PERDIR, OnUpdateBool, rfc1867_enabled, php_ps_globals, ps_globals) + STD_PHP_INI_BOOLEAN("session.upload_progress.cleanup", + "1", ZEND_INI_PERDIR, OnUpdateBool, rfc1867_cleanup, php_ps_globals, ps_globals) + STD_PHP_INI_ENTRY("session.upload_progress.prefix", + "upload_progress_", ZEND_INI_PERDIR, OnUpdateSmartStr, rfc1867_prefix, php_ps_globals, ps_globals) + STD_PHP_INI_ENTRY("session.upload_progress.name", + "PHP_SESSION_UPLOAD_PROGRESS", ZEND_INI_PERDIR, OnUpdateSmartStr, rfc1867_name, php_ps_globals, ps_globals) + STD_PHP_INI_ENTRY("session.upload_progress.freq", "1%", ZEND_INI_PERDIR, OnUpdateRfc1867Freq, rfc1867_freq, php_ps_globals, ps_globals) + STD_PHP_INI_ENTRY("session.upload_progress.min_freq", + "1", ZEND_INI_PERDIR, OnUpdateReal, rfc1867_min_freq,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() +/* }}} */ + +/* *************** + * Serializers * + *************** */ + +#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; + } + smart_str_0(&buf); + *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; ) { + zval **tmp; + namelen = ((unsigned char)(*p)) & (~PS_BIN_UNDEF); + + if (namelen < 0 || namelen > PS_BIN_MAX || (p + namelen) >= endptr) { + return FAILURE; + } + + has_value = *p & PS_BIN_UNDEF ? 0 : 1; + + name = estrndup(p + 1, namelen); + + p += namelen + 1; + + if (zend_hash_find(&EG(symbol_table), name, namelen + 1, (void **) &tmp) == SUCCESS) { + if ((Z_TYPE_PP(tmp) == IS_ARRAY && Z_ARRVAL_PP(tmp) == &EG(symbol_table)) || *tmp == PS(http_session_vars)) { + efree(name); + continue; + } + } + + if (has_value) { + ALLOC_INIT_ZVAL(current); + if (php_var_unserialize(¤t, (const unsigned char **) &p, (const unsigned char *) endptr, &var_hash TSRMLS_CC)) { + php_set_session_var(name, namelen, current, &var_hash TSRMLS_CC); + } + zval_ptr_dtor(¤t); + } + PS_ADD_VARL(name, namelen); + efree(name); + } + + PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + + return SUCCESS; +} +/* }}} */ + +#define PS_DELIMITER '|' +#define PS_UNDEF_MARKER '!' + +PS_SERIALIZER_ENCODE_FUNC(php) /* {{{ */ +{ + 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, key_length); + if (memchr(key, PS_DELIMITER, key_length) || memchr(key, PS_UNDEF_MARKER, key_length)) { + PHP_VAR_SERIALIZE_DESTROY(var_hash); + smart_str_free(&buf); + return FAILURE; + } + 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; + } + smart_str_0(&buf); + *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) { + zval **tmp; + 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 (zend_hash_find(&EG(symbol_table), name, namelen + 1, (void **) &tmp) == SUCCESS) { + if ((Z_TYPE_PP(tmp) == IS_ARRAY && Z_ARRVAL_PP(tmp) == &EG(symbol_table)) || *tmp == PS(http_session_vars)) { + goto skip; + } + } + + if (has_value) { + ALLOC_INIT_ZVAL(current); + if (php_var_unserialize(¤t, (const unsigned char **) &q, (const unsigned char *) endptr, &var_hash TSRMLS_CC)) { + php_set_session_var(name, namelen, current, &var_hash TSRMLS_CC); + } + zval_ptr_dtor(¤t); + } + PS_ADD_VARL(name, namelen); +skip: + efree(name); + + p = q; + } +break_outer_loop: + + PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + + return SUCCESS; +} +/* }}} */ + +#define MAX_SERIALIZERS 10 +#define PREDEFINED_SERIALIZERS 2 + +static ps_serializer ps_serializers[MAX_SERIALIZERS + 1] = { + PS_SERIALIZER_ENTRY(php), + PS_SERIALIZER_ENTRY(php_binary) +}; + +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; +} +/* }}} */ + +/* ******************* + * Storage Modules * + ******************* */ + +#define MAX_MODULES 10 +#define PREDEFINED_MODULES 2 + +static ps_module *ps_modules[MAX_MODULES + 1] = { + ps_files_ptr, + ps_user_ptr +}; + +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; +} +/* }}} */ + +/* ****************** + * Cache Limiters * + ****************** */ + +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 + +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 inline void strcpy_gmt(char *ubuf, time_t *when) /* {{{ */ +{ + char buf[MAX_STR]; + struct tm tm, *res; + int n; + + res = php_gmtime_r(when, &tm); + + if (!res) { + buf[0] = '\0'; + return; + } + + n = slprintf(buf, sizeof(buf), "%s, %02d %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 inline 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); + } +} +/* }}} */ + +#define EXPIRES "Expires: " +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; + memcpy(buf, EXPIRES, sizeof(EXPIRES) - 1); + strcpy_gmt(buf + sizeof(EXPIRES) - 1, &now); + ADD_HEADER(buf); + + snprintf(buf, sizeof(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]; + + snprintf(buf, sizeof(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)) { + const char *output_start_filename = php_output_get_start_filename(TSRMLS_C); + int output_start_lineno = php_output_get_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; +} +/* }}} */ + +/* ********************* + * Cookie Management * + ********************* */ + +#define COOKIE_SET_COOKIE "Set-Cookie: " +#define COOKIE_EXPIRES "; expires=" +#define COOKIE_PATH "; path=" +#define COOKIE_DOMAIN "; domain=" +#define COOKIE_SECURE "; secure" +#define COOKIE_HTTPONLY "; HttpOnly" + +static void php_session_send_cookie(TSRMLS_D) /* {{{ */ +{ + smart_str ncookie = {0}; + char *date_fmt = NULL; + char *e_session_name, *e_id; + + if (SG(headers_sent)) { + const char *output_start_filename = php_output_get_start_filename(TSRMLS_C); + int output_start_lineno = php_output_get_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; + } + + /* URL encode session_name and id because they might be user supplied */ + e_session_name = php_url_encode(PS(session_name), strlen(PS(session_name)), NULL); + e_id = php_url_encode(PS(id), strlen(PS(id)), NULL); + + smart_str_appends(&ncookie, COOKIE_SET_COOKIE); + smart_str_appends(&ncookie, e_session_name); + smart_str_appendc(&ncookie, '='); + smart_str_appends(&ncookie, e_id); + + efree(e_session_name); + efree(e_id); + + if (PS(cookie_lifetime) > 0) { + struct timeval tv; + time_t t; + + gettimeofday(&tv, NULL); + t = tv.tv_sec + PS(cookie_lifetime); + + if (t > 0) { + date_fmt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, t, 0 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); + } + + if (PS(cookie_httponly)) { + smart_str_appends(&ncookie, COOKIE_HTTPONLY); + } + + smart_str_0(&ncookie); + + /* 'replace' must be 0 here, else a previous Set-Cookie + header, probably sent with setcookie() will be replaced! */ + sapi_add_header_ex(ncookie.c, ncookie.len, 0, 0 TSRMLS_CC); +} +/* }}} */ + +PHPAPI 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; +} +/* }}} */ + +PHPAPI 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(use_cookies) && PS(send_cookie)) { + php_session_send_cookie(TSRMLS_C); + PS(send_cookie) = 0; + } + + /* 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", STR_EMPTY_ALLOC(), 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, *value; + int nrand; + int lensess; + + if (PS(use_only_cookies)) { + PS(apply_trans_sid) = 0; + } else { + PS(apply_trans_sid) = PS(use_trans_sid); + } + + switch (PS(session_status)) { + case php_session_active: + php_error(E_NOTICE, "A session had already been started - ignoring session_start()"); + return; + break; + + case php_session_disabled: + value = zend_ini_string("session.save_handler", sizeof("session.save_handler"), 0); + if (!PS(mod) && value) { + PS(mod) = _php_find_ps_module(value TSRMLS_CC); + if (!PS(mod)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find save handler '%s' - session startup failed", value); + return; + } + } + value = zend_ini_string("session.serialize_handler", sizeof("session.serialize_handler"), 0); + if (!PS(serializer) && value) { + PS(serializer) = _php_find_ps_serializer(value TSRMLS_CC); + if (!PS(serializer)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find serialization handler '%s' - session startup failed", value); + return; + } + } + PS(session_status) = php_session_none; + /* fallthrough */ + + default: + case php_session_none: + PS(define_sid) = 1; + PS(send_cookie) = 1; + } + + lensess = strlen(PS(session_name)); + + /* Cookies are preferred, because initially + * cookie and get variables will be available. */ + + if (!PS(id)) { + if (PS(use_cookies) && 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) && PG(http_globals)[TRACK_VARS_SERVER] && + zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "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); + PS(send_cookie) = 0; + } + } + + /* 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' && + PG(http_globals)[TRACK_VARS_SERVER] && + zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "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(use_only_cookies)) { + PS(apply_trans_sid) = 1; + } + } + + php_session_initialize(TSRMLS_C); + + if (!PS(use_cookies) && PS(send_cookie)) { + if (PS(use_trans_sid) && !PS(use_only_cookies)) { + 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(mod_user_implemented)) && 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); +#ifdef SESSION_DEBUG + if (nrdels != -1) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "purged %d expired session objects", nrdels); + } +#endif + } + } +} +/* }}} */ + +static void php_session_flush(TSRMLS_D) /* {{{ */ +{ + if (PS(session_status) == php_session_active) { + PS(session_status) = php_session_none; + php_session_save_current_state(TSRMLS_C); + } +} +/* }}} */ + +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); + } +} +/* }}} */ + +/* ******************************** + * Userspace exported functions * + ******************************** */ + +/* {{{ proto void session_set_cookie_params(int lifetime [, string path [, string domain [, bool secure[, bool httponly]]]]) + Set session cookie parameters */ +static PHP_FUNCTION(session_set_cookie_params) +{ + zval **lifetime = NULL; + char *path = NULL, *domain = NULL; + int path_len, domain_len, argc = ZEND_NUM_ARGS(); + zend_bool secure = 0, httponly = 0; + + if (!PS(use_cookies) || + zend_parse_parameters(argc TSRMLS_CC, "Z|ssbb", &lifetime, &path, &path_len, &domain, &domain_len, &secure, &httponly) == FAILURE) { + return; + } + + convert_to_string_ex(lifetime); + + zend_alter_ini_entry("session.cookie_lifetime", sizeof("session.cookie_lifetime"), Z_STRVAL_PP(lifetime), Z_STRLEN_PP(lifetime), PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + + if (path) { + zend_alter_ini_entry("session.cookie_path", sizeof("session.cookie_path"), path, path_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } + if (domain) { + zend_alter_ini_entry("session.cookie_domain", sizeof("session.cookie_domain"), domain, domain_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } + + if (argc > 3) { + zend_alter_ini_entry("session.cookie_secure", sizeof("session.cookie_secure"), secure ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } + if (argc > 4) { + zend_alter_ini_entry("session.cookie_httponly", sizeof("session.cookie_httponly"), httponly ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } +} +/* }}} */ + +/* {{{ proto array session_get_cookie_params(void) + Return the session cookie parameters */ +static PHP_FUNCTION(session_get_cookie_params) +{ + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + 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)); + add_assoc_bool(return_value, "httponly", PS(cookie_httponly)); +} +/* }}} */ + +/* {{{ proto string session_name([string newname]) + Return the current session name. If newname is given, the session name is replaced with newname */ +static PHP_FUNCTION(session_name) +{ + char *name = NULL; + int name_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) { + return; + } + + RETVAL_STRING(PS(session_name), 1); + + if (name) { + zend_alter_ini_entry("session.name", sizeof("session.name"), name, name_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } +} +/* }}} */ + +/* {{{ 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 */ +static PHP_FUNCTION(session_module_name) +{ + char *name = NULL; + int name_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) { + return; + } + + /* Set return_value to current module name */ + if (PS(mod) && PS(mod)->s_name) { + RETVAL_STRING(safe_estrdup(PS(mod)->s_name), 0); + } else { + RETVAL_EMPTY_STRING(); + } + + if (name) { + if (!_php_find_ps_module(name TSRMLS_CC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find named PHP session module (%s)", name); + + zval_dtor(return_value); + RETURN_FALSE; + } + if (PS(mod_data) || PS(mod_user_implemented)) { + PS(mod)->s_close(&PS(mod_data) TSRMLS_CC); + } + PS(mod_data) = NULL; + + zend_alter_ini_entry("session.save_handler", sizeof("session.save_handler"), name, name_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } +} +/* }}} */ + +/* {{{ proto void session_set_save_handler(string open, string close, string read, string write, string destroy, string gc) + Sets user-level functions */ +static PHP_FUNCTION(session_set_save_handler) +{ + zval ***args = NULL; + int i, num_args, argc = ZEND_NUM_ARGS(); + char *name; + + if (PS(session_status) != php_session_none) { + RETURN_FALSE; + } + + if (argc != 1 && argc != 2 && argc != 6) { + WRONG_PARAM_COUNT; + } + + if (argc <= 2) { + zval *obj = NULL, *callback = NULL; + zend_uint func_name_len; + char *func_name; + HashPosition pos; + zend_function *default_mptr, *current_mptr; + ulong func_index; + php_shutdown_function_entry shutdown_function_entry; + zend_bool register_shutdown = 1; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &obj, php_session_iface_entry, ®ister_shutdown) == FAILURE) { + RETURN_FALSE; + } + + /* Find implemented methods */ + zend_hash_internal_pointer_reset_ex(&php_session_class_entry->function_table, &pos); + i = 0; + while (zend_hash_get_current_data_ex(&php_session_class_entry->function_table, (void **) &default_mptr, &pos) == SUCCESS) { + zend_hash_get_current_key_ex(&php_session_class_entry->function_table, &func_name, &func_name_len, &func_index, 0, &pos); + + if (zend_hash_find(&Z_OBJCE_P(obj)->function_table, func_name, func_name_len, (void **)¤t_mptr) == SUCCESS) { + if (PS(mod_user_names).names[i] != NULL) { + zval_ptr_dtor(&PS(mod_user_names).names[i]); + } + + MAKE_STD_ZVAL(callback); + array_init_size(callback, 2); + Z_ADDREF_P(obj); + add_next_index_zval(callback, obj); + add_next_index_stringl(callback, func_name, func_name_len - 1, 1); + PS(mod_user_names).names[i] = callback; + } else { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Session handler's function table is corrupt"); + RETURN_FALSE; + } + + zend_hash_move_forward_ex(&php_session_class_entry->function_table, &pos); + ++i; + } + + if (register_shutdown) { + /* create shutdown function */ + shutdown_function_entry.arg_count = 1; + shutdown_function_entry.arguments = (zval **) safe_emalloc(sizeof(zval *), 1, 0); + + MAKE_STD_ZVAL(callback); + ZVAL_STRING(callback, "session_register_shutdown", 1); + shutdown_function_entry.arguments[0] = callback; + + /* add shutdown function, removing the old one if it exists */ + if (!register_user_shutdown_function("session_shutdown", sizeof("session_shutdown"), &shutdown_function_entry TSRMLS_CC)) { + zval_ptr_dtor(&callback); + efree(shutdown_function_entry.arguments); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to register session shutdown function"); + RETURN_FALSE; + } + } else { + /* remove shutdown function */ + remove_user_shutdown_function("session_shutdown", sizeof("session_shutdown") TSRMLS_CC); + } + + if (PS(mod) && PS(session_status) == php_session_none && PS(mod) != &ps_mod_user) { + zend_alter_ini_entry("session.save_handler", sizeof("session.save_handler"), "user", sizeof("user")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } + + RETURN_TRUE; + } + + if (zend_parse_parameters(argc TSRMLS_CC, "+", &args, &num_args) == FAILURE) { + return; + } + + /* remove shutdown function */ + remove_user_shutdown_function("session_shutdown", sizeof("session_shutdown") TSRMLS_CC); + + for (i = 0; i < 6; i++) { + if (!zend_is_callable(*args[i], 0, &name TSRMLS_CC)) { + efree(args); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument %d is not a valid callback", i+1); + efree(name); + RETURN_FALSE; + } + efree(name); + } + + if (PS(mod) && PS(mod) != &ps_mod_user) { + zend_alter_ini_entry("session.save_handler", sizeof("session.save_handler"), "user", sizeof("user")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } + + for (i = 0; i < 6; i++) { + if (PS(mod_user_names).names[i] != NULL) { + zval_ptr_dtor(&PS(mod_user_names).names[i]); + } + Z_ADDREF_PP(args[i]); + PS(mod_user_names).names[i] = *args[i]; + } + + efree(args); + 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 */ +static PHP_FUNCTION(session_save_path) +{ + char *name = NULL; + int name_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) { + return; + } + + RETVAL_STRING(PS(save_path), 1); + + if (name) { + if (memchr(name, '\0', name_len) != NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The save_path cannot contain NULL characters"); + zval_dtor(return_value); + RETURN_FALSE; + } + zend_alter_ini_entry("session.save_path", sizeof("session.save_path"), name, name_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } +} +/* }}} */ + +/* {{{ proto string session_id([string newid]) + Return the current session id. If newid is given, the session id is replaced with newid */ +static PHP_FUNCTION(session_id) +{ + char *name = NULL; + int name_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) { + return; + } + + if (PS(id)) { + RETVAL_STRING(PS(id), 1); + } else { + RETVAL_EMPTY_STRING(); + } + + if (name) { + if (PS(id)) { + efree(PS(id)); + } + PS(id) = estrndup(name, name_len); + } +} +/* }}} */ + +/* {{{ proto bool session_regenerate_id([bool delete_old_session]) + Update the current session id with a newly generated one. If delete_old_session is set to true, remove the old session. */ +static PHP_FUNCTION(session_regenerate_id) +{ + zend_bool del_ses = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &del_ses) == FAILURE) { + return; + } + + if (SG(headers_sent) && PS(use_cookies)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot regenerate session id - headers already sent"); + RETURN_FALSE; + } + + if (PS(session_status) == php_session_active) { + if (PS(id)) { + if (del_ses && PS(mod)->s_destroy(&PS(mod_data), PS(id) TSRMLS_CC) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session object destruction failed"); + RETURN_FALSE; + } + efree(PS(id)); + PS(id) = NULL; + } + + PS(id) = PS(mod)->s_create_sid(&PS(mod_data), NULL TSRMLS_CC); + + PS(send_cookie) = 1; + 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 */ +static PHP_FUNCTION(session_cache_limiter) +{ + char *limiter = NULL; + int limiter_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &limiter, &limiter_len) == FAILURE) { + return; + } + + RETVAL_STRING(PS(cache_limiter), 1); + + if (limiter) { + zend_alter_ini_entry("session.cache_limiter", sizeof("session.cache_limiter"), limiter, limiter_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } +} +/* }}} */ + +/* {{{ 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 */ +static PHP_FUNCTION(session_cache_expire) +{ + zval **expires = NULL; + int argc = ZEND_NUM_ARGS(); + + if (zend_parse_parameters(argc TSRMLS_CC, "|Z", &expires) == FAILURE) { + return; + } + + RETVAL_LONG(PS(cache_expire)); + + if (argc == 1) { + convert_to_string_ex(expires); + zend_alter_ini_entry("session.cache_expire", sizeof("session.cache_expire"), Z_STRVAL_PP(expires), Z_STRLEN_PP(expires), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); + } +} +/* }}} */ + +/* {{{ proto string session_encode(void) + Serializes the current setup and returns the serialized representation */ +static PHP_FUNCTION(session_encode) +{ + int len; + char *enc; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + 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 */ +static PHP_FUNCTION(session_decode) +{ + char *str; + int str_len; + + if (PS(session_status) == php_session_none) { + RETURN_FALSE; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + return; + } + + php_session_decode(str, str_len TSRMLS_CC); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto bool session_start(void) + Begin session - reinitializes freezed variables, registers browsers etc */ +static PHP_FUNCTION(session_start) +{ + /* skipping check for non-zero args for performance reasons here ?*/ + php_session_start(TSRMLS_C); + + if (PS(session_status) != php_session_active) { + RETURN_FALSE; + } + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto bool session_destroy(void) + Destroy the current session and all data associated with it */ +static PHP_FUNCTION(session_destroy) +{ + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + RETURN_BOOL(php_session_destroy(TSRMLS_C) == SUCCESS); +} +/* }}} */ + +/* {{{ proto void session_unset(void) + Unset all registered variables */ +static PHP_FUNCTION(session_unset) +{ + if (PS(session_status) == php_session_none) { + RETURN_FALSE; + } + + IF_SESSION_VARS() { + HashTable *ht_sess_var; + + SEPARATE_ZVAL_IF_NOT_REF(&PS(http_session_vars)); + ht_sess_var = Z_ARRVAL_P(PS(http_session_vars)); + + /* Clean $_SESSION. */ + zend_hash_clean(ht_sess_var); + } +} +/* }}} */ + +/* {{{ proto void session_write_close(void) + Write session data and end session */ +static PHP_FUNCTION(session_write_close) +{ + php_session_flush(TSRMLS_C); +} +/* }}} */ + +/* {{{ proto int session_status(void) + Returns the current session status */ +static PHP_FUNCTION(session_status) +{ + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + RETURN_LONG(PS(session_status)); +} +/* }}} */ + +/* {{{ proto void session_register_shutdown(void) + Registers session_write_close() as a shutdown function */ +static PHP_FUNCTION(session_register_shutdown) +{ + php_shutdown_function_entry shutdown_function_entry; + zval *callback; + + /* This function is registered itself as a shutdown function by + * session_set_save_handler($obj). The reason we now register another + * shutdown function is in case the user registered their own shutdown + * function after calling session_set_save_handler(), which expects + * the session still to be available. + */ + + shutdown_function_entry.arg_count = 1; + shutdown_function_entry.arguments = (zval **) safe_emalloc(sizeof(zval *), 1, 0); + + MAKE_STD_ZVAL(callback); + ZVAL_STRING(callback, "session_write_close", 1); + shutdown_function_entry.arguments[0] = callback; + + if (!append_user_shutdown_function(shutdown_function_entry TSRMLS_CC)) { + zval_ptr_dtor(&callback); + efree(shutdown_function_entry.arguments); + + /* Unable to register shutdown function, presumably because of lack + * of memory, so flush the session now. It would be done in rshutdown + * anyway but the handler will have had it's dtor called by then. + * If the user does have a later shutdown function which needs the + * session then tough luck. + */ + php_session_flush(TSRMLS_C); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to register session flush function"); + } +} +/* }}} */ + +/* {{{ arginfo */ +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_name, 0, 0, 0) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_module_name, 0, 0, 0) + ZEND_ARG_INFO(0, module) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_save_path, 0, 0, 0) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_id, 0, 0, 0) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_regenerate_id, 0, 0, 0) + ZEND_ARG_INFO(0, delete_old_session) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_decode, 0, 0, 1) + ZEND_ARG_INFO(0, data) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_session_void, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_set_save_handler, 0, 0, 6) + ZEND_ARG_INFO(0, open) + ZEND_ARG_INFO(0, close) + ZEND_ARG_INFO(0, read) + ZEND_ARG_INFO(0, write) + ZEND_ARG_INFO(0, destroy) + ZEND_ARG_INFO(0, gc) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_cache_limiter, 0, 0, 0) + ZEND_ARG_INFO(0, cache_limiter) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_cache_expire, 0, 0, 0) + ZEND_ARG_INFO(0, new_cache_expire) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_session_set_cookie_params, 0, 0, 1) + ZEND_ARG_INFO(0, lifetime) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, domain) + ZEND_ARG_INFO(0, secure) + ZEND_ARG_INFO(0, httponly) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_session_class_open, 0) + ZEND_ARG_INFO(0, save_path) + ZEND_ARG_INFO(0, session_name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_session_class_close, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_session_class_read, 0) + ZEND_ARG_INFO(0, key) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_session_class_write, 0) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, val) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_session_class_destroy, 0) + ZEND_ARG_INFO(0, key) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_session_class_gc, 0) + ZEND_ARG_INFO(0, maxlifetime) +ZEND_END_ARG_INFO() +/* }}} */ + +/* {{{ session_functions[] + */ +static const zend_function_entry session_functions[] = { + PHP_FE(session_name, arginfo_session_name) + PHP_FE(session_module_name, arginfo_session_module_name) + PHP_FE(session_save_path, arginfo_session_save_path) + PHP_FE(session_id, arginfo_session_id) + PHP_FE(session_regenerate_id, arginfo_session_regenerate_id) + PHP_FE(session_decode, arginfo_session_decode) + PHP_FE(session_encode, arginfo_session_void) + PHP_FE(session_start, arginfo_session_void) + PHP_FE(session_destroy, arginfo_session_void) + PHP_FE(session_unset, arginfo_session_void) + PHP_FE(session_set_save_handler, arginfo_session_set_save_handler) + PHP_FE(session_cache_limiter, arginfo_session_cache_limiter) + PHP_FE(session_cache_expire, arginfo_session_cache_expire) + PHP_FE(session_set_cookie_params, arginfo_session_set_cookie_params) + PHP_FE(session_get_cookie_params, arginfo_session_void) + PHP_FE(session_write_close, arginfo_session_void) + PHP_FE(session_status, arginfo_session_void) + PHP_FE(session_register_shutdown, arginfo_session_void) + PHP_FALIAS(session_commit, session_write_close, arginfo_session_void) + PHP_FE_END +}; +/* }}} */ + +/* {{{ SessionHandlerInterface functions[] +*/ +static const zend_function_entry php_session_iface_functions[] = { + PHP_ABSTRACT_ME(SessionHandlerInterface, open, arginfo_session_class_open) + PHP_ABSTRACT_ME(SessionHandlerInterface, close, arginfo_session_class_close) + PHP_ABSTRACT_ME(SessionHandlerInterface, read, arginfo_session_class_read) + PHP_ABSTRACT_ME(SessionHandlerInterface, write, arginfo_session_class_write) + PHP_ABSTRACT_ME(SessionHandlerInterface, destroy, arginfo_session_class_destroy) + PHP_ABSTRACT_ME(SessionHandlerInterface, gc, arginfo_session_class_gc) + { NULL, NULL, NULL } +}; +/* }}} */ + +/* {{{ SessionHandler functions[] + */ +static const zend_function_entry php_session_class_functions[] = { + PHP_ME(SessionHandler, open, arginfo_session_class_open, ZEND_ACC_PUBLIC) + PHP_ME(SessionHandler, close, arginfo_session_class_close, ZEND_ACC_PUBLIC) + PHP_ME(SessionHandler, read, arginfo_session_class_read, ZEND_ACC_PUBLIC) + PHP_ME(SessionHandler, write, arginfo_session_class_write, ZEND_ACC_PUBLIC) + PHP_ME(SessionHandler, destroy, arginfo_session_class_destroy, ZEND_ACC_PUBLIC) + PHP_ME(SessionHandler, gc, arginfo_session_class_gc, ZEND_ACC_PUBLIC) + { NULL, NULL, NULL } +}; +/* }}} */ + +/* ******************************** + * Module Setup and Destruction * + ******************************** */ + +static int php_rinit_session(zend_bool auto_start TSRMLS_DC) /* {{{ */ +{ + 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(serializer) == NULL) { + char *value; + + value = zend_ini_string("session.serialize_handler", sizeof("session.serialize_handler"), 0); + if (value) { + PS(serializer) = _php_find_ps_serializer(value TSRMLS_CC); + } + } + + if (PS(mod) == NULL || PS(serializer) == NULL) { + /* current status is unusable */ + PS(session_status) = php_session_disabled; + return SUCCESS; + } + + if (auto_start) { + php_session_start(TSRMLS_C); + } + + return SUCCESS; +} /* }}} */ + +static PHP_RINIT_FUNCTION(session) /* {{{ */ +{ + return php_rinit_session(PS(auto_start) TSRMLS_CC); +} +/* }}} */ + +static PHP_RSHUTDOWN_FUNCTION(session) /* {{{ */ +{ + int i; + + zend_try { + php_session_flush(TSRMLS_C); + } zend_end_try(); + php_rshutdown_session_globals(TSRMLS_C); + + /* this should NOT be done in php_rshutdown_session_globals() */ + for (i = 0; i < 6; i++) { + if (PS(mod_user_names).names[i] != NULL) { + zval_ptr_dtor(&PS(mod_user_names).names[i]); + PS(mod_user_names).names[i] = NULL; + } + } + + return SUCCESS; +} +/* }}} */ + +static PHP_GINIT_FUNCTION(ps) /* {{{ */ +{ + int i; + + ps_globals->save_path = NULL; + ps_globals->session_name = NULL; + ps_globals->id = NULL; + ps_globals->mod = NULL; + ps_globals->serializer = NULL; + ps_globals->mod_data = NULL; + ps_globals->session_status = php_session_none; + ps_globals->default_mod = NULL; + ps_globals->mod_user_implemented = 0; + ps_globals->mod_user_is_open = 0; + for (i = 0; i < 6; i++) { + ps_globals->mod_user_names.names[i] = NULL; + } + ps_globals->http_session_vars = NULL; +} +/* }}} */ + +static PHP_MINIT_FUNCTION(session) /* {{{ */ +{ + zend_class_entry ce; + + zend_register_auto_global("_SESSION", sizeof("_SESSION")-1, 0, 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 + php_session_rfc1867_orig_callback = php_rfc1867_callback; + php_rfc1867_callback = php_session_rfc1867_callback; + + /* Register interface */ + INIT_CLASS_ENTRY(ce, PS_IFACE_NAME, php_session_iface_functions); + php_session_iface_entry = zend_register_internal_class(&ce TSRMLS_CC); + php_session_iface_entry->ce_flags |= ZEND_ACC_INTERFACE; + + /* Register base class */ + INIT_CLASS_ENTRY(ce, PS_CLASS_NAME, php_session_class_functions); + php_session_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + zend_class_implements(php_session_class_entry TSRMLS_CC, 1, php_session_iface_entry); + + REGISTER_LONG_CONSTANT("PHP_SESSION_DISABLED", php_session_disabled, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_SESSION_NONE", php_session_none, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_SESSION_ACTIVE", php_session_active, CONST_CS | CONST_PERSISTENT); + + return SUCCESS; +} +/* }}} */ + +static PHP_MSHUTDOWN_FUNCTION(session) /* {{{ */ +{ + UNREGISTER_INI_ENTRIES(); + +#ifdef HAVE_LIBMM + PHP_MSHUTDOWN(ps_mm) (SHUTDOWN_FUNC_ARGS_PASSTHRU); +#endif + + ps_serializers[PREDEFINED_SERIALIZERS].name = NULL; + memset(&ps_modules[PREDEFINED_MODULES], 0, (MAX_MODULES-PREDEFINED_MODULES)*sizeof(ps_module *)); + + return SUCCESS; +} +/* }}} */ + +static PHP_MINFO_FUNCTION(session) /* {{{ */ +{ + ps_module **mod; + ps_serializer *ser; + smart_str save_handlers = {0}; + smart_str ser_handlers = {0}; + int i; + + /* Get save handlers */ + for (i = 0, mod = ps_modules; i < MAX_MODULES; i++, mod++) { + if (*mod && (*mod)->s_name) { + smart_str_appends(&save_handlers, (*mod)->s_name); + smart_str_appendc(&save_handlers, ' '); + } + } + + /* Get serializer handlers */ + for (i = 0, ser = ps_serializers; i < MAX_SERIALIZERS; i++, ser++) { + if (ser && ser->name) { + smart_str_appends(&ser_handlers, ser->name); + smart_str_appendc(&ser_handlers, ' '); + } + } + + php_info_print_table_start(); + php_info_print_table_row(2, "Session Support", "enabled" ); + + if (save_handlers.c) { + smart_str_0(&save_handlers); + php_info_print_table_row(2, "Registered save handlers", save_handlers.c); + smart_str_free(&save_handlers); + } else { + php_info_print_table_row(2, "Registered save handlers", "none"); + } + + if (ser_handlers.c) { + smart_str_0(&ser_handlers); + php_info_print_table_row(2, "Registered serializer handlers", ser_handlers.c); + smart_str_free(&ser_handlers); + } else { + php_info_print_table_row(2, "Registered serializer handlers", "none"); + } + + php_info_print_table_end(); + + DISPLAY_INI_ENTRIES(); +} +/* }}} */ + +static const zend_module_dep session_deps[] = { /* {{{ */ + ZEND_MOD_OPTIONAL("hash") + ZEND_MOD_REQUIRED("spl") + ZEND_MOD_END +}; +/* }}} */ + +/* ************************ + * Upload hook handling * + ************************ */ + +static zend_bool early_find_sid_in(zval *dest, int where, php_session_rfc1867_progress *progress TSRMLS_DC) /* {{{ */ +{ + zval **ppid; + + if (!PG(http_globals)[where]) { + return 0; + } + + if (zend_hash_find(Z_ARRVAL_P(PG(http_globals)[where]), PS(session_name), progress->sname_len+1, (void **)&ppid) == SUCCESS + && Z_TYPE_PP(ppid) == IS_STRING) { + zval_dtor(dest); + ZVAL_ZVAL(dest, *ppid, 1, 0); + return 1; + } + + return 0; +} /* }}} */ + +static void php_session_rfc1867_early_find_sid(php_session_rfc1867_progress *progress TSRMLS_DC) /* {{{ */ +{ + + if (PS(use_cookies)) { + sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); + if (early_find_sid_in(&progress->sid, TRACK_VARS_COOKIE, progress TSRMLS_CC)) { + progress->apply_trans_sid = 0; + return; + } + } + if (PS(use_only_cookies)) { + return; + } + sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); + early_find_sid_in(&progress->sid, TRACK_VARS_GET, progress TSRMLS_CC); +} /* }}} */ + +static zend_bool php_check_cancel_upload(php_session_rfc1867_progress *progress TSRMLS_DC) /* {{{ */ +{ + zval **progress_ary, **cancel_upload; + + if (zend_symtable_find(Z_ARRVAL_P(PS(http_session_vars)), progress->key.c, progress->key.len+1, (void**)&progress_ary) != SUCCESS) { + return 0; + } + if (Z_TYPE_PP(progress_ary) != IS_ARRAY) { + return 0; + } + if (zend_hash_find(Z_ARRVAL_PP(progress_ary), "cancel_upload", sizeof("cancel_upload"), (void**)&cancel_upload) != SUCCESS) { + return 0; + } + return Z_TYPE_PP(cancel_upload) == IS_BOOL && Z_LVAL_PP(cancel_upload); +} /* }}} */ + +static void php_session_rfc1867_update(php_session_rfc1867_progress *progress, int force_update TSRMLS_DC) /* {{{ */ +{ + if (!force_update) { + if (Z_LVAL_P(progress->post_bytes_processed) < progress->next_update) { + return; + } +#ifdef HAVE_GETTIMEOFDAY + if (PS(rfc1867_min_freq) > 0.0) { + struct timeval tv = {0}; + double dtv; + gettimeofday(&tv, NULL); + dtv = (double) tv.tv_sec + tv.tv_usec / 1000000.0; + if (dtv < progress->next_update_time) { + return; + } + progress->next_update_time = dtv + PS(rfc1867_min_freq); + } +#endif + progress->next_update = Z_LVAL_P(progress->post_bytes_processed) + progress->update_step; + } + + php_session_initialize(TSRMLS_C); + PS(session_status) = php_session_active; + IF_SESSION_VARS() { + progress->cancel_upload = php_check_cancel_upload(progress TSRMLS_CC); + ZEND_SET_SYMBOL_WITH_LENGTH(Z_ARRVAL_P(PS(http_session_vars)), progress->key.c, progress->key.len+1, progress->data, 2, 0); + } + php_session_flush(TSRMLS_C); +} /* }}} */ + +static void php_session_rfc1867_cleanup(php_session_rfc1867_progress *progress TSRMLS_DC) /* {{{ */ +{ + php_session_initialize(TSRMLS_C); + PS(session_status) = php_session_active; + IF_SESSION_VARS() { + zend_hash_del(Z_ARRVAL_P(PS(http_session_vars)), progress->key.c, progress->key.len+1); + } + php_session_flush(TSRMLS_C); +} /* }}} */ + +static int php_session_rfc1867_callback(unsigned int event, void *event_data, void **extra TSRMLS_DC) /* {{{ */ +{ + php_session_rfc1867_progress *progress; + int retval = SUCCESS; + + if (php_session_rfc1867_orig_callback) { + retval = php_session_rfc1867_orig_callback(event, event_data, extra TSRMLS_CC); + } + if (!PS(rfc1867_enabled)) { + return retval; + } + + progress = PS(rfc1867_progress); + + switch(event) { + case MULTIPART_EVENT_START: { + multipart_event_start *data = (multipart_event_start *) event_data; + progress = ecalloc(1, sizeof(php_session_rfc1867_progress)); + progress->content_length = data->content_length; + progress->sname_len = strlen(PS(session_name)); + PS(rfc1867_progress) = progress; + } + break; + case MULTIPART_EVENT_FORMDATA: { + multipart_event_formdata *data = (multipart_event_formdata *) event_data; + size_t value_len; + + if (Z_TYPE(progress->sid) && progress->key.c) { + break; + } + + /* orig callback may have modified *data->newlength */ + if (data->newlength) { + value_len = *data->newlength; + } else { + value_len = data->length; + } + + if (data->name && data->value && value_len) { + size_t name_len = strlen(data->name); + + if (name_len == progress->sname_len && memcmp(data->name, PS(session_name), name_len) == 0) { + zval_dtor(&progress->sid); + ZVAL_STRINGL(&progress->sid, (*data->value), value_len, 1); + + } else if (name_len == PS(rfc1867_name).len && memcmp(data->name, PS(rfc1867_name).c, name_len) == 0) { + smart_str_free(&progress->key); + smart_str_appendl(&progress->key, PS(rfc1867_prefix).c, PS(rfc1867_prefix).len); + smart_str_appendl(&progress->key, *data->value, value_len); + smart_str_0(&progress->key); + + progress->apply_trans_sid = PS(use_trans_sid); + php_session_rfc1867_early_find_sid(progress TSRMLS_CC); + } + } + } + break; + case MULTIPART_EVENT_FILE_START: { + multipart_event_file_start *data = (multipart_event_file_start *) event_data; + + /* Do nothing when $_POST["PHP_SESSION_UPLOAD_PROGRESS"] is not set + * or when we have no session id */ + if (!Z_TYPE(progress->sid) || !progress->key.c) { + break; + } + + /* First FILE_START event, initializing data */ + if (!progress->data) { + + if (PS(rfc1867_freq) >= 0) { + progress->update_step = PS(rfc1867_freq); + } else if (PS(rfc1867_freq) < 0) { /* % of total size */ + progress->update_step = progress->content_length * -PS(rfc1867_freq) / 100; + } + progress->next_update = 0; + progress->next_update_time = 0.0; + + ALLOC_INIT_ZVAL(progress->data); + array_init(progress->data); + + ALLOC_INIT_ZVAL(progress->post_bytes_processed); + ZVAL_LONG(progress->post_bytes_processed, data->post_bytes_processed); + + ALLOC_INIT_ZVAL(progress->files); + array_init(progress->files); + + add_assoc_long_ex(progress->data, "start_time", sizeof("start_time"), (long)sapi_get_request_time(TSRMLS_C)); + add_assoc_long_ex(progress->data, "content_length", sizeof("content_length"), progress->content_length); + add_assoc_zval_ex(progress->data, "bytes_processed", sizeof("bytes_processed"), progress->post_bytes_processed); + add_assoc_bool_ex(progress->data, "done", sizeof("done"), 0); + add_assoc_zval_ex(progress->data, "files", sizeof("files"), progress->files); + + php_rinit_session(0 TSRMLS_CC); + PS(id) = estrndup(Z_STRVAL(progress->sid), Z_STRLEN(progress->sid)); + PS(apply_trans_sid) = progress->apply_trans_sid; + PS(send_cookie) = 0; + } + + ALLOC_INIT_ZVAL(progress->current_file); + array_init(progress->current_file); + + ALLOC_INIT_ZVAL(progress->current_file_bytes_processed); + ZVAL_LONG(progress->current_file_bytes_processed, 0); + + /* Each uploaded file has its own array. Trying to make it close to $_FILES entries. */ + add_assoc_string_ex(progress->current_file, "field_name", sizeof("field_name"), data->name, 1); + add_assoc_string_ex(progress->current_file, "name", sizeof("name"), *data->filename, 1); + add_assoc_null_ex(progress->current_file, "tmp_name", sizeof("tmp_name")); + add_assoc_long_ex(progress->current_file, "error", sizeof("error"), 0); + + add_assoc_bool_ex(progress->current_file, "done", sizeof("done"), 0); + add_assoc_long_ex(progress->current_file, "start_time", sizeof("start_time"), (long)time(NULL)); + add_assoc_zval_ex(progress->current_file, "bytes_processed", sizeof("bytes_processed"), progress->current_file_bytes_processed); + + add_next_index_zval(progress->files, progress->current_file); + + Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed; + + php_session_rfc1867_update(progress, 0 TSRMLS_CC); + } + break; + case MULTIPART_EVENT_FILE_DATA: { + multipart_event_file_data *data = (multipart_event_file_data *) event_data; + + if (!Z_TYPE(progress->sid) || !progress->key.c) { + break; + } + + Z_LVAL_P(progress->current_file_bytes_processed) = data->offset + data->length; + Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed; + + php_session_rfc1867_update(progress, 0 TSRMLS_CC); + } + break; + case MULTIPART_EVENT_FILE_END: { + multipart_event_file_end *data = (multipart_event_file_end *) event_data; + + if (!Z_TYPE(progress->sid) || !progress->key.c) { + break; + } + + if (data->temp_filename) { + add_assoc_string_ex(progress->current_file, "tmp_name", sizeof("tmp_name"), data->temp_filename, 1); + } + add_assoc_long_ex(progress->current_file, "error", sizeof("error"), data->cancel_upload); + add_assoc_bool_ex(progress->current_file, "done", sizeof("done"), 1); + + Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed; + + php_session_rfc1867_update(progress, 0 TSRMLS_CC); + } + break; + case MULTIPART_EVENT_END: { + multipart_event_end *data = (multipart_event_end *) event_data; + + if (Z_TYPE(progress->sid) && progress->key.c) { + if (PS(rfc1867_cleanup)) { + php_session_rfc1867_cleanup(progress TSRMLS_CC); + } else { + add_assoc_bool_ex(progress->data, "done", sizeof("done"), 1); + Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed; + php_session_rfc1867_update(progress, 1 TSRMLS_CC); + } + php_rshutdown_session_globals(TSRMLS_C); + } + + if (progress->data) { + zval_ptr_dtor(&progress->data); + } + zval_dtor(&progress->sid); + smart_str_free(&progress->key); + efree(progress); + progress = NULL; + PS(rfc1867_progress) = NULL; + } + break; + } + + if (progress && progress->cancel_upload) { + return FAILURE; + } + return retval; + +} /* }}} */ + +zend_module_entry session_module_entry = { + STANDARD_MODULE_HEADER_EX, + NULL, + session_deps, + "session", + session_functions, + PHP_MINIT(session), PHP_MSHUTDOWN(session), + PHP_RINIT(session), PHP_RSHUTDOWN(session), + PHP_MINFO(session), + NO_VERSION_YET, + PHP_MODULE_GLOBALS(ps), + PHP_GINIT(ps), + NULL, + NULL, + STANDARD_MODULE_PROPERTIES_EX +}; + +#ifdef COMPILE_DL_SESSION +ZEND_GET_MODULE(session) +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet 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 new file mode 100644 index 0000000..eb04dc1 --- /dev/null +++ b/ext/session/tests/001.phpt @@ -0,0 +1,36 @@ +--TEST-- +session object serialization +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +class foo { + public $bar = "ok"; + + function method() { $this->yes = "done"; } +} + +$baz = new foo; +$baz->method(); + +$arr[3] = new foo; +$arr[3]->method(); + +session_start(); + +$_SESSION["baz"] = $baz; +$_SESSION["arr"] = $arr; + +print session_encode()."\n"; + +session_destroy(); +--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 new file mode 100644 index 0000000..6fff01e --- /dev/null +++ b/ext/session/tests/002.phpt @@ -0,0 +1,11 @@ +--TEST-- +session_unset() without a initialized session +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php +error_reporting(E_ALL); +session_unset(); +print "ok\n"; +--EXPECT-- +ok diff --git a/ext/session/tests/003.phpt b/ext/session/tests/003.phpt new file mode 100644 index 0000000..03c3b95 --- /dev/null +++ b/ext/session/tests/003.phpt @@ -0,0 +1,45 @@ +--TEST-- +session object deserialization +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +class foo { + public $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;}}'); + +$_SESSION["baz"]->method(); +$_SESSION["arr"][3]->method(); + +var_dump($_SESSION["baz"]); +var_dump($_SESSION["arr"]); +session_destroy(); +--EXPECT-- +object(foo)#1 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#2 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) + } +} + diff --git a/ext/session/tests/004.phpt b/ext/session/tests/004.phpt new file mode 100644 index 0000000..aeb2c8b --- /dev/null +++ b/ext/session/tests/004.phpt @@ -0,0 +1,110 @@ +--TEST-- +session_set_save_handler test +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.name=PHPSESSID +session.serialize_handler=php +--FILE-- +<?php +error_reporting(E_ALL); + +class handler { + public $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 { + public $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(); +$_SESSION["baz"]->method(); +$_SESSION["arr"][3]->method(); + +var_dump($_SESSION["baz"]); +var_dump($_SESSION["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($_SESSION["baz"]); +var_dump($_SESSION["arr"]); + +session_destroy(); +?> +--EXPECT-- +OPEN: PHPSESSID +READ: abtest +object(foo)#2 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#3 (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)#3 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#2 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) + } +} +DESTROY: abtest diff --git a/ext/session/tests/005.phpt b/ext/session/tests/005.phpt new file mode 100644 index 0000000..a970e6b --- /dev/null +++ b/ext/session/tests/005.phpt @@ -0,0 +1,151 @@ +--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= +session.name=PHPSESSID +session.serialize_handler=php +--FILE-- +<?php + +error_reporting(E_ALL); + +class handler { + public $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 { + public $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(); +session_decode($hnd->data); + +$_SESSION["baz"]->method(); +$_SESSION["arr"][3]->method(); + +var_dump($_SESSION["baz"]); +var_dump($_SESSION["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(); +$_SESSION["baz"]->method(); +$_SESSION["arr"][3]->method(); + + +$_SESSION["c"] = 123; +var_dump($_SESSION["baz"]); +var_dump($_SESSION["arr"]); +var_dump($_SESSION["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($_SESSION["baz"]); +var_dump($_SESSION["arr"]); +var_dump($_SESSION["c"]); + +session_destroy(); +?> +--EXPECTF-- +OPEN: PHPSESSID +READ: abtest +object(foo)#4 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#2 (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 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(3) +} +array(1) { + [3]=> + object(foo)#4 (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)#4 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(3) +} +array(1) { + [3]=> + object(foo)#2 (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 new file mode 100644 index 0000000..03fca10 --- /dev/null +++ b/ext/session/tests/006.phpt @@ -0,0 +1,69 @@ +--TEST-- +correct instantiation of references between variables in sessions +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +session_id("abtest"); +session_start(); + +class a { + public $test = "hallo"; +} + +class b { + public $a; + function b(&$a) { + $this->a = &$a; + } +} + +$a = new a(); +$b = new b($a); + +echo "original values:\n"; +var_dump($a,$b); + +$_SESSION["a"] = $a; +$_SESSION["b"] = $b; +session_write_close(); + +unset($_SESSION["a"], $_SESSION["b"]); + +session_start(); + +echo "values after session:\n"; +var_dump($a,$b); +?> +--EXPECTF-- +original values: +object(a)#%d (1) { + ["test"]=> + string(5) "hallo" +} +object(b)#%d (1) { + ["a"]=> + &object(a)#%d (1) { + ["test"]=> + string(5) "hallo" + } +} +values after session: +object(a)#%d (1) { + ["test"]=> + string(5) "hallo" +} +object(b)#%d (1) { + ["a"]=> + &object(a)#%d (1) { + ["test"]=> + string(5) "hallo" + } +} diff --git a/ext/session/tests/009.phpt b/ext/session/tests/009.phpt new file mode 100644 index 0000000..d73bc23 --- /dev/null +++ b/ext/session/tests/009.phpt @@ -0,0 +1,56 @@ +--TEST-- +unset($_SESSION["name"]); test +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +session_id("abtest"); + +### Phase 1 cleanup +session_start(); +session_destroy(); + +### Phase 2 $_SESSION["c"] does not contain any value +session_id("abtest"); +session_start(); +var_dump($_SESSION); +$_SESSION["name"] = "foo"; +var_dump($_SESSION); +session_write_close(); + +### Phase 3 $_SESSION["c"] is set +session_start(); +var_dump($_SESSION); +unset($_SESSION["name"]); +var_dump($_SESSION); +session_write_close(); + +### Phase 4 final + +session_start(); +var_dump($_SESSION); +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 new file mode 100644 index 0000000..79638d2 --- /dev/null +++ b/ext/session/tests/010.phpt @@ -0,0 +1,16 @@ +--TEST-- +$session_array = explode(";", session_encode()); should not segfault +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +--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 new file mode 100644 index 0000000..ff1adba --- /dev/null +++ b/ext/session/tests/011.phpt @@ -0,0 +1,17 @@ +--TEST-- +session_decode(); should not segfault +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +--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 new file mode 100644 index 0000000..8708011 --- /dev/null +++ b/ext/session/tests/012.phpt @@ -0,0 +1,32 @@ +--TEST-- +registering $_SESSION should not segfault +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +### Absurd example, value of $_SESSION does not matter + +session_id("abtest"); +session_start(); +$_SESSION["_SESSION"] = Array(); +$_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 new file mode 100644 index 0000000..8d0f284 --- /dev/null +++ b/ext/session/tests/013.phpt @@ -0,0 +1,24 @@ +--TEST-- +redefining SID should not cause warnings +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--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 new file mode 100644 index 0000000..73bc28e --- /dev/null +++ b/ext/session/tests/014.phpt @@ -0,0 +1,39 @@ +--TEST-- +a script should not be able to modify session.use_trans_sid +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_trans_sid=0 +session.use_cookies=0 +session.cache_limiter= +session.name=PHPSESSID +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +session_id("abtest"); +session_start(); + +?> +<a href="/link"> +<?php +ini_set("session.use_trans_sid","1"); +?> +<a href="/link"> +<?php +ini_set("session.use_trans_sid","0"); +?> +<a href="/link"> +<?php +session_destroy(); +?> +--EXPECTF-- +<a href="/link"> + +Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in %s on line %d +<a href="/link"> + +Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in %s on line %d +<a href="/link"> diff --git a/ext/session/tests/015.phpt b/ext/session/tests/015.phpt new file mode 100644 index 0000000..7d7b737 --- /dev/null +++ b/ext/session/tests/015.phpt @@ -0,0 +1,26 @@ +--TEST-- +use_trans_sid should not affect SID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_trans_sid=1 +session.use_cookies=0 +session.use_only_cookies=0 +session.cache_limiter= +arg_separator.output=& +session.name=PHPSESSID +session.serialize_handler=php +session.save_handler=files +--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 new file mode 100644 index 0000000..8370329 --- /dev/null +++ b/ext/session/tests/016.phpt @@ -0,0 +1,25 @@ +--TEST-- +invalid session.save_path should not cause a segfault +--SKIPIF-- +<?php +if (!extension_loaded("session")) { + die("skip Session module not loaded"); +} +?> +--INI-- +session.save_path="123;:/really\\completely:::/invalid;;,23123;213" +session.use_cookies=0 +session.cache_limiter= +session.save_handler=files +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 new file mode 100644 index 0000000..dbe53f5 --- /dev/null +++ b/ext/session/tests/017.phpt @@ -0,0 +1,26 @@ +--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 +session.save_handler=files +--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 new file mode 100644 index 0000000..def1f41 --- /dev/null +++ b/ext/session/tests/018.phpt @@ -0,0 +1,26 @@ +--TEST-- +rewriter correctly handles attribute names which contain dashes +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.use_only_cookies=0 +session.cache_limiter= +session.use_trans_sid=1 +session.name=PHPSESSID +session.serialize_handler=php +session.save_handler=files +--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 new file mode 100644 index 0000000..3ee8ccd --- /dev/null +++ b/ext/session/tests/019.phpt @@ -0,0 +1,73 @@ +--TEST-- +serializing references test case using globals +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php + +error_reporting(E_ALL); + +class TFoo { + public $c; + function TFoo($c) { + $this->c = $c; + } + function inc() { + $this->c++; + } +} + +session_id("abtest"); +session_start(); + +$_SESSION["o1"] = new TFoo(42); +$_SESSION["o2"] =& $_SESSION["o1"]; + +session_write_close(); + +unset($_SESSION["o1"]); +unset($_SESSION["o2"]); + +session_start(); + +var_dump($_SESSION); + +$_SESSION["o1"]->inc(); +$_SESSION["o2"]->inc(); + +var_dump($_SESSION); + +session_destroy(); +?> +--EXPECTF-- + +array(2) { + ["o1"]=> + &object(TFoo)#%d (1) { + ["c"]=> + int(42) + } + ["o2"]=> + &object(TFoo)#%d (1) { + ["c"]=> + int(42) + } +} +array(2) { + ["o1"]=> + &object(TFoo)#%d (1) { + ["c"]=> + int(44) + } + ["o2"]=> + &object(TFoo)#%d (1) { + ["c"]=> + int(44) + } +} + diff --git a/ext/session/tests/020.phpt b/ext/session/tests/020.phpt new file mode 100644 index 0000000..f43bac5 --- /dev/null +++ b/ext/session/tests/020.phpt @@ -0,0 +1,27 @@ +--TEST-- +rewriter uses arg_seperator.output for modifying URLs +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.use_only_cookies=0 +session.cache_limiter= +session.use_trans_sid=1 +arg_separator.output="&" +session.name=PHPSESSID +session.serialize_handler=php +session.save_handler=files +--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&PHPSESSID=abtest"> diff --git a/ext/session/tests/021.phpt b/ext/session/tests/021.phpt new file mode 100644 index 0000000..1ad3c5d --- /dev/null +++ b/ext/session/tests/021.phpt @@ -0,0 +1,63 @@ +--TEST-- +rewriter handles form and fieldset tags correctly +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.use_only_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 +session.save_handler=files +--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/022.phpt b/ext/session/tests/022.phpt new file mode 100644 index 0000000..5923bbe --- /dev/null +++ b/ext/session/tests/022.phpt @@ -0,0 +1,32 @@ +--TEST-- +session object serialization +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +class foo { + public $bar = "ok"; + + function method() { $this->yes = "done"; } +} + +$baz = new foo; +$baz->method(); + +$arr[3] = new foo; +$arr[3]->method(); +session_start(); +$_SESSION["baz"] = $baz; +$_SESSION["arr"] = $arr; +var_dump(session_encode()); +session_destroy(); +?> +--EXPECT-- +string(126) "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/023.phpt b/ext/session/tests/023.phpt new file mode 100644 index 0000000..42b1e5b --- /dev/null +++ b/ext/session/tests/023.phpt @@ -0,0 +1,46 @@ +--TEST-- +session object deserialization +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +class foo { + public $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 = $_SESSION['baz']; +$arr = $_SESSION['arr']; + +$baz->method(); +$arr[3]->method(); + +var_dump($baz); +var_dump($arr); +session_destroy(); +--EXPECT-- +object(foo)#1 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#2 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) + } +} diff --git a/ext/session/tests/024.phpt b/ext/session/tests/024.phpt new file mode 100644 index 0000000..2ad2606 --- /dev/null +++ b/ext/session/tests/024.phpt @@ -0,0 +1,114 @@ +--TEST-- +session_set_save_handler test +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.name=PHPSESSID +session.serialize_handler=php +--FILE-- +<?php +error_reporting(E_ALL); + +class handler { + public $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 { + public $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 = $_SESSION['baz']; +$arr = $_SESSION['arr']; +$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(); +?> +--EXPECTF-- +OPEN: PHPSESSID +READ: abtest +object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#%d (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)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) + } +} +DESTROY: abtest diff --git a/ext/session/tests/025.phpt b/ext/session/tests/025.phpt new file mode 100644 index 0000000..4fd095f --- /dev/null +++ b/ext/session/tests/025.phpt @@ -0,0 +1,159 @@ +--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= +session.name=PHPSESSID +session.serialize_handler=php +--FILE-- +<?php + +error_reporting(E_ALL); + +class handler { + public $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; } + + function __construct() + { + if (ini_get("unicode.semantics")) { + $this->data = str_replace('s:', 'U:', $this->data); + } + } +} + +$hnd = new handler; + +class foo { + public $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 = $_SESSION['baz']; +$arr = $_SESSION['arr']; +$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 = $_SESSION['baz']; +$arr = $_SESSION['arr']; + + +$baz->method(); +$arr[3]->method(); + + +$c = 123; +$_SESSION['c'] = $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(); +?> +--EXPECTF-- +OPEN: PHPSESSID +READ: abtest +object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#%d (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)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(3) +} +array(1) { + [3]=> + object(foo)#%d (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)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(3) +} +array(1) { + [3]=> + object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(3) + } +} +int(123) +DESTROY: abtest +CLOSE diff --git a/ext/session/tests/026.phpt b/ext/session/tests/026.phpt new file mode 100644 index 0000000..06c135d --- /dev/null +++ b/ext/session/tests/026.phpt @@ -0,0 +1,71 @@ +--TEST-- +correct instantiation of references between variables in sessions +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +session_id("abtest"); +session_start(); + +class a { + public $test = "hallo"; +} + +class b { + public $a; + function b(&$a) { + $this->a = &$a; + } +} + +$a = new a(); +$b = new b($a); + +echo "original values:\n"; +var_dump($a,$b); + +$_SESSION['a'] = $a; +$_SESSION['b'] = $b; + +session_write_close(); +unset($_SESSION['a']); +unset($_SESSION['b']); + +session_start(); +$a = $_SESSION['a']; +$b = $_SESSION['b']; +echo "values after session:\n"; +var_dump($a,$b); +?> +--EXPECTF-- +original values: +object(a)#%d (1) { + ["test"]=> + string(5) "hallo" +} +object(b)#%d (1) { + ["a"]=> + &object(a)#%d (1) { + ["test"]=> + string(5) "hallo" + } +} +values after session: +object(a)#%d (1) { + ["test"]=> + string(5) "hallo" +} +object(b)#%d (1) { + ["a"]=> + &object(a)#%d (1) { + ["test"]=> + string(5) "hallo" + } +} diff --git a/ext/session/tests/027.phpt b/ext/session/tests/027.phpt new file mode 100644 index 0000000..600a992 --- /dev/null +++ b/ext/session/tests/027.phpt @@ -0,0 +1,55 @@ +--TEST-- +unset($_SESSION["name"]); should work +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +session_id("abtest"); + +### Phase 1 cleanup +session_start(); +session_destroy(); + +### Phase 2 $_SESSION["c"] does not contain any value +session_id("abtest"); +session_start(); +var_dump($_SESSION); +$_SESSION["name"] = "foo"; +var_dump($_SESSION); +session_write_close(); + +### Phase 3 $_SESSION["c"] is set +session_start(); +var_dump($_SESSION); +unset($_SESSION["name"]); +var_dump($_SESSION); +session_write_close(); + +### Phase 4 final + +session_start(); +var_dump($_SESSION); +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/028.phpt b/ext/session/tests/028.phpt new file mode 100644 index 0000000..79638d2 --- /dev/null +++ b/ext/session/tests/028.phpt @@ -0,0 +1,16 @@ +--TEST-- +$session_array = explode(";", session_encode()); should not segfault +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +--FILE-- +<?php +error_reporting(E_ALL); + +$session_array = explode(";", @session_encode()); +print "I live\n"; +?> +--EXPECT-- +I live diff --git a/ext/session/tests/029.phpt b/ext/session/tests/029.phpt new file mode 100644 index 0000000..ff1adba --- /dev/null +++ b/ext/session/tests/029.phpt @@ -0,0 +1,17 @@ +--TEST-- +session_decode(); should not segfault +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +--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/030.phpt b/ext/session/tests/030.phpt new file mode 100644 index 0000000..8d0f284 --- /dev/null +++ b/ext/session/tests/030.phpt @@ -0,0 +1,24 @@ +--TEST-- +redefining SID should not cause warnings +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--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/031.phpt b/ext/session/tests/031.phpt new file mode 100644 index 0000000..e8deb3d --- /dev/null +++ b/ext/session/tests/031.phpt @@ -0,0 +1,22 @@ +--TEST-- +setting hash_function to sha512 and hash_bits_per_character > 4 should not crash +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +session.hash_function=sha512 +session.hash_bits_per_character=5 +--FILE-- +<?php +error_reporting(E_ALL); + +session_start(); +session_regenerate_id(TRUE); + +print "I live\n"; +?> +--EXPECT-- +I live diff --git a/ext/session/tests/bug24592.phpt b/ext/session/tests/bug24592.phpt new file mode 100644 index 0000000..9f6c395 --- /dev/null +++ b/ext/session/tests/bug24592.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #24592 (crash when multiple NULL values are being stored) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +html_errors=0 +session.save_handler=files +--FILE-- +<?php +@session_start(); + +$foo = $_SESSION['foo']; +$bar = $_SESSION['bar']; + +var_dump($foo, $bar, $_SESSION); + +$_SESSION['foo'] = $foo; +$_SESSION['bar'] = $bar; + +var_dump($_SESSION); +?> +--EXPECTF-- +Notice: Undefined index: foo in %s on line %d + +Notice: Undefined index: bar in %s on line %d +NULL +NULL +array(0) { +} +array(2) { + ["foo"]=> + NULL + ["bar"]=> + NULL +} diff --git a/ext/session/tests/bug26862.phpt b/ext/session/tests/bug26862.phpt new file mode 100644 index 0000000..7990f74 --- /dev/null +++ b/ext/session/tests/bug26862.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #26862 (ob_flush() before output_reset_rewrite_vars() results in data loss) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +html_errors=0 +session.use_trans_sid=0 +session.save_handler=files +--FILE-- +<?php +session_start(); +output_add_rewrite_var('var', 'value'); + +echo '<a href="file.php">link</a>'; + +ob_flush(); + +output_reset_rewrite_vars(); +echo '<a href="file.php">link</a>'; +?> +--EXPECT-- +<a href="file.php?var=value">link</a><a href="file.php">link</a> diff --git a/ext/session/tests/bug31454.phpt b/ext/session/tests/bug31454.phpt new file mode 100644 index 0000000..dd60996 --- /dev/null +++ b/ext/session/tests/bug31454.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #31454 (session_set_save_handler crashes PHP when supplied non-existent object ref) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +session_set_save_handler( + array(&$arf, 'open'), + array(&$arf, 'close'), + array(&$arf, 'read'), + array(&$arf, 'write'), + array(&$arf, 'destroy'), + array(&$arf, 'gc')); + +echo "Done\n"; +?> +--EXPECTF-- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %sbug31454.php on line %d +Done diff --git a/ext/session/tests/bug32330.phpt b/ext/session/tests/bug32330.phpt new file mode 100644 index 0000000..98d442a --- /dev/null +++ b/ext/session/tests/bug32330.phpt @@ -0,0 +1,85 @@ +--TEST-- +Bug #32330 (session_destroy, "Failed to initialize storage module", custom session handler) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_trans_sid=0 +session.use_cookies=1 +session.name=sid +session.save_path=/tmp +session.gc_probability=1 +session.gc_divisor=1 +--FILE-- +<?php +error_reporting(E_ALL); + +function sOpen($path, $name) +{ + echo "open: path = {$path}, name = {$name}\n"; + return TRUE; +} + +function sClose() +{ + echo "close\n"; + return TRUE; +} + +function sRead($id) +{ + echo "read: id = {$id}\n"; + return ''; +} + +function sWrite($id, $data) +{ + echo "write: id = {$id}, data = {$data}\n"; + return TRUE; +} + +function sDestroy($id) +{ + echo "destroy: id = {$id}\n"; + return TRUE; +} + +function sGC($maxlifetime) +{ + echo "gc: maxlifetime = {$maxlifetime}\n"; + return TRUE; +} + +session_set_save_handler( 'sOpen', 'sClose', 'sRead', 'sWrite', 'sDestroy', 'sGC' ); + +// without output buffering, the debug messages will cause all manner of warnings +ob_start(); + +session_start(); +$_SESSION['A'] = 'B'; +session_write_close(); + +session_start(); +$_SESSION['C'] = 'D'; +session_destroy(); + +session_start(); +$_SESSION['E'] = 'F'; +// Don't try to destroy this time! + +?> +--EXPECTF-- +open: path = /tmp, name = sid +read: id = %s +gc: maxlifetime = %d +write: id = %s, data = A|s:1:"B"; +close +open: path = /tmp, name = sid +read: id = %s +gc: maxlifetime = %d +destroy: id = %s +close +open: path = /tmp, name = sid +read: id = %s +gc: maxlifetime = %d +write: id = %s, data = E|s:1:"F"; +close diff --git a/ext/session/tests/bug36459.phpt b/ext/session/tests/bug36459.phpt new file mode 100644 index 0000000..66a4ac1 --- /dev/null +++ b/ext/session/tests/bug36459.phpt @@ -0,0 +1,42 @@ +--TEST--
+Bug #31454 (Incorrect adding PHPSESSID to links, which contains \r\n)
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--INI--
+session.use_trans_sid=1
+session.use_cookies=0
+session.use_only_cookies=0
+session.name=sid
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+session_start();
+
+# Do not remove \r from this tests, they are essential!
+?>
+<html>
+ <head>
+ <title>Bug #36459 Incorrect adding PHPSESSID to links, which contains \r\n</title>
+ </head>
+ <body>
+ <p>See source html code</p>
+ <a href="/b2w/www/ru/adm/pages/?action=prev&rec_id=8&pid=2"
+ style="font: normal 11pt Times New Roman">incorrect link</a><br />
+ <br />
+ <a href="/b2w/www/ru/adm/pages/?action=prev&rec_id=8&pid=2" style="font: normal 11pt Times New Roman">correct link</a>
+ </body>
+</html>
+--EXPECTF--
+<html>
+ <head>
+ <title>Bug #36459 Incorrect adding PHPSESSID to links, which contains \r\n</title>
+ </head>
+ <body>
+ <p>See source html code</p>
+ <a href="/b2w/www/ru/adm/pages/?action=prev&rec_id=8&pid=2&sid=%s"
+ style="font: normal 11pt Times New Roman">incorrect link</a><br />
+ <br />
+ <a href="/b2w/www/ru/adm/pages/?action=prev&rec_id=8&pid=2&sid=%s" style="font: normal 11pt Times New Roman">correct link</a>
+ </body>
+</html>
diff --git a/ext/session/tests/bug38377.phpt b/ext/session/tests/bug38377.phpt new file mode 100644 index 0000000..bd33bdd --- /dev/null +++ b/ext/session/tests/bug38377.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #38377 (session_destroy() gives warning after session_regenerate_id()) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php +session_start(); +session_regenerate_id(); +session_destroy(); +echo "Done\n"; +?> +--EXPECT-- +Done diff --git a/ext/session/tests/bug41600.phpt b/ext/session/tests/bug41600.phpt new file mode 100644 index 0000000..690347a --- /dev/null +++ b/ext/session/tests/bug41600.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #41600 (url rewriter tags doesn't work with namespaced tags) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.use_only_cookies=0 +session.cache_limiter= +session.use_trans_sid=1 +arg_separator.output="&" +session.name=PHPSESSID +session.serialize_handler=php +session.save_handler=files +--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&PHPSESSID=abtest"> diff --git a/ext/session/tests/bug42596.phpt b/ext/session/tests/bug42596.phpt new file mode 100644 index 0000000..3d11607 --- /dev/null +++ b/ext/session/tests/bug42596.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #42596 (session.save_path MODE option will not set "write" bit for group or world) +--SKIPIF-- +<?php + if(substr(PHP_OS, 0, 3) == "WIN") die("skip not for Windows"); + include('skipif.inc'); +?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.use_trans_sid=1 +arg_separator.output="&" +session.name=PHPSESSID +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +$sessdir = dirname(__FILE__).'/sessions/'; +@rmdir($sessdir); +mkdir($sessdir); +$save_path = '0;0777;'.$sessdir; +umask(0); +session_save_path($save_path); +session_start(); +echo "hello world\n"; +session_write_close(); + +foreach (glob($sessdir. "*") as $sessfile) { + var_dump(decoct(fileperms($sessfile))); + unlink($sessfile); +} +rmdir($sessdir); +--EXPECT-- +hello world +string(6) "100777" + diff --git a/ext/session/tests/bug51338.phpt b/ext/session/tests/bug51338.phpt new file mode 100644 index 0000000..d806c0b --- /dev/null +++ b/ext/session/tests/bug51338.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #51338 (URL-Rewriter should not get enabled if use_only_cookies is set to 1) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_only_cookies=1 +session.use_trans_sid=1 +--FILE-- +<?php +session_start(); +print_r(ob_list_handlers()); +--EXPECT-- +Array +( +) diff --git a/ext/session/tests/bug53141.phpt b/ext/session/tests/bug53141.phpt new file mode 100644 index 0000000..765d272 --- /dev/null +++ b/ext/session/tests/bug53141.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #53141 (autoload misbehaves if called from closing session) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php +spl_autoload_register(function ($class) { + var_dump("Loading $class"); + eval('class Bar {}'); +}); + +class Foo +{ + function __sleep() + { + new Bar; + return array(); + } +} + +session_start(); +$_SESSION['foo'] = new Foo; + +?> +--EXPECT-- +string(11) "Loading Bar"
\ No newline at end of file diff --git a/ext/session/tests/bug55688.phpt b/ext/session/tests/bug55688.phpt new file mode 100644 index 0000000..8db4838 --- /dev/null +++ b/ext/session/tests/bug55688.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #55688 (Crash when calling SessionHandler::gc()) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +html_errors=0 +session.save_handler=files +--FILE-- +<?php +ini_set('session.save_handler', 'files'); +$x = new SessionHandler; +$x->gc(1); +?> +--EXPECTF-- +Warning: SessionHandler::gc(): Parent session handler is not open in %s on line %d diff --git a/ext/session/tests/bug60634.phpt b/ext/session/tests/bug60634.phpt new file mode 100644 index 0000000..2ec0c26 --- /dev/null +++ b/ext/session/tests/bug60634.phpt @@ -0,0 +1,46 @@ +--TEST-- +Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) +--XFAIL-- +Long term low priority bug, working on it +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +function open($save_path, $session_name) { + return true; +} + +function close() { + die("close: goodbye cruel world\n"); +} + +function read($id) { + return ''; +} + +function write($id, $session_data) { + die("write: goodbye cruel world\n"); +} + +function destroy($id) { + return true; +} + +function gc($maxlifetime) { + return true; +} + +session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); +session_start(); +session_write_close(); +echo "um, hi\n"; + +?> +--EXPECTF-- +write: goodbye cruel world diff --git a/ext/session/tests/bug60634_error_1.phpt b/ext/session/tests/bug60634_error_1.phpt new file mode 100644 index 0000000..3b6e394 --- /dev/null +++ b/ext/session/tests/bug60634_error_1.phpt @@ -0,0 +1,49 @@ +--TEST-- +Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) - fatal error in write during exec +--XFAIL-- +Long term low priority bug, working on it +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +function open($save_path, $session_name) { + return true; +} + +function close() { + echo "close: goodbye cruel world\n"; +} + +function read($id) { + return ''; +} + +function write($id, $session_data) { + echo "write: goodbye cruel world\n"; + undefined_function(); +} + +function destroy($id) { + return true; +} + +function gc($maxlifetime) { + return true; +} + +session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); +session_start(); +session_write_close(); +echo "um, hi\n"; + +?> +--EXPECTF-- +write: goodbye cruel world + +Fatal error: Call to undefined function undefined_function() in %s on line %d diff --git a/ext/session/tests/bug60634_error_2.phpt b/ext/session/tests/bug60634_error_2.phpt new file mode 100644 index 0000000..265fb30 --- /dev/null +++ b/ext/session/tests/bug60634_error_2.phpt @@ -0,0 +1,49 @@ +--TEST-- +Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) - exception in write during exec +--XFAIL-- +Long term low priority bug, working on it +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +function open($save_path, $session_name) { + return true; +} + +function close() { + echo "close: goodbye cruel world\n"; +} + +function read($id) { + return ''; +} + +function write($id, $session_data) { + echo "write: goodbye cruel world\n"; + throw new Exception; +} + +function destroy($id) { + return true; +} + +function gc($maxlifetime) { + return true; +} + +session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); +session_start(); +session_write_close(); +echo "um, hi\n"; + +?> +--EXPECTF-- +write: goodbye cruel world + +Fatal error: Uncaught exception 'Exception' in %s diff --git a/ext/session/tests/bug60634_error_3.phpt b/ext/session/tests/bug60634_error_3.phpt new file mode 100644 index 0000000..b2004d6 --- /dev/null +++ b/ext/session/tests/bug60634_error_3.phpt @@ -0,0 +1,48 @@ +--TEST-- +Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) - fatal error in write after exec +--XFAIL-- +Long term low priority bug, working on it +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +function open($save_path, $session_name) { + return true; +} + +function close() { + echo "close: goodbye cruel world\n"; + exit; +} + +function read($id) { + return ''; +} + +function write($id, $session_data) { + echo "write: goodbye cruel world\n"; + undefined_function(); +} + +function destroy($id) { + return true; +} + +function gc($maxlifetime) { + return true; +} + +session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); +session_start(); + +?> +--EXPECTF-- +write: goodbye cruel world + +Fatal error: Call to undefined function undefined_function() in %s on line %d diff --git a/ext/session/tests/bug60634_error_4.phpt b/ext/session/tests/bug60634_error_4.phpt new file mode 100644 index 0000000..60bc0dc --- /dev/null +++ b/ext/session/tests/bug60634_error_4.phpt @@ -0,0 +1,48 @@ +--TEST-- +Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) - exception in write after exec +--XFAIL-- +Long term low priority bug, working on it +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +function open($save_path, $session_name) { + return true; +} + +function close() { + echo "close: goodbye cruel world\n"; + exit; +} + +function read($id) { + return ''; +} + +function write($id, $session_data) { + echo "write: goodbye cruel world\n"; + throw new Exception; +} + +function destroy($id) { + return true; +} + +function gc($maxlifetime) { + return true; +} + +session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); +session_start(); + +?> +--EXPECTF-- +write: goodbye cruel world + +Fatal error: Uncaught exception 'Exception' in %s diff --git a/ext/session/tests/bug60634_error_5.phpt b/ext/session/tests/bug60634_error_5.phpt new file mode 100644 index 0000000..8081ab9 --- /dev/null +++ b/ext/session/tests/bug60634_error_5.phpt @@ -0,0 +1,47 @@ +--TEST-- +Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) - fatal error in close during exec +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +function open($save_path, $session_name) { + return true; +} + +function close() { + echo "close: goodbye cruel world\n"; + undefined_function(); +} + +function read($id) { + return ''; +} + +function write($id, $session_data) { + return true; +} + +function destroy($id) { + return true; +} + +function gc($maxlifetime) { + return true; +} + +session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); +session_start(); +session_write_close(); +echo "um, hi\n"; + +?> +--EXPECTF-- +close: goodbye cruel world + +Fatal error: Call to undefined function undefined_function() in %s on line %d diff --git a/ext/session/tests/bug60860.phpt b/ext/session/tests/bug60860.phpt new file mode 100644 index 0000000..8318586 --- /dev/null +++ b/ext/session/tests/bug60860.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #60860 (session.save_handler=user without defined function core dumps) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.save_handler=user +--FILE-- +<?php + +session_start(); +echo "ok\n"; + +?> +--EXPECTF-- +Warning: session_start(): user session functions not defined in %s on line 3 + +Fatal error: session_start(): Failed to initialize storage module: user (path:%s) in %s on line 3 diff --git a/ext/session/tests/bug61728.phpt b/ext/session/tests/bug61728.phpt new file mode 100644 index 0000000..3f8dbeb --- /dev/null +++ b/ext/session/tests/bug61728.phpt @@ -0,0 +1,39 @@ +--TEST-- +Bug #61728 (PHP crash when calling ob_start in request_shutdown phase) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php +function output_html($ext) { + return strlen($ext); +} + +function open ($save_path, $session_name) { + return true; +} + +function close() { + return true; +} + +function read ($id) { +} + +function write ($id, $sess_data) { + ob_start("output_html"); + echo "laruence"; + ob_end_flush(); + return true; +} + +function destroy ($id) { +} + +function gc ($maxlifetime) { + return true; +} + +session_set_save_handler ("open", "close", "read", "write", "destroy", "gc"); +session_start(); +--EXPECTF-- +8 diff --git a/ext/session/tests/bug63379.phpt b/ext/session/tests/bug63379.phpt new file mode 100644 index 0000000..8094182 --- /dev/null +++ b/ext/session/tests/bug63379.phpt @@ -0,0 +1,57 @@ +--TEST-- +Bug #63379: Warning when using session_regenerate_id(TRUE) with a SessionHandler +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +$handler = new SessionHandler; +session_set_save_handler($handler); + +session_start(); + +$_SESSION['foo'] = 'hello'; +var_dump($_SESSION); + +session_regenerate_id(true); + +echo "*** Regenerated ***\n"; +var_dump($_SESSION); + +$_SESSION['bar'] = 'world'; + +var_dump($_SESSION); + +session_write_close(); +session_unset(); + +session_start(); +var_dump($_SESSION); + +--EXPECTF-- +array(1) { + ["foo"]=> + string(5) "hello" +} +*** Regenerated *** +array(1) { + ["foo"]=> + string(5) "hello" +} +array(2) { + ["foo"]=> + string(5) "hello" + ["bar"]=> + string(5) "world" +} +array(2) { + ["foo"]=> + string(5) "hello" + ["bar"]=> + string(5) "world" +} diff --git a/ext/session/tests/bug63379_nodestroy.phpt b/ext/session/tests/bug63379_nodestroy.phpt new file mode 100644 index 0000000..03a9ae7 --- /dev/null +++ b/ext/session/tests/bug63379_nodestroy.phpt @@ -0,0 +1,57 @@ +--TEST-- +Bug #63379: Warning when using session_regenerate_id(TRUE) with a SessionHandler +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +$handler = new SessionHandler; +session_set_save_handler($handler); + +session_start(); + +$_SESSION['foo'] = 'hello'; +var_dump($_SESSION); + +session_regenerate_id(false); + +echo "*** Regenerated ***\n"; +var_dump($_SESSION); + +$_SESSION['bar'] = 'world'; + +var_dump($_SESSION); + +session_write_close(); +session_unset(); + +session_start(); +var_dump($_SESSION); + +--EXPECTF-- +array(1) { + ["foo"]=> + string(5) "hello" +} +*** Regenerated *** +array(1) { + ["foo"]=> + string(5) "hello" +} +array(2) { + ["foo"]=> + string(5) "hello" + ["bar"]=> + string(5) "world" +} +array(2) { + ["foo"]=> + string(5) "hello" + ["bar"]=> + string(5) "world" +} diff --git a/ext/session/tests/rfc1867.phpt b/ext/session/tests/rfc1867.phpt new file mode 100644 index 0000000..dc44e8b --- /dev/null +++ b/ext/session/tests/rfc1867.phpt @@ -0,0 +1,129 @@ +--TEST-- +session rfc1867 +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=0 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=1% +session.upload_progress.min_freq=0.000000001 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--COOKIE-- +PHPSESSID=rfc1867-tests +--GET-- +PHPSESSID=rfc1867-tests-get +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867.php +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump(basename(__FILE__) == $_POST[ini_get("session.upload_progress.name")]); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +bool(true) +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +array(5) { + [%u|b%"start_time"]=> + int(%d) + [%u|b%"content_length"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(%d) + [%u|b%"done"]=> + bool(true) + [%u|b%"files"]=> + array(2) { + [0]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file1" + [%u|b%"name"]=> + %unicode|string%(9) "file1.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + [1]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file2" + [%u|b%"name"]=> + %unicode|string%(9) "file2.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + } +} diff --git a/ext/session/tests/rfc1867_cleanup.phpt b/ext/session/tests/rfc1867_cleanup.phpt new file mode 100644 index 0000000..f70b395 --- /dev/null +++ b/ext/session/tests/rfc1867_cleanup.phpt @@ -0,0 +1,83 @@ +--TEST-- +session rfc1867 +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=0 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=1 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=1% +session.upload_progress.min_freq=0.000000001 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--COOKIE-- +PHPSESSID=rfc1867-tests +--GET-- +PHPSESSID=rfc1867-tests-get +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867_cleanup.php +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump(basename(__FILE__) == $_POST[ini_get("session.upload_progress.name")]); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +bool(true) +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +NULL diff --git a/ext/session/tests/rfc1867_disabled.phpt b/ext/session/tests/rfc1867_disabled.phpt new file mode 100644 index 0000000..4490055 --- /dev/null +++ b/ext/session/tests/rfc1867_disabled.phpt @@ -0,0 +1,76 @@ +--TEST-- +session rfc1867 disabled +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=0 +session.upload_progress.enabled=0 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=1% +--SKIPIF-- +<?php include('skipif.inc'); ?> +--COOKIE-- +PHPSESSID=rfc1867-tests +--GET-- +PHPSESSID=rfc1867-tests-get +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +NULL diff --git a/ext/session/tests/rfc1867_disabled_2.phpt b/ext/session/tests/rfc1867_disabled_2.phpt new file mode 100644 index 0000000..e878f46 --- /dev/null +++ b/ext/session/tests/rfc1867_disabled_2.phpt @@ -0,0 +1,76 @@ +--TEST-- +session rfc1867 disabled 2 +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=0 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=1% +--SKIPIF-- +<?php include('skipif.inc'); ?> +--COOKIE-- +PHPSESSID=rfc1867-tests +--GET-- +PHPSESSID=rfc1867-tests-get +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +NULL diff --git a/ext/session/tests/rfc1867_inter.phpt b/ext/session/tests/rfc1867_inter.phpt new file mode 100644 index 0000000..7686371 --- /dev/null +++ b/ext/session/tests/rfc1867_inter.phpt @@ -0,0 +1,133 @@ +--TEST-- +session rfc1867 +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=0 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=1% +session.upload_progress.min_freq=0.000000001 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--COOKIE-- +PHPSESSID=rfc1867-tests +--GET-- +PHPSESSID=rfc1867-tests-get +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867_inter.php_1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867_inter.php_2 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__) . "_1"]); +var_dump($_SESSION["upload_progress_" . basename(__FILE__) . "_2"]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +array(5) { + [%u|b%"start_time"]=> + int(%d) + [%u|b%"content_length"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(%d) + [%u|b%"done"]=> + bool(true) + [%u|b%"files"]=> + array(2) { + [0]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file1" + [%u|b%"name"]=> + %unicode|string%(9) "file1.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + [1]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file2" + [%u|b%"name"]=> + %unicode|string%(9) "file2.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + } +} +NULL diff --git a/ext/session/tests/rfc1867_invalid_settings-win.phpt b/ext/session/tests/rfc1867_invalid_settings-win.phpt new file mode 100644 index 0000000..ed854e8 --- /dev/null +++ b/ext/session/tests/rfc1867_invalid_settings-win.phpt @@ -0,0 +1,19 @@ +--TEST-- +session rfc1867 invalid settings +--INI-- +session.upload_progress.freq=-1 +error_log= +--SKIPIF-- +<?php +include('skipif.inc'); +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip windows only test"); +?> +--FILE-- +<?php +var_dump(ini_get("session.upload_progress.freq")); +?> +--EXPECTF-- +Warning: PHP Startup: session.upload_progress.freq must be greater than or equal to zero in %s +string(2) "1%" +PHP Warning: PHP Startup: session.upload_progress.freq must be greater than or equal to zero in %s diff --git a/ext/session/tests/rfc1867_invalid_settings.phpt b/ext/session/tests/rfc1867_invalid_settings.phpt new file mode 100644 index 0000000..640c4d2 --- /dev/null +++ b/ext/session/tests/rfc1867_invalid_settings.phpt @@ -0,0 +1,20 @@ +--TEST-- +session rfc1867 invalid settings +--INI-- +session.upload_progress.freq=-1 +error_log= +--SKIPIF-- +<?php +include('skipif.inc'); +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not for Windows"); +?> +--FILE-- +<?php +var_dump(ini_get("session.upload_progress.freq")); +?> +--EXPECTF-- +PHP Warning: PHP Startup: session.upload_progress.freq must be greater than or equal to zero in %s + +Warning: PHP Startup: session.upload_progress.freq must be greater than or equal to zero in %s +string(%d) "1%" diff --git a/ext/session/tests/rfc1867_invalid_settings_2-win.phpt b/ext/session/tests/rfc1867_invalid_settings_2-win.phpt new file mode 100644 index 0000000..f8e6b6d --- /dev/null +++ b/ext/session/tests/rfc1867_invalid_settings_2-win.phpt @@ -0,0 +1,19 @@ +--TEST-- +session rfc1867 invalid settings 2 +--INI-- +session.upload_progress.freq=200% +error_log= +--SKIPIF-- +<?php +include('skipif.inc'); +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip windows only test"); +?> +--FILE-- +<?php +var_dump(ini_get("session.upload_progress.freq")); +?> +--EXPECTF-- +Warning: PHP Startup: session.upload_progress.freq cannot be over 100% in %s +string(2) "1%" +PHP Warning: PHP Startup: session.upload_progress.freq cannot be over 100% in %s diff --git a/ext/session/tests/rfc1867_invalid_settings_2.phpt b/ext/session/tests/rfc1867_invalid_settings_2.phpt new file mode 100644 index 0000000..c2a0c6a --- /dev/null +++ b/ext/session/tests/rfc1867_invalid_settings_2.phpt @@ -0,0 +1,20 @@ +--TEST-- +session rfc1867 invalid settings 2 +--INI-- +session.upload_progress.freq=200% +error_log= +--SKIPIF-- +<?php +include('skipif.inc'); +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not for Windows"); +?> +--FILE-- +<?php +var_dump(ini_get("session.upload_progress.freq")); +?> +--EXPECTF-- +PHP Warning: PHP Startup: session.upload_progress.freq cannot be over 100% in %s + +Warning: PHP Startup: session.upload_progress.freq cannot be over 100% in %s +string(%d) "1%" diff --git a/ext/session/tests/rfc1867_no_name.phpt b/ext/session/tests/rfc1867_no_name.phpt new file mode 100644 index 0000000..c1dda81 --- /dev/null +++ b/ext/session/tests/rfc1867_no_name.phpt @@ -0,0 +1,76 @@ +--TEST-- +session rfc1867 no name +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=0 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=1% +--SKIPIF-- +<?php include('skipif.inc'); ?> +--COOKIE-- +PHPSESSID=rfc1867-tests +--GET-- +PHPSESSID=rfc1867-tests-get +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +NULL diff --git a/ext/session/tests/rfc1867_sid_cookie.phpt b/ext/session/tests/rfc1867_sid_cookie.phpt new file mode 100644 index 0000000..735a5ac --- /dev/null +++ b/ext/session/tests/rfc1867_sid_cookie.phpt @@ -0,0 +1,128 @@ +--TEST-- +session rfc1867 sid cookie +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=0 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=0 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--COOKIE-- +PHPSESSID=rfc1867-tests +--GET-- +PHPSESSID=rfc1867-tests-get +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867_sid_cookie.php +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump(basename(__FILE__) == $_POST[ini_get("session.upload_progress.name")]); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +bool(true) +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +array(5) { + [%u|b%"start_time"]=> + int(%d) + [%u|b%"content_length"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(%d) + [%u|b%"done"]=> + bool(true) + [%u|b%"files"]=> + array(2) { + [0]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file1" + [%u|b%"name"]=> + %unicode|string%(9) "file1.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + [1]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file2" + [%u|b%"name"]=> + %unicode|string%(9) "file2.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + } +} diff --git a/ext/session/tests/rfc1867_sid_get.phpt b/ext/session/tests/rfc1867_sid_get.phpt new file mode 100644 index 0000000..cc5a793 --- /dev/null +++ b/ext/session/tests/rfc1867_sid_get.phpt @@ -0,0 +1,126 @@ +--TEST-- +session rfc1867 sid get +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=0 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=0 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--GET-- +PHPSESSID=rfc1867-tests +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867_sid_get.php +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump(basename(__FILE__) == $_POST[ini_get("session.upload_progress.name")]); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +bool(true) +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +array(5) { + [%u|b%"start_time"]=> + int(%d) + [%u|b%"content_length"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(%d) + [%u|b%"done"]=> + bool(true) + [%u|b%"files"]=> + array(2) { + [0]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file1" + [%u|b%"name"]=> + %unicode|string%(9) "file1.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + [1]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file2" + [%u|b%"name"]=> + %unicode|string%(9) "file2.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + } +} diff --git a/ext/session/tests/rfc1867_sid_get_2.phpt b/ext/session/tests/rfc1867_sid_get_2.phpt new file mode 100644 index 0000000..1d22e59 --- /dev/null +++ b/ext/session/tests/rfc1867_sid_get_2.phpt @@ -0,0 +1,128 @@ +--TEST-- +session rfc1867 sid get 2 +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=0 +session.use_only_cookies=0 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=0 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--COOKIE-- +PHPSESSID=rfc1867-tests-cookie +--GET-- +PHPSESSID=rfc1867-tests +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867_sid_get_2.php +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump(basename(__FILE__) == $_POST[ini_get("session.upload_progress.name")]); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +bool(true) +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +array(5) { + [%u|b%"start_time"]=> + int(%d) + [%u|b%"content_length"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(%d) + [%u|b%"done"]=> + bool(true) + [%u|b%"files"]=> + array(2) { + [0]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file1" + [%u|b%"name"]=> + %unicode|string%(9) "file1.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + [1]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file2" + [%u|b%"name"]=> + %unicode|string%(9) "file2.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + } +} diff --git a/ext/session/tests/rfc1867_sid_invalid.phpt b/ext/session/tests/rfc1867_sid_invalid.phpt new file mode 100644 index 0000000..b28a2e3 --- /dev/null +++ b/ext/session/tests/rfc1867_sid_invalid.phpt @@ -0,0 +1,79 @@ +--TEST-- +session rfc1867 sid cookie +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=0 +session.auto_start=0 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=0 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--COOKIE-- +PHPSESSID=_ +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867_sid_invalid.php +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +error_reporting(0); +session_start(); +var_dump(session_id()); +var_dump(basename(__FILE__) == $_POST[ini_get("session.upload_progress.name")]); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0 +string(%d) "%s" +bool(true) +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +NULL diff --git a/ext/session/tests/rfc1867_sid_only_cookie.phpt b/ext/session/tests/rfc1867_sid_only_cookie.phpt new file mode 100644 index 0000000..9a01056 --- /dev/null +++ b/ext/session/tests/rfc1867_sid_only_cookie.phpt @@ -0,0 +1,128 @@ +--TEST-- +session rfc1867 sid only cookie +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=1 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=0 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--COOKIE-- +PHPSESSID=rfc1867-tests +--GET-- +PHPSESSID=rfc1867-tests-get +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867_sid_only_cookie.php +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump(basename(__FILE__) == $_POST[ini_get("session.upload_progress.name")]); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +bool(true) +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +array(5) { + [%u|b%"start_time"]=> + int(%d) + [%u|b%"content_length"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(%d) + [%u|b%"done"]=> + bool(true) + [%u|b%"files"]=> + array(2) { + [0]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file1" + [%u|b%"name"]=> + %unicode|string%(9) "file1.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + [1]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file2" + [%u|b%"name"]=> + %unicode|string%(9) "file2.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + } +} diff --git a/ext/session/tests/rfc1867_sid_only_cookie_2.phpt b/ext/session/tests/rfc1867_sid_only_cookie_2.phpt new file mode 100644 index 0000000..e705314 --- /dev/null +++ b/ext/session/tests/rfc1867_sid_only_cookie_2.phpt @@ -0,0 +1,80 @@ +--TEST-- +session rfc1867 sid only cookie 2 +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=1 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=0 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--GET-- +PHPSESSID=rfc1867-tests-get +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests-post +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867_sid_only_cookie_2.php +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump(basename(__FILE__) == $_POST[ini_get("session.upload_progress.name")]); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "%s" +bool(true) +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +NULL diff --git a/ext/session/tests/rfc1867_sid_post.phpt b/ext/session/tests/rfc1867_sid_post.phpt new file mode 100644 index 0000000..7c1eb2d --- /dev/null +++ b/ext/session/tests/rfc1867_sid_post.phpt @@ -0,0 +1,124 @@ +--TEST-- +session rfc1867 sid post +--INI-- +file_uploads=1 +error_reporting=E_ALL&~E_NOTICE +comment=debug builds show some additional E_NOTICE errors +upload_max_filesize=1024 +session.save_path= +session.name=PHPSESSID +session.use_cookies=1 +session.use_only_cookies=0 +session.upload_progress.enabled=1 +session.upload_progress.cleanup=0 +session.upload_progress.prefix=upload_progress_ +session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS +session.upload_progress.freq=0 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHPSESSID" + +rfc1867-tests +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" + +rfc1867_sid_post.php +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file1"; filename="file1.txt" + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="file2"; filename="file2.txt" + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +session_start(); +var_dump(session_id()); +var_dump(basename(__FILE__) == $_POST[ini_get("session.upload_progress.name")]); +var_dump($_FILES); +var_dump($_SESSION["upload_progress_" . basename(__FILE__)]); +session_destroy(); +?> +--EXPECTF-- +string(%d) "rfc1867-tests" +bool(true) +array(2) { + [%u|b%"file1"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file1.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } + [%u|b%"file2"]=> + array(5) { + [%u|b%"name"]=> + %string|unicode%(9) "file2.txt" + [%u|b%"type"]=> + %string|unicode%(0) "" + [%u|b%"tmp_name"]=> + %string|unicode%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"size"]=> + int(1) + } +} +array(5) { + [%u|b%"start_time"]=> + int(%d) + [%u|b%"content_length"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(%d) + [%u|b%"done"]=> + bool(true) + [%u|b%"files"]=> + array(2) { + [0]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file1" + [%u|b%"name"]=> + %unicode|string%(9) "file1.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + [1]=> + array(7) { + [%u|b%"field_name"]=> + %unicode|string%(5) "file2" + [%u|b%"name"]=> + %unicode|string%(9) "file2.txt" + [%u|b%"tmp_name"]=> + %unicode|string%(%d) "%s" + [%u|b%"error"]=> + int(0) + [%u|b%"done"]=> + bool(true) + [%u|b%"start_time"]=> + int(%d) + [%u|b%"bytes_processed"]=> + int(1) + } + } +} diff --git a/ext/session/tests/save_handler.inc b/ext/session/tests/save_handler.inc new file mode 100644 index 0000000..ebe9cac --- /dev/null +++ b/ext/session/tests/save_handler.inc @@ -0,0 +1,63 @@ +<?php + +DEFINE("SESSION_FILE_PREFIX" ,"session_test_"); +function open($save_path, $session_name) { + global $session_save_path, $name; + $session_save_path = $save_path; + $name = $session_name; + echo "Open [${session_save_path},${session_name}]\n"; + return true; +} + +function close() { + global $session_save_path, $name; + echo "Close [${session_save_path},${name}]\n"; + return true; +} + +function read($id) { + global $session_save_path, $name, $session_id; + $session_id = $id; + echo "Read [${session_save_path},${id}]\n"; + $session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id; + return (string) @file_get_contents($session_file); +} + +function write($id, $session_data) { + global $session_save_path, $name, $session_id; + $session_id = $id; + echo "Write [${session_save_path},${id},${session_data}]\n"; + $session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id; + if ($fp = fopen($session_file, "w")) { + $return = fwrite($fp, $session_data); + fclose($fp); + return $return; + } + return false; +} + +function destroy($id) { + global $session_save_path, $name; + echo "Destroy [${session_save_path},${id}]\n"; + $session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id; + return unlink($session_file); +} + +function gc($maxlifetime) { + global $session_save_path, $name; + $directory = opendir($session_save_path."/"); + $length = strlen(SESSION_FILE_PREFIX); + while (($file = readdir($directory)) !== FALSE) { + $qualified = ($session_save_path."/".$file); + if (is_file($qualified) === TRUE) { + if (substr($file, 0, $length) === SESSION_FILE_PREFIX) { + unlink($qualified); + } + } + } + closedir($directory); + return true; +} + +?> + diff --git a/ext/session/tests/save_handler_closures.inc b/ext/session/tests/save_handler_closures.inc new file mode 100644 index 0000000..50f33c1 --- /dev/null +++ b/ext/session/tests/save_handler_closures.inc @@ -0,0 +1,9 @@ +<?php + +require_once 'save_handler.inc'; + +foreach (array ('open', 'close', 'read', 'write', 'destroy', 'gc') as $fn) { + ${$fn.'_closure'} = function () use ($fn) { return call_user_func_array ($fn, func_get_args ()); }; +} + +?> diff --git a/ext/session/tests/session_cache_expire_basic.phpt b/ext/session/tests/session_cache_expire_basic.phpt new file mode 100644 index 0000000..7166485 --- /dev/null +++ b/ext/session/tests/session_cache_expire_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test session_cache_expire() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : int session_cache_expire([int $new_cache_expire]) + * Description : Return current cache expire + * Source code : ext/session/session.c + */ + +echo "*** Testing session_cache_expire() : basic functionality ***\n"; + +var_dump(session_cache_expire()); +var_dump(session_cache_expire(1234567890)); +var_dump(session_cache_expire(180)); +var_dump(session_start()); +var_dump(session_cache_expire()); +var_dump(session_destroy()); +var_dump(session_cache_expire()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_cache_expire() : basic functionality *** +int(180) +int(180) +int(1234567890) +bool(true) +int(180) +bool(true) +int(180) +Done + diff --git a/ext/session/tests/session_cache_expire_error.phpt b/ext/session/tests/session_cache_expire_error.phpt new file mode 100644 index 0000000..486ba78 --- /dev/null +++ b/ext/session/tests/session_cache_expire_error.phpt @@ -0,0 +1,170 @@ +--TEST-- +Test session_cache_expire() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : int session_cache_expire([int $new_cache_expire]) + * Description : Return current cache expire + * Source code : ext/session/session.c + */ + +echo "*** Testing session_cache_expire() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_cache_expire($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_cache_expire() : error functionality *** + +-- Iteration 1 -- +int(180) + +-- Iteration 2 -- +int(0) + +-- Iteration 3 -- +int(1) + +-- Iteration 4 -- +int(12345) + +-- Iteration 5 -- +int(-2345) + +-- Iteration 6 -- +int(10) + +-- Iteration 7 -- +int(-10) + +-- Iteration 8 -- +int(%s) + +-- Iteration 9 -- +int(1) + +-- Iteration 10 -- +int(0) + +-- Iteration 11 -- +int(0) + +-- Iteration 12 -- +int(0) + +-- Iteration 13 -- +int(1) + +-- Iteration 14 -- +int(0) + +-- Iteration 15 -- +int(1) + +-- Iteration 16 -- +int(0) + +-- Iteration 17 -- +int(0) + +-- Iteration 18 -- +int(0) + +-- Iteration 19 -- +int(0) + +-- Iteration 20 -- +int(0) + +-- Iteration 21 -- +int(0) + +-- Iteration 22 -- +int(0) + +-- Iteration 23 -- +int(0) + +-- Iteration 24 -- +int(0) +Done + diff --git a/ext/session/tests/session_cache_expire_variation1.phpt b/ext/session/tests/session_cache_expire_variation1.phpt new file mode 100644 index 0000000..9d0ba27 --- /dev/null +++ b/ext/session/tests/session_cache_expire_variation1.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test session_cache_expire() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.cache_expire=360 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : int session_cache_expire([int $new_cache_expire]) + * Description : Return current cache expire + * Source code : ext/session/session.c + */ + +echo "*** Testing session_cache_expire() : variation ***\n"; + +var_dump(session_cache_expire()); +var_dump(session_cache_expire(1234567890)); +var_dump(session_cache_expire(180)); +var_dump(session_start()); +var_dump(session_cache_expire()); +var_dump(session_destroy()); +var_dump(session_cache_expire()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_cache_expire() : variation *** +int(360) +int(360) +int(1234567890) +bool(true) +int(180) +bool(true) +int(180) +Done + diff --git a/ext/session/tests/session_cache_expire_variation2.phpt b/ext/session/tests/session_cache_expire_variation2.phpt new file mode 100644 index 0000000..f17f471 --- /dev/null +++ b/ext/session/tests/session_cache_expire_variation2.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test session_cache_expire() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : int session_cache_expire([int $new_cache_expire]) + * Description : Return current cache expire + * Source code : ext/session/session.c + */ + +echo "*** Testing session_cache_expire() : variation ***\n"; + +ini_set("session.cache_expire", 360); +var_dump(session_cache_expire()); +var_dump(session_cache_expire(1234567890)); +var_dump(session_cache_expire(180)); +var_dump(session_start()); +var_dump(session_cache_expire()); +var_dump(session_destroy()); +var_dump(session_cache_expire()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_cache_expire() : variation *** +int(360) +int(360) +int(1234567890) +bool(true) +int(180) +bool(true) +int(180) +Done + + diff --git a/ext/session/tests/session_cache_expire_variation3.phpt b/ext/session/tests/session_cache_expire_variation3.phpt new file mode 100644 index 0000000..c243c1f --- /dev/null +++ b/ext/session/tests/session_cache_expire_variation3.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test session_cache_expire() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : int session_cache_expire([int $new_cache_expire]) + * Description : Return current cache expire + * Source code : ext/session/session.c + */ + +echo "*** Testing session_cache_expire() : variation ***\n"; + +var_dump(ini_get("session.cache_expire")); +var_dump(session_cache_expire()); +var_dump(ini_get("session.cache_expire")); +var_dump(session_cache_expire(1234567890)); +var_dump(ini_get("session.cache_expire")); +var_dump(session_start()); +var_dump(session_cache_expire()); +var_dump(ini_get("session.cache_expire")); +var_dump(session_destroy()); +var_dump(session_cache_expire()); +var_dump(ini_get("session.cache_expire")); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_cache_expire() : variation *** +string(3) "180" +int(180) +string(3) "180" +int(180) +string(10) "1234567890" +bool(true) +int(1234567890) +string(10) "1234567890" +bool(true) +int(1234567890) +string(10) "1234567890" +Done + diff --git a/ext/session/tests/session_cache_limiter_basic.phpt b/ext/session/tests/session_cache_limiter_basic.phpt new file mode 100644 index 0000000..d053187 --- /dev/null +++ b/ext/session/tests/session_cache_limiter_basic.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test session_cache_limiter() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_cache_limiter([string $cache_limiter]) + * Description : Get and/or set the current cache limiter + * Source code : ext/session/session.c + */ + +echo "*** Testing session_cache_limiter() : basic functionality ***\n"; + +var_dump(session_start()); +var_dump(session_cache_limiter()); +var_dump(session_cache_limiter("public")); +var_dump(session_cache_limiter()); +var_dump(session_destroy()); + +var_dump(session_start()); +var_dump(session_cache_limiter()); +var_dump(session_cache_limiter("private")); +var_dump(session_cache_limiter()); +var_dump(session_destroy()); + +var_dump(session_start()); +var_dump(session_cache_limiter()); +var_dump(session_cache_limiter("nocache")); +var_dump(session_cache_limiter()); +var_dump(session_destroy()); + +var_dump(session_start()); +var_dump(session_cache_limiter()); +var_dump(session_cache_limiter("private_no_expire")); +var_dump(session_cache_limiter()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_cache_limiter() : basic functionality *** +bool(true) +string(7) "nocache" +string(7) "nocache" +string(6) "public" +bool(true) +bool(true) +string(6) "public" +string(6) "public" +string(7) "private" +bool(true) +bool(true) +string(7) "private" +string(7) "private" +string(7) "nocache" +bool(true) +bool(true) +string(7) "nocache" +string(7) "nocache" +string(17) "private_no_expire" +bool(true) +Done + diff --git a/ext/session/tests/session_cache_limiter_error.phpt b/ext/session/tests/session_cache_limiter_error.phpt new file mode 100644 index 0000000..df689d6 --- /dev/null +++ b/ext/session/tests/session_cache_limiter_error.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test session_cache_limiter() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_cache_limiter([string $cache_limiter]) + * Description : Get and/or set the current cache limiter + * Source code : ext/session/session.c + */ + +echo "*** Testing session_cache_limiter() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_cache_limiter($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_cache_limiter() : error functionality *** + +-- Iteration 1 -- +string(7) "nocache" + +-- Iteration 2 -- +string(1) "0" + +-- Iteration 3 -- +string(1) "1" + +-- Iteration 4 -- +string(5) "12345" + +-- Iteration 5 -- +string(5) "-2345" + +-- Iteration 6 -- +string(4) "10.5" + +-- Iteration 7 -- +string(5) "-10.5" + +-- Iteration 8 -- +string(12) "123456789000" + +-- Iteration 9 -- +string(13) "1.23456789E-9" + +-- Iteration 10 -- +string(3) "0.5" + +-- Iteration 11 -- +string(0) "" + +-- Iteration 12 -- +string(0) "" + +-- Iteration 13 -- +string(1) "1" + +-- Iteration 14 -- +string(0) "" + +-- Iteration 15 -- +string(1) "1" + +-- Iteration 16 -- +string(0) "" + +-- Iteration 17 -- +string(0) "" + +-- Iteration 18 -- +string(0) "" + +-- Iteration 19 -- +string(7) "Nothing" + +-- Iteration 20 -- +string(7) "Nothing" + +-- Iteration 21 -- +string(12) "Hello World!" + +-- Iteration 22 -- +string(12) "Hello World!" + +-- Iteration 23 -- +string(0) "" + +-- Iteration 24 -- + +Warning: session_cache_limiter() expects parameter 1 to be string, resource given in %s on line %d +NULL +Done + diff --git a/ext/session/tests/session_cache_limiter_variation1.phpt b/ext/session/tests/session_cache_limiter_variation1.phpt new file mode 100644 index 0000000..7c6e71e --- /dev/null +++ b/ext/session/tests/session_cache_limiter_variation1.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test session_cache_limiter() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.cache_limiter=nocache +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_cache_limiter([string $cache_limiter]) + * Description : Get and/or set the current cache limiter + * Source code : ext/session/session.c + */ + +echo "*** Testing session_cache_limiter() : variation ***\n"; + +var_dump(session_cache_limiter()); +var_dump(session_start()); +var_dump(session_cache_limiter()); +var_dump(session_cache_limiter("public")); +var_dump(session_cache_limiter()); +var_dump(session_destroy()); +var_dump(session_cache_limiter()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_cache_limiter() : variation *** +string(7) "nocache" +bool(true) +string(7) "nocache" +string(7) "nocache" +string(6) "public" +bool(true) +string(6) "public" +Done + diff --git a/ext/session/tests/session_cache_limiter_variation2.phpt b/ext/session/tests/session_cache_limiter_variation2.phpt new file mode 100644 index 0000000..b6d97a3 --- /dev/null +++ b/ext/session/tests/session_cache_limiter_variation2.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test session_cache_limiter() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_cache_limiter([string $cache_limiter]) + * Description : Get and/or set the current cache limiter + * Source code : ext/session/session.c + */ + +echo "*** Testing session_cache_limiter() : variation ***\n"; + +ini_set("session.cache_limiter", "nocache"); +var_dump(session_cache_limiter()); +var_dump(session_start()); +var_dump(session_cache_limiter()); +var_dump(session_cache_limiter("public")); +var_dump(session_cache_limiter()); +var_dump(session_destroy()); +var_dump(session_cache_limiter()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_cache_limiter() : variation *** +string(7) "nocache" +bool(true) +string(7) "nocache" +string(7) "nocache" +string(6) "public" +bool(true) +string(6) "public" +Done + diff --git a/ext/session/tests/session_cache_limiter_variation3.phpt b/ext/session/tests/session_cache_limiter_variation3.phpt new file mode 100644 index 0000000..7aab95b --- /dev/null +++ b/ext/session/tests/session_cache_limiter_variation3.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test session_cache_limiter() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_cache_limiter([string $cache_limiter]) + * Description : Get and/or set the current cache limiter + * Source code : ext/session/session.c + */ + +echo "*** Testing session_cache_limiter() : variation ***\n"; + +var_dump(ini_get("session.cache_limiter")); +var_dump(session_start()); +var_dump(ini_get("session.cache_limiter")); +var_dump(session_cache_limiter("public")); +var_dump(ini_get("session.cache_limiter")); +var_dump(session_destroy()); +var_dump(ini_get("session.cache_limiter")); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_cache_limiter() : variation *** +string(7) "nocache" +bool(true) +string(7) "nocache" +string(7) "nocache" +string(6) "public" +bool(true) +string(6) "public" +Done + diff --git a/ext/session/tests/session_commit_basic.phpt b/ext/session/tests/session_commit_basic.phpt new file mode 100644 index 0000000..c20db10 --- /dev/null +++ b/ext/session/tests/session_commit_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test session_commit() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_commit(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_commit() : basic functionality ***\n"; + +var_dump(session_start()); +var_dump($_SESSION); +var_dump(session_commit()); +var_dump($_SESSION); +var_dump(session_start()); +var_dump($_SESSION); +var_dump(session_destroy()); +var_dump($_SESSION); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_commit() : basic functionality *** +bool(true) +array(0) { +} +NULL +array(0) { +} +bool(true) +array(0) { +} +bool(true) +array(0) { +} +Done + diff --git a/ext/session/tests/session_commit_error.phpt b/ext/session/tests/session_commit_error.phpt new file mode 100644 index 0000000..b867572 --- /dev/null +++ b/ext/session/tests/session_commit_error.phpt @@ -0,0 +1,170 @@ +--TEST-- +Test session_commit() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_commit(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_commit() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_commit($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_commit() : error functionality *** + +-- Iteration 1 -- +NULL + +-- Iteration 2 -- +NULL + +-- Iteration 3 -- +NULL + +-- Iteration 4 -- +NULL + +-- Iteration 5 -- +NULL + +-- Iteration 6 -- +NULL + +-- Iteration 7 -- +NULL + +-- Iteration 8 -- +NULL + +-- Iteration 9 -- +NULL + +-- Iteration 10 -- +NULL + +-- Iteration 11 -- +NULL + +-- Iteration 12 -- +NULL + +-- Iteration 13 -- +NULL + +-- Iteration 14 -- +NULL + +-- Iteration 15 -- +NULL + +-- Iteration 16 -- +NULL + +-- Iteration 17 -- +NULL + +-- Iteration 18 -- +NULL + +-- Iteration 19 -- +NULL + +-- Iteration 20 -- +NULL + +-- Iteration 21 -- +NULL + +-- Iteration 22 -- +NULL + +-- Iteration 23 -- +NULL + +-- Iteration 24 -- +NULL +Done + diff --git a/ext/session/tests/session_commit_variation1.phpt b/ext/session/tests/session_commit_variation1.phpt new file mode 100644 index 0000000..81240da --- /dev/null +++ b/ext/session/tests/session_commit_variation1.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test session_commit() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_commit(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_commit() : variation ***\n"; + +var_dump(session_start()); +var_dump(session_commit()); +var_dump(session_commit()); +var_dump(session_commit()); +var_dump(session_commit()); +var_dump(session_commit()); +var_dump(session_start()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_commit() : variation *** +bool(true) +NULL +NULL +NULL +NULL +NULL +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_commit_variation2.phpt b/ext/session/tests/session_commit_variation2.phpt new file mode 100644 index 0000000..b38885a --- /dev/null +++ b/ext/session/tests/session_commit_variation2.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test session_commit() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_commit(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_commit() : variation ***\n"; + +var_dump(session_start()); +var_dump($_SESSION); +var_dump(session_commit()); +var_dump($_SESSION); +var_dump(session_start()); +var_dump($_SESSION); +var_dump(session_commit()); +var_dump($_SESSION); +var_dump(session_start()); +var_dump($_SESSION); +var_dump(session_commit()); +var_dump($_SESSION); +var_dump(session_start()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_commit() : variation *** +bool(true) +array(0) { +} +NULL +array(0) { +} +bool(true) +array(0) { +} +NULL +array(0) { +} +bool(true) +array(0) { +} +NULL +array(0) { +} +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_commit_variation3.phpt b/ext/session/tests/session_commit_variation3.phpt new file mode 100644 index 0000000..4cee2f4 --- /dev/null +++ b/ext/session/tests/session_commit_variation3.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.auto_start=1 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_commit(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_commit() : variation ***\n"; + +var_dump($_SESSION); +var_dump(session_commit()); +var_dump($_SESSION); +var_dump(session_start()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_commit() : variation *** +array(0) { +} +NULL +array(0) { +} +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_commit_variation4.phpt b/ext/session/tests/session_commit_variation4.phpt new file mode 100644 index 0000000..57f4253 --- /dev/null +++ b/ext/session/tests/session_commit_variation4.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test session_commit() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_commit(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_commit() : variation ***\n"; + +var_dump(session_id("test")); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_commit()); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_commit()); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_commit()); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_commit() : variation *** +string(0) "" +bool(true) +string(4) "test" +NULL +string(4) "test" +bool(true) +string(4) "test" +NULL +string(4) "test" +bool(true) +string(4) "test" +NULL +string(4) "test" +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_decode_basic.phpt b/ext/session/tests/session_decode_basic.phpt new file mode 100644 index 0000000..f8aa243 --- /dev/null +++ b/ext/session/tests/session_decode_basic.phpt @@ -0,0 +1,273 @@ +--TEST-- +Test session_decode() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_decode(void) + * Description : Decodes session data from a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_decode() : basic functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + +var_dump(session_start()); +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + $_SESSION["data"] = $input; + $encoded = session_encode(); + var_dump(session_decode($encoded)); + var_dump($_SESSION); + $iterator++; +}; + +var_dump(session_destroy()); +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_decode() : basic functionality *** +bool(true) + +-- Iteration 1 -- +bool(true) +array(1) { + ["data"]=> + int(0) +} + +-- Iteration 2 -- +bool(true) +array(1) { + ["data"]=> + int(1) +} + +-- Iteration 3 -- +bool(true) +array(1) { + ["data"]=> + int(12345) +} + +-- Iteration 4 -- +bool(true) +array(1) { + ["data"]=> + int(-2345) +} + +-- Iteration 5 -- +bool(true) +array(1) { + ["data"]=> + float(10.5) +} + +-- Iteration 6 -- +bool(true) +array(1) { + ["data"]=> + float(-10.5) +} + +-- Iteration 7 -- +bool(true) +array(1) { + ["data"]=> + float(123456789000) +} + +-- Iteration 8 -- +bool(true) +array(1) { + ["data"]=> + float(1.23456789E-9) +} + +-- Iteration 9 -- +bool(true) +array(1) { + ["data"]=> + float(0.5) +} + +-- Iteration 10 -- +bool(true) +array(1) { + ["data"]=> + NULL +} + +-- Iteration 11 -- +bool(true) +array(1) { + ["data"]=> + NULL +} + +-- Iteration 12 -- +bool(true) +array(1) { + ["data"]=> + bool(true) +} + +-- Iteration 13 -- +bool(true) +array(1) { + ["data"]=> + bool(false) +} + +-- Iteration 14 -- +bool(true) +array(1) { + ["data"]=> + bool(true) +} + +-- Iteration 15 -- +bool(true) +array(1) { + ["data"]=> + bool(false) +} + +-- Iteration 16 -- +bool(true) +array(1) { + ["data"]=> + string(0) "" +} + +-- Iteration 17 -- +bool(true) +array(1) { + ["data"]=> + string(0) "" +} + +-- Iteration 18 -- +bool(true) +array(1) { + ["data"]=> + string(7) "Nothing" +} + +-- Iteration 19 -- +bool(true) +array(1) { + ["data"]=> + string(7) "Nothing" +} + +-- Iteration 20 -- +bool(true) +array(1) { + ["data"]=> + string(12) "Hello World!" +} + +-- Iteration 21 -- +bool(true) +array(1) { + ["data"]=> + object(classA)#2 (0) { + } +} + +-- Iteration 22 -- +bool(true) +array(1) { + ["data"]=> + NULL +} + +-- Iteration 23 -- +bool(true) +array(1) { + ["data"]=> + NULL +} + +-- Iteration 24 -- +bool(true) +array(1) { + ["data"]=> + int(0) +} +bool(true) +Done + diff --git a/ext/session/tests/session_decode_error.phpt b/ext/session/tests/session_decode_error.phpt new file mode 100644 index 0000000..098ecce --- /dev/null +++ b/ext/session/tests/session_decode_error.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test session_decode() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_decode(void) + * Description : Decodes session data from a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_decode() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + +var_dump(session_start()); +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_decode($input)); + var_dump($_SESSION); + $iterator++; +}; + +var_dump(session_destroy()); +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_decode() : error functionality *** +bool(true) + +-- Iteration 1 -- +bool(true) +array(0) { +} + +-- Iteration 2 -- +bool(true) +array(0) { +} + +-- Iteration 3 -- +bool(true) +array(0) { +} + +-- Iteration 4 -- +bool(true) +array(0) { +} + +-- Iteration 5 -- +bool(true) +array(0) { +} + +-- Iteration 6 -- +bool(true) +array(0) { +} + +-- Iteration 7 -- +bool(true) +array(0) { +} + +-- Iteration 8 -- +bool(true) +array(0) { +} + +-- Iteration 9 -- +bool(true) +array(0) { +} + +-- Iteration 10 -- +bool(true) +array(0) { +} + +-- Iteration 11 -- +bool(true) +array(0) { +} + +-- Iteration 12 -- +bool(true) +array(0) { +} + +-- Iteration 13 -- +bool(true) +array(0) { +} + +-- Iteration 14 -- +bool(true) +array(0) { +} + +-- Iteration 15 -- +bool(true) +array(0) { +} + +-- Iteration 16 -- +bool(true) +array(0) { +} + +-- Iteration 17 -- +bool(true) +array(0) { +} + +-- Iteration 18 -- +bool(true) +array(0) { +} + +-- Iteration 19 -- +bool(true) +array(0) { +} + +-- Iteration 20 -- +bool(true) +array(0) { +} + +-- Iteration 21 -- +bool(true) +array(0) { +} + +-- Iteration 22 -- +bool(true) +array(0) { +} + +-- Iteration 23 -- +bool(true) +array(0) { +} + +-- Iteration 24 -- + +Warning: session_decode() expects parameter 1 to be string, resource given in %s on line %d +NULL +array(0) { +} +bool(true) +Done diff --git a/ext/session/tests/session_decode_error2.phpt b/ext/session/tests/session_decode_error2.phpt new file mode 100644 index 0000000..4160f87 --- /dev/null +++ b/ext/session/tests/session_decode_error2.phpt @@ -0,0 +1,615 @@ +--TEST-- +Test session_decode() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_decode(void) + * Description : Decodes session data from a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_decode() : error functionality ***\n"; +$data = "foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}guff|R:1;blah|R:1;"; + +var_dump(session_start()); +for($index = 0; $index < strlen($data); $index++) { + echo "\n-- Iteration $index --\n"; + $encoded = substr($data, 0, $index); + var_dump(session_decode($encoded)); + var_dump($_SESSION); +}; + +var_dump(session_destroy()); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_decode() : error functionality *** +bool(true) + +-- Iteration 0 -- +bool(true) +array(0) { +} + +-- Iteration 1 -- +bool(true) +array(0) { +} + +-- Iteration 2 -- +bool(true) +array(0) { +} + +-- Iteration 3 -- +bool(true) +array(0) { +} + +-- Iteration 4 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 5 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 6 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 7 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 8 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 9 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 10 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 11 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 12 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 13 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 14 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 15 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 16 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 17 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 18 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 19 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 20 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 21 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 22 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 23 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 24 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 25 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 26 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 27 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 28 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 29 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 30 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 31 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 32 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 33 -- +bool(true) +array(1) { + ["foo"]=> + NULL +} + +-- Iteration 34 -- +bool(true) +array(1) { + ["foo"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Iteration 35 -- +bool(true) +array(1) { + ["foo"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Iteration 36 -- +bool(true) +array(1) { + ["foo"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Iteration 37 -- +bool(true) +array(1) { + ["foo"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Iteration 38 -- +bool(true) +array(1) { + ["foo"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Iteration 39 -- +bool(true) +array(2) { + ["foo"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + NULL +} + +-- Iteration 40 -- +bool(true) +array(2) { + ["foo"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + NULL +} + +-- Iteration 41 -- +bool(true) +array(2) { + ["foo"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + NULL +} + +-- Iteration 42 -- +bool(true) +array(2) { + ["foo"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + NULL +} + +-- Iteration 43 -- +bool(true) +array(2) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Iteration 44 -- +bool(true) +array(2) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Iteration 45 -- +bool(true) +array(2) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Iteration 46 -- +bool(true) +array(2) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Iteration 47 -- +bool(true) +array(2) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Iteration 48 -- +bool(true) +array(3) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["blah"]=> + NULL +} + +-- Iteration 49 -- +bool(true) +array(3) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["blah"]=> + NULL +} + +-- Iteration 50 -- +bool(true) +array(3) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["blah"]=> + NULL +} + +-- Iteration 51 -- +bool(true) +array(3) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["blah"]=> + NULL +} +bool(true) +Done + diff --git a/ext/session/tests/session_decode_variation1.phpt b/ext/session/tests/session_decode_variation1.phpt new file mode 100644 index 0000000..b2d06b1 --- /dev/null +++ b/ext/session/tests/session_decode_variation1.phpt @@ -0,0 +1,189 @@ +--TEST-- +Test session_decode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_decode(void) + * Description : Decodes session data from a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_decode() : variation ***\n"; + +var_dump(session_start()); +var_dump(session_decode("foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}guff|R:1;blah|R:1;")); +var_dump($_SESSION); +var_dump(session_decode("foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}guff|R:1;blah|R:1;")); +var_dump($_SESSION); +var_dump(session_decode("foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}guff|R:1;blah|R:1;")); +var_dump($_SESSION); +var_dump(session_decode("foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}guff|R:1;blah|R:1;")); +var_dump($_SESSION); +var_dump(session_decode("foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}guff|R:1;blah|R:1;")); +var_dump($_SESSION); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_decode() : variation *** +bool(true) +bool(true) +array(3) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["blah"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +bool(true) +array(3) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["blah"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +bool(true) +array(3) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["blah"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +bool(true) +array(3) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["blah"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +bool(true) +array(3) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["blah"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +bool(true) +Done + diff --git a/ext/session/tests/session_decode_variation2.phpt b/ext/session/tests/session_decode_variation2.phpt new file mode 100644 index 0000000..1a9b687 --- /dev/null +++ b/ext/session/tests/session_decode_variation2.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test session_decode() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_decode(void) + * Description : Decodes session data from a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_decode() : variation ***\n"; + +var_dump(session_start()); +var_dump($_SESSION); +$_SESSION["foo"] = 1234567890; +$_SESSION["bar"] = "Hello World!"; +$_SESSION["guff"] = 123.456; +var_dump($_SESSION); +var_dump(session_decode("foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}guff|R:1;blah|R:1;")); +var_dump($_SESSION); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_decode() : variation *** +bool(true) +array(0) { +} +array(3) { + ["foo"]=> + int(1234567890) + ["bar"]=> + string(12) "Hello World!" + ["guff"]=> + float(123.456) +} +bool(true) +array(4) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["bar"]=> + string(12) "Hello World!" + ["guff"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["blah"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +bool(true) +Done + diff --git a/ext/session/tests/session_decode_variation3.phpt b/ext/session/tests/session_decode_variation3.phpt new file mode 100644 index 0000000..4a6f768 --- /dev/null +++ b/ext/session/tests/session_decode_variation3.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test session_decode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.serialize_handler=blah +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_decode(void) + * Description : Decodes session data from a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_decode() : variation ***\n"; + +var_dump(session_start()); +var_dump($_SESSION); +$_SESSION["foo"] = 1234567890; +$_SESSION["bar"] = "Blah!"; +$_SESSION["guff"] = 123.456; +var_dump($_SESSION); +$encoded = "foo|i:1234567890;"; +var_dump(session_decode($encoded)); +var_dump($_SESSION); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_decode() : variation *** + +Warning: session_start(): Cannot find serialization handler 'blah' - session startup failed in %s on line %d +bool(false) + +Notice: Undefined variable: _SESSION in %s on line %d +NULL +array(3) { + ["foo"]=> + int(1234567890) + ["bar"]=> + string(5) "Blah!" + ["guff"]=> + float(123.456) +} + +Warning: session_decode(): Unknown session.serialize_handler. Failed to decode session object in %s on line %d +bool(true) +array(3) { + ["foo"]=> + int(1234567890) + ["bar"]=> + string(5) "Blah!" + ["guff"]=> + float(123.456) +} + +Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d +bool(false) +Done diff --git a/ext/session/tests/session_decode_variation4.phpt b/ext/session/tests/session_decode_variation4.phpt new file mode 100644 index 0000000..8164275 --- /dev/null +++ b/ext/session/tests/session_decode_variation4.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test session_decode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_decode(void) + * Description : Decodes session data from a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_decode() : variation ***\n"; + +var_dump(session_start()); +var_dump($_SESSION); +$_SESSION["foo"] = 1234567890; +$_SESSION["bar"] = "Blah!"; +$_SESSION["guff"] = 123.456; +var_dump($_SESSION); +$encoded = "A2Zvb2k6MTIzNDU2Nzg5MDs="; +var_dump(session_decode(base64_decode($encoded))); +var_dump($_SESSION); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_decode() : variation *** +bool(true) +array(0) { +} +array(3) { + ["foo"]=> + int(1234567890) + ["bar"]=> + string(5) "Blah!" + ["guff"]=> + float(123.456) +} +bool(true) +array(3) { + ["foo"]=> + int(1234567890) + ["bar"]=> + string(5) "Blah!" + ["guff"]=> + float(123.456) +} +bool(true) +Done + diff --git a/ext/session/tests/session_destroy_error.phpt b/ext/session/tests/session_destroy_error.phpt new file mode 100644 index 0000000..a3e443e --- /dev/null +++ b/ext/session/tests/session_destroy_error.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test session_destroy() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_destroy(void) + * Description : Destroys all data registered to a session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_destroy() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_destroy($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_destroy() : error functionality *** + +-- Iteration 1 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: session_destroy() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done + diff --git a/ext/session/tests/session_destroy_variation1.phpt b/ext/session/tests/session_destroy_variation1.phpt new file mode 100644 index 0000000..fdbdf08 --- /dev/null +++ b/ext/session/tests/session_destroy_variation1.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test session_destroy() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_destroy(void) + * Description : Destroys all data registered to a session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_destroy() : variation ***\n"; + +var_dump(session_start()); +var_dump(session_destroy()); +var_dump(session_destroy()); +var_dump(session_destroy()); +var_dump(session_destroy()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_destroy() : variation *** +bool(true) +bool(true) + +Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d +bool(false) + +Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d +bool(false) + +Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d +bool(false) + +Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d +bool(false) +Done + diff --git a/ext/session/tests/session_destroy_variation2.phpt b/ext/session/tests/session_destroy_variation2.phpt new file mode 100644 index 0000000..c72c65b --- /dev/null +++ b/ext/session/tests/session_destroy_variation2.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test session_destroy() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_destroy(void) + * Description : Destroys all data registered to a session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_destroy() : variation ***\n"; + +var_dump(session_start()); +var_dump(session_destroy()); +var_dump(session_start()); +var_dump(session_destroy()); +var_dump(session_start()); +var_dump(session_destroy()); +var_dump(session_start()); +var_dump(session_destroy()); +var_dump(session_start()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_destroy() : variation *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_destroy_variation3.phpt b/ext/session/tests/session_destroy_variation3.phpt new file mode 100644 index 0000000..b63c17e --- /dev/null +++ b/ext/session/tests/session_destroy_variation3.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test session_destroy() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_destroy(void) + * Description : Destroys all data registered to a session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_destroy() : variation ***\n"; + +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); +var_dump(session_id()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_destroy() : variation *** +bool(true) +string(%d) "%s" +bool(true) +string(0) "" +bool(true) +string(%d) "%s" +bool(true) +string(0) "" +Done + diff --git a/ext/session/tests/session_encode_basic.phpt b/ext/session/tests/session_encode_basic.phpt new file mode 100644 index 0000000..dfe40d2 --- /dev/null +++ b/ext/session/tests/session_encode_basic.phpt @@ -0,0 +1,176 @@ +--TEST-- +Test session_encode() function : basic functionality +--INI-- +serialize_precision=100 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : basic functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + +var_dump(session_start()); +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + $_SESSION["data"] = $input; + var_dump(session_encode()); + $iterator++; +}; + +var_dump(session_destroy()); +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : basic functionality *** +bool(true) + +-- Iteration 1 -- +string(9) "data|i:0;" + +-- Iteration 2 -- +string(9) "data|i:1;" + +-- Iteration 3 -- +string(13) "data|i:12345;" + +-- Iteration 4 -- +string(13) "data|i:-2345;" + +-- Iteration 5 -- +string(12) "data|d:10.5;" + +-- Iteration 6 -- +string(13) "data|d:-10.5;" + +-- Iteration 7 -- +string(20) "data|d:123456789000;" + +-- Iteration 8 -- +string(%d) "data|d:1.2345678899999999145113427164344339914681114578343112953007221221923828125E-9;" + +-- Iteration 9 -- +string(11) "data|d:0.5;" + +-- Iteration 10 -- +string(7) "data|N;" + +-- Iteration 11 -- +string(7) "data|N;" + +-- Iteration 12 -- +string(9) "data|b:1;" + +-- Iteration 13 -- +string(9) "data|b:0;" + +-- Iteration 14 -- +string(9) "data|b:1;" + +-- Iteration 15 -- +string(9) "data|b:0;" + +-- Iteration 16 -- +string(12) "data|s:0:"";" + +-- Iteration 17 -- +string(12) "data|s:0:"";" + +-- Iteration 18 -- +string(19) "data|s:7:"Nothing";" + +-- Iteration 19 -- +string(19) "data|s:7:"Nothing";" + +-- Iteration 20 -- +string(25) "data|s:12:"Hello World!";" + +-- Iteration 21 -- +string(22) "data|O:6:"classA":0:{}" + +-- Iteration 22 -- +string(7) "data|N;" + +-- Iteration 23 -- +string(7) "data|N;" + +-- Iteration 24 -- +string(9) "data|i:0;" +bool(true) +Done + diff --git a/ext/session/tests/session_encode_error.phpt b/ext/session/tests/session_encode_error.phpt new file mode 100644 index 0000000..955aff4 --- /dev/null +++ b/ext/session/tests/session_encode_error.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test session_encode() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : basic functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + +session_start(); + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_encode($input)); + $iterator++; +}; + +session_destroy(); +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : basic functionality *** + +-- Iteration 1 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: session_encode() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done + diff --git a/ext/session/tests/session_encode_error2.phpt b/ext/session/tests/session_encode_error2.phpt new file mode 100644 index 0000000..2c31ceb --- /dev/null +++ b/ext/session/tests/session_encode_error2.phpt @@ -0,0 +1,251 @@ +--TEST-- +Test session_encode() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_start()); + $_SESSION[$input] = "Hello World!"; + var_dump(session_encode()); + var_dump(session_destroy()); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : error functionality *** + +-- Iteration 1 -- +bool(true) + +Notice: session_encode(): Skipping numeric key 0 in %s on line %d +bool(false) +bool(true) + +-- Iteration 2 -- +bool(true) + +Notice: session_encode(): Skipping numeric key 1 in %s on line %d +bool(false) +bool(true) + +-- Iteration 3 -- +bool(true) + +Notice: session_encode(): Skipping numeric key 12345 in %s on line %d +bool(false) +bool(true) + +-- Iteration 4 -- +bool(true) + +Notice: session_encode(): Skipping numeric key -2345 in %s on line %d +bool(false) +bool(true) + +-- Iteration 5 -- +bool(true) + +Notice: session_encode(): Skipping numeric key 10 in %s on line %d +bool(false) +bool(true) + +-- Iteration 6 -- +bool(true) + +Notice: session_encode(): Skipping numeric key -10 in %s on line %d +bool(false) +bool(true) + +-- Iteration 7 -- +bool(true) + +Notice: session_encode(): Skipping numeric key %s in %s on line %d +bool(false) +bool(true) + +-- Iteration 8 -- +bool(true) + +Notice: session_encode(): Skipping numeric key 0 in %s on line %d +bool(false) +bool(true) + +-- Iteration 9 -- +bool(true) + +Notice: session_encode(): Skipping numeric key 0 in %s on line %d +bool(false) +bool(true) + +-- Iteration 10 -- +bool(true) +string(21) "|s:12:"Hello World!";" +bool(true) + +-- Iteration 11 -- +bool(true) +string(21) "|s:12:"Hello World!";" +bool(true) + +-- Iteration 12 -- +bool(true) + +Notice: session_encode(): Skipping numeric key 1 in %s on line %d +bool(false) +bool(true) + +-- Iteration 13 -- +bool(true) + +Notice: session_encode(): Skipping numeric key 0 in %s on line %d +bool(false) +bool(true) + +-- Iteration 14 -- +bool(true) + +Notice: session_encode(): Skipping numeric key 1 in %s on line %d +bool(false) +bool(true) + +-- Iteration 15 -- +bool(true) + +Notice: session_encode(): Skipping numeric key 0 in %s on line %d +bool(false) +bool(true) + +-- Iteration 16 -- +bool(true) +string(21) "|s:12:"Hello World!";" +bool(true) + +-- Iteration 17 -- +bool(true) +string(21) "|s:12:"Hello World!";" +bool(true) + +-- Iteration 18 -- +bool(true) +string(28) "Nothing|s:12:"Hello World!";" +bool(true) + +-- Iteration 19 -- +bool(true) +string(28) "Nothing|s:12:"Hello World!";" +bool(true) + +-- Iteration 20 -- +bool(true) +bool(false) +bool(true) + +-- Iteration 21 -- +bool(true) + +Warning: Illegal offset type in %s on line 82 +bool(false) +bool(true) + +-- Iteration 22 -- +bool(true) +string(21) "|s:12:"Hello World!";" +bool(true) + +-- Iteration 23 -- +bool(true) +string(21) "|s:12:"Hello World!";" +bool(true) + +-- Iteration 24 -- +bool(true) + +Strict Standards: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d + +Notice: session_encode(): Skipping numeric key %d in %s on line %d +bool(false) +bool(true) +Done diff --git a/ext/session/tests/session_encode_variation1.phpt b/ext/session/tests/session_encode_variation1.phpt new file mode 100644 index 0000000..ce3a921 --- /dev/null +++ b/ext/session/tests/session_encode_variation1.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test session_encode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : variation ***\n"; + +var_dump(session_encode()); +var_dump(session_start()); +var_dump(session_encode()); +var_dump(session_write_close()); +var_dump(session_encode()); +var_dump(session_start()); +var_dump(session_encode()); +var_dump(session_destroy()); +var_dump(session_encode()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : variation *** + +Warning: session_encode(): Cannot encode non-existent session in %s on line %d +bool(false) +bool(true) +bool(false) +NULL +bool(false) +bool(true) +bool(false) +bool(true) + +Warning: session_encode(): Cannot encode non-existent session in %s on line %d +bool(false) +Done diff --git a/ext/session/tests/session_encode_variation2.phpt b/ext/session/tests/session_encode_variation2.phpt new file mode 100644 index 0000000..93fab30 --- /dev/null +++ b/ext/session/tests/session_encode_variation2.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test session_encode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.auto_start=1 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : variation ***\n"; + +var_dump(session_encode()); +var_dump(session_destroy()); +var_dump(session_encode()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : variation *** +bool(false) +bool(true) + +Warning: session_encode(): Cannot encode non-existent session in %s on line %d +bool(false) +Done diff --git a/ext/session/tests/session_encode_variation3.phpt b/ext/session/tests/session_encode_variation3.phpt new file mode 100644 index 0000000..47b2441 --- /dev/null +++ b/ext/session/tests/session_encode_variation3.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test session_encode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : variation ***\n"; + +var_dump(session_start()); + +$array = array(1,2,3); +$_SESSION["foo"] = &$array; +var_dump(session_encode()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : variation *** +bool(true) +string(34) "foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}" +bool(true) +Done diff --git a/ext/session/tests/session_encode_variation4.phpt b/ext/session/tests/session_encode_variation4.phpt new file mode 100644 index 0000000..89af6eb --- /dev/null +++ b/ext/session/tests/session_encode_variation4.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test session_encode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : variation ***\n"; + +var_dump(session_start()); + +$array = array(1,2,3); +$_SESSION["foo"] = &$array; +$_SESSION["guff"] = &$array; +$_SESSION["blah"] = &$array; +var_dump(session_encode()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : variation *** +bool(true) +string(52) "foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}guff|R:1;blah|R:1;" +bool(true) +Done diff --git a/ext/session/tests/session_encode_variation5.phpt b/ext/session/tests/session_encode_variation5.phpt new file mode 100644 index 0000000..d7639fa --- /dev/null +++ b/ext/session/tests/session_encode_variation5.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test session_encode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : variation ***\n"; + +var_dump(session_start()); + +$array = array(1,2,3); +$array["foo"] = &$array; +$array["blah"] = &$array; +$_SESSION["data"] = &$array; +var_dump(session_encode()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : variation *** +bool(true) +string(64) "data|a:5:{i:0;i:1;i:1;i:2;i:2;i:3;s:3:"foo";R:1;s:4:"blah";R:1;}" +bool(true) +Done diff --git a/ext/session/tests/session_encode_variation6.phpt b/ext/session/tests/session_encode_variation6.phpt new file mode 100644 index 0000000..c5f1f4b --- /dev/null +++ b/ext/session/tests/session_encode_variation6.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test session_encode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : variation ***\n"; + +var_dump(session_start()); +$_SESSION[] = 1234567890; +var_dump(session_encode()); +var_dump(session_destroy()); +var_dump(session_start()); +$_SESSION[1234567890] = "Hello World!"; +var_dump(session_encode()); +var_dump(session_destroy()); +var_dump(session_start()); +$_SESSION[-1234567890] = 1234567890; +var_dump(session_encode()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : variation *** +bool(true) + +Notice: session_encode(): Skipping numeric key 0 in %s on line %d +bool(false) +bool(true) +bool(true) + +Notice: session_encode(): Skipping numeric key 1234567890 in %s on line %d +bool(false) +bool(true) +bool(true) + +Notice: session_encode(): Skipping numeric key -1234567890 in %s on line %d +bool(false) +bool(true) +Done diff --git a/ext/session/tests/session_encode_variation7.phpt b/ext/session/tests/session_encode_variation7.phpt new file mode 100644 index 0000000..04cfe44 --- /dev/null +++ b/ext/session/tests/session_encode_variation7.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test session_encode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.serialize_handler=php_binary +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : variation ***\n"; + +var_dump(session_start()); +$_SESSION["foo"] = 1234567890; +$encoded = session_encode(); +var_dump(base64_encode($encoded)); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : variation *** +bool(true) +string(24) "A2Zvb2k6MTIzNDU2Nzg5MDs=" +bool(true) +Done diff --git a/ext/session/tests/session_encode_variation8.phpt b/ext/session/tests/session_encode_variation8.phpt new file mode 100644 index 0000000..7ffa948 --- /dev/null +++ b/ext/session/tests/session_encode_variation8.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test session_encode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.serialize_handler=blah +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : variation ***\n"; + +var_dump(session_start()); +$_SESSION["foo"] = 1234567890; +$encoded = session_encode(); +var_dump(base64_encode($encoded)); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : variation *** + +Warning: session_start(): Cannot find serialization handler 'blah' - session startup failed in %s on line %d +bool(false) + +Warning: session_encode(): Cannot encode non-existent session in %s on line %d +string(0) "" + +Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d +bool(false) +Done diff --git a/ext/session/tests/session_get_cookie_params_basic.phpt b/ext/session/tests/session_get_cookie_params_basic.phpt new file mode 100644 index 0000000..e984f55 --- /dev/null +++ b/ext/session/tests/session_get_cookie_params_basic.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test session_get_cookie_params() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.cookie_lifetime=0 +session.cookie_path="/" +session.cookie_domain="" +session.cookie_secure=0 +session.cookie_httponly=0 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : array session_get_cookie_params(void) + * Description : Get the session cookie parameters + * Source code : ext/session/session.c + */ + +echo "*** Testing session_get_cookie_params() : basic functionality ***\n"; + +var_dump(session_get_cookie_params()); +var_dump(session_set_cookie_params(3600, "/path", "blah", FALSE, FALSE)); +var_dump(session_get_cookie_params()); +var_dump(session_set_cookie_params(1234567890, "/guff", "foo", TRUE, TRUE)); +var_dump(session_get_cookie_params()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_get_cookie_params() : basic functionality *** +array(5) { + ["lifetime"]=> + int(0) + ["path"]=> + string(1) "/" + ["domain"]=> + string(0) "" + ["secure"]=> + bool(false) + ["httponly"]=> + bool(false) +} +NULL +array(5) { + ["lifetime"]=> + int(3600) + ["path"]=> + string(5) "/path" + ["domain"]=> + string(4) "blah" + ["secure"]=> + bool(false) + ["httponly"]=> + bool(false) +} +NULL +array(5) { + ["lifetime"]=> + int(1234567890) + ["path"]=> + string(5) "/guff" + ["domain"]=> + string(3) "foo" + ["secure"]=> + bool(true) + ["httponly"]=> + bool(true) +} +Done diff --git a/ext/session/tests/session_get_cookie_params_error.phpt b/ext/session/tests/session_get_cookie_params_error.phpt new file mode 100644 index 0000000..243536c --- /dev/null +++ b/ext/session/tests/session_get_cookie_params_error.phpt @@ -0,0 +1,217 @@ +--TEST-- +Test session_get_cookie_params() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : array session_get_cookie_params(void) + * Description : Get the session cookie parameters + * Source code : ext/session/session.c + */ + +echo "*** Testing session_get_cookie_params() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_get_cookie_params($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_get_cookie_params() : error functionality *** + +-- Iteration 1 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: session_get_cookie_params() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done + diff --git a/ext/session/tests/session_get_cookie_params_variation1.phpt b/ext/session/tests/session_get_cookie_params_variation1.phpt new file mode 100644 index 0000000..bb921a5 --- /dev/null +++ b/ext/session/tests/session_get_cookie_params_variation1.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test session_get_cookie_params() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.cookie_lifetime=0 +session.cookie_path="/" +session.cookie_domain="" +session.cookie_secure=0 +session.cookie_httponly=0 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : array session_get_cookie_params(void) + * Description : Get the session cookie parameters + * Source code : ext/session/session.c + */ + +echo "*** Testing session_get_cookie_params() : variation ***\n"; + +var_dump(session_get_cookie_params()); +ini_set("session.cookie_lifetime", 3600); +var_dump(session_get_cookie_params()); +ini_set("session.cookie_path", "/path"); +var_dump(session_get_cookie_params()); +ini_set("session.cookie_domain", "foo"); +var_dump(session_get_cookie_params()); +ini_set("session.cookie_secure", TRUE); +var_dump(session_get_cookie_params()); +ini_set("session.cookie_httponly", TRUE); +var_dump(session_get_cookie_params()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_get_cookie_params() : variation *** +array(5) { + ["lifetime"]=> + int(0) + ["path"]=> + string(1) "/" + ["domain"]=> + string(0) "" + ["secure"]=> + bool(false) + ["httponly"]=> + bool(false) +} +array(5) { + ["lifetime"]=> + int(3600) + ["path"]=> + string(1) "/" + ["domain"]=> + string(0) "" + ["secure"]=> + bool(false) + ["httponly"]=> + bool(false) +} +array(5) { + ["lifetime"]=> + int(3600) + ["path"]=> + string(5) "/path" + ["domain"]=> + string(0) "" + ["secure"]=> + bool(false) + ["httponly"]=> + bool(false) +} +array(5) { + ["lifetime"]=> + int(3600) + ["path"]=> + string(5) "/path" + ["domain"]=> + string(3) "foo" + ["secure"]=> + bool(false) + ["httponly"]=> + bool(false) +} +array(5) { + ["lifetime"]=> + int(3600) + ["path"]=> + string(5) "/path" + ["domain"]=> + string(3) "foo" + ["secure"]=> + bool(true) + ["httponly"]=> + bool(false) +} +array(5) { + ["lifetime"]=> + int(3600) + ["path"]=> + string(5) "/path" + ["domain"]=> + string(3) "foo" + ["secure"]=> + bool(true) + ["httponly"]=> + bool(true) +} +Done + diff --git a/ext/session/tests/session_id_basic.phpt b/ext/session/tests/session_id_basic.phpt new file mode 100644 index 0000000..5cb13c2 --- /dev/null +++ b/ext/session/tests/session_id_basic.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test session_id() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_id([string $id]) + * Description : Get and/or set the current session id + * Source code : ext/session/session.c + */ + +echo "*** Testing session_id() : basic functionality ***\n"; + +var_dump(session_id()); +var_dump(session_id("test")); +var_dump(session_id()); +var_dump(session_id("1234567890")); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); +var_dump(session_id()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_id() : basic functionality *** +string(0) "" +string(0) "" +string(4) "test" +string(4) "test" +string(10) "1234567890" +bool(true) +string(10) "1234567890" +bool(true) +string(0) "" +Done + diff --git a/ext/session/tests/session_id_error.phpt b/ext/session/tests/session_id_error.phpt new file mode 100644 index 0000000..6337cb9 --- /dev/null +++ b/ext/session/tests/session_id_error.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test session_id() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_id([string $id]) + * Description : Get and/or set the current session id + * Source code : ext/session/session.c + */ + +echo "*** Testing session_id() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_id($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_id() : error functionality *** + +-- Iteration 1 -- +string(0) "" + +-- Iteration 2 -- +string(1) "0" + +-- Iteration 3 -- +string(1) "1" + +-- Iteration 4 -- +string(5) "12345" + +-- Iteration 5 -- +string(5) "-2345" + +-- Iteration 6 -- +string(4) "10.5" + +-- Iteration 7 -- +string(5) "-10.5" + +-- Iteration 8 -- +string(12) "123456789000" + +-- Iteration 9 -- +string(13) "1.23456789E-9" + +-- Iteration 10 -- +string(3) "0.5" + +-- Iteration 11 -- +string(0) "" + +-- Iteration 12 -- +string(0) "" + +-- Iteration 13 -- +string(1) "1" + +-- Iteration 14 -- +string(0) "" + +-- Iteration 15 -- +string(1) "1" + +-- Iteration 16 -- +string(0) "" + +-- Iteration 17 -- +string(0) "" + +-- Iteration 18 -- +string(0) "" + +-- Iteration 19 -- +string(7) "Nothing" + +-- Iteration 20 -- +string(7) "Nothing" + +-- Iteration 21 -- +string(12) "Hello World!" + +-- Iteration 22 -- +string(12) "Hello World!" + +-- Iteration 23 -- +string(0) "" + +-- Iteration 24 -- + +Warning: session_id() expects parameter 1 to be string, resource given in %s on line %d +NULL +Done + diff --git a/ext/session/tests/session_id_error2.phpt b/ext/session/tests/session_id_error2.phpt new file mode 100644 index 0000000..05284e7 --- /dev/null +++ b/ext/session/tests/session_id_error2.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test session_id() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_id([string $id]) + * Description : Get and/or set the current session id + * Source code : ext/session/session.c + */ + +echo "*** Testing session_id() : error functionality ***\n"; + +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id("test")); +var_dump(session_id()); +var_dump(session_id("1234567890")); +var_dump(session_id()); +var_dump(session_destroy()); +var_dump(session_id()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_id() : error functionality *** +string(0) "" +bool(true) +string(%d) "%s" +string(4) "test" +string(4) "test" +string(10) "1234567890" +bool(true) +string(0) "" +Done + diff --git a/ext/session/tests/session_id_error3.phpt b/ext/session/tests/session_id_error3.phpt new file mode 100644 index 0000000..fc29138 --- /dev/null +++ b/ext/session/tests/session_id_error3.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test session_id() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_id([string $id]) + * Description : Get and/or set the current session id + * Source code : ext/session/session.c + */ + +echo "*** Testing session_id() : error functionality ***\n"; + +@session_start(); +var_dump(session_id()); +var_dump(session_id("!")); +var_dump(session_id()); +@session_destroy(); + +@session_start(); +var_dump(session_id()); +var_dump(session_id("?><")); +var_dump(session_id()); +@session_destroy(); + +@session_start(); +var_dump(session_id()); +var_dump(session_id("£$%^&*()")); +var_dump(session_id()); +@session_destroy(); + +@session_start(); +var_dump(session_id()); +var_dump(session_id("\r\n")); +var_dump(session_id()); +@session_destroy(); + +@session_start(); +var_dump(session_id()); +var_dump(session_id("\0")); +var_dump(session_id()); +@session_destroy(); + +@session_start(); +var_dump(session_id()); +var_dump(session_id("¬``@~:{>?><,./[]+--")); +var_dump(session_id()); +@session_destroy(); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_id() : error functionality *** +string(%d) "%s" +string(%d) "%s" +string(1) "!" +string(%d) "%s" +string(%d) "%s" +string(3) "?><" +string(%d) "%s" +string(%d) "%s" +string(8) "£$%^&*()" +string(%d) "%s" +string(%d) "%s" +string(2) " +" +string(%d) "%s" +string(%d) "%s" +string(0) "" +string(%d) "%s" +string(%d) "%s" +string(19) "¬``@~:{>?><,./[]+--" +Done + diff --git a/ext/session/tests/session_id_error4.phpt b/ext/session/tests/session_id_error4.phpt new file mode 100644 index 0000000..6c1fdbc --- /dev/null +++ b/ext/session/tests/session_id_error4.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test session_id() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.hash_function=0 +session.hash_bits_per_character=4 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_id([string $id]) + * Description : Get and/or set the current session id + * Source code : ext/session/session.c + */ + +echo "*** Testing session_id() : error functionality ***\n"; + +var_dump(ini_set("session.hash_function", -1)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_id() : error functionality *** +string(1) "0" +string(0) "" +bool(true) +string(40) "%s" +bool(true) +Done diff --git a/ext/session/tests/session_id_variation1.phpt b/ext/session/tests/session_id_variation1.phpt new file mode 100644 index 0000000..983ca29 --- /dev/null +++ b/ext/session/tests/session_id_variation1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test session_id() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.hash_function=0 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_id([string $id]) + * Description : Get and/or set the current session id + * Source code : ext/session/session.c + */ + +echo "*** Testing session_id() : variation ***\n"; + +var_dump(ini_set("session.hash_function", 0)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); + +var_dump(ini_set("session.hash_function", 1)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_id() : variation *** +string(1) "0" +string(0) "" +bool(true) +string(%d) "%s" +bool(true) +string(1) "0" +string(0) "" +bool(true) +string(%d) "%s" +bool(true) +Done + diff --git a/ext/session/tests/session_id_variation2.phpt b/ext/session/tests/session_id_variation2.phpt new file mode 100644 index 0000000..f69aa44 --- /dev/null +++ b/ext/session/tests/session_id_variation2.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test session_id() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.hash_function=0 +session.entropy_file= +session.entropy_length=0 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_id([string $id]) + * Description : Get and/or set the current session id + * Source code : ext/session/session.c + */ + +echo "*** Testing session_id() : variation ***\n"; + +$directory = dirname(__FILE__); +$filename = ($directory."/entropy.txt"); +var_dump(ini_set("session.entropy_file", $filename)); +var_dump(file_put_contents($filename, "Hello World!")); +var_dump(ini_set("session.entropy_length", filesize($filename))); + +var_dump(ini_set("session.hash_function", 0)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); + +var_dump(ini_set("session.hash_function", 1)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); +var_dump(unlink($filename)); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_id() : variation *** +string(0) "" +int(12) +string(1) "0" +string(1) "0" +string(0) "" +bool(true) +string(%d) "%s" +bool(true) +string(1) "0" +string(0) "" +bool(true) +string(%d) "%s" +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_module_name_basic.phpt b/ext/session/tests/session_module_name_basic.phpt new file mode 100644 index 0000000..2daf6fc --- /dev/null +++ b/ext/session/tests/session_module_name_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test session_module_name() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_module_name([string $module]) + * Description : Get and/or set the current session module + * Source code : ext/session/session.c + */ + +echo "*** Testing session_module_name() : basic functionality ***\n"; +var_dump(session_module_name("files")); +var_dump(session_module_name()); +var_dump(session_start()); +var_dump(session_module_name()); +var_dump(session_destroy()); +var_dump(session_module_name()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_module_name() : basic functionality *** +string(%d) "%s" +string(5) "files" +bool(true) +string(5) "files" +bool(true) +string(5) "files" +Done diff --git a/ext/session/tests/session_module_name_error.phpt b/ext/session/tests/session_module_name_error.phpt new file mode 100644 index 0000000..08c080a --- /dev/null +++ b/ext/session/tests/session_module_name_error.phpt @@ -0,0 +1,216 @@ +--TEST-- +Test session_module_name() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_module_name([string $module]) + * Description : Get and/or set the current session module + * Source code : ext/session/session.c + */ + +echo "*** Testing session_module_name() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_module_name($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_module_name() : error functionality *** + +-- Iteration 1 -- + +Warning: session_module_name(): Cannot find named PHP session module (0) in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: session_module_name(): Cannot find named PHP session module (1) in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: session_module_name(): Cannot find named PHP session module (12345) in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: session_module_name(): Cannot find named PHP session module (-2345) in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: session_module_name(): Cannot find named PHP session module (10.5) in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: session_module_name(): Cannot find named PHP session module (-10.5) in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: session_module_name(): Cannot find named PHP session module (123456789000) in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: session_module_name(): Cannot find named PHP session module (1.23456789E-9) in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: session_module_name(): Cannot find named PHP session module (0.5) in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: session_module_name(): Cannot find named PHP session module (1) in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: session_module_name(): Cannot find named PHP session module (1) in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: session_module_name(): Cannot find named PHP session module (Nothing) in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: session_module_name(): Cannot find named PHP session module (Nothing) in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: session_module_name(): Cannot find named PHP session module (Hello World!) in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: session_module_name(): Cannot find named PHP session module (Hello World!) in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: session_module_name() expects parameter 1 to be string, resource given in %s on line %d +NULL +Done diff --git a/ext/session/tests/session_module_name_variation1.phpt b/ext/session/tests/session_module_name_variation1.phpt new file mode 100644 index 0000000..2034b7e --- /dev/null +++ b/ext/session/tests/session_module_name_variation1.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test session_module_name() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_module_name([string $module]) + * Description : Get and/or set the current session module + * Source code : ext/session/session.c + */ + +echo "*** Testing session_module_name() : variation ***\n"; +var_dump(session_module_name("blah")); +var_dump(session_start()); +var_dump(session_module_name()); +var_dump(session_destroy()); +var_dump(session_module_name()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_module_name() : variation *** + +Warning: session_module_name(): Cannot find named PHP session module (blah) in %s on line %d +bool(false) +bool(true) +string(%d) "%s" +bool(true) +string(%d) "%s" +Done diff --git a/ext/session/tests/session_module_name_variation2.phpt b/ext/session/tests/session_module_name_variation2.phpt new file mode 100644 index 0000000..aa7b33c --- /dev/null +++ b/ext/session/tests/session_module_name_variation2.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test session_module_name() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_module_name([string $module]) + * Description : Get and/or set the current session module + * Source code : ext/session/session.c + */ + +echo "*** Testing session_module_name() : variation ***\n"; + +function open($save_path, $session_name) { } +function close() { } +function read($id) { } +function write($id, $session_data) { } +function destroy($id) { } +function gc($maxlifetime) { } + +var_dump(session_module_name("files")); +session_set_save_handler("open", "close", "read", "write", "destroy", "gc"); +var_dump(session_module_name()); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_module_name() : variation *** +string(%d) "%s" +string(4) "user" diff --git a/ext/session/tests/session_module_name_variation3.phpt b/ext/session/tests/session_module_name_variation3.phpt new file mode 100644 index 0000000..dc1c6ba --- /dev/null +++ b/ext/session/tests/session_module_name_variation3.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test session_module_name() function : variation +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_module_name([string $module]) + * Description : Get and/or set the current session module + * Source code : ext/session/session.c + */ + +echo "*** Testing session_module_name() : variation ***\n"; +function open($save_path, $session_name) { + throw new Exception("Stop...!"); +} + +function close() { } +function read($id) { } +function write($id, $session_data) { } +function destroy($id) { } +function gc($maxlifetime) { } + +var_dump(session_module_name("files")); +session_set_save_handler("open", "close", "read", "write", "destroy", "gc"); +var_dump(session_module_name()); +var_dump(session_start()); +var_dump(session_module_name()); +var_dump(session_destroy()); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_module_name() : variation *** +string(%d) "%s" +string(4) "user" + +Fatal error: Uncaught exception 'Exception' with message 'Stop...!' in %s:%d +Stack trace: +#0 [internal function]: open('', 'PHPSESSID') +#1 %s(%d): session_start() +#2 {main} + thrown in %s on line %d diff --git a/ext/session/tests/session_module_name_variation4.phpt b/ext/session/tests/session_module_name_variation4.phpt new file mode 100644 index 0000000..0748b3d --- /dev/null +++ b/ext/session/tests/session_module_name_variation4.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test session_module_name() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.gc_probability=1 +session.gc_divisor=1 +session.gc_maxlifetime=0 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_module_name([string $module]) + * Description : Get and/or set the current session module + * Source code : ext/session/session.c + */ + +echo "*** Testing session_module_name() : variation ***\n"; + +require_once "save_handler.inc"; +$path = dirname(__FILE__); +session_save_path($path); +session_module_name("files"); + +session_start(); +$_SESSION["Blah"] = "Hello World!"; +$_SESSION["Foo"] = FALSE; +$_SESSION["Guff"] = 1234567890; +var_dump($_SESSION); + +var_dump(session_write_close()); +session_start(); +var_dump($_SESSION); +var_dump(session_destroy()); +session_start(); +var_dump($_SESSION); +var_dump(session_destroy()); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_module_name() : variation *** + +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +NULL +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +bool(true) +array(0) { +} +bool(true) + diff --git a/ext/session/tests/session_name_basic.phpt b/ext/session/tests/session_name_basic.phpt new file mode 100644 index 0000000..959f406 --- /dev/null +++ b/ext/session/tests/session_name_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test session_name() function : error functionality +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_name([string $name]) + * Description : Get and/or set the current session name + * Source code : ext/session/session.c + */ + +echo "*** Testing session_name() : error functionality ***\n"; + +var_dump(session_name()); +var_dump(session_name("blah")); +var_dump(session_start()); +var_dump(session_name()); +var_dump(session_destroy()); +var_dump(session_name()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_name() : error functionality *** +string(9) "PHPSESSID" +string(9) "PHPSESSID" +bool(true) +string(4) "blah" +bool(true) +string(4) "blah" +Done + diff --git a/ext/session/tests/session_name_error.phpt b/ext/session/tests/session_name_error.phpt new file mode 100644 index 0000000..2ed10d9 --- /dev/null +++ b/ext/session/tests/session_name_error.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test session_name() function : error functionality +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_name([string $name]) + * Description : Get and/or set the current session name + * Source code : ext/session/session.c + */ + +echo "*** Testing session_name() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_name($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_name() : error functionality *** + +-- Iteration 1 -- +string(9) "PHPSESSID" + +-- Iteration 2 -- +string(1) "0" + +-- Iteration 3 -- +string(1) "1" + +-- Iteration 4 -- +string(5) "12345" + +-- Iteration 5 -- +string(5) "-2345" + +-- Iteration 6 -- +string(4) "10.5" + +-- Iteration 7 -- +string(5) "-10.5" + +-- Iteration 8 -- +string(12) "123456789000" + +-- Iteration 9 -- +string(13) "1.23456789E-9" + +-- Iteration 10 -- +string(3) "0.5" + +-- Iteration 11 -- +string(0) "" + +-- Iteration 12 -- +string(0) "" + +-- Iteration 13 -- +string(1) "1" + +-- Iteration 14 -- +string(0) "" + +-- Iteration 15 -- +string(1) "1" + +-- Iteration 16 -- +string(0) "" + +-- Iteration 17 -- +string(0) "" + +-- Iteration 18 -- +string(0) "" + +-- Iteration 19 -- +string(7) "Nothing" + +-- Iteration 20 -- +string(7) "Nothing" + +-- Iteration 21 -- +string(12) "Hello World!" + +-- Iteration 22 -- +string(12) "Hello World!" + +-- Iteration 23 -- +string(0) "" + +-- Iteration 24 -- + +Warning: session_name() expects parameter 1 to be string, resource given in %s on line %d +NULL +Done + diff --git a/ext/session/tests/session_name_variation1.phpt b/ext/session/tests/session_name_variation1.phpt new file mode 100644 index 0000000..16d6ad4 --- /dev/null +++ b/ext/session/tests/session_name_variation1.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test session_name() function : variation +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_name([string $name]) + * Description : Get and/or set the current session name + * Source code : ext/session/session.c + */ + +echo "*** Testing session_name() : variation ***\n"; + +var_dump(session_name("\0")); +var_dump(session_start()); +var_dump(session_name()); +var_dump(session_destroy()); +var_dump(session_name()); + +var_dump(session_name("\t")); +var_dump(session_start()); +var_dump(session_name()); +var_dump(session_destroy()); +var_dump(session_name()); + +var_dump(session_name("")); +var_dump(session_start()); +var_dump(session_name()); +var_dump(session_destroy()); +var_dump(session_name()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_name() : variation *** +string(9) "PHPSESSID" +bool(true) +string(0) "" +bool(true) +string(0) "" +string(0) "" +bool(true) +string(1) " " +bool(true) +string(1) " " +string(1) " " +bool(true) +string(0) "" +bool(true) +string(0) "" +Done + diff --git a/ext/session/tests/session_name_variation2.phpt b/ext/session/tests/session_name_variation2.phpt new file mode 100644 index 0000000..84bfeba --- /dev/null +++ b/ext/session/tests/session_name_variation2.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test session_name() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.name=blah +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_name([string $name]) + * Description : Get and/or set the current session name + * Source code : ext/session/session.c + */ + +echo "*** Testing session_name() : variation ***\n"; + +var_dump(session_name()); +var_dump(session_name("blah")); +var_dump(session_start()); +var_dump(session_name()); +var_dump(session_destroy()); +var_dump(session_name()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_name() : variation *** +string(4) "blah" +string(4) "blah" +bool(true) +string(4) "blah" +bool(true) +string(4) "blah" +Done + diff --git a/ext/session/tests/session_regenerate_id_basic.phpt b/ext/session/tests/session_regenerate_id_basic.phpt new file mode 100644 index 0000000..910620a --- /dev/null +++ b/ext/session/tests/session_regenerate_id_basic.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test session_regenerate_id() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_regenerate_id([bool $delete_old_session]) + * Description : Update the current session id with a newly generated one + * Source code : ext/session/session.c + */ + +echo "*** Testing session_regenerate_id() : basic functionality ***\n"; + +var_dump(session_id()); +var_dump(session_regenerate_id()); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_regenerate_id()); +var_dump(session_id()); +var_dump(session_destroy()); +var_dump(session_regenerate_id()); +var_dump(session_id()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_regenerate_id() : basic functionality *** +string(0) "" +bool(false) +string(0) "" +bool(true) +bool(true) +string(%d) "%s" +bool(true) +bool(false) +string(0) "" +Done + diff --git a/ext/session/tests/session_regenerate_id_error.phpt b/ext/session/tests/session_regenerate_id_error.phpt new file mode 100644 index 0000000..9e119f1 --- /dev/null +++ b/ext/session/tests/session_regenerate_id_error.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test session_regenerate_id() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_regenerate_id([bool $delete_old_session]) + * Description : Update the current session id with a newly generated one + * Source code : ext/session/session.c + */ + +echo "*** Testing session_regenerate_id() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_regenerate_id($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_regenerate_id() : error functionality *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- +bool(false) + +-- Iteration 20 -- +bool(false) + +-- Iteration 21 -- + +Warning: session_regenerate_id() expects parameter 1 to be boolean, object given in %s on line %d +NULL + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- + +Warning: session_regenerate_id() expects parameter 1 to be boolean, resource given in %s on line %d +NULL +Done + diff --git a/ext/session/tests/session_regenerate_id_variation1.phpt b/ext/session/tests/session_regenerate_id_variation1.phpt new file mode 100644 index 0000000..95d4a77 --- /dev/null +++ b/ext/session/tests/session_regenerate_id_variation1.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test session_regenerate_id() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_regenerate_id([bool $delete_old_session]) + * Description : Update the current session id with a newly generated one + * Source code : ext/session/session.c + */ + +echo "*** Testing session_regenerate_id() : variation ***\n"; + +var_dump(session_id()); +var_dump(session_regenerate_id(TRUE)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_regenerate_id(TRUE)); +var_dump(session_id()); +var_dump(session_destroy()); +var_dump(session_regenerate_id(TRUE)); +var_dump(session_id()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_regenerate_id() : variation *** +string(0) "" +bool(false) +string(0) "" +bool(true) +bool(true) +string(%d) "%s" +bool(true) +bool(false) +string(0) "" +Done + diff --git a/ext/session/tests/session_save_path_basic.phpt b/ext/session/tests/session_save_path_basic.phpt new file mode 100644 index 0000000..2895f46 --- /dev/null +++ b/ext/session/tests/session_save_path_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test session_save_path() function : basic functionality +--INI-- +session.gc_probability=0 +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_save_path([string $path]) + * Description : Get and/or set the current session save path + * Source code : ext/session/session.c + */ + +echo "*** Testing session_save_path() : error functionality ***\n"; + +$directory = dirname(__FILE__); +var_dump(session_save_path()); +var_dump(session_save_path($directory)); +var_dump(session_save_path()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_save_path() : error functionality *** +string(0) "" +string(0) "" +string(%d) "%s" +Done + diff --git a/ext/session/tests/session_save_path_error.phpt b/ext/session/tests/session_save_path_error.phpt new file mode 100644 index 0000000..815feee --- /dev/null +++ b/ext/session/tests/session_save_path_error.phpt @@ -0,0 +1,178 @@ +--TEST-- +Test session_save_path() function : error functionality +--INI-- +session.gc_probability=0 +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_save_path([string $path]) + * Description : Get and/or set the current session save path + * Source code : ext/session/session.c + */ + +echo "*** Testing session_save_path() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + +session_start(); + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_save_path($input)); + $iterator++; +}; + +session_destroy(); +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_save_path() : error functionality *** + +-- Iteration 1 -- +string(0) "" + +-- Iteration 2 -- +string(1) "0" + +-- Iteration 3 -- +string(1) "1" + +-- Iteration 4 -- +string(5) "12345" + +-- Iteration 5 -- +string(5) "-2345" + +-- Iteration 6 -- +string(4) "10.5" + +-- Iteration 7 -- +string(5) "-10.5" + +-- Iteration 8 -- +string(12) "123456789000" + +-- Iteration 9 -- +string(13) "1.23456789E-9" + +-- Iteration 10 -- +string(3) "0.5" + +-- Iteration 11 -- +string(0) "" + +-- Iteration 12 -- +string(0) "" + +-- Iteration 13 -- +string(1) "1" + +-- Iteration 14 -- +string(0) "" + +-- Iteration 15 -- +string(1) "1" + +-- Iteration 16 -- +string(0) "" + +-- Iteration 17 -- +string(0) "" + +-- Iteration 18 -- +string(0) "" + +-- Iteration 19 -- +string(7) "Nothing" + +-- Iteration 20 -- +string(7) "Nothing" + +-- Iteration 21 -- +string(12) "Hello World!" + +-- Iteration 22 -- +string(12) "Hello World!" + +-- Iteration 23 -- +string(0) "" + +-- Iteration 24 -- + +Warning: session_save_path() expects parameter 1 to be string, resource given in %s on line %d +NULL +Done + diff --git a/ext/session/tests/session_save_path_variation1.phpt b/ext/session/tests/session_save_path_variation1.phpt new file mode 100644 index 0000000..d5f64d9 --- /dev/null +++ b/ext/session/tests/session_save_path_variation1.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test session_save_path() function : variation +--INI-- +session.gc_probability=0 +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_save_path([string $path]) + * Description : Get and/or set the current session save path + * Source code : ext/session/session.c + */ + +echo "*** Testing session_save_path() : variation ***\n"; + +$directory = dirname(__FILE__); +var_dump(session_save_path()); +var_dump(session_start()); +var_dump(session_save_path()); +var_dump(session_save_path($directory)); +var_dump(session_save_path()); +var_dump(session_destroy()); +var_dump(session_save_path()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_save_path() : variation *** +string(0) "" +bool(true) +string(0) "" +string(0) "" +string(%d) "%s" +bool(true) +string(%d) "%s" +Done + diff --git a/ext/session/tests/session_save_path_variation2.phpt b/ext/session/tests/session_save_path_variation2.phpt new file mode 100644 index 0000000..6b08480 --- /dev/null +++ b/ext/session/tests/session_save_path_variation2.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test session_save_path() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.save_handler=files +session.gc_probability=0 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_save_path([string $path]) + * Description : Get and/or set the current session save path + * Source code : ext/session/session.c + */ + +echo "*** Testing session_save_path() : variation ***\n"; + +ini_set("session.save_path", "/blah"); +var_dump(ini_get("session.save_path")); +var_dump(session_start()); +var_dump(ini_get("session.save_path")); +var_dump(session_destroy()); +var_dump(ini_get("session.save_path")); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_save_path() : variation *** +string(5) "/blah" + +Warning: session_start(): open(%s, O_RDWR) failed: No such file or directory (2) in %s on line %d +bool(true) +string(5) "/blah" +bool(true) +string(5) "/blah" +Done diff --git a/ext/session/tests/session_save_path_variation3.phpt b/ext/session/tests/session_save_path_variation3.phpt new file mode 100644 index 0000000..b064f30 --- /dev/null +++ b/ext/session/tests/session_save_path_variation3.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test session_save_path() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.save_handler=files +session.gc_probability=0 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_save_path([string $path]) + * Description : Get and/or set the current session save path + * Source code : ext/session/session.c + */ + +echo "*** Testing session_save_path() : variation ***\n"; + +ini_set("session.save_path", "/blah"); +var_dump(session_save_path()); +var_dump(session_start()); +var_dump(session_save_path()); +var_dump(session_destroy()); +var_dump(session_save_path()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_save_path() : variation *** +string(5) "/blah" + +Warning: session_start(): open(%s, O_RDWR) failed: No such file or directory (2) in %s on line %d +bool(true) +string(5) "/blah" +bool(true) +string(5) "/blah" +Done diff --git a/ext/session/tests/session_save_path_variation4.phpt b/ext/session/tests/session_save_path_variation4.phpt new file mode 100644 index 0000000..80db6ca --- /dev/null +++ b/ext/session/tests/session_save_path_variation4.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test session_save_path() function : variation +--SKIPIF-- +<?php include('skipif.inc');?> +--INI-- +open_basedir=. +session.save_handler=files +session.save_path= +session.name=PHPSESSID +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_save_path([string $path]) + * Description : Get and/or set the current session save path + * Source code : ext/session/session.c + */ + +echo "*** Testing session_save_path() : variation ***\n"; +$initdir = getcwd(); +$sessions = ($initdir."/sessions"); + +chdir($initdir); + +// Delete the existing directory +if (file_exists($sessions) === TRUE) { + @rmdir($sessions); +} + +var_dump(mkdir($sessions)); +var_dump(chdir($sessions)); +ini_set("session.save_path", $initdir); +var_dump(session_save_path()); +var_dump(session_start()); +var_dump(session_save_path()); +var_dump(session_destroy()); +var_dump(session_save_path()); +var_dump(rmdir($sessions)); + +echo "Done"; +ob_end_flush(); +?> +--CLEAN-- +$initdir = getcwd(); +$sessions = ($initdir."/sessions"); +var_dump(rmdir($sessions)); +--EXPECTF-- +*** Testing session_save_path() : variation *** +bool(true) +bool(true) + +Warning: ini_set(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d +string(0) "" + +Warning: session_start(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d + +Fatal error: session_start(): Failed to initialize storage module: files (path: ) in %s on line %d + diff --git a/ext/session/tests/session_save_path_variation5.phpt b/ext/session/tests/session_save_path_variation5.phpt new file mode 100644 index 0000000..5407b5e --- /dev/null +++ b/ext/session/tests/session_save_path_variation5.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test session_save_path() function : variation +--SKIPIF-- +<?php include('skipif.inc'); +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not for Windows"); +?> +--INI-- +session.save_handler=files +session.save_path= +session.name=PHPSESSID +open_basedir=. +--FILE-- +<?php + +ob_start(); +/* + * Prototype : string session_save_path([string $path]) + * Description : Get and/or set the current session save path + * Source code : ext/session/session.c + */ + +echo "*** Testing session_save_path() : variation ***\n"; +$directory = dirname(__FILE__); +$sessions = ($directory."/sessions"); + +chdir($directory); + +// Delete the existing directory +if (file_exists($sessions) === TRUE) { + @rmdir($sessions); +} + +var_dump(mkdir($sessions)); +var_dump(chdir($sessions)); +ini_set("session.save_path", $directory); +var_dump(session_save_path()); +var_dump(rmdir($sessions)); + +echo "Done"; +ob_end_flush(); +?> +--CLEAN-- +$directory = dirname(__FILE__); +$sessions = ($directory."/sessions"); +var_dump(rmdir($sessions)); +--EXPECTF-- +*** Testing session_save_path() : variation *** +bool(true) +bool(true) + +Warning: ini_set(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d +string(0) "" +bool(true) +Done + diff --git a/ext/session/tests/session_set_cookie_params_basic.phpt b/ext/session/tests/session_set_cookie_params_basic.phpt new file mode 100644 index 0000000..5055d1c --- /dev/null +++ b/ext/session/tests/session_set_cookie_params_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test session_set_cookie_params() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : void session_set_cookie_params(int $lifetime [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]) + * Description : Set the session cookie parameters + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_cookie_params() : basic functionality ***\n"; + +var_dump(session_set_cookie_params(3600)); +var_dump(session_start()); +var_dump(session_set_cookie_params(1800)); +var_dump(session_destroy()); +var_dump(session_set_cookie_params(1234567890)); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_cookie_params() : basic functionality *** +NULL +bool(true) +NULL +bool(true) +NULL +Done + diff --git a/ext/session/tests/session_set_cookie_params_error.phpt b/ext/session/tests/session_set_cookie_params_error.phpt new file mode 100644 index 0000000..0dc5310 --- /dev/null +++ b/ext/session/tests/session_set_cookie_params_error.phpt @@ -0,0 +1,306 @@ +--TEST-- +Test session_set_cookie_params() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : void session_set_cookie_params(int $lifetime [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]) + * Description : Set the session cookie parameters + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_cookie_params() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_set_cookie_params($input)); + var_dump(session_set_cookie_params(1234567890, $input)); + var_dump(session_set_cookie_params(1234567890, "blah", $input)); + var_dump(session_set_cookie_params(1234567890, "blah", "foo", $input)); + var_dump(session_set_cookie_params(1234567890, "blah", "foo", TRUE, $input)); + var_dump(session_set_cookie_params(1234567890, "blah", "foo", TRUE, FALSE)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_cookie_params() : error functionality *** + +-- Iteration 1 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 2 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 3 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 4 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 5 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 6 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 7 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 8 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 9 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 10 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 11 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 12 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 13 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 14 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 15 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 16 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 17 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 18 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 19 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 20 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 21 -- +NULL +NULL +NULL + +Warning: session_set_cookie_params() expects parameter 4 to be boolean, object given in %s on line %d +NULL + +Warning: session_set_cookie_params() expects parameter 5 to be boolean, object given in %s on line %d +NULL +NULL + +-- Iteration 22 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 23 -- +NULL +NULL +NULL +NULL +NULL +NULL + +-- Iteration 24 -- +NULL + +Warning: session_set_cookie_params() expects parameter 2 to be string, resource given in %s on line %d +NULL + +Warning: session_set_cookie_params() expects parameter 3 to be string, resource given in %s on line %d +NULL + +Warning: session_set_cookie_params() expects parameter 4 to be boolean, resource given in %s on line %d +NULL + +Warning: session_set_cookie_params() expects parameter 5 to be boolean, resource given in %s on line %d +NULL +NULL +Done + diff --git a/ext/session/tests/session_set_cookie_params_variation1.phpt b/ext/session/tests/session_set_cookie_params_variation1.phpt new file mode 100644 index 0000000..02b901f --- /dev/null +++ b/ext/session/tests/session_set_cookie_params_variation1.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test session_set_cookie_params() function : variation +--INI-- +session.cookie_lifetime=3600 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : void session_set_cookie_params(int $lifetime [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]) + * Description : Set the session cookie parameters + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_cookie_params() : variation ***\n"; + +var_dump(ini_get("session.cookie_lifetime")); +var_dump(session_set_cookie_params(3600)); +var_dump(ini_get("session.cookie_lifetime")); +var_dump(session_start()); +var_dump(ini_get("session.cookie_lifetime")); +var_dump(session_set_cookie_params(1800)); +var_dump(ini_get("session.cookie_lifetime")); +var_dump(session_destroy()); +var_dump(ini_get("session.cookie_lifetime")); +var_dump(session_set_cookie_params(1234567890)); +var_dump(ini_get("session.cookie_lifetime")); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_cookie_params() : variation *** +string(4) "3600" +NULL +string(4) "3600" +bool(true) +string(4) "3600" +NULL +string(4) "1800" +bool(true) +string(4) "1800" +NULL +string(10) "1234567890" +Done + diff --git a/ext/session/tests/session_set_cookie_params_variation2.phpt b/ext/session/tests/session_set_cookie_params_variation2.phpt new file mode 100644 index 0000000..5d7a010 --- /dev/null +++ b/ext/session/tests/session_set_cookie_params_variation2.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test session_set_cookie_params() function : variation +--INI-- +session.cookie_path=/path +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : void session_set_cookie_params(int $lifetime [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]) + * Description : Set the session cookie parameters + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_cookie_params() : variation ***\n"; + +var_dump(ini_get("session.cookie_path")); +var_dump(session_set_cookie_params(3600, "/foo")); +var_dump(ini_get("session.cookie_path")); +var_dump(session_start()); +var_dump(ini_get("session.cookie_path")); +var_dump(session_set_cookie_params(3600, "/blah")); +var_dump(ini_get("session.cookie_path")); +var_dump(session_destroy()); +var_dump(ini_get("session.cookie_path")); +var_dump(session_set_cookie_params(3600, "/guff")); +var_dump(ini_get("session.cookie_path")); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_cookie_params() : variation *** +string(5) "/path" +NULL +string(4) "/foo" +bool(true) +string(4) "/foo" +NULL +string(5) "/blah" +bool(true) +string(5) "/blah" +NULL +string(5) "/guff" +Done + diff --git a/ext/session/tests/session_set_cookie_params_variation3.phpt b/ext/session/tests/session_set_cookie_params_variation3.phpt new file mode 100644 index 0000000..5e8f0ff --- /dev/null +++ b/ext/session/tests/session_set_cookie_params_variation3.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test session_set_cookie_params() function : variation +--INI-- +session.cookie_domain=foo +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : void session_set_cookie_params(int $lifetime [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]) + * Description : Set the session cookie parameters + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_cookie_params() : variation ***\n"; + +var_dump(ini_get("session.cookie_domain")); +var_dump(session_set_cookie_params(3600, "/path", "blah")); +var_dump(ini_get("session.cookie_domain")); +var_dump(session_start()); +var_dump(ini_get("session.cookie_domain")); +var_dump(session_set_cookie_params(3600, "/path", "guff")); +var_dump(ini_get("session.cookie_domain")); +var_dump(session_destroy()); +var_dump(ini_get("session.cookie_domain")); +var_dump(session_set_cookie_params(3600, "/path", "foo")); +var_dump(ini_get("session.cookie_domain")); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_cookie_params() : variation *** +string(3) "foo" +NULL +string(4) "blah" +bool(true) +string(4) "blah" +NULL +string(4) "guff" +bool(true) +string(4) "guff" +NULL +string(3) "foo" +Done + diff --git a/ext/session/tests/session_set_cookie_params_variation4.phpt b/ext/session/tests/session_set_cookie_params_variation4.phpt new file mode 100644 index 0000000..7b82596 --- /dev/null +++ b/ext/session/tests/session_set_cookie_params_variation4.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test session_set_cookie_params() function : variation +--INI-- +session.cookie_secure=TRUE +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : void session_set_cookie_params(int $lifetime [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]) + * Description : Set the session cookie parameters + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_cookie_params() : variation ***\n"; + +var_dump(ini_get("session.cookie_secure")); +var_dump(session_set_cookie_params(3600, "/path", "blah", FALSE)); +var_dump(ini_get("session.cookie_secure")); +var_dump(session_start()); +var_dump(ini_get("session.cookie_secure")); +var_dump(session_set_cookie_params(3600, "/path", "blah", TRUE)); +var_dump(ini_get("session.cookie_secure")); +var_dump(session_destroy()); +var_dump(ini_get("session.cookie_secure")); +var_dump(session_set_cookie_params(3600, "/path", "blah", FALSE)); +var_dump(ini_get("session.cookie_secure")); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_cookie_params() : variation *** +string(1) "1" +NULL +string(1) "0" +bool(true) +string(1) "0" +NULL +string(1) "1" +bool(true) +string(1) "1" +NULL +string(1) "0" +Done + diff --git a/ext/session/tests/session_set_cookie_params_variation5.phpt b/ext/session/tests/session_set_cookie_params_variation5.phpt new file mode 100644 index 0000000..29559f7 --- /dev/null +++ b/ext/session/tests/session_set_cookie_params_variation5.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test session_set_cookie_params() function : variation +--INI-- +session.cookie_httponly=TRUE +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : void session_set_cookie_params(int $lifetime [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]) + * Description : Set the session cookie parameters + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_cookie_params() : variation ***\n"; + +var_dump(ini_get("session.cookie_httponly")); +var_dump(session_set_cookie_params(3600, "/path", "blah", FALSE, FALSE)); +var_dump(ini_get("session.cookie_httponly")); +var_dump(session_start()); +var_dump(ini_get("session.cookie_httponly")); +var_dump(session_set_cookie_params(3600, "/path", "blah", FALSE, TRUE)); +var_dump(ini_get("session.cookie_httponly")); +var_dump(session_destroy()); +var_dump(ini_get("session.cookie_httponly")); +var_dump(session_set_cookie_params(3600, "/path", "blah", FALSE, FALSE)); +var_dump(ini_get("session.cookie_httponly")); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_cookie_params() : variation *** +string(1) "1" +NULL +string(1) "0" +bool(true) +string(1) "0" +NULL +string(1) "1" +bool(true) +string(1) "1" +NULL +string(1) "0" +Done + diff --git a/ext/session/tests/session_set_save_handler_basic.phpt b/ext/session/tests/session_set_save_handler_basic.phpt new file mode 100644 index 0000000..3897ba9 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_basic.phpt @@ -0,0 +1,95 @@ +--TEST-- +Test session_set_save_handler() function : basic functionality +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : basic functionality ***\n"; + +require_once "save_handler.inc"; +var_dump(session_module_name()); +var_dump(session_module_name(FALSE)); +var_dump(session_module_name("blah")); +var_dump(session_module_name("foo")); + +$path = dirname(__FILE__); +session_save_path($path); +session_set_save_handler("open", "close", "read", "write", "destroy", "gc"); + +session_start(); +$_SESSION["Blah"] = "Hello World!"; +$_SESSION["Foo"] = FALSE; +$_SESSION["Guff"] = 1234567890; +var_dump($_SESSION); + +session_write_close(); +session_unset(); +var_dump($_SESSION); + +echo "Starting session again..!\n"; +session_id($session_id); +session_set_save_handler("open", "close", "read", "write", "destroy", "gc"); +session_start(); +var_dump($_SESSION); +session_write_close(); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : basic functionality *** + +string(%d) "%s" + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) + +Warning: session_module_name(): Cannot find named PHP session module (blah) in %s on line %d +bool(false) + +Warning: session_module_name(): Cannot find named PHP session module (foo) in %s on line %d +bool(false) +Open [%s,PHPSESSID] +Read [%s,%s] +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;] +Close [%s,PHPSESSID] +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +Starting session again..! +Open [%s,PHPSESSID] +Read [%s,%s] +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;] +Close [%s,PHPSESSID] diff --git a/ext/session/tests/session_set_save_handler_class_001.phpt b/ext/session/tests/session_set_save_handler_class_001.phpt new file mode 100644 index 0000000..83e899a --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_001.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test session_set_save_handler() : basic class wrapping existing handler +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : basic class wrapping existing handler ***\n"; + +class MySession extends SessionHandler { + public $i = 0; + public function open($path, $name) { + ++$this->i; + echo 'Open ', session_id(), "\n"; + return parent::open($path, $name); + } + public function read($key) { + ++$this->i; + echo 'Read ', session_id(), "\n"; + return parent::read($key); + } +} + +$oldHandler = ini_get('session.save_handler'); +$handler = new MySession; +session_set_save_handler($handler); +session_start(); + +var_dump(session_id(), $oldHandler, ini_get('session.save_handler'), $handler->i, $_SESSION); + +$_SESSION['foo'] = "hello"; + +session_write_close(); +session_unset(); + +session_start(); +var_dump($_SESSION); + +session_write_close(); +session_unset(); + +--EXPECTF-- +*** Testing session_set_save_handler() : basic class wrapping existing handler *** +Open +Read %s +string(%d) "%s" +string(5) "files" +string(4) "user" +int(2) +array(0) { +} +Open %s +Read %s +array(1) { + ["foo"]=> + string(5) "hello" +} diff --git a/ext/session/tests/session_set_save_handler_class_002.phpt b/ext/session/tests/session_set_save_handler_class_002.phpt new file mode 100644 index 0000000..6fb831f --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_002.phpt @@ -0,0 +1,113 @@ +--TEST-- +Test session_set_save_handler() : full handler implementation +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : full handler implementation ***\n"; + +class MySession2 extends SessionHandler { + public $path; + + public function open($path, $name) { + if (!$path) { + $path = sys_get_temp_dir(); + } + $this->path = $path . '/u_sess_' . $name; + return true; + } + + public function close() { + return true; + } + + public function read($id) { + return @file_get_contents($this->path . $id); + } + + public function write($id, $data) { + return file_put_contents($this->path . $id, $data); + } + + public function destroy($id) { + @unlink($this->path . $id); + } + + public function gc($maxlifetime) { + foreach (glob($this->path . '*') as $filename) { + if (filemtime($filename) + $maxlifetime < time()) { + @unlink($filename); + } + } + return true; + } +} + +$handler = new MySession2; +session_set_save_handler(array($handler, 'open'), array($handler, 'close'), + array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc')); +session_start(); + +$_SESSION['foo'] = "hello"; + +var_dump(session_id(), ini_get('session.save_handler'), $_SESSION); + +session_write_close(); +session_unset(); + +session_start(); +var_dump($_SESSION); + +session_write_close(); +session_unset(); + +session_set_save_handler($handler); +session_start(); + +$_SESSION['foo'] = "hello"; + +var_dump(session_id(), ini_get('session.save_handler'), $_SESSION); + +session_write_close(); +session_unset(); + +session_start(); +var_dump($_SESSION); + +session_write_close(); +session_unset(); + +--EXPECTF-- +*** Testing session_set_save_handler() : full handler implementation *** +string(%d) "%s" +string(4) "user" +array(1) { + ["foo"]=> + string(5) "hello" +} +array(1) { + ["foo"]=> + string(5) "hello" +} +string(%d) "%s" +string(4) "user" +array(1) { + ["foo"]=> + string(5) "hello" +} +array(1) { + ["foo"]=> + string(5) "hello" +} diff --git a/ext/session/tests/session_set_save_handler_class_003.phpt b/ext/session/tests/session_set_save_handler_class_003.phpt new file mode 100644 index 0000000..e9a3cc2 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_003.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test session_set_save_handler() : inheritance +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : inheritance ***\n"; + +class MySession3 extends SessionHandler { + public $i = 0; + public function open($path, $name) { + ++$this->i; + return parent::open($path, $name); + } + public function read($key) { + ++$this->i; + return parent::read($key); + } +} + +class MySession4 extends MySession3 { + public function write($id, $data) { + $this->i = "hai"; + return parent::write($id, $data); + } +} + +$handler = new MySession3; +session_set_save_handler($handler); +session_start(); + +$_SESSION['foo'] = "hello"; + +session_write_close(); +session_unset(); + +session_start(); + +var_dump($_SESSION, $handler->i); + +session_write_close(); +session_unset(); + +$handler = new MySession4; +session_set_save_handler($handler); + +session_start(); + +session_write_close(); +session_unset(); + +var_dump(session_id(), $_SESSION, $handler->i); + +--EXPECTF-- +*** Testing session_set_save_handler() : inheritance *** +array(1) { + ["foo"]=> + string(5) "hello" +} +int(4) +string(%d) "%s" +array(1) { + ["foo"]=> + string(5) "hello" +} +string(3) "hai" diff --git a/ext/session/tests/session_set_save_handler_class_004.phpt b/ext/session/tests/session_set_save_handler_class_004.phpt new file mode 100644 index 0000000..103b13b --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_004.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test session_set_save_handler() : default object +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : default object ***\n"; + +session_set_save_handler(new SessionHandler); +session_start(); + +$_SESSION['foo'] = "hello"; + +var_dump(session_id(), ini_get('session.save_handler'), $_SESSION); + +session_write_close(); +session_unset(); +session_start(); + +var_dump($_SESSION); + +session_write_close(); +session_unset(); + +--EXPECTF-- +*** Testing session_set_save_handler() : default object *** +string(%d) "%s" +string(4) "user" +array(1) { + ["foo"]=> + string(5) "hello" +} +array(1) { + ["foo"]=> + string(5) "hello" +} diff --git a/ext/session/tests/session_set_save_handler_class_005.phpt b/ext/session/tests/session_set_save_handler_class_005.phpt new file mode 100644 index 0000000..a996eb8 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_005.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test session_set_save_handler() : incomplete implementation +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : incomplete implementation ***\n"; + +class MySession6 extends SessionHandler { + public function open($path, $name) { + // don't call parent + return true; + } + + public function read($id) { + // should error because parent::open hasn't been called + return parent::read($id); + } +} + +$handler = new MySession6; +session_set_save_handler($handler); +session_start(); + +var_dump(session_id(), ini_get('session.save_handler'), $_SESSION); + +session_write_close(); +session_unset(); + + +--EXPECTF-- +*** Testing session_set_save_handler() : incomplete implementation *** + +Warning: SessionHandler::read(): Parent session handler is not open in %ssession_set_save_handler_class_005.php on line %d +string(%d) "%s" +string(4) "user" +array(0) { +} + +Warning: SessionHandler::write(): Parent session handler is not open in %ssession_set_save_handler_class_005.php on line %d + +Warning: SessionHandler::close(): Parent session handler is not open in %ssession_set_save_handler_class_005.php on line %d diff --git a/ext/session/tests/session_set_save_handler_class_006.phpt b/ext/session/tests/session_set_save_handler_class_006.phpt new file mode 100644 index 0000000..5830b6d --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_006.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test session_set_save_handler() : using objects in close +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : using objects in close ***\n"; + +class MySession7_Foo { + public $state = 'ok'; + function __destruct() { + $this->state = 'destroyed'; + } +} + +class MySession7 extends SessionHandler { + public $foo; + public function close() { + var_dump($this->foo); + @var_dump($GLOBALS['bar']); + return parent::close(); + } +} + +$bar = new MySession7_Foo; +$handler = new MySession7; +$handler->foo = new MySession7_Foo; +session_set_save_handler($handler); +session_start(); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : using objects in close *** +object(MySession7_Foo)#%d (%d) { + ["state"]=> + string(2) "ok" +} +object(MySession7_Foo)#%d (%d) { + ["state"]=> + string(2) "ok" +} diff --git a/ext/session/tests/session_set_save_handler_class_007.phpt b/ext/session/tests/session_set_save_handler_class_007.phpt new file mode 100644 index 0000000..7344ae1 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_007.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test session_set_save_handler() : manual shutdown, reopen +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : manual shutdown, reopen ***\n"; + +class MySession extends SessionHandler { + public $num; + public function __construct($num) { + $this->num = $num; + echo "(#$this->num) constructor called\n"; + } + public function __destruct() { + echo "(#$this->num) destructor called\n"; + } + public function finish() { + $id = session_id(); + echo "(#$this->num) finish called $id\n"; + session_write_close(); + } + public function write($id, $data) { + echo "(#$this->num) writing $id = $data\n"; + return parent::write($id, $data); + } + public function close() { + $id = session_id(); + echo "(#$this->num) closing $id\n"; + return parent::close(); + } +} + +$handler = new MySession(1); +session_set_save_handler($handler); +session_start(); + +$_SESSION['foo'] = 'bar'; + +// explicit close +$handler->finish(); + +$handler = new MySession(2); +session_set_save_handler($handler); +session_start(); + +// implicit close (called by shutdown function) +echo "done\n"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : manual shutdown, reopen *** +(#1) constructor called +(#1) finish called %s +(#1) writing %s = foo|s:3:"bar"; +(#1) closing %s +(#2) constructor called +(#1) destructor called +done +(#2) writing %s = foo|s:3:"bar"; +(#2) closing %s +(#2) destructor called diff --git a/ext/session/tests/session_set_save_handler_class_008.phpt b/ext/session/tests/session_set_save_handler_class_008.phpt new file mode 100644 index 0000000..28cb692 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_008.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test session_set_save_handler() : manual shutdown +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : manual shutdown ***\n"; + +class MySession extends SessionHandler { + public $num; + public function __construct($num) { + $this->num = $num; + echo "(#$this->num) constructor called\n"; + } + public function __destruct() { + echo "(#$this->num) destructor called\n"; + } + public function finish() { + $id = session_id(); + echo "(#$this->num) finish called $id\n"; + session_write_close(); + } + public function write($id, $data) { + echo "(#$this->num) writing $id = $data\n"; + return parent::write($id, $data); + } + public function close() { + $id = session_id(); + echo "(#$this->num) closing $id\n"; + return parent::close(); + } +} + +$handler = new MySession(1); +session_set_save_handler($handler); +session_start(); + +$_SESSION['foo'] = 'bar'; + +// explicit close +$handler->finish(); + +echo "done\n"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : manual shutdown *** +(#1) constructor called +(#1) finish called %s +(#1) writing %s = foo|s:3:"bar"; +(#1) closing %s +done +(#1) destructor called diff --git a/ext/session/tests/session_set_save_handler_class_009.phpt b/ext/session/tests/session_set_save_handler_class_009.phpt new file mode 100644 index 0000000..a8b57dc --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_009.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test session_set_save_handler() : implicit shutdown +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : implicit shutdown ***\n"; + +class MySession extends SessionHandler { + public $num; + public function __construct($num) { + $this->num = $num; + echo "(#$this->num) constructor called\n"; + } + public function __destruct() { + echo "(#$this->num) destructor called\n"; + } + public function finish() { + $id = session_id(); + echo "(#$this->num) finish called $id\n"; + $this->shutdown(); + } + public function write($id, $data) { + echo "(#$this->num) writing $id = $data\n"; + return parent::write($id, $data); + } + public function close() { + $id = session_id(); + echo "(#$this->num) closing $id\n"; + return parent::close(); + } +} + +$handler = new MySession(1); +session_set_save_handler($handler); +session_start(); + +$_SESSION['foo'] = 'bar'; + +// implicit close +echo "done\n"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : implicit shutdown *** +(#1) constructor called +done +(#1) writing %s = foo|s:3:"bar"; +(#1) closing %s +(#1) destructor called diff --git a/ext/session/tests/session_set_save_handler_class_010.phpt b/ext/session/tests/session_set_save_handler_class_010.phpt new file mode 100644 index 0000000..02304f4 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_010.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test session_set_save_handler() : manual shutdown function +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : manual shutdown function ***\n"; + +class MySession extends SessionHandler { + public $num; + public function __construct($num) { + $this->num = $num; + echo "(#$this->num) constructor called\n"; + } + public function __destruct() { + echo "(#$this->num) destructor called\n"; + } + public function finish() { + $id = session_id(); + echo "(#$this->num) finish called $id\n"; + session_write_close(); + } + public function write($id, $data) { + echo "(#$this->num) writing $id = $data\n"; + return parent::write($id, $data); + } + public function close() { + $id = session_id(); + echo "(#$this->num) closing $id\n"; + return parent::close(); + } +} + +$handler = new MySession(1); +session_set_save_handler($handler, false); +register_shutdown_function(array($handler, 'finish')); +session_start(); + +$_SESSION['foo'] = 'bar'; + +echo "done\n"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : manual shutdown function *** +(#1) constructor called +done +(#1) finish called %s +(#1) writing %s = foo|s:3:"bar"; +(#1) closing %s +(#1) destructor called diff --git a/ext/session/tests/session_set_save_handler_class_011.phpt b/ext/session/tests/session_set_save_handler_class_011.phpt new file mode 100644 index 0000000..7fa3657 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_011.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test session_set_save_handler() : shutdown failure +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : shutdown failure ***\n"; + +class MySession extends SessionHandler { + public $num; + public $destroyed = false; + public function __construct($num) { + $this->num = $num; + echo "(#$this->num) constructor called\n"; + } + public function __destruct() { + echo "(#$this->num) destructor called\n"; + $this->destroyed = true; + } + public function write($id, $data) { + if ($this->destroyed) { + echo "(#$this->num) destroyed, cannot write\n"; + } else { + echo "(#$this->num) writing $id = $data\n"; + } + return parent::write($id, $data); + } + public function close() { + $id = session_id(); + if ($this->destroyed) { + echo "(#$this->num) destroyed, cannot write\n"; + } else { + echo "(#$this->num) closing $id\n"; + } + return parent::close(); + } +} + +$handler = new MySession(1); +session_set_save_handler($handler, false); +session_start(); + +$_SESSION['foo'] = 'bar'; + +echo "done\n"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : shutdown failure *** +(#1) constructor called +done +(#1) destructor called +(#1) destroyed, cannot write +(#1) destroyed, cannot write diff --git a/ext/session/tests/session_set_save_handler_class_012.phpt b/ext/session/tests/session_set_save_handler_class_012.phpt new file mode 100644 index 0000000..706ef79 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_012.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test session_set_save_handler() : incorrect arguments for existing handler open +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : incorrect arguments for existing handler open ***\n"; + +class MySession extends SessionHandler { + public $i = 0; + public function open($path, $name) { + ++$this->i; + echo 'Open ', session_id(), "\n"; + return parent::open(); + } + public function read($key) { + ++$this->i; + echo 'Read ', session_id(), "\n"; + return parent::read($key); + } +} + +$oldHandler = ini_get('session.save_handler'); +$handler = new MySession; +session_set_save_handler($handler); +session_start(); + +var_dump(session_id(), $oldHandler, ini_get('session.save_handler'), $handler->i, $_SESSION); + +--EXPECTF-- +*** Testing session_set_save_handler() : incorrect arguments for existing handler open *** +Open + +Warning: SessionHandler::open() expects exactly 2 parameters, 0 given in %s on line %d +Read %s + +Warning: SessionHandler::read(): Parent session handler is not open in %s on line %d +string(%d) "%s" +string(5) "files" +string(4) "user" +int(2) +array(0) { +} + +Warning: Unknown: Parent session handler is not open in Unknown on line 0 + +Warning: Unknown: Parent session handler is not open in Unknown on line 0 diff --git a/ext/session/tests/session_set_save_handler_class_013.phpt b/ext/session/tests/session_set_save_handler_class_013.phpt new file mode 100644 index 0000000..f536aa7 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_013.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test session_set_save_handler() : incorrect arguments for existing handler close +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : incorrect arguments for existing handler close ***\n"; + +class MySession extends SessionHandler { + public $i = 0; + public function open($path, $name) { + ++$this->i; + echo 'Open ', session_id(), "\n"; + return parent::open($path, $name); + } + public function read($key) { + ++$this->i; + echo 'Read ', session_id(), "\n"; + return parent::read($key); + } + public function close() { + return parent::close(false); + } +} + +$oldHandler = ini_get('session.save_handler'); +$handler = new MySession; +session_set_save_handler($handler); +session_start(); + +var_dump(session_id(), $oldHandler, ini_get('session.save_handler'), $handler->i, $_SESSION); + +--EXPECTF-- +*** Testing session_set_save_handler() : incorrect arguments for existing handler close *** +Open +Read %s +string(%d) "%s" +string(5) "files" +string(4) "user" +int(2) +array(0) { +} + +Warning: SessionHandler::close() expects exactly 0 parameters, 1 given in %s on line %d diff --git a/ext/session/tests/session_set_save_handler_class_014.phpt b/ext/session/tests/session_set_save_handler_class_014.phpt new file mode 100644 index 0000000..ea62beb --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_014.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test session_set_save_handler() : calling default handler when save_handler=user +--INI-- +session.save_handler=user +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : calling default handler when save_handler=user ***\n"; + +$oldHandler = ini_get('session.save_handler'); +$handler = new SessionHandler; +session_set_save_handler($handler); + +session_start(); + +--EXPECTF-- +*** Testing session_set_save_handler() : calling default handler when save_handler=user *** + +Fatal error: SessionHandler::open(): Cannot call default session handler in %s on line %d diff --git a/ext/session/tests/session_set_save_handler_class_015.phpt b/ext/session/tests/session_set_save_handler_class_015.phpt new file mode 100644 index 0000000..3bef51b --- /dev/null +++ b/ext/session/tests/session_set_save_handler_class_015.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test session_set_save_handler() : register session handler but don't start +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : register session handler but don't start ***\n"; + +session_set_save_handler(new SessionHandler); + +--EXPECTF-- +*** Testing session_set_save_handler() : register session handler but don't start *** diff --git a/ext/session/tests/session_set_save_handler_closures.phpt b/ext/session/tests/session_set_save_handler_closures.phpt new file mode 100644 index 0000000..21b2c68 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_closures.phpt @@ -0,0 +1,95 @@ +--TEST-- +Test session_set_save_handler() function : using closures as callbacks +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : using closures as callbacks ***\n"; + +require_once "save_handler_closures.inc"; +var_dump(session_module_name()); +var_dump(session_module_name(FALSE)); +var_dump(session_module_name("blah")); +var_dump(session_module_name("foo")); + +$path = dirname(__FILE__); +session_save_path($path); +session_set_save_handler($open_closure, $close_closure, $read_closure, $write_closure, $destroy_closure, $gc_closure); + +session_start(); +$_SESSION["Blah"] = "Hello World!"; +$_SESSION["Foo"] = FALSE; +$_SESSION["Guff"] = 1234567890; +var_dump($_SESSION); + +session_write_close(); +session_unset(); +var_dump($_SESSION); + +echo "Starting session again..!\n"; +session_id($session_id); +session_set_save_handler($open_closure, $close_closure, $read_closure, $write_closure, $destroy_closure, $gc_closure); +session_start(); +var_dump($_SESSION); +session_write_close(); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : using closures as callbacks *** + +string(%d) "%s" + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) + +Warning: session_module_name(): Cannot find named PHP session module (blah) in %s on line %d +bool(false) + +Warning: session_module_name(): Cannot find named PHP session module (foo) in %s on line %d +bool(false) +Open [%s,PHPSESSID] +Read [%s,%s] +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;] +Close [%s,PHPSESSID] +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +Starting session again..! +Open [%s,PHPSESSID] +Read [%s,%s] +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;] +Close [%s,PHPSESSID] diff --git a/ext/session/tests/session_set_save_handler_error.phpt b/ext/session/tests/session_set_save_handler_error.phpt new file mode 100644 index 0000000..bf9d25d --- /dev/null +++ b/ext/session/tests/session_set_save_handler_error.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test session_set_save_handler() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_set_save_handler($input, NULL, NULL, NULL, NULL, NULL)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : error functionality *** + +-- Iteration 1 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: session_set_save_handler(): Argument 1 is not a valid callback in %s on line %d +bool(false) +Done + diff --git a/ext/session/tests/session_set_save_handler_error2.phpt b/ext/session/tests/session_set_save_handler_error2.phpt new file mode 100644 index 0000000..03ba3b0 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_error2.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test session_set_save_handler() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : error functionality ***\n"; + +function open($save_path, $session_name) { return true; } +function close() { return true; } +function read($id) { return false; } +function write($id, $session_data) { } +function destroy($id) { return true; } +function gc($maxlifetime) { return true; } + +session_set_save_handler("open", "close", "read", "write", "destroy", "gc"); + +session_start(); +$_SESSION["Blah"] = "Hello World!"; +$_SESSION["Foo"] = FALSE; +$_SESSION["Guff"] = 1234567890; +var_dump($_SESSION); + +session_write_close(); +var_dump($_SESSION); +session_set_save_handler("open", "close", "read", "write", "destroy", "gc"); +session_start(); +var_dump($_SESSION); +session_destroy(); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : error functionality *** +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +array(0) { +} + diff --git a/ext/session/tests/session_set_save_handler_error3.phpt b/ext/session/tests/session_set_save_handler_error3.phpt new file mode 100644 index 0000000..446ef7b --- /dev/null +++ b/ext/session/tests/session_set_save_handler_error3.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test session_set_save_handler() function : error functionality +--INI-- +session.save_path= +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : error functionality ***\n"; +function open($save_path, $session_name) { + throw new Exception("Do something bad..!"); +} + +function close() { return true; } +function read($id) { return false; } +function write($id, $session_data) { } +function destroy($id) { return true; } +function gc($maxlifetime) { return true; } + +session_set_save_handler("open", "close", "read", "write", "destroy", "gc"); +session_start(); +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : error functionality *** + +Fatal error: Uncaught exception 'Exception' with message 'Do something bad..!' in %s:%d +Stack trace: +#0 [internal function]: open('', 'PHPSESSID') +#1 %s(%d): session_start() +#2 {main} + thrown in %s on line %d + diff --git a/ext/session/tests/session_set_save_handler_error4.phpt b/ext/session/tests/session_set_save_handler_error4.phpt new file mode 100644 index 0000000..4debde5 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_error4.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test session_set_save_handler() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : error functionality ***\n"; + +function callback() { } + +session_set_save_handler("callback", "callback", "callback", "callback", "callback", "callback"); +session_set_save_handler("callback", "echo", "callback", "callback", "callback", "callback"); +session_set_save_handler("callback", "callback", "echo", "callback", "callback", "callback"); +session_set_save_handler("callback", "callback", "callback", "echo", "callback", "callback"); +session_set_save_handler("callback", "callback", "callback", "callback", "echo", "callback"); +session_set_save_handler("callback", "callback", "callback", "callback", "callback", "echo"); +session_set_save_handler("callback", "callback", "callback", "callback", "callback", "callback"); +session_start(); +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : error functionality *** + +Warning: session_set_save_handler(): Argument 2 is not a valid callback in %s on line %d + +Warning: session_set_save_handler(): Argument 3 is not a valid callback in %s on line %d + +Warning: session_set_save_handler(): Argument 4 is not a valid callback in %s on line %d + +Warning: session_set_save_handler(): Argument 5 is not a valid callback in %s on line %d + +Warning: session_set_save_handler(): Argument 6 is not a valid callback in %s on line %d + diff --git a/ext/session/tests/session_set_save_handler_iface_001.phpt b/ext/session/tests/session_set_save_handler_iface_001.phpt new file mode 100644 index 0000000..39a4b99 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_iface_001.phpt @@ -0,0 +1,113 @@ +--TEST-- +Test session_set_save_handler() function: interface +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandlerInterface $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() function: interface ***\n"; + +class MySession2 implements SessionHandlerInterface { + public $path; + + public function open($path, $name) { + if (!$path) { + $path = sys_get_temp_dir(); + } + $this->path = $path . '/u_sess_' . $name; + return true; + } + + public function close() { + return true; + } + + public function read($id) { + return @file_get_contents($this->path . $id); + } + + public function write($id, $data) { + return file_put_contents($this->path . $id, $data); + } + + public function destroy($id) { + @unlink($this->path . $id); + } + + public function gc($maxlifetime) { + foreach (glob($this->path . '*') as $filename) { + if (filemtime($filename) + $maxlifetime < time()) { + @unlink($filename); + } + } + return true; + } +} + +$handler = new MySession2; +session_set_save_handler(array($handler, 'open'), array($handler, 'close'), + array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc')); +session_start(); + +$_SESSION['foo'] = "hello"; + +var_dump(session_id(), ini_get('session.save_handler'), $_SESSION); + +session_write_close(); +session_unset(); + +session_start(); +var_dump($_SESSION); + +session_write_close(); +session_unset(); + +session_set_save_handler($handler); +session_start(); + +$_SESSION['foo'] = "hello"; + +var_dump(session_id(), ini_get('session.save_handler'), $_SESSION); + +session_write_close(); +session_unset(); + +session_start(); +var_dump($_SESSION); + +session_write_close(); +session_unset(); + +--EXPECTF-- +*** Testing session_set_save_handler() function: interface *** +string(%d) "%s" +string(4) "user" +array(1) { + ["foo"]=> + string(5) "hello" +} +array(1) { + ["foo"]=> + string(5) "hello" +} +string(%d) "%s" +string(4) "user" +array(1) { + ["foo"]=> + string(5) "hello" +} +array(1) { + ["foo"]=> + string(5) "hello" +} diff --git a/ext/session/tests/session_set_save_handler_iface_002.phpt b/ext/session/tests/session_set_save_handler_iface_002.phpt new file mode 100644 index 0000000..40c9ac6 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_iface_002.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test session_set_save_handler() function: interface wrong +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(SessionHandlerInterface $handler [, bool $register_shutdown_function = true]) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() function: interface wrong ***\n"; + +interface MySessionHandlerInterface { + public function open($path, $name); + public function close(); + public function read($id); + public function write($id, $data); + public function destroy($id); + public function gc($maxlifetime); +} + +class MySession2 implements MySessionHandlerInterface { + public $path; + + public function open($path, $name) { + if (!$path) { + $path = sys_get_temp_dir(); + } + $this->path = $path . '/u_sess_' . $name; + return true; + } + + public function close() { + return true; + } + + public function read($id) { + return @file_get_contents($this->path . $id); + } + + public function write($id, $data) { + echo "Unsupported session handler in use\n"; + } + + public function destroy($id) { + @unlink($this->path . $id); + } + + public function gc($maxlifetime) { + foreach (glob($this->path . '*') as $filename) { + if (filemtime($filename) + $maxlifetime < time()) { + @unlink($filename); + } + } + return true; + } +} + +function good_write($id, $data) { + global $handler; + echo "good handler writing\n"; + return file_put_contents($handler->path . $id, $data); +} + +$handler = new MySession2; + +$ret = session_set_save_handler(array($handler, 'open'), array($handler, 'close'), + array($handler, 'read'), 'good_write', array($handler, 'destroy'), array($handler, 'gc')); + +var_dump($ret); +$ret = session_set_save_handler($handler); +var_dump($ret); + +session_start(); + +--EXPECTF-- +*** Testing session_set_save_handler() function: interface wrong *** +bool(true) + +Warning: session_set_save_handler() expects parameter 1 to be SessionHandlerInterface, object given in %s +bool(false) +good handler writing diff --git a/ext/session/tests/session_set_save_handler_variation1.phpt b/ext/session/tests/session_set_save_handler_variation1.phpt new file mode 100644 index 0000000..fe1d2b0 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_variation1.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test session_set_save_handler() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : variation ***\n"; + +var_dump(session_module_name()); +var_dump(session_module_name(FALSE)); +var_dump(session_module_name()); +var_dump(session_module_name("blah")); +var_dump(session_module_name()); +var_dump(session_module_name("files")); +var_dump(session_module_name()); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : variation *** +string(%d) "%s" + +Warning: session_module_name(): Cannot find named PHP session module () in %s on line %d +bool(false) +string(%d) "%s" + +Warning: session_module_name(): Cannot find named PHP session module (blah) in %s on line %d +bool(false) +string(%d) "%s" +string(%d) "%s" +string(5) "files" diff --git a/ext/session/tests/session_set_save_handler_variation2.phpt b/ext/session/tests/session_set_save_handler_variation2.phpt new file mode 100644 index 0000000..1c019bb --- /dev/null +++ b/ext/session/tests/session_set_save_handler_variation2.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test session_set_save_handler() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : variation ***\n"; + +require_once "save_handler.inc"; +$path = dirname(__FILE__); +session_save_path($path); +var_dump(session_start()); +var_dump(session_set_save_handler("open", "close", "read", "write", "destroy", "gc")); +var_dump(session_destroy()); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : variation *** + +bool(true) +bool(false) +bool(true) + diff --git a/ext/session/tests/session_set_save_handler_variation3.phpt b/ext/session/tests/session_set_save_handler_variation3.phpt new file mode 100644 index 0000000..774d0db --- /dev/null +++ b/ext/session/tests/session_set_save_handler_variation3.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test session_set_save_handler() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.auto_start=1 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : variation ***\n"; + +require_once "save_handler.inc"; +$path = dirname(__FILE__); +session_save_path($path); +var_dump(session_set_save_handler("open", "close", "read", "write", "destroy", "gc")); +var_dump(session_destroy()); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : variation *** + +bool(false) +bool(true) + diff --git a/ext/session/tests/session_set_save_handler_variation4.phpt b/ext/session/tests/session_set_save_handler_variation4.phpt new file mode 100644 index 0000000..3485f23 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_variation4.phpt @@ -0,0 +1,83 @@ +--TEST-- +Test session_set_save_handler() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.gc_probability=1 +session.gc_divisor=1 +session.gc_maxlifetime=0 +session.save_path= +session.name=PHPSESSID +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : variation ***\n"; + +function noisy_gc($maxlifetime) { + echo("GC [".$maxlifetime."]\n"); + gc($maxlifetime); +} + +require_once "save_handler.inc"; +$path = dirname(__FILE__); +session_save_path($path); +session_set_save_handler("open", "close", "read", "write", "destroy", "noisy_gc"); + +session_start(); +$_SESSION["Blah"] = "Hello World!"; +$_SESSION["Foo"] = FALSE; +$_SESSION["Guff"] = 1234567890; +var_dump($_SESSION); +$session_id = session_id(); +var_dump(session_write_close()); + +session_set_save_handler("open", "close", "read", "write", "destroy", "noisy_gc"); +session_id($session_id); +session_start(); +var_dump($_SESSION); +var_dump(session_destroy()); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : variation *** + +Open [%s,PHPSESSID] +Read [%s,%s] +GC [0] +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;] +Close [%s,PHPSESSID] +NULL +Open [%s,PHPSESSID] +Read [%s,%s] +GC [0] +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +Destroy [%s,%s] + +Warning: unlink(%s): No such file or directory in %s on line %d +Close [%s,PHPSESSID] +bool(true) + diff --git a/ext/session/tests/session_start_error.phpt b/ext/session/tests/session_start_error.phpt new file mode 100644 index 0000000..8cbf42c --- /dev/null +++ b/ext/session/tests/session_start_error.phpt @@ -0,0 +1,195 @@ +--TEST-- +Test session_start() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_start(void) + * Description : Initialize session data + * Source code : ext/session/session.c + */ + +echo "*** Testing session_start() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_start($input)); + var_dump(session_destroy()); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_start() : error functionality *** + +-- Iteration 1 -- +bool(true) +bool(true) + +-- Iteration 2 -- +bool(true) +bool(true) + +-- Iteration 3 -- +bool(true) +bool(true) + +-- Iteration 4 -- +bool(true) +bool(true) + +-- Iteration 5 -- +bool(true) +bool(true) + +-- Iteration 6 -- +bool(true) +bool(true) + +-- Iteration 7 -- +bool(true) +bool(true) + +-- Iteration 8 -- +bool(true) +bool(true) + +-- Iteration 9 -- +bool(true) +bool(true) + +-- Iteration 10 -- +bool(true) +bool(true) + +-- Iteration 11 -- +bool(true) +bool(true) + +-- Iteration 12 -- +bool(true) +bool(true) + +-- Iteration 13 -- +bool(true) +bool(true) + +-- Iteration 14 -- +bool(true) +bool(true) + +-- Iteration 15 -- +bool(true) +bool(true) + +-- Iteration 16 -- +bool(true) +bool(true) + +-- Iteration 17 -- +bool(true) +bool(true) + +-- Iteration 18 -- +bool(true) +bool(true) + +-- Iteration 19 -- +bool(true) +bool(true) + +-- Iteration 20 -- +bool(true) +bool(true) + +-- Iteration 21 -- +bool(true) +bool(true) + +-- Iteration 22 -- +bool(true) +bool(true) + +-- Iteration 23 -- +bool(true) +bool(true) + +-- Iteration 24 -- +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_start_variation1.phpt b/ext/session/tests/session_start_variation1.phpt new file mode 100644 index 0000000..1c8f3eb --- /dev/null +++ b/ext/session/tests/session_start_variation1.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_start(void) + * Description : Initialize session data + * Source code : ext/session/session.c + */ + +echo "*** Testing session_start() : variation ***\n"; + +var_dump(session_start()); +var_dump(session_start()); +var_dump(session_start()); +var_dump(session_start()); +var_dump(session_start()); + +session_destroy(); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_start() : variation *** +bool(true) + +Notice: A session had already been started - ignoring session_start() in %s on line %d +bool(true) + +Notice: A session had already been started - ignoring session_start() in %s on line %d +bool(true) + +Notice: A session had already been started - ignoring session_start() in %s on line %d +bool(true) + +Notice: A session had already been started - ignoring session_start() in %s on line %d +bool(true) +Done + diff --git a/ext/session/tests/session_start_variation2.phpt b/ext/session/tests/session_start_variation2.phpt new file mode 100644 index 0000000..6c9b29e --- /dev/null +++ b/ext/session/tests/session_start_variation2.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_start(void) + * Description : Initialize session data + * Source code : ext/session/session.c + */ + +echo "*** Testing session_start() : variation ***\n"; + +var_dump(session_start()); +var_dump(session_destroy()); +var_dump(session_start()); +var_dump(session_destroy()); +var_dump(session_start()); +var_dump(session_destroy()); +var_dump(session_start()); +var_dump(session_destroy()); +var_dump(session_start()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_start() : variation *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_start_variation3.phpt b/ext/session/tests/session_start_variation3.phpt new file mode 100644 index 0000000..e87f84b --- /dev/null +++ b/ext/session/tests/session_start_variation3.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_start(void) + * Description : Initialize session data + * Source code : ext/session/session.c + */ + +echo "*** Testing session_start() : variation ***\n"; + +var_dump(session_start()); +var_dump(session_write_close()); +var_dump(session_start()); +var_dump(session_write_close()); +var_dump(session_start()); +var_dump(session_write_close()); +var_dump(session_start()); +var_dump(session_write_close()); +var_dump(session_start()); +var_dump(session_write_close()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_start() : variation *** +bool(true) +NULL +bool(true) +NULL +bool(true) +NULL +bool(true) +NULL +bool(true) +NULL + +Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d +bool(false) +Done + diff --git a/ext/session/tests/session_start_variation4.phpt b/ext/session/tests/session_start_variation4.phpt new file mode 100644 index 0000000..4289549 --- /dev/null +++ b/ext/session/tests/session_start_variation4.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_start(void) + * Description : Initialize session data + * Source code : ext/session/session.c + */ + +echo "*** Testing session_start() : variation ***\n"; + +$_SESSION['blah'] = 'foo'; +var_dump($_SESSION); +session_start(); +var_dump($_SESSION); + +session_destroy(); +echo "Done"; +ob_end_flush(); + +?> +--EXPECTF-- +*** Testing session_start() : variation *** +array(1) { + ["blah"]=> + string(3) "foo" +} +array(0) { +} +Done + diff --git a/ext/session/tests/session_start_variation5.phpt b/ext/session/tests/session_start_variation5.phpt new file mode 100644 index 0000000..4dcafac --- /dev/null +++ b/ext/session/tests/session_start_variation5.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_start(void) + * Description : Initialize session data + * Source code : ext/session/session.c + */ + +echo "*** Testing session_start() : variation ***\n"; + +session_start(); + +$_SESSION['colour'] = 'green'; +$_SESSION['animal'] = 'cat'; +$_SESSION['person'] = 'julia'; +$_SESSION['age'] = 6; + +var_dump($_SESSION); +var_dump(session_write_close()); +var_dump($_SESSION); + +session_start(); +session_destroy(); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_start() : variation *** +array(4) { + ["colour"]=> + string(5) "green" + ["animal"]=> + string(3) "cat" + ["person"]=> + string(5) "julia" + ["age"]=> + int(6) +} +NULL +array(4) { + ["colour"]=> + string(5) "green" + ["animal"]=> + string(3) "cat" + ["person"]=> + string(5) "julia" + ["age"]=> + int(6) +} +Done + diff --git a/ext/session/tests/session_start_variation6.phpt b/ext/session/tests/session_start_variation6.phpt new file mode 100644 index 0000000..378554b --- /dev/null +++ b/ext/session/tests/session_start_variation6.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_start(void) + * Description : Initialize session data + * Source code : ext/session/session.c + */ + +echo "*** Testing session_start() : variation ***\n"; + +session_start(); + +$_SESSION['colour'] = 'green'; +$_SESSION['animal'] = 'cat'; +$_SESSION['person'] = 'julia'; +$_SESSION['age'] = 6; + +var_dump($_SESSION); +var_dump(session_write_close()); +var_dump($_SESSION); +session_start(); +var_dump($_SESSION); + +session_destroy(); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_start() : variation *** +array(4) { + ["colour"]=> + string(5) "green" + ["animal"]=> + string(3) "cat" + ["person"]=> + string(5) "julia" + ["age"]=> + int(6) +} +NULL +array(4) { + ["colour"]=> + string(5) "green" + ["animal"]=> + string(3) "cat" + ["person"]=> + string(5) "julia" + ["age"]=> + int(6) +} +array(4) { + ["colour"]=> + string(5) "green" + ["animal"]=> + string(3) "cat" + ["person"]=> + string(5) "julia" + ["age"]=> + int(6) +} +Done + diff --git a/ext/session/tests/session_start_variation7.phpt b/ext/session/tests/session_start_variation7.phpt new file mode 100644 index 0000000..be079f3 --- /dev/null +++ b/ext/session/tests/session_start_variation7.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_start(void) + * Description : Initialize session data + * Source code : ext/session/session.c + */ + +echo "*** Testing session_start() : variation ***\n"; + +session_start(); + +$_SESSION['colour'] = 'green'; +$_SESSION['animal'] = 'cat'; +$_SESSION['person'] = 'julia'; +$_SESSION['age'] = 6; + +var_dump($_SESSION); +var_dump(session_destroy()); +var_dump($_SESSION); +session_start(); +var_dump($_SESSION); + +session_destroy(); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_start() : variation *** +array(4) { + ["colour"]=> + string(5) "green" + ["animal"]=> + string(3) "cat" + ["person"]=> + string(5) "julia" + ["age"]=> + int(6) +} +bool(true) +array(4) { + ["colour"]=> + string(5) "green" + ["animal"]=> + string(3) "cat" + ["person"]=> + string(5) "julia" + ["age"]=> + int(6) +} +array(0) { +} +Done + diff --git a/ext/session/tests/session_start_variation8.phpt b/ext/session/tests/session_start_variation8.phpt new file mode 100644 index 0000000..9365475 --- /dev/null +++ b/ext/session/tests/session_start_variation8.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_start(void) + * Description : Initialize session data + * Source code : ext/session/session.c + */ + +echo "*** Testing session_start() : variation ***\n"; + +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); +var_dump(session_id()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_start() : variation *** +string(0) "" +bool(true) +string(%d) "%s" +bool(true) +string(0) "" +Done + diff --git a/ext/session/tests/session_start_variation9.phpt b/ext/session/tests/session_start_variation9.phpt new file mode 100644 index 0000000..21523e0 --- /dev/null +++ b/ext/session/tests/session_start_variation9.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.auto_start=1 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_start(void) + * Description : Initialize session data + * Source code : ext/session/session.c + */ + +echo "*** Testing session_start() : variation ***\n"; + +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); +var_dump(session_id()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_start() : variation *** +string(%d) "%s" + +Notice: A session had already been started - ignoring session_start() in %s on line %d +bool(true) +string(%d) "%s" +bool(true) +string(0) "" +Done + diff --git a/ext/session/tests/session_status.phpt b/ext/session/tests/session_status.phpt new file mode 100644 index 0000000..d1f7e2f --- /dev/null +++ b/ext/session/tests/session_status.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test session_status() function : active, none +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +echo "*** Testing session_status() : active, none\n"; + +var_dump(PHP_SESSION_NONE != PHP_SESSION_ACTIVE); +var_dump(session_status() == PHP_SESSION_NONE); + +session_start(); + +var_dump(session_status() == PHP_SESSION_ACTIVE); + +?> +--EXPECTF-- +*** Testing session_status() : active, none +bool(true) +bool(true) +bool(true) diff --git a/ext/session/tests/session_status_disabled.phpt b/ext/session/tests/session_status_disabled.phpt new file mode 100644 index 0000000..24e0ecd --- /dev/null +++ b/ext/session/tests/session_status_disabled.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test session_status() function : disabled +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.save_handler=non-existant +--FILE-- +<?php + +echo "*** Testing session_status() : disabled\n"; + +var_dump(session_status() == PHP_SESSION_DISABLED); + +?> +--EXPECTF-- +*** Testing session_status() : disabled +bool(true) diff --git a/ext/session/tests/session_unset_basic.phpt b/ext/session/tests/session_unset_basic.phpt new file mode 100644 index 0000000..21b12c4 --- /dev/null +++ b/ext/session/tests/session_unset_basic.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test session_unset() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : void session_unset(void) + * Description : Free all session variables + * Source code : ext/session/session.c + */ + +echo "*** Testing session_unset() : basic functionality ***\n"; + +var_dump(session_start()); +$_SESSION["foo"] = "Hello World!"; +var_dump($_SESSION); +var_dump(session_unset()); +var_dump($_SESSION); +var_dump(session_destroy()); +var_dump($_SESSION); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_unset() : basic functionality *** +bool(true) +array(1) { + ["foo"]=> + string(12) "Hello World!" +} +NULL +array(0) { +} +bool(true) +array(0) { +} +Done + diff --git a/ext/session/tests/session_unset_error.phpt b/ext/session/tests/session_unset_error.phpt new file mode 100644 index 0000000..9478345 --- /dev/null +++ b/ext/session/tests/session_unset_error.phpt @@ -0,0 +1,170 @@ +--TEST-- +Test session_unset() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : void session_unset(void) + * Description : Free all session variables + * Source code : ext/session/session.c + */ + +echo "*** Testing session_unset() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_unset($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_unset() : error functionality *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- +bool(false) + +-- Iteration 20 -- +bool(false) + +-- Iteration 21 -- +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- +bool(false) +Done + diff --git a/ext/session/tests/session_unset_variation1.phpt b/ext/session/tests/session_unset_variation1.phpt new file mode 100644 index 0000000..17ab283 --- /dev/null +++ b/ext/session/tests/session_unset_variation1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test session_unset() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : void session_unset(void) + * Description : Free all session variables + * Source code : ext/session/session.c + */ + +echo "*** Testing session_unset() : variation ***\n"; + +var_dump(session_unset()); +var_dump(session_start()); +var_dump(session_unset()); +$_SESSION["foo"] = "Hello World!"; +var_dump($_SESSION); +var_dump(session_destroy()); +var_dump(session_unset()); +var_dump($_SESSION); +var_dump(session_unset()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_unset() : variation *** +bool(false) +bool(true) +NULL +array(1) { + ["foo"]=> + string(12) "Hello World!" +} +bool(true) +bool(false) +array(1) { + ["foo"]=> + string(12) "Hello World!" +} +bool(false) +Done + diff --git a/ext/session/tests/session_write_close_basic.phpt b/ext/session/tests/session_write_close_basic.phpt new file mode 100644 index 0000000..0841afe --- /dev/null +++ b/ext/session/tests/session_write_close_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test session_write_close() function : basic functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_write_close(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_write_close() : basic functionality ***\n"; + +var_dump(session_start()); +var_dump($_SESSION); +var_dump(session_write_close()); +var_dump($_SESSION); +var_dump(session_start()); +var_dump($_SESSION); +var_dump(session_destroy()); +var_dump($_SESSION); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_write_close() : basic functionality *** +bool(true) +array(0) { +} +NULL +array(0) { +} +bool(true) +array(0) { +} +bool(true) +array(0) { +} +Done + diff --git a/ext/session/tests/session_write_close_error.phpt b/ext/session/tests/session_write_close_error.phpt new file mode 100644 index 0000000..cbdb55f --- /dev/null +++ b/ext/session/tests/session_write_close_error.phpt @@ -0,0 +1,170 @@ +--TEST-- +Test session_write_close() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_write_close(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_write_close() : error functionality ***\n"; + +// Get an unset variable +$unset_var = 10; +unset($unset_var); + +class classA +{ + public function __toString() { + return "Hello World!"; + } +} + +$heredoc = <<<EOT +Hello World! +EOT; + +$fp = fopen(__FILE__, "r"); + +// Unexpected values to be passed as arguments +$inputs = array( + + // Integer data +/*1*/ 0, + 1, + 12345, + -2345, + + // Float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // Null data +/*10*/ NULL, + null, + + // Boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // Empty strings +/*16*/ "", + '', + + // Invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // Object data +/*21*/ new classA(), + + // Undefined data +/*22*/ @$undefined_var, + + // Unset data +/*23*/ @$unset_var, + + // Resource variable +/*24*/ $fp +); + + +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(session_write_close($input)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_write_close() : error functionality *** + +-- Iteration 1 -- +NULL + +-- Iteration 2 -- +NULL + +-- Iteration 3 -- +NULL + +-- Iteration 4 -- +NULL + +-- Iteration 5 -- +NULL + +-- Iteration 6 -- +NULL + +-- Iteration 7 -- +NULL + +-- Iteration 8 -- +NULL + +-- Iteration 9 -- +NULL + +-- Iteration 10 -- +NULL + +-- Iteration 11 -- +NULL + +-- Iteration 12 -- +NULL + +-- Iteration 13 -- +NULL + +-- Iteration 14 -- +NULL + +-- Iteration 15 -- +NULL + +-- Iteration 16 -- +NULL + +-- Iteration 17 -- +NULL + +-- Iteration 18 -- +NULL + +-- Iteration 19 -- +NULL + +-- Iteration 20 -- +NULL + +-- Iteration 21 -- +NULL + +-- Iteration 22 -- +NULL + +-- Iteration 23 -- +NULL + +-- Iteration 24 -- +NULL +Done + diff --git a/ext/session/tests/session_write_close_variation1.phpt b/ext/session/tests/session_write_close_variation1.phpt new file mode 100644 index 0000000..595796d --- /dev/null +++ b/ext/session/tests/session_write_close_variation1.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test session_write_close() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_write_close(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_write_close() : variation ***\n"; + +var_dump(session_start()); +var_dump(session_write_close()); +var_dump(session_write_close()); +var_dump(session_write_close()); +var_dump(session_write_close()); +var_dump(session_write_close()); +var_dump(session_start()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_write_close() : variation *** +bool(true) +NULL +NULL +NULL +NULL +NULL +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_write_close_variation2.phpt b/ext/session/tests/session_write_close_variation2.phpt new file mode 100644 index 0000000..40871c5 --- /dev/null +++ b/ext/session/tests/session_write_close_variation2.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test session_write_close() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_write_close(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_write_close() : variation ***\n"; + +var_dump(session_start()); +var_dump($_SESSION); +var_dump(session_write_close()); +var_dump($_SESSION); +var_dump(session_start()); +var_dump($_SESSION); +var_dump(session_write_close()); +var_dump($_SESSION); +var_dump(session_start()); +var_dump($_SESSION); +var_dump(session_write_close()); +var_dump($_SESSION); +var_dump(session_start()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_write_close() : variation *** +bool(true) +array(0) { +} +NULL +array(0) { +} +bool(true) +array(0) { +} +NULL +array(0) { +} +bool(true) +array(0) { +} +NULL +array(0) { +} +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_write_close_variation3.phpt b/ext/session/tests/session_write_close_variation3.phpt new file mode 100644 index 0000000..0f80616 --- /dev/null +++ b/ext/session/tests/session_write_close_variation3.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test session_start() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.auto_start=1 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_write_close(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_write_close() : variation ***\n"; + +var_dump($_SESSION); +var_dump(session_write_close()); +var_dump($_SESSION); +var_dump(session_start()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_write_close() : variation *** +array(0) { +} +NULL +array(0) { +} +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_write_close_variation4.phpt b/ext/session/tests/session_write_close_variation4.phpt new file mode 100644 index 0000000..249c155 --- /dev/null +++ b/ext/session/tests/session_write_close_variation4.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test session_write_close() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_write_close(void) + * Description : Write session data and end session + * Source code : ext/session/session.c + */ + +echo "*** Testing session_write_close() : variation ***\n"; + +var_dump(session_id("test")); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_write_close()); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_write_close()); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_write_close()); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_write_close() : variation *** +string(0) "" +bool(true) +string(4) "test" +NULL +string(4) "test" +bool(true) +string(4) "test" +NULL +string(4) "test" +bool(true) +string(4) "test" +NULL +string(4) "test" +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/sessionhandler_open_001.phpt b/ext/session/tests/sessionhandler_open_001.phpt new file mode 100644 index 0000000..6ade9e0 --- /dev/null +++ b/ext/session/tests/sessionhandler_open_001.phpt @@ -0,0 +1,19 @@ +--TEST-- +Testing repated SessionHandler::open() calls +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ini_set('session.save_handler', 'files'); +$x = new SessionHandler; +$x->open('',''); +$x->open('',''); +$x->open('',''); +$x->open('',''); + +print "Done!\n"; + +?> +--EXPECTF-- +Done! diff --git a/ext/session/tests/skipif.inc b/ext/session/tests/skipif.inc new file mode 100644 index 0000000..e63f963 --- /dev/null +++ b/ext/session/tests/skipif.inc @@ -0,0 +1,25 @@ +<?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 Session module not loaded"); +} +$save_path = ini_get("session.save_path"); +if ($save_path) { + if (!file_exists($save_path)) { + die("skip Session save_path doesn't exist"); + } + + if ($save_path && !@is_writable($save_path)) { + if (($p = strpos($save_path, ';')) !== false) { + $save_path = substr($save_path, ++$p); + } + if (!@is_writable($save_path)) { + die("skip session.save_path $save_path is not writable\n"); + } + } +} +?> |