jani Mon May 18 17:23:42 2009 UTC Modified files: (Branch: PHP_5_2) /php-src/ext/session mod_files.c mod_mm.c mod_user.c php_session.h session.c Log: MFH: Sync WS / CS changes where applicable
http://cvs.php.net/viewvc.cgi/php-src/ext/session/mod_files.c?r1=1.100.2.3.2.13&r2=1.100.2.3.2.14&diff_format=u Index: php-src/ext/session/mod_files.c diff -u php-src/ext/session/mod_files.c:1.100.2.3.2.13 php-src/ext/session/mod_files.c:1.100.2.3.2.14 --- php-src/ext/session/mod_files.c:1.100.2.3.2.13 Mon Apr 6 11:49:33 2009 +++ php-src/ext/session/mod_files.c Mon May 18 17:23:42 2009 @@ -1,4 +1,4 @@ -/* +/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mod_files.c,v 1.100.2.3.2.13 2009/04/06 11:49:33 bjori Exp $ */ +/* $Id: mod_files.c,v 1.100.2.3.2.14 2009/05/18 17:23:42 jani Exp $ */ #include "php.h" @@ -86,7 +86,7 @@ } len = p - key; - + if (len == 0) { ret = 0; } @@ -100,7 +100,7 @@ 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))) { @@ -120,18 +120,18 @@ memcpy(buf + n, key, key_len); n += key_len; buf[n] = '\0'; - + return buf; } #ifndef O_BINARY -#define O_BINARY 0 -#endif +# define O_BINARY 0 +#endif static void ps_files_close(ps_files *data) { if (data->fd != -1) { -#ifdef PHP_WIN32 +#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); @@ -177,13 +177,12 @@ return; } if ( - S_ISLNK(sbuf.st_mode) && + S_ISLNK(sbuf.st_mode) && ( php_check_open_basedir(buf TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(buf, NULL, CHECKUID_CHECK_FILE_AND_DIR)) ) ) { - close(data->fd); return; } @@ -200,8 +199,7 @@ } #endif } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "open(%s, O_RDWR) failed: %s (%d)", buf, - strerror(errno), errno); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "open(%s, O_RDWR) failed: %s (%d)", buf, strerror(errno), errno); } } } @@ -230,7 +228,7 @@ /* 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)) { @@ -245,7 +243,7 @@ buf[dirname_len + entry_len + 1] = '\0'; /* check whether its last access was more than maxlifet ago */ - if (VCWD_STAT(buf, &sbuf) == 0 && + if (VCWD_STAT(buf, &sbuf) == 0 && #ifdef NETWARE (now - sbuf.st_mtime.tv_sec) > maxlifetime) { #else @@ -278,16 +276,14 @@ /* if save path is an empty string, determine the temporary dir */ save_path = php_get_temporary_directory(); - if (strcmp(save_path, "/tmp")) { - if (PG(safe_mode) && (!php_checkuid(save_path, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - return FAILURE; - } - if (php_check_open_basedir(save_path TSRMLS_CC)) { - return FAILURE; - } + if (PG(safe_mode) && (!php_checkuid(save_path, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + return FAILURE; + } + if (php_check_open_basedir(save_path TSRMLS_CC)) { + return FAILURE; } } - + /* split up input parameter */ last = save_path; p = strchr(save_path, ';'); @@ -307,7 +303,7 @@ return FAILURE; } } - + if (argc > 2) { errno = 0; filemode = strtol(argv[1], NULL, 8); @@ -318,17 +314,16 @@ } save_path = argv[argc - 1]; - data = emalloc(sizeof(*data)); - memset(data, 0, sizeof(*data)); - + 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); - + PS_SET_MOD_DATA(data); - + return SUCCESS; } @@ -389,7 +384,7 @@ efree(*val); return FAILURE; } - + return SUCCESS; } @@ -403,11 +398,8 @@ 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) { ftruncate(data->fd, 0); } @@ -442,11 +434,10 @@ 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 - */ + * that was not yet written to disk. */ if (!VCWD_ACCESS(buf, F_OK)) { return FAILURE; } @@ -456,14 +447,14 @@ return SUCCESS; } -PS_GC_FUNC(files) +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); } http://cvs.php.net/viewvc.cgi/php-src/ext/session/mod_mm.c?r1=1.46.2.1.2.7&r2=1.46.2.1.2.8&diff_format=u Index: php-src/ext/session/mod_mm.c diff -u php-src/ext/session/mod_mm.c:1.46.2.1.2.7 php-src/ext/session/mod_mm.c:1.46.2.1.2.8 --- php-src/ext/session/mod_mm.c:1.46.2.1.2.7 Wed Dec 31 11:17:43 2008 +++ php-src/ext/session/mod_mm.c Mon May 18 17:23:42 2009 @@ -1,4 +1,4 @@ -/* +/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mod_mm.c,v 1.46.2.1.2.7 2008/12/31 11:17:43 sebastian Exp $ */ +/* $Id: mod_mm.c,v 1.46.2.1.2.8 2009/05/18 17:23:42 jani Exp $ */ #include "php.h" @@ -42,9 +42,7 @@ /* For php_uint32 */ #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 { struct ps_sd *next; @@ -67,21 +65,21 @@ static ps_mm *ps_mm_instance = NULL; #if 0 -#define ps_mm_debug(a) printf a +# define ps_mm_debug(a) printf a #else -#define ps_mm_debug(a) +# 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; } @@ -91,10 +89,10 @@ 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; @@ -119,9 +117,9 @@ 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(); @@ -132,24 +130,25 @@ 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) + 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; @@ -161,19 +160,22 @@ slot = ps_sd_hash(sd->key, strlen(sd->key)) & data->hash_max; - if (data->hash[slot] == sd) + if (data->hash[slot] == sd) { data->hash[slot] = sd->next; - else { + } 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) + + if (sd->data) { mm_free(data->mm, sd->data); + } + mm_free(data->mm, sd); } @@ -184,22 +186,25 @@ 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)) + + 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) + 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; } @@ -214,6 +219,9 @@ data->owner = getpid(); data->mm = mm_create(0, path); if (!data->mm) { + TSRMLS_FETCH(); + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "mm_create(0, %s) failed, err %s", path, mm_error()); return FAILURE; } @@ -236,14 +244,17 @@ /* 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; + 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) { next = sd->next; ps_sd_destroy(data, sd); } - + } + mm_free(data->mm, data->hash); mm_destroy(data->mm); free(data); @@ -258,17 +269,17 @@ int ret; ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1); - if (!ps_mm_instance) { + if (!ps_mm_instance) { return FAILURE; } if (!(euid_len = slprintf(euid, sizeof(euid), "%d", geteuid()))) { 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) - 1) + mod_name_len + euid_len + 1); - + memcpy(ps_mm_path, PS(save_path), save_path_len); if (PS(save_path)[save_path_len - 1] != DEFAULT_SLASH) { ps_mm_path[save_path_len] = DEFAULT_SLASH; @@ -282,15 +293,15 @@ 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; } @@ -307,12 +318,12 @@ PS_OPEN_FUNC(mm) { ps_mm_debug(("open: ps_mm_instance=%p\n", ps_mm_instance)); - - if (!ps_mm_instance) + + if (!ps_mm_instance) { return FAILURE; - + } PS_SET_MOD_DATA(ps_mm_instance); - + return SUCCESS; } @@ -330,7 +341,7 @@ int ret = FAILURE; mm_lock(data->mm, MM_LOCK_RD); - + sd = ps_sd_lookup(data, key, 0); if (sd) { *vallen = sd->datalen; @@ -341,7 +352,7 @@ } mm_unlock(data->mm); - + return ret; } @@ -360,8 +371,9 @@ if (sd) { if (vallen >= sd->alloclen) { - if (data->mm) + if (data->mm) { mm_free(data->mm, sd->data); + } sd->alloclen = vallen + 1; sd->data = mm_malloc(data->mm, sd->alloclen); @@ -379,7 +391,7 @@ } mm_unlock(data->mm); - + return sd ? SUCCESS : FAILURE; } @@ -387,28 +399,29 @@ { PS_MM_DATA; ps_sd *sd; - + mm_lock(data->mm, MM_LOCK_RW); - + sd = ps_sd_lookup(data, key, 0); - if (sd) + if (sd) { ps_sd_destroy(data, sd); - + } + mm_unlock(data->mm); - + return SUCCESS; } -PS_GC_FUNC(mm) +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; @@ -416,7 +429,7 @@ mm_lock(data->mm, MM_LOCK_RW); ehash = data->hash + data->hash_max + 1; - for (ohash = data->hash; ohash < ehash; ohash++) + for (ohash = data->hash; ohash < ehash; ohash++) { for (sd = *ohash; sd; sd = next) { next = sd->next; if (sd->ctime < limit) { @@ -425,9 +438,10 @@ (*nrdels)++; } } + } mm_unlock(data->mm); - + return SUCCESS; } http://cvs.php.net/viewvc.cgi/php-src/ext/session/mod_user.c?r1=1.29.2.1.2.3&r2=1.29.2.1.2.4&diff_format=u Index: php-src/ext/session/mod_user.c diff -u php-src/ext/session/mod_user.c:1.29.2.1.2.3 php-src/ext/session/mod_user.c:1.29.2.1.2.4 --- php-src/ext/session/mod_user.c:1.29.2.1.2.3 Wed Dec 31 11:17:43 2008 +++ php-src/ext/session/mod_user.c Mon May 18 17:23:42 2009 @@ -1,4 +1,4 @@ -/* +/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mod_user.c,v 1.29.2.1.2.3 2008/12/31 11:17:43 sebastian Exp $ */ +/* $Id: mod_user.c,v 1.29.2.1.2.4 2009/05/18 17:23:42 jani Exp $ */ #include "php.h" #include "php_session.h" @@ -26,39 +26,31 @@ PS_MOD(user) }; -#define SESS_ZVAL_LONG(val, a) \ -{ \ - MAKE_STD_ZVAL(a); \ - Z_TYPE_P(a) = IS_LONG; \ - Z_LVAL_P(a) = val; \ -} - -#define SESS_ZVAL_STRING(vl, a) \ -{ \ - int len = strlen(vl); \ - MAKE_STD_ZVAL(a); \ - Z_TYPE_P(a) = IS_STRING; \ - Z_STRLEN_P(a) = len; \ - Z_STRVAL_P(a) = estrndup(vl, len); \ -} - -#define SESS_ZVAL_STRINGN(vl, ln, a) \ -{ \ - MAKE_STD_ZVAL(a); \ - Z_TYPE_P(a) = IS_STRING; \ - Z_STRLEN_P(a) = ln; \ - Z_STRVAL_P(a) = estrndup(vl, ln); \ +#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) { + if (call_user_function(EG(function_table), NULL, func, retval, argc, argv TSRMLS_CC) == FAILURE) { zval_ptr_dtor(&retval); retval = NULL; } @@ -70,33 +62,33 @@ return retval; } -#define STDVARS \ - zval *retval; \ - int ret = FAILURE; \ +#define STDVARS \ + zval *retval; \ + int ret = FAILURE; \ ps_user *mdata = PS_GET_MOD_DATA(); \ - if (!mdata) \ + if (!mdata) \ return FAILURE #define PSF(a) mdata->name.ps_##a -#define FINISH \ +#define FINISH \ if (retval) { \ convert_to_long(retval); \ - ret = Z_LVAL_P(retval); \ + ret = Z_LVAL_P(retval); \ zval_ptr_dtor(&retval); \ - } \ + } \ return ret PS_OPEN_FUNC(user) { zval *args[2]; STDVARS; - - SESS_ZVAL_STRING(save_path, args[0]); - SESS_ZVAL_STRING(session_name, args[1]); - + + 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); - + FINISH; } @@ -107,8 +99,9 @@ retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC); - for (i = 0; i < 6; i++) + for (i = 0; i < 6; i++) { zval_ptr_dtor(&mdata->names[i]); + } efree(mdata); PS_SET_MOD_DATA(NULL); @@ -121,10 +114,10 @@ zval *args[1]; STDVARS; - SESS_ZVAL_STRING(key, args[0]); + 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)); @@ -141,9 +134,9 @@ { zval *args[2]; STDVARS; - - SESS_ZVAL_STRING(key, args[0]); - SESS_ZVAL_STRINGN(val, vallen, args[1]); + + 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); @@ -155,7 +148,7 @@ zval *args[1]; STDVARS; - SESS_ZVAL_STRING(key, args[0]); + SESS_ZVAL_STRING((char*)key, args[0]); retval = ps_call_handler(PSF(destroy), 1, args TSRMLS_CC); http://cvs.php.net/viewvc.cgi/php-src/ext/session/php_session.h?r1=1.101.2.2.2.8&r2=1.101.2.2.2.9&diff_format=u Index: php-src/ext/session/php_session.h diff -u php-src/ext/session/php_session.h:1.101.2.2.2.8 php-src/ext/session/php_session.h:1.101.2.2.2.9 --- php-src/ext/session/php_session.h:1.101.2.2.2.8 Sun Apr 26 01:20:56 2009 +++ php-src/ext/session/php_session.h Mon May 18 17:23:42 2009 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_session.h,v 1.101.2.2.2.8 2009/04/26 01:20:56 jani Exp $ */ +/* $Id: php_session.h,v 1.101.2.2.2.9 2009/05/18 17:23:42 jani Exp $ */ #ifndef PHP_SESSION_H #define PHP_SESSION_H @@ -202,18 +202,18 @@ zval **struc; #define PS_ENCODE_LOOP(code) do { \ - HashTable *_ht = Z_ARRVAL_P(PS(http_session_vars)); \ - int key_type; \ + 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); \ (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) { \ + 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; \ } \ } \ http://cvs.php.net/viewvc.cgi/php-src/ext/session/session.c?r1=1.417.2.8.2.47&r2=1.417.2.8.2.48&diff_format=u Index: php-src/ext/session/session.c diff -u php-src/ext/session/session.c:1.417.2.8.2.47 php-src/ext/session/session.c:1.417.2.8.2.48 --- php-src/ext/session/session.c:1.417.2.8.2.47 Sun Apr 26 01:20:56 2009 +++ php-src/ext/session/session.c Mon May 18 17:23:42 2009 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: session.c,v 1.417.2.8.2.47 2009/04/26 01:20:56 jani Exp $ */ +/* $Id: session.c,v 1.417.2.8.2.48 2009/05/18 17:23:42 jani Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -82,7 +82,7 @@ PS(id) = NULL; PS(session_status) = php_session_none; PS(mod_data) = NULL; - + /* Do NOT init PS(mod_user_names) here! */ PS(http_session_vars) = NULL; } /* }}} */ @@ -94,7 +94,7 @@ zval_ptr_dtor(&PS(http_session_vars)); PS(http_session_vars) = NULL; } - + /* Do NOT destroy PS(mod_user_names) here! */ if (PS(mod_data)) { zend_try { PS(mod)->s_close(&PS(mod_data) TSRMLS_CC); @@ -132,15 +132,12 @@ zval **sym_track = NULL; IF_SESSION_VARS() { - zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, namelen + 1, - (void *) &sym_track); + zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, namelen + 1, (void *) &sym_track); } else { return; } - /* - * Set up a proper reference between $_SESSION["x"] and $x. - */ + /* Set up a proper reference between $_SESSION["x"] and $x. */ if (PG(register_globals)) { zval **sym_global = NULL; @@ -180,13 +177,12 @@ { if (PG(register_globals)) { zval **old_symbol; - if (zend_hash_find(&EG(symbol_table),name,namelen+1,(void *)&old_symbol) == SUCCESS) { + if (zend_hash_find(&EG(symbol_table),name,namelen+1,(void *)&old_symbol) == SUCCESS) { if ((Z_TYPE_PP(old_symbol) == IS_ARRAY && Z_ARRVAL_PP(old_symbol) == &EG(symbol_table)) || *old_symbol == PS(http_session_vars)) { return; } - /* - * A global symbol with the same name exists already. That + /* A global symbol with the same name exists already. That * symbol might have been created by other means (e.g. $_GET). * * hash_update in zend_set_hash_symbol is not good, because @@ -194,16 +190,13 @@ * of a global variable) dangling. * * BTW: if you use register_globals references between - * session-vars won't work because of this very reason! - */ + * session-vars won't work because of this very reason! */ REPLACE_ZVAL_VALUE(old_symbol,state_val,1); - /* - * The following line will update the reference table used for - * unserialization. It is optional, because some storage - * formats may not be able to represent references. - */ + /* The following line will update the reference table used for + * unserialization. It is optional, because some storage + * formats may not be able to represent references. */ if (var_hash) { PHP_VAR_UNSERIALIZE_ZVAL_CHANGED(var_hash,state_val,*old_symbol); @@ -224,23 +217,18 @@ int ret = FAILURE; IF_SESSION_VARS() { - ret = zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, - namelen+1, (void **) state_var); + ret = zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, namelen + 1, (void **) state_var); - /* - * If register_globals is enabled, and + /* If register_globals is enabled, and * if there is an entry for the slot in $_SESSION, and * if that entry is still set to NULL, and * if the global var exists, then - * we prefer the same key in the global sym table - */ + * we prefer the same key in the global sym table. */ - if (PG(register_globals) && ret == SUCCESS - && Z_TYPE_PP(*state_var) == IS_NULL) { + if (PG(register_globals) && ret == SUCCESS && Z_TYPE_PP(*state_var) == IS_NULL) { zval **tmp; - if (zend_hash_find(&EG(symbol_table), name, namelen + 1, - (void **) &tmp) == SUCCESS) { + if (zend_hash_find(&EG(symbol_table), name, namelen + 1, (void **) &tmp) == SUCCESS) { *state_var = tmp; } } @@ -287,7 +275,7 @@ ret = NULL; } } 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; } @@ -373,17 +361,15 @@ gettimeofday(&tv, NULL); - if (zend_hash_find(&EG(symbol_table), "_SERVER", - sizeof("_SERVER"), (void **) &array) == SUCCESS && + 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) { + 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); + 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: @@ -489,8 +475,7 @@ /* 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 - */ + * 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) { @@ -518,11 +503,10 @@ switch (n) { case HASH_KEY_IS_STRING: - if (zend_hash_find(&EG(symbol_table), str, str_len, - (void **) &val) == SUCCESS - && val && Z_TYPE_PP(val) != IS_NULL) { - ZEND_SET_SYMBOL_WITH_LENGTH(ht, str, str_len, *val, - (*val)->refcount + 1 , 1); + if (zend_hash_find(&EG(symbol_table), str, str_len, (void **) &val) == SUCCESS && + val && Z_TYPE_PP(val) != IS_NULL + ) { + ZEND_SET_SYMBOL_WITH_LENGTH(ht, str, str_len, *val, (*val)->refcount + 1 , 1); ret = 1; } break; @@ -549,11 +533,11 @@ zend_hash_internal_pointer_reset_ex(ht, &pos); - while (zend_hash_get_current_data_ex(ht, - (void **) &val, &pos) != FAILURE) { + while (zend_hash_get_current_data_ex(ht, (void **) &val, &pos) != FAILURE) { if (Z_TYPE_PP(val) == IS_NULL) { - if (migrate_global(ht, &pos TSRMLS_CC)) + if (migrate_global(ht, &pos TSRMLS_CC)) { do_warn = 1; + } } zend_hash_move_forward_ex(ht, &pos); } @@ -610,6 +594,8 @@ } 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); } @@ -636,6 +622,8 @@ } 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); } @@ -685,6 +673,7 @@ return FAILURE; } } + OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); return SUCCESS; } @@ -916,10 +905,7 @@ 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)) /* {{{ */ +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; @@ -1004,9 +990,9 @@ } 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, + 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'; @@ -1102,8 +1088,7 @@ int output_start_lineno = php_get_output_start_lineno(TSRMLS_C); if (output_start_filename) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cache limiter - headers already sent (output started at %s:%d)", - output_start_filename, output_start_lineno); + 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"); } @@ -1143,8 +1128,7 @@ int output_start_lineno = php_get_output_start_lineno(TSRMLS_C); if (output_start_filename) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cookie - headers already sent by (output started at %s:%d)", - output_start_filename, output_start_lineno); + 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"); } @@ -1314,17 +1298,14 @@ lensess = strlen(PS(session_name)); - /* - * Cookies are preferred, because initially - * cookie and get variables will be available. - */ + /* 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 && + 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) { + 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; @@ -1332,36 +1313,34 @@ } if (!PS(use_only_cookies) && !PS(id) && - zend_hash_find(&EG(symbol_table), "_GET", - sizeof("_GET"), (void **) &data) == SUCCESS && + 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) { + 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 && + 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) { + 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 */ + /* 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 && + 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] == '=') { + p[lensess] == '=' + ) { char *q; p += lensess + 1; @@ -1371,17 +1350,17 @@ } } - /* check whether the current request was referred to by - an external site which invalidates the previously found id */ + /* 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 && + 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) { + strstr(Z_STRVAL_PP(data), PS(extern_referer_chk)) == NULL + ) { efree(PS(id)); PS(id) = NULL; PS(send_cookie) = 1; @@ -1472,17 +1451,17 @@ convert_to_long_ex(secure); zend_alter_ini_entry("session.cookie_secure", sizeof("session.cookie_secure"), Z_BVAL_PP(secure)?"1":"0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); } - if (ZEND_NUM_ARGS() > 4) { - convert_to_long_ex(httponly); - zend_alter_ini_entry("session.cookie_httponly", sizeof("session.cookie_httponly"), Z_BVAL_PP(httponly)?"1":"0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - } + if (ZEND_NUM_ARGS() > 4) { + convert_to_long_ex(httponly); + zend_alter_ini_entry("session.cookie_httponly", sizeof("session.cookie_httponly"), Z_BVAL_PP(httponly)?"1":"0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + } } } } /* }}} */ /* {{{ proto array session_get_cookie_params(void) - Return the session cookie parameters */ + Return the session cookie parameters */ static PHP_FUNCTION(session_get_cookie_params) { if (ZEND_NUM_ARGS() != 0) { @@ -1759,7 +1738,8 @@ convert_to_string_ex(entry); if ((strcmp(Z_STRVAL_PP(entry), "HTTP_SESSION_VARS") != 0) && - (strcmp(Z_STRVAL_PP(entry), "_SESSION") != 0)) { + (strcmp(Z_STRVAL_PP(entry), "_SESSION") != 0) + ) { PS_ADD_VARL(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry)); } } @@ -1853,8 +1833,7 @@ zend_hash_internal_pointer_reset_ex(ht, &pos); - while (zend_hash_get_current_key_ex(ht, &str, &str_len, &num_key, - 0, &pos) == HASH_KEY_IS_STRING) { + while (zend_hash_get_current_key_ex(ht, &str, &str_len, &num_key, 0, &pos) == HASH_KEY_IS_STRING) { zend_delete_global_variable(str, str_len-1 TSRMLS_CC); zend_hash_move_forward_ex(ht, &pos); } @@ -1961,7 +1940,7 @@ /* {{{ session_functions[] */ -static const zend_function_entry session_functions[] = { +static zend_function_entry session_functions[] = { PHP_FE(session_name, NULL) PHP_FE(session_module_name, NULL) PHP_FE(session_save_path, NULL)
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php