- WS + sync with PHP_5_3 (thanks Ilia & Co.)

This commit is contained in:
Jani Taskinen 2009-05-18 16:09:51 +00:00
parent 34907a2aaa
commit 1aee5ff9fc
5 changed files with 194 additions and 216 deletions

View file

@ -1,4 +1,4 @@
/* /*
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| PHP Version 6 | | PHP Version 6 |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
@ -86,7 +86,7 @@ static int ps_files_valid_key(const char *key)
} }
len = p - key; len = p - key;
if (len == 0) { if (len == 0) {
ret = 0; ret = 0;
} }
@ -100,7 +100,7 @@ static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, cons
const char *p; const char *p;
int i; int i;
int n; int n;
key_len = strlen(key); key_len = strlen(key);
if (key_len <= data->dirdepth || if (key_len <= data->dirdepth ||
buflen < (strlen(data->basedir) + 2 * data->dirdepth + key_len + 5 + sizeof(FILE_PREFIX))) { buflen < (strlen(data->basedir) + 2 * data->dirdepth + key_len + 5 + sizeof(FILE_PREFIX))) {
@ -142,18 +142,18 @@ static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, cons
efree(newbuf); efree(newbuf);
} }
} }
return buf; return buf;
} }
#ifndef O_BINARY #ifndef O_BINARY
#define O_BINARY 0 # define O_BINARY 0
#endif #endif
static void ps_files_close(ps_files *data) static void ps_files_close(ps_files *data)
{ {
if (data->fd != -1) { if (data->fd != -1) {
#ifdef PHP_WIN32 #ifdef PHP_WIN32
/* On Win32 locked files that are closed without being explicitly unlocked /* On Win32 locked files that are closed without being explicitly unlocked
will be unlocked only when "system resources become available". */ will be unlocked only when "system resources become available". */
flock(data->fd, LOCK_UN); flock(data->fd, LOCK_UN);
@ -199,8 +199,8 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC)
return; return;
} }
if ( if (
S_ISLNK(sbuf.st_mode) && S_ISLNK(sbuf.st_mode) &&
php_check_open_basedir(buf TSRMLS_CC) php_check_open_basedir(buf TSRMLS_CC)
) { ) {
close(data->fd); close(data->fd);
return; return;
@ -218,8 +218,7 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC)
} }
#endif #endif
} else { } else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "open(%s, O_RDWR) failed: %s (%d)", buf, php_error_docref(NULL TSRMLS_CC, E_WARNING, "open(%s, O_RDWR) failed: %s (%d)", buf, strerror(errno), errno);
strerror(errno), errno);
} }
} }
} }
@ -248,7 +247,7 @@ static int ps_files_cleanup_dir(const char *dirname, int maxlifetime TSRMLS_DC)
/* Prepare buffer (dirname never changes) */ /* Prepare buffer (dirname never changes) */
memcpy(buf, dirname, dirname_len); memcpy(buf, dirname, dirname_len);
buf[dirname_len] = PHP_DIR_SEPARATOR; buf[dirname_len] = PHP_DIR_SEPARATOR;
while (php_readdir_r(dir, (struct dirent *) dentry, &entry) == 0 && entry) { while (php_readdir_r(dir, (struct dirent *) dentry, &entry) == 0 && entry) {
/* does the file start with our prefix? */ /* does the file start with our prefix? */
if (!strncmp(entry->d_name, FILE_PREFIX, sizeof(FILE_PREFIX) - 1)) { if (!strncmp(entry->d_name, FILE_PREFIX, sizeof(FILE_PREFIX) - 1)) {
@ -263,7 +262,7 @@ static int ps_files_cleanup_dir(const char *dirname, int maxlifetime TSRMLS_DC)
buf[dirname_len + entry_len + 1] = '\0'; buf[dirname_len + entry_len + 1] = '\0';
/* check whether its last access was more than maxlifet ago */ /* check whether its last access was more than maxlifet ago */
if (VCWD_STAT(buf, &sbuf) == 0 && if (VCWD_STAT(buf, &sbuf) == 0 &&
#ifdef NETWARE #ifdef NETWARE
(now - sbuf.st_mtime.tv_sec) > maxlifetime) { (now - sbuf.st_mtime.tv_sec) > maxlifetime) {
#else #else
@ -300,7 +299,7 @@ PS_OPEN_FUNC(files)
return FAILURE; return FAILURE;
} }
} }
/* split up input parameter */ /* split up input parameter */
last = save_path; last = save_path;
p = strchr(save_path, ';'); p = strchr(save_path, ';');
@ -320,7 +319,7 @@ PS_OPEN_FUNC(files)
return FAILURE; return FAILURE;
} }
} }
if (argc > 2) { if (argc > 2) {
errno = 0; errno = 0;
filemode = strtol(argv[1], NULL, 8); filemode = strtol(argv[1], NULL, 8);
@ -332,15 +331,15 @@ PS_OPEN_FUNC(files)
save_path = argv[argc - 1]; save_path = argv[argc - 1];
data = ecalloc(1, sizeof(*data)); data = ecalloc(1, sizeof(*data));
data->fd = -1; data->fd = -1;
data->dirdepth = dirdepth; data->dirdepth = dirdepth;
data->filemode = filemode; data->filemode = filemode;
data->basedir_len = strlen(save_path); data->basedir_len = strlen(save_path);
data->basedir = estrndup(save_path, data->basedir_len); data->basedir = estrndup(save_path, data->basedir_len);
PS_SET_MOD_DATA(data); PS_SET_MOD_DATA(data);
return SUCCESS; return SUCCESS;
} }
@ -401,7 +400,7 @@ PS_READ_FUNC(files)
efree(*val); efree(*val);
return FAILURE; return FAILURE;
} }
return SUCCESS; return SUCCESS;
} }
@ -415,11 +414,8 @@ PS_WRITE_FUNC(files)
return FAILURE; return FAILURE;
} }
/* /* Truncate file if the amount of new data is smaller than the existing data set. */
* truncate file, if the amount of new data is smaller than
* the existing data set.
*/
if (vallen < (int)data->st_size) { if (vallen < (int)data->st_size) {
ftruncate(data->fd, 0); ftruncate(data->fd, 0);
} }
@ -454,11 +450,10 @@ PS_DESTROY_FUNC(files)
if (data->fd != -1) { if (data->fd != -1) {
ps_files_close(data); ps_files_close(data);
if (VCWD_UNLINK(buf) == -1) { if (VCWD_UNLINK(buf) == -1) {
/* This is a little safety check for instances when we are dealing with a regenerated session /* This is a little safety check for instances when we are dealing with a regenerated session
* that was not yet written to disk * that was not yet written to disk. */
*/
if (!VCWD_ACCESS(buf, F_OK)) { if (!VCWD_ACCESS(buf, F_OK)) {
return FAILURE; return FAILURE;
} }
@ -468,14 +463,14 @@ PS_DESTROY_FUNC(files)
return SUCCESS; return SUCCESS;
} }
PS_GC_FUNC(files) PS_GC_FUNC(files)
{ {
PS_FILES_DATA; PS_FILES_DATA;
/* we don't perform any cleanup, if dirdepth is larger than 0. /* we don't perform any cleanup, if dirdepth is larger than 0.
we return SUCCESS, since all cleanup should be handled by we return SUCCESS, since all cleanup should be handled by
an external entity (i.e. find -ctime x | xargs rm) */ an external entity (i.e. find -ctime x | xargs rm) */
if (data->dirdepth == 0) { if (data->dirdepth == 0) {
*nrdels = ps_files_cleanup_dir(data->basedir, maxlifetime TSRMLS_CC); *nrdels = ps_files_cleanup_dir(data->basedir, maxlifetime TSRMLS_CC);
} }

View file

@ -1,4 +1,4 @@
/* /*
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| PHP Version 6 | | PHP Version 6 |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
@ -42,9 +42,7 @@
/* For php_uint32 */ /* For php_uint32 */
#include "ext/standard/basic_functions.h" #include "ext/standard/basic_functions.h"
/* /* This list holds all data associated with one session. */
* this list holds all data associated with one session
*/
typedef struct ps_sd { typedef struct ps_sd {
struct ps_sd *next; struct ps_sd *next;
@ -67,21 +65,21 @@ typedef struct {
static ps_mm *ps_mm_instance = NULL; static ps_mm *ps_mm_instance = NULL;
#if 0 #if 0
#define ps_mm_debug(a) printf a # define ps_mm_debug(a) printf a
#else #else
#define ps_mm_debug(a) # define ps_mm_debug(a)
#endif #endif
static inline php_uint32 ps_sd_hash(const char *data, int len) static inline php_uint32 ps_sd_hash(const char *data, int len)
{ {
php_uint32 h; php_uint32 h;
const char *e = data + len; const char *e = data + len;
for (h = 2166136261U; data < e; ) { for (h = 2166136261U; data < e; ) {
h *= 16777619; h *= 16777619;
h ^= *data++; h ^= *data++;
} }
return h; return h;
} }
@ -91,10 +89,10 @@ static void hash_split(ps_mm *data)
ps_sd **nhash; ps_sd **nhash;
ps_sd **ohash, **ehash; ps_sd **ohash, **ehash;
ps_sd *ps, *next; ps_sd *ps, *next;
nmax = ((data->hash_max + 1) << 1) - 1; nmax = ((data->hash_max + 1) << 1) - 1;
nhash = mm_calloc(data->mm, nmax + 1, sizeof(*data->hash)); nhash = mm_calloc(data->mm, nmax + 1, sizeof(*data->hash));
if (!nhash) { if (!nhash) {
/* no further memory to expand hash table */ /* no further memory to expand hash table */
return; return;
@ -119,9 +117,9 @@ static ps_sd *ps_sd_new(ps_mm *data, const char *key)
php_uint32 hv, slot; php_uint32 hv, slot;
ps_sd *sd; ps_sd *sd;
int keylen; int keylen;
keylen = strlen(key); keylen = strlen(key);
sd = mm_malloc(data->mm, sizeof(ps_sd) + keylen); sd = mm_malloc(data->mm, sizeof(ps_sd) + keylen);
if (!sd) { if (!sd) {
TSRMLS_FETCH(); TSRMLS_FETCH();
@ -132,24 +130,25 @@ static ps_sd *ps_sd_new(ps_mm *data, const char *key)
hv = ps_sd_hash(key, keylen); hv = ps_sd_hash(key, keylen);
slot = hv & data->hash_max; slot = hv & data->hash_max;
sd->ctime = 0; sd->ctime = 0;
sd->hv = hv; sd->hv = hv;
sd->data = NULL; sd->data = NULL;
sd->alloclen = sd->datalen = 0; sd->alloclen = sd->datalen = 0;
memcpy(sd->key, key, keylen + 1); memcpy(sd->key, key, keylen + 1);
sd->next = data->hash[slot]; sd->next = data->hash[slot];
data->hash[slot] = sd; data->hash[slot] = sd;
data->hash_cnt++; data->hash_cnt++;
if (!sd->next) { if (!sd->next) {
if (data->hash_cnt >= data->hash_max) if (data->hash_cnt >= data->hash_max) {
hash_split(data); hash_split(data);
}
} }
ps_mm_debug(("inserting %s(%p) into slot %d\n", key, sd, slot)); ps_mm_debug(("inserting %s(%p) into slot %d\n", key, sd, slot));
return sd; return sd;
@ -170,7 +169,7 @@ static void ps_sd_destroy(ps_mm *data, ps_sd *sd)
for (prev = data->hash[slot]; prev->next != sd; prev = prev->next); for (prev = data->hash[slot]; prev->next != sd; prev = prev->next);
prev->next = sd->next; prev->next = sd->next;
} }
data->hash_cnt--; data->hash_cnt--;
if (sd->data) { if (sd->data) {
@ -187,7 +186,7 @@ static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw)
hv = ps_sd_hash(key, strlen(key)); hv = ps_sd_hash(key, strlen(key));
slot = hv & data->hash_max; slot = hv & data->hash_max;
for (prev = NULL, ret = data->hash[slot]; ret; prev = ret, ret = ret->next) { for (prev = NULL, ret = data->hash[slot]; ret; prev = ret, ret = ret->next) {
if (ret->hv == hv && !strcmp(ret->key, key)) { if (ret->hv == hv && !strcmp(ret->key, key)) {
break; break;
@ -196,7 +195,6 @@ static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw)
if (ret && rw && ret != data->hash[slot]) { if (ret && rw && ret != data->hash[slot]) {
/* Move the entry to the top of the linked list */ /* Move the entry to the top of the linked list */
if (prev) { if (prev) {
prev->next = ret->next; prev->next = ret->next;
} }
@ -206,7 +204,7 @@ static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw)
} }
ps_mm_debug(("lookup(%s): ret=%p,hv=%u,slot=%d\n", key, ret, hv, slot)); ps_mm_debug(("lookup(%s): ret=%p,hv=%u,slot=%d\n", key, ret, hv, slot));
return ret; return ret;
} }
@ -243,7 +241,9 @@ static void ps_mm_destroy(ps_mm *data)
/* This function is called during each module shutdown, /* This function is called during each module shutdown,
but we must not release the shared memory pool, when but we must not release the shared memory pool, when
an Apache child dies! */ an Apache child dies! */
if (data->owner != getpid()) return; if (data->owner != getpid()) {
return;
}
for (h = 0; h < data->hash_max + 1; h++) { for (h = 0; h < data->hash_max + 1; h++) {
for (sd = data->hash[h]; sd; sd = next) { for (sd = data->hash[h]; sd; sd = next) {
@ -251,7 +251,7 @@ static void ps_mm_destroy(ps_mm *data)
ps_sd_destroy(data, sd); ps_sd_destroy(data, sd);
} }
} }
mm_free(data->mm, data->hash); mm_free(data->mm, data->hash);
mm_destroy(data->mm); mm_destroy(data->mm);
free(data); free(data);
@ -261,41 +261,44 @@ PHP_MINIT_FUNCTION(ps_mm)
{ {
int save_path_len = strlen(PS(save_path)); int save_path_len = strlen(PS(save_path));
int mod_name_len = strlen(sapi_module.name); int mod_name_len = strlen(sapi_module.name);
int euid_len;
char *ps_mm_path, euid[30]; char *ps_mm_path, euid[30];
int ret; int ret;
ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1); ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1);
if (!ps_mm_instance) { if (!ps_mm_instance) {
return FAILURE; return FAILURE;
} }
if (!snprintf(euid, sizeof(euid), "%d", geteuid())) { if (!(euid_len = slprintf(euid, sizeof(euid), "%d", geteuid()))) {
return FAILURE; return FAILURE;
} }
/* Directory + '/' + File + Module Name + Effective UID + \0 */ /* Directory + '/' + File + Module Name + Effective UID + \0 */
ps_mm_path = emalloc(save_path_len+1+sizeof(PS_MM_FILE)+mod_name_len+strlen(euid)+1); 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 + 1); memcpy(ps_mm_path, PS(save_path), save_path_len);
if (save_path_len > 0 && ps_mm_path[save_path_len - 1] != DEFAULT_SLASH) { if (PS(save_path)[save_path_len - 1] != DEFAULT_SLASH) {
ps_mm_path[save_path_len] = DEFAULT_SLASH; ps_mm_path[save_path_len] = DEFAULT_SLASH;
ps_mm_path[save_path_len+1] = '\0'; 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';
strcat(ps_mm_path, PS_MM_FILE);
strcat(ps_mm_path, sapi_module.name);
strcat(ps_mm_path, euid);
ret = ps_mm_initialize(ps_mm_instance, ps_mm_path); ret = ps_mm_initialize(ps_mm_instance, ps_mm_path);
efree(ps_mm_path); efree(ps_mm_path);
if (ret != SUCCESS) { if (ret != SUCCESS) {
free(ps_mm_instance); free(ps_mm_instance);
ps_mm_instance = NULL; ps_mm_instance = NULL;
return FAILURE; return FAILURE;
} }
php_session_register_module(&ps_mod_mm); php_session_register_module(&ps_mod_mm);
return SUCCESS; return SUCCESS;
} }
@ -312,13 +315,12 @@ PHP_MSHUTDOWN_FUNCTION(ps_mm)
PS_OPEN_FUNC(mm) PS_OPEN_FUNC(mm)
{ {
ps_mm_debug(("open: ps_mm_instance=%p\n", ps_mm_instance)); ps_mm_debug(("open: ps_mm_instance=%p\n", ps_mm_instance));
if (!ps_mm_instance) { if (!ps_mm_instance) {
return FAILURE; return FAILURE;
} }
PS_SET_MOD_DATA(ps_mm_instance); PS_SET_MOD_DATA(ps_mm_instance);
return SUCCESS; return SUCCESS;
} }
@ -336,7 +338,7 @@ PS_READ_FUNC(mm)
int ret = FAILURE; int ret = FAILURE;
mm_lock(data->mm, MM_LOCK_RD); mm_lock(data->mm, MM_LOCK_RD);
sd = ps_sd_lookup(data, key, 0); sd = ps_sd_lookup(data, key, 0);
if (sd) { if (sd) {
*vallen = sd->datalen; *vallen = sd->datalen;
@ -347,7 +349,7 @@ PS_READ_FUNC(mm)
} }
mm_unlock(data->mm); mm_unlock(data->mm);
return ret; return ret;
} }
@ -386,7 +388,7 @@ PS_WRITE_FUNC(mm)
} }
mm_unlock(data->mm); mm_unlock(data->mm);
return sd ? SUCCESS : FAILURE; return sd ? SUCCESS : FAILURE;
} }
@ -394,29 +396,29 @@ PS_DESTROY_FUNC(mm)
{ {
PS_MM_DATA; PS_MM_DATA;
ps_sd *sd; ps_sd *sd;
mm_lock(data->mm, MM_LOCK_RW); mm_lock(data->mm, MM_LOCK_RW);
sd = ps_sd_lookup(data, key, 0); sd = ps_sd_lookup(data, key, 0);
if (sd) { if (sd) {
ps_sd_destroy(data, sd); ps_sd_destroy(data, sd);
} }
mm_unlock(data->mm); mm_unlock(data->mm);
return SUCCESS; return SUCCESS;
} }
PS_GC_FUNC(mm) PS_GC_FUNC(mm)
{ {
PS_MM_DATA; PS_MM_DATA;
time_t limit; time_t limit;
ps_sd **ohash, **ehash; ps_sd **ohash, **ehash;
ps_sd *sd, *next; ps_sd *sd, *next;
*nrdels = 0; *nrdels = 0;
ps_mm_debug(("gc\n")); ps_mm_debug(("gc\n"));
time(&limit); time(&limit);
limit -= maxlifetime; limit -= maxlifetime;
@ -436,7 +438,7 @@ PS_GC_FUNC(mm)
} }
mm_unlock(data->mm); mm_unlock(data->mm);
return SUCCESS; return SUCCESS;
} }

View file

@ -1,4 +1,4 @@
/* /*
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| PHP Version 6 | | PHP Version 6 |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
@ -26,34 +26,31 @@ ps_module ps_mod_user = {
PS_MOD(user) PS_MOD(user)
}; };
#define SESS_ZVAL_LONG(val, a) \ #define SESS_ZVAL_LONG(val, a) \
{ \ { \
MAKE_STD_ZVAL(a); \ MAKE_STD_ZVAL(a); \
ZVAL_LONG(a, val); \ 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) \ #define SESS_ZVAL_STRINGN(vl, ln, a) \
{ \ { \
MAKE_STD_ZVAL(a); \ MAKE_STD_ZVAL(a); \
ZVAL_UTF8_STRINGL(a, vl, ln, ZSTR_DUPLICATE); \ ZVAL_UTF8_STRINGL(a, vl, ln, ZSTR_DUPLICATE); \
} }
#define SESS_ZVAL_STRING(vl, a) \
{ \
char *__vl = vl; \
SESS_ZVAL_STRINGN(__vl, strlen(__vl), a); \
}
static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC) static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC)
{ {
int i; int i;
zval *retval = NULL; zval *retval = NULL;
MAKE_STD_ZVAL(retval); MAKE_STD_ZVAL(retval);
if (call_user_function(EG(function_table), NULL, func, retval, if (call_user_function(EG(function_table), NULL, func, retval, argc, argv TSRMLS_CC) == FAILURE) {
argc, argv TSRMLS_CC) == FAILURE) {
zval_ptr_dtor(&retval); zval_ptr_dtor(&retval);
retval = NULL; retval = NULL;
} }
@ -66,7 +63,7 @@ static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC)
} }
#define STDVARS1 \ #define STDVARS1 \
zval *retval; \ zval *retval; \
int ret = FAILURE int ret = FAILURE
#define STDVARS \ #define STDVARS \
@ -76,12 +73,12 @@ static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC)
#define PSF(a) PS(mod_user_names).name.ps_##a #define PSF(a) PS(mod_user_names).name.ps_##a
#define FINISH \ #define FINISH \
if (retval) { \ if (retval) { \
convert_to_long(retval); \ convert_to_long(retval); \
ret = Z_LVAL_P(retval); \ ret = Z_LVAL_P(retval); \
zval_ptr_dtor(&retval); \ zval_ptr_dtor(&retval); \
} \ } \
return ret return ret
PS_OPEN_FUNC(user) PS_OPEN_FUNC(user)
@ -89,21 +86,20 @@ PS_OPEN_FUNC(user)
zval *args[2]; zval *args[2];
static char dummy = 0; static char dummy = 0;
STDVARS1; STDVARS1;
SESS_ZVAL_STRING((char*)save_path, args[0]); SESS_ZVAL_STRING((char*)save_path, args[0]);
SESS_ZVAL_STRING((char*)session_name, args[1]); SESS_ZVAL_STRING((char*)session_name, args[1]);
retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC); retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC);
if (retval) { if (retval) {
/* This is necessary to fool the session module. Yes, it's safe to /* This is necessary to fool the session module. Yes, it's safe to
* use a static. Neither mod_user nor the session module itself will * use a static. Neither mod_user nor the session module itself will
* ever touch this pointer. It could be set to 0xDEADBEEF for all the * ever touch this pointer. It could be set to 0xDEADBEEF for all the
* difference it makes, but for the sake of paranoia it's set to some * difference it makes, but for the sake of paranoia it's set to some
* valid value. * valid value. */
*/
PS_SET_MOD_DATA(&dummy); PS_SET_MOD_DATA(&dummy);
} }
FINISH; FINISH;
} }
@ -126,7 +122,7 @@ PS_READ_FUNC(user)
SESS_ZVAL_STRING((char*)key, args[0]); SESS_ZVAL_STRING((char*)key, args[0]);
retval = ps_call_handler(PSF(read), 1, args TSRMLS_CC); retval = ps_call_handler(PSF(read), 1, args TSRMLS_CC);
if (retval) { if (retval) {
if (Z_TYPE_P(retval) == IS_STRING) { if (Z_TYPE_P(retval) == IS_STRING) {
*val = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); *val = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
@ -148,7 +144,6 @@ PS_READ_FUNC(user)
ret = SUCCESS; ret = SUCCESS;
} }
} }
zval_ptr_dtor(&retval); zval_ptr_dtor(&retval);
} }
@ -159,7 +154,7 @@ PS_WRITE_FUNC(user)
{ {
zval *args[2]; zval *args[2];
STDVARS; STDVARS;
SESS_ZVAL_STRING((char*)key, args[0]); SESS_ZVAL_STRING((char*)key, args[0]);
SESS_ZVAL_STRINGN((char*)val, vallen, args[1]); SESS_ZVAL_STRINGN((char*)val, vallen, args[1]);

View file

@ -245,32 +245,37 @@ PHPAPI const ps_serializer *_php_find_ps_serializer(char *name TSRMLS_DC);
/* (Possibly) needed for BC (e.g. by external modules using the session registry) */ /* (Possibly) needed for BC (e.g. by external modules using the session registry) */
#define PS_ENCODE_LOOP(code) do { \ #define PS_ENCODE_LOOP(code) do { \
HashTable *_ht = Z_ARRVAL_P(PS(http_session_vars)); \ HashTable *_ht = Z_ARRVAL_P(PS(http_session_vars)); \
int key_type; \
\ \
for (zend_hash_internal_pointer_reset(_ht); \ for (zend_hash_internal_pointer_reset(_ht); \
zend_hash_get_current_key_ex(_ht, &key, &key_length, &num_key, 0, NULL) == HASH_KEY_IS_STRING; \ (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)) { \ zend_hash_move_forward(_ht)) { \
key_length--; \ if (key_type == HASH_KEY_IS_LONG) { \
if (php_get_session_var(key.s, key_length, &struc TSRMLS_CC) == SUCCESS) { \ 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; \ code; \
} \ } \
} \ } \
} while(0) } while(0)
#define PS_UENCODE_LOOP(code) do { \ #define PS_UENCODE_LOOP(code) do { \
int key_type; \ HashTable *_ht = Z_ARRVAL_P(PS(http_session_vars)); \
HashTable *_ht = Z_ARRVAL_P(PS(http_session_vars)); \ HashPosition _pos; \
HashPosition _pos; \ int key_type; \
\ \
for (zend_hash_internal_pointer_reset_ex(_ht, &_pos); \ for (zend_hash_internal_pointer_reset_ex(_ht, &_pos); \
(key_type = zend_hash_get_current_key_ex(_ht, &key, &key_length, &num_key, 0, &_pos)) != HASH_KEY_NON_EXISTANT; \ (key_type = zend_hash_get_current_key_ex(_ht, &key, &key_length, &num_key, 0, &_pos)) != HASH_KEY_NON_EXISTANT; \
zend_hash_move_forward_ex(_ht, &_pos)) { \ zend_hash_move_forward_ex(_ht, &_pos)) { \
if (key_type != HASH_KEY_IS_STRING && key_type != HASH_KEY_IS_UNICODE) { break; } \ if (key_type != HASH_KEY_IS_STRING && key_type != HASH_KEY_IS_UNICODE) { break; } \
key_length--; \ key_length--; \
struc = NULL; \ struc = NULL; \
zend_hash_get_current_data_ex(_ht, (void**)&struc, &_pos); \ zend_hash_get_current_data_ex(_ht, (void**)&struc, &_pos); \
\ \
code; \ code; \
} \ } \
} while(0) } while(0)

View file

@ -137,8 +137,7 @@ PHPAPI void php_add_session_var(char *name, size_t namelen TSRMLS_DC) /* {{{ */
zval **sym_track = NULL; zval **sym_track = NULL;
IF_SESSION_VARS() { IF_SESSION_VARS() {
zend_rt_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, namelen + 1, zend_rt_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, namelen + 1, (void *) &sym_track);
(void *) &sym_track);
} else { } else {
return; return;
} }
@ -165,8 +164,7 @@ PHPAPI int php_get_session_var(char *name, size_t namelen, zval ***state_var TSR
int ret = FAILURE; int ret = FAILURE;
IF_SESSION_VARS() { IF_SESSION_VARS() {
ret = zend_rt_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, ret = zend_rt_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, namelen + 1, (void **) state_var);
namelen+1, (void **) state_var);
} }
return ret; return ret;
} }
@ -203,7 +201,7 @@ static char *php_session_encode(int *newlen TSRMLS_DC) /* {{{ */
ret = NULL; ret = NULL;
} }
} else { } else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot encode non-existent session"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot encode non-existent session");
} }
return ret; return ret;
} }
@ -294,17 +292,15 @@ PHPAPI char *php_session_create_id(PS_CREATE_SID_ARGS) /* {{{ */
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
if (zend_ascii_hash_find(&EG(symbol_table), "_SERVER", if (zend_ascii_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &array) == SUCCESS &&
sizeof("_SERVER"), (void **) &array) == SUCCESS &&
Z_TYPE_PP(array) == IS_ARRAY && Z_TYPE_PP(array) == IS_ARRAY &&
zend_ascii_hash_find(Z_ARRVAL_PP(array), "REMOTE_ADDR", zend_ascii_hash_find(Z_ARRVAL_PP(array), "REMOTE_ADDR", sizeof("REMOTE_ADDR"), (void **) &token) == SUCCESS
sizeof("REMOTE_ADDR"), (void **) &token) == SUCCESS) { ) {
remote_addr = Z_STRVAL_PP(token); remote_addr = Z_STRVAL_PP(token);
} }
/* maximum 15+19+19+10 bytes */ /* maximum 15+19+19+10 bytes */
spprintf(&buf, 0, "%.15s%ld%ld%0.8F", remote_addr ? remote_addr : "", 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);
tv.tv_sec, (long int)tv.tv_usec, php_combined_lcg(TSRMLS_C) * 10);
switch (PS(hash_func)) { switch (PS(hash_func)) {
case PS_HASH_FUNC_MD5: case PS_HASH_FUNC_MD5:
@ -443,8 +439,7 @@ new_session:
/* Question: if you create a SID here, should you also try to 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 * 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" * it could prove usefull for those sites which wish to have "default"
* session information * session information. */
*/
php_session_track_init(TSRMLS_C); php_session_track_init(TSRMLS_C);
PS(invalid_session_id) = 0; PS(invalid_session_id) = 0;
if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == SUCCESS) { if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == SUCCESS) {
@ -689,15 +684,11 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("session.hash_bits_per_character", "4", PHP_INI_ALL, OnUpdateLong, hash_bits_per_character, php_ps_globals, ps_globals) STD_PHP_INI_ENTRY("session.hash_bits_per_character", "4", PHP_INI_ALL, OnUpdateLong, hash_bits_per_character, php_ps_globals, ps_globals)
/* Upload progress */ /* Upload progress */
STD_PHP_INI_BOOLEAN("session.upload_progress.enabled", STD_PHP_INI_BOOLEAN("session.upload_progress.enabled", "1", ZEND_INI_PERDIR, OnUpdateBool, rfc1867_enabled, php_ps_globals, ps_globals)
"1", ZEND_INI_PERDIR, OnUpdateBool, rfc1867_enabled, php_ps_globals, ps_globals) STD_PHP_INI_ENTRY("session.upload_progress.prefix", "upload_progress_", ZEND_INI_PERDIR, OnUpdateUTF8String, rfc1867_prefix, php_ps_globals, ps_globals)
STD_PHP_INI_ENTRY("session.upload_progress.prefix", STD_PHP_INI_ENTRY("session.upload_progress.name", "PHP_SESSION_UPLOAD_PROGRESS", ZEND_INI_PERDIR, OnUpdateUTF8String, rfc1867_name, php_ps_globals, ps_globals)
"upload_progress_", ZEND_INI_PERDIR, OnUpdateUTF8String, rfc1867_prefix, 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.name", STD_PHP_INI_ENTRY("session.upload_progress.min_freq", "0", ZEND_INI_PERDIR, OnUpdateReal, rfc1867_min_freq,php_ps_globals, ps_globals)
"PHP_SESSION_UPLOAD_PROGRESS", ZEND_INI_PERDIR, OnUpdateUTF8String, 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",
"0", ZEND_INI_PERDIR, OnUpdateReal, rfc1867_min_freq,php_ps_globals, ps_globals)
/* Commented out until future discussion */ /* Commented out until future discussion */
/* PHP_INI_ENTRY("session.encode_sources", "globals,track", PHP_INI_ALL, NULL) */ /* PHP_INI_ENTRY("session.encode_sources", "globals,track", PHP_INI_ALL, NULL) */
@ -920,10 +911,7 @@ static ps_serializer ps_serializers[MAX_SERIALIZERS + 1] = {
PS_SERIALIZER_ENTRY(php_binary) PS_SERIALIZER_ENTRY(php_binary)
}; };
PHPAPI int php_session_register_serializer( PHPAPI int php_session_register_serializer(const char *name, int (*encode)(PS_SERIALIZER_ENCODE_ARGS), int (*decode)(PS_SERIALIZER_DECODE_ARGS)) /* {{{ */
const char *name,
int (*encode)(PS_SERIALIZER_ENCODE_ARGS),
int (*decode)(PS_SERIALIZER_DECODE_ARGS)) /* {{{ */
{ {
int ret = -1; int ret = -1;
int i; int i;
@ -1008,9 +996,9 @@ static inline void strcpy_gmt(char *ubuf, time_t *when) /* {{{ */
} }
n = slprintf(buf, sizeof(buf), "%s, %02d %s %d %02d:%02d:%02d GMT", /* SAFE */ n = slprintf(buf, sizeof(buf), "%s, %02d %s %d %02d:%02d:%02d GMT", /* SAFE */
week_days[tm.tm_wday], tm.tm_mday, week_days[tm.tm_wday], tm.tm_mday,
month_names[tm.tm_mon], tm.tm_year + 1900, month_names[tm.tm_mon], tm.tm_year + 1900,
tm.tm_hour, tm.tm_min, tm.tm_hour, tm.tm_min,
tm.tm_sec); tm.tm_sec);
memcpy(ubuf, buf, n); memcpy(ubuf, buf, n);
ubuf[n] = '\0'; ubuf[n] = '\0';
@ -1106,8 +1094,7 @@ static int php_session_cache_limiter(TSRMLS_D) /* {{{ */
int output_start_lineno = php_output_get_start_lineno(TSRMLS_C); int output_start_lineno = php_output_get_start_lineno(TSRMLS_C);
if (output_start_filename) { 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)", 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);
output_start_filename, output_start_lineno);
} else { } else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cache limiter - headers already sent"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cache limiter - headers already sent");
} }
@ -1147,8 +1134,7 @@ static void php_session_send_cookie(TSRMLS_D) /* {{{ */
int output_start_lineno = php_output_get_start_lineno(TSRMLS_C); int output_start_lineno = php_output_get_start_lineno(TSRMLS_C);
if (output_start_filename) { 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)", 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);
output_start_filename, output_start_lineno);
} else { } else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cookie - headers already sent"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cookie - headers already sent");
} }
@ -1318,17 +1304,14 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */
lensess = strlen(PS(session_name)); lensess = strlen(PS(session_name));
/* /* Cookies are preferred, because initially
* Cookies are preferred, because initially * cookie and get variables will be available. */
* cookie and get variables will be available.
*/
if (!PS(id)) { if (!PS(id)) {
if (PS(use_cookies) && zend_ascii_hash_find(&EG(symbol_table), "_COOKIE", if (PS(use_cookies) && zend_ascii_hash_find(&EG(symbol_table), "_COOKIE", sizeof("_COOKIE"), (void **) &data) == SUCCESS &&
sizeof("_COOKIE"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_ARRAY && Z_TYPE_PP(data) == IS_ARRAY &&
zend_ascii_hash_find(Z_ARRVAL_PP(data), PS(session_name), zend_ascii_hash_find(Z_ARRVAL_PP(data), PS(session_name), lensess + 1, (void **) &ppid) == SUCCESS
lensess + 1, (void **) &ppid) == SUCCESS) { ) {
PPID2SID; PPID2SID;
PS(apply_trans_sid) = 0; PS(apply_trans_sid) = 0;
PS(send_cookie) = 0; PS(send_cookie) = 0;
@ -1336,36 +1319,34 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */
} }
if (!PS(use_only_cookies) && !PS(id) && if (!PS(use_only_cookies) && !PS(id) &&
zend_ascii_hash_find(&EG(symbol_table), "_GET", zend_ascii_hash_find(&EG(symbol_table), "_GET", sizeof("_GET"), (void **) &data) == SUCCESS &&
sizeof("_GET"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_ARRAY && Z_TYPE_PP(data) == IS_ARRAY &&
zend_rt_hash_find(Z_ARRVAL_PP(data), PS(session_name), zend_rt_hash_find(Z_ARRVAL_PP(data), PS(session_name), lensess + 1, (void **) &ppid) == SUCCESS
lensess + 1, (void **) &ppid) == SUCCESS) { ) {
PPID2SID; PPID2SID;
PS(send_cookie) = 0; PS(send_cookie) = 0;
} }
if (!PS(use_only_cookies) && !PS(id) && if (!PS(use_only_cookies) && !PS(id) &&
zend_ascii_hash_find(&EG(symbol_table), "_POST", zend_ascii_hash_find(&EG(symbol_table), "_POST", sizeof("_POST"), (void **) &data) == SUCCESS &&
sizeof("_POST"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_ARRAY && Z_TYPE_PP(data) == IS_ARRAY &&
zend_rt_hash_find(Z_ARRVAL_PP(data), PS(session_name), zend_rt_hash_find(Z_ARRVAL_PP(data), PS(session_name), lensess + 1, (void **) &ppid) == SUCCESS
lensess + 1, (void **) &ppid) == SUCCESS) { ) {
PPID2SID; PPID2SID;
PS(send_cookie) = 0; PS(send_cookie) = 0;
} }
} }
/* check the REQUEST_URI symbol for a string of the form /* Check the REQUEST_URI symbol for a string of the form
'<session-name>=<session-id>' to allow URLs of the form * '<session-name>=<session-id>' to allow URLs of the form
http://yoursite/<session-name>=<session-id>/script.php */ * http://yoursite/<session-name>=<session-id>/script.php */
if (!PS(use_only_cookies) && !PS(id) && PG(http_globals)[TRACK_VARS_SERVER] && if (!PS(use_only_cookies) && !PS(id) && PG(http_globals)[TRACK_VARS_SERVER] &&
zend_ascii_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_URI", zend_ascii_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_URI", sizeof("REQUEST_URI"), (void **) &data) == SUCCESS &&
sizeof("REQUEST_URI"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_STRING && Z_TYPE_PP(data) == IS_STRING &&
(p = strstr(Z_STRVAL_PP(data), PS(session_name))) && (p = strstr(Z_STRVAL_PP(data), PS(session_name))) &&
p[lensess] == '=') { p[lensess] == '='
) {
char *q; char *q;
p += lensess + 1; p += lensess + 1;
@ -1375,17 +1356,17 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */
} }
} }
/* check whether the current request was referred to by /* Check whether the current request was referred to by
an external site which invalidates the previously found id */ * an external site which invalidates the previously found id. */
if (PS(id) && if (PS(id) &&
PS(extern_referer_chk)[0] != '\0' && PS(extern_referer_chk)[0] != '\0' &&
PG(http_globals)[TRACK_VARS_SERVER] && PG(http_globals)[TRACK_VARS_SERVER] &&
zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_REFERER", zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_REFERER", sizeof("HTTP_REFERER"), (void **) &data) == SUCCESS &&
sizeof("HTTP_REFERER"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_STRING && Z_TYPE_PP(data) == IS_STRING &&
Z_STRLEN_PP(data) != 0 && Z_STRLEN_PP(data) != 0 &&
strstr(Z_STRVAL_PP(data), PS(extern_referer_chk)) == NULL) { strstr(Z_STRVAL_PP(data), PS(extern_referer_chk)) == NULL
) {
efree(PS(id)); efree(PS(id));
PS(id) = NULL; PS(id) = NULL;
PS(send_cookie) = 1; PS(send_cookie) = 1;
@ -1452,18 +1433,19 @@ PHPAPI void session_adapt_url(const char *url, size_t urllen, char **new, size_t
Set session cookie parameters */ Set session cookie parameters */
static PHP_FUNCTION(session_set_cookie_params) static PHP_FUNCTION(session_set_cookie_params)
{ {
/* lifetime is really a numeric, but the alter_ini_entry method wants a string */ zval **lifetime = NULL;
char *lifetime, *path = NULL, *domain = NULL; char *path = NULL, *domain = NULL;
int lifetime_len, path_len, domain_len, argc = ZEND_NUM_ARGS(); int path_len, domain_len, argc = ZEND_NUM_ARGS();
zend_bool secure = 0, httponly = 0; zend_bool secure = 0, httponly = 0;
if (!PS(use_cookies) || if (!PS(use_cookies) ||
zend_parse_parameters(argc TSRMLS_CC, "s|ssbb", &lifetime, &lifetime_len, &path, &path_len, zend_parse_parameters(argc TSRMLS_CC, "Z|ssbb", &lifetime, &path, &path_len, &domain, &domain_len, &secure, &httponly) == FAILURE) {
&domain, &domain_len, &secure, &httponly) == FAILURE) {
return; return;
} }
zend_alter_ini_entry("session.cookie_lifetime", sizeof("session.cookie_lifetime"), lifetime, lifetime_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); 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) { if (path) {
zend_alter_ini_entry("session.cookie_path", sizeof("session.cookie_path"), path, path_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); zend_alter_ini_entry("session.cookie_path", sizeof("session.cookie_path"), path, path_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
@ -1482,7 +1464,7 @@ static PHP_FUNCTION(session_set_cookie_params)
/* }}} */ /* }}} */
/* {{{ proto array session_get_cookie_params(void) U /* {{{ proto array session_get_cookie_params(void) U
Return the session cookie parameters */ Return the session cookie parameters */
static PHP_FUNCTION(session_get_cookie_params) static PHP_FUNCTION(session_get_cookie_params)
{ {
if (zend_parse_parameters_none() == FAILURE) { if (zend_parse_parameters_none() == FAILURE) {
@ -1730,18 +1712,18 @@ static PHP_FUNCTION(session_cache_limiter)
Return the current cache expire. If new_cache_expire is given, the current cache_expire is replaced with 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) static PHP_FUNCTION(session_cache_expire)
{ {
/* Expires is really a numeric, but the alter_ini_entry method wants a string */ zval **expires = NULL;
char *expires = NULL; int argc = ZEND_NUM_ARGS();
int expires_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s&", &expires, &expires_len, UG(utf8_conv)) == FAILURE) { if (zend_parse_parameters(argc TSRMLS_CC, "|Z", &expires) == FAILURE) {
return; return;
} }
RETVAL_LONG(PS(cache_expire)); RETVAL_LONG(PS(cache_expire));
if (expires) { if (argc == 1) {
zend_alter_ini_entry("session.cache_expire", sizeof("session.cache_expire"), expires, expires_len, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); 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);
} }
} }
/* }}} */ /* }}} */
@ -1934,7 +1916,7 @@ static const zend_function_entry session_functions[] = {
PHP_FE(session_get_cookie_params, arginfo_session_void) PHP_FE(session_get_cookie_params, arginfo_session_void)
PHP_FE(session_write_close, arginfo_session_void) PHP_FE(session_write_close, arginfo_session_void)
PHP_FALIAS(session_commit, session_write_close, arginfo_session_void) PHP_FALIAS(session_commit, session_write_close, arginfo_session_void)
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
/* }}} */ /* }}} */
@ -2115,9 +2097,9 @@ static inline void php_session_rfc1867_early_find_sid(php_session_rfc1867_progre
if (PS(use_cookies)) { if (PS(use_cookies)) {
sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC);
if (PG(http_globals)[TRACK_VARS_COOKIE] if (PG(http_globals)[TRACK_VARS_COOKIE] &&
&& zend_u_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]), Z_TYPE(progress->sname), Z_UNIVAL(progress->sname), Z_UNILEN(progress->sname)+1, (void **)&ppid) == SUCCESS) { zend_u_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]), Z_TYPE(progress->sname), Z_UNIVAL(progress->sname), Z_UNILEN(progress->sname)+1, (void **)&ppid) == SUCCESS
) {
zval_dtor(&progress->sid); zval_dtor(&progress->sid);
ZVAL_ZVAL(&progress->sid, *ppid, 1, 0); ZVAL_ZVAL(&progress->sid, *ppid, 1, 0);
convert_to_string(&progress->sid); convert_to_string(&progress->sid);
@ -2129,9 +2111,9 @@ static inline void php_session_rfc1867_early_find_sid(php_session_rfc1867_progre
return; return;
} }
sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC);
if (PG(http_globals)[TRACK_VARS_GET] if (PG(http_globals)[TRACK_VARS_GET] &&
&& zend_u_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), Z_TYPE(progress->sname), Z_UNIVAL(progress->sname), Z_UNILEN(progress->sname)+1, (void **)&ppid) == SUCCESS) { zend_u_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), Z_TYPE(progress->sname), Z_UNIVAL(progress->sname), Z_UNILEN(progress->sname)+1, (void **)&ppid) == SUCCESS
) {
zval_dtor(&progress->sid); zval_dtor(&progress->sid);
ZVAL_ZVAL(&progress->sid, *ppid, 1, 0); ZVAL_ZVAL(&progress->sid, *ppid, 1, 0);
convert_to_string(&progress->sid); convert_to_string(&progress->sid);
@ -2218,7 +2200,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
multipart_event_formdata *data = (multipart_event_formdata *) event_data; multipart_event_formdata *data = (multipart_event_formdata *) event_data;
size_t name_len, value_len; size_t name_len, value_len;
zstr str; zstr str;
/* orig callback may have modified *data->newlength */ /* orig callback may have modified *data->newlength */
if (data->newlength) { if (data->newlength) {
value_len = *data->newlength; value_len = *data->newlength;
@ -2253,15 +2235,14 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
case MULTIPART_EVENT_FILE_START: { case MULTIPART_EVENT_FILE_START: {
multipart_event_file_start *data = (multipart_event_file_start *) event_data; multipart_event_file_start *data = (multipart_event_file_start *) event_data;
/* Do nothing when $_POST[session.upload_progress.name] is not set /* Do nothing when $_POST[session.upload_progress.name] is not set
* or when no session id was sent */ * or when no session id was sent */
if (!Z_TYPE(progress->sid) || !Z_TYPE(progress->key)) { if (!Z_TYPE(progress->sid) || !Z_TYPE(progress->key)) {
break; break;
} }
/* First FILE_START event, initializing */ /* First FILE_START event, initializing */
if (!progress->data) { if (!progress->data) {
php_rinit_session(0 TSRMLS_CC); php_rinit_session(0 TSRMLS_CC);
PS(id) = estrndup(Z_STRVAL(progress->sid), Z_STRLEN(progress->sid)); PS(id) = estrndup(Z_STRVAL(progress->sid), Z_STRLEN(progress->sid));
PS(apply_trans_sid) = progress->apply_trans_sid; PS(apply_trans_sid) = progress->apply_trans_sid;
@ -2307,7 +2288,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
add_ascii_assoc_zval_ex(progress->current_file, "bytes_processed", sizeof("bytes_processed"), progress->current_file_bytes_processed); add_ascii_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); add_next_index_zval(progress->files, progress->current_file);
Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed; Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed;
php_session_rfc1867_update(progress, 0 TSRMLS_CC); php_session_rfc1867_update(progress, 0 TSRMLS_CC);
@ -2319,7 +2300,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
if (!Z_TYPE(progress->sid) || !Z_TYPE(progress->key)) { if (!Z_TYPE(progress->sid) || !Z_TYPE(progress->key)) {
break; break;
} }
Z_LVAL_P(progress->current_file_bytes_processed) = data->offset + data->length; Z_LVAL_P(progress->current_file_bytes_processed) = data->offset + data->length;
Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed; Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed;
@ -2332,7 +2313,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
if (!Z_TYPE(progress->sid) || !Z_TYPE(progress->key)) { if (!Z_TYPE(progress->sid) || !Z_TYPE(progress->key)) {
break; break;
} }
if (data->temp_filename.v) { if (data->temp_filename.v) {
add_ascii_assoc_text_ex(progress->current_file, "tmp_name", sizeof("tmp_name"), data->temp_filename, 1); add_ascii_assoc_text_ex(progress->current_file, "tmp_name", sizeof("tmp_name"), data->temp_filename, 1);
} }