diff options
author | Rasmus Lerdorf <rasmus@php.net> | 2014-10-16 21:28:40 -0700 |
---|---|---|
committer | Rasmus Lerdorf <rasmus@php.net> | 2014-10-16 21:28:40 -0700 |
commit | a9d6556971a435f71eabf142d8fb814382f3b6ac (patch) | |
tree | 4fecce88bbc1bc3259856eb0314d780184de85eb /ext/session/session.c | |
parent | 86674b5837bffe4486714f9661620020ee498f3b (diff) | |
parent | 176b8d7ca3aef3a172d8e429627c98e0328d02d8 (diff) | |
download | php-git-a9d6556971a435f71eabf142d8fb814382f3b6ac.tar.gz |
Merge branch 'master' of git.php.net:php-src
* 'master' of git.php.net:php-src: (1132 commits)
Micro optimizations for isset/empty
Micro optimization for zend_hash_next_index_insert_new()
Fix array_keys() on $GLOBALS
Fix procedural finfo calls in methods
Fix allocator for 64bit zend_long with 32bit long
Use intptr_t for zend_intptr_t typedef
Fix format strings in zend_alloc
Drop zend_long64 in favor of int64_t
Removed deprecated fields
NEWS
cleanup NEWS
removing the NEWS entry as we had to revert this fix for now
Revert "Merge branch 'PHP-5.5' into PHP-5.6"
Revert "fix TS build"
Revert "Merge branch 'PHP-5.4' into PHP-5.5"
Revert "Bug #67965: Fix blocking behavior in non-blocking crypto streams"
Revert "Bug #41631: Fix regression from first attempt (6569db8)"
NEWS
Fixed Bug #65171 imagescale() fails
Fixed bug #68234
...
Diffstat (limited to 'ext/session/session.c')
-rw-r--r-- | ext/session/session.c | 308 |
1 files changed, 148 insertions, 160 deletions
diff --git a/ext/session/session.c b/ext/session/session.c index 8632ba493c..dae965b048 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -48,7 +48,7 @@ #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 "zend_smart_str.h" #include "ext/standard/url.h" #include "ext/standard/basic_functions.h" #include "ext/standard/head.h" @@ -115,7 +115,7 @@ static inline void php_rshutdown_session_globals(TSRMLS_D) /* {{{ */ } zend_end_try(); } if (PS(id)) { - STR_RELEASE(PS(id)); + zend_string_release(PS(id)); } } /* }}} */ @@ -181,7 +181,7 @@ PHPAPI zval* php_get_session_var(zend_string *name TSRMLS_DC) /* {{{ */ static void php_session_track_init(TSRMLS_D) /* {{{ */ { zval session_vars; - zend_string *var_name = STR_INIT("_SESSION", sizeof("_SESSION") - 1, 0); + zend_string *var_name = zend_string_init("_SESSION", sizeof("_SESSION") - 1, 0); /* Unconditionally destroy existing array -- possible dirty data */ zend_delete_global_variable(var_name TSRMLS_CC); @@ -193,7 +193,7 @@ static void php_session_track_init(TSRMLS_D) /* {{{ */ ZVAL_NEW_REF(&PS(http_session_vars), &session_vars); Z_ADDREF_P(&PS(http_session_vars)); zend_hash_update_ind(&EG(symbol_table).ht, var_name, &PS(http_session_vars)); - STR_RELEASE(var_name); + zend_string_release(var_name); } /* }}} */ @@ -305,7 +305,7 @@ PHPAPI zend_string *php_session_create_id(PS_CREATE_SID_ARGS) /* {{{ */ } /* maximum 15+19+19+10 bytes */ - spprintf(&buf, 0, "%.15s%ld%ld%0.8F", remote_addr ? remote_addr : "", tv.tv_sec, (php_int_t)tv.tv_usec, php_combined_lcg(TSRMLS_C) * 10); + spprintf(&buf, 0, "%.15s%ld" ZEND_LONG_FMT "%0.8F", remote_addr ? remote_addr : "", tv.tv_sec, (zend_long)tv.tv_usec, php_combined_lcg(TSRMLS_C) * 10); switch (PS(hash_func)) { case PS_HASH_FUNC_MD5: @@ -416,7 +416,7 @@ PHPAPI zend_string *php_session_create_id(PS_CREATE_SID_ARGS) /* {{{ */ 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 = STR_ALLOC((digest_len + 2) * ((8.0f / PS(hash_bits_per_character) + 0.5)), 0); + outid = zend_string_alloc((digest_len + 2) * ((8.0f / PS(hash_bits_per_character) + 0.5)), 0); outid->len = (int)(bin_to_readable((char *)digest, digest_len, outid->val, (char)PS(hash_bits_per_character)) - (char *)&outid->val); efree(digest); @@ -514,7 +514,7 @@ static void php_session_initialize(TSRMLS_D) /* {{{ */ PHP_MD5Final(PS(session_data_hash), &context); php_session_decode(val->val, val->len TSRMLS_CC); - STR_RELEASE(val); + zend_string_release(val); } else { memset(PS(session_data_hash),'\0', 16); } @@ -551,7 +551,7 @@ static void php_session_save_current_state(TSRMLS_D) /* {{{ */ } else { ret = SUCCESS; } - STR_RELEASE(val); + zend_string_release(val); } else { ret = PS(mod)->s_write(&PS(mod_data), PS(id), STR_EMPTY_ALLOC() TSRMLS_CC); } @@ -581,7 +581,7 @@ static PHP_INI_MH(OnUpdateSaveHandler) /* {{{ */ ps_module *tmp; SESSION_CHECK_ACTIVE_STATE; - tmp = _php_find_ps_module(new_value TSRMLS_CC); + tmp = _php_find_ps_module(new_value->val TSRMLS_CC); if (PG(modules_activated) && !tmp) { int err_type; @@ -594,7 +594,7 @@ static PHP_INI_MH(OnUpdateSaveHandler) /* {{{ */ /* 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); + php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find save handler '%s'", new_value->val); } return FAILURE; } @@ -611,7 +611,7 @@ static PHP_INI_MH(OnUpdateSerializer) /* {{{ */ const ps_serializer *tmp; SESSION_CHECK_ACTIVE_STATE; - tmp = _php_find_ps_serializer(new_value TSRMLS_CC); + tmp = _php_find_ps_serializer(new_value->val TSRMLS_CC); if (PG(modules_activated) && !tmp) { int err_type; @@ -624,7 +624,7 @@ static PHP_INI_MH(OnUpdateSerializer) /* {{{ */ /* 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); + php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find serialization handler '%s'", new_value->val); } return FAILURE; } @@ -638,10 +638,10 @@ static PHP_INI_MH(OnUpdateTransSid) /* {{{ */ { SESSION_CHECK_ACTIVE_STATE; - if (!strncasecmp(new_value, "on", sizeof("on"))) { + if (!strncasecmp(new_value->val, "on", sizeof("on"))) { PS(use_trans_sid) = (zend_bool) 1; } else { - PS(use_trans_sid) = (zend_bool) atoi(new_value); + PS(use_trans_sid) = (zend_bool) atoi(new_value->val); } return SUCCESS; @@ -654,19 +654,19 @@ static PHP_INI_MH(OnUpdateSaveDir) /* {{{ */ if (stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) { char *p; - if (memchr(new_value, '\0', new_value_length) != NULL) { + if (memchr(new_value->val, '\0', new_value->len) != NULL) { return FAILURE; } /* we do not use zend_memrchr() since path can contain ; itself */ - if ((p = strchr(new_value, ';'))) { + if ((p = strchr(new_value->val, ';'))) { char *p2; p++; if ((p2 = strchr(p, ';'))) { p = p2 + 1; } } else { - p = new_value; + p = new_value->val; } if (PG(open_basedir) && *p && php_check_open_basedir(p TSRMLS_CC)) { @@ -674,7 +674,7 @@ static PHP_INI_MH(OnUpdateSaveDir) /* {{{ */ } } - OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); return SUCCESS; } /* }}} */ @@ -682,7 +682,7 @@ static PHP_INI_MH(OnUpdateSaveDir) /* {{{ */ static PHP_INI_MH(OnUpdateName) /* {{{ */ { /* Numeric session.name won't work at all */ - if ((!new_value_length || is_numeric_string(new_value, new_value_length, NULL, NULL, 0))) { + if ((!new_value->len || is_numeric_string(new_value->val, new_value->len, NULL, NULL, 0))) { int err_type; if (stage == ZEND_INI_STAGE_RUNTIME || stage == ZEND_INI_STAGE_ACTIVATE || stage == ZEND_INI_STAGE_STARTUP) { @@ -693,26 +693,26 @@ static PHP_INI_MH(OnUpdateName) /* {{{ */ /* Do not output error when restoring ini options. */ if (stage != ZEND_INI_STAGE_DEACTIVATE) { - php_error_docref(NULL TSRMLS_CC, err_type, "session.name cannot be a numeric or empty '%s'", new_value); + php_error_docref(NULL TSRMLS_CC, err_type, "session.name cannot be a numeric or empty '%s'", new_value->val); } return FAILURE; } - OnUpdateStringUnempty(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + OnUpdateStringUnempty(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); return SUCCESS; } /* }}} */ static PHP_INI_MH(OnUpdateHashFunc) /* {{{ */ { - php_int_t val; + zend_long val; char *endptr = NULL; #if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) PS(hash_ops) = NULL; #endif - val = ZEND_STRTOI(new_value, &endptr, 10); + val = ZEND_STRTOL(new_value->val, &endptr, 10); if (endptr && (*endptr == '\0')) { /* Numeric value */ PS(hash_func) = val ? 1 : 0; @@ -720,15 +720,15 @@ static PHP_INI_MH(OnUpdateHashFunc) /* {{{ */ return SUCCESS; } - if (new_value_length == (sizeof("md5") - 1) && - strncasecmp(new_value, "md5", sizeof("md5") - 1) == 0) { + if (new_value->len == (sizeof("md5") - 1) && + strncasecmp(new_value->val, "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) { + if (new_value->len == (sizeof("sha1") - 1) && + strncasecmp(new_value->val, "sha1", sizeof("sha1") - 1) == 0) { PS(hash_func) = PS_HASH_FUNC_SHA1; return SUCCESS; @@ -736,7 +736,7 @@ static PHP_INI_MH(OnUpdateHashFunc) /* {{{ */ #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); + php_hash_ops *ops = (php_hash_ops*)php_hash_fetch_ops(new_value->val, new_value->len); if (ops) { PS(hash_func) = PS_HASH_FUNC_OTHER; @@ -747,7 +747,7 @@ static PHP_INI_MH(OnUpdateHashFunc) /* {{{ */ } #endif /* HAVE_HASH_EXT }}} */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "session.configuration 'session.hash_function' must be existing hash function. %s does not exist.", new_value); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "session.configuration 'session.hash_function' must be existing hash function. %s does not exist.", new_value->val); return FAILURE; } /* }}} */ @@ -755,12 +755,12 @@ static PHP_INI_MH(OnUpdateHashFunc) /* {{{ */ static PHP_INI_MH(OnUpdateRfc1867Freq) /* {{{ */ { int tmp; - tmp = zend_atoi(new_value, new_value_length); + tmp = zend_atoi(new_value->val, new_value->len); 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(new_value->len > 0 && new_value->val[new_value->len-1] == '%') { if(tmp > 100) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "session.upload_progress.freq cannot be over 100%%"); return FAILURE; @@ -846,11 +846,11 @@ PS_SERIALIZER_DECODE_FUNC(php_serialize) /* {{{ */ const char *endptr = val + vallen; zval session_vars; php_unserialize_data_t var_hash; - zend_string *var_name = STR_INIT("_SESSION", sizeof("_SESSION") - 1, 0); + zend_string *var_name = zend_string_init("_SESSION", sizeof("_SESSION") - 1, 0); ZVAL_NULL(&session_vars); PHP_VAR_UNSERIALIZE_INIT(var_hash); - php_var_unserialize(&session_vars, &val, endptr, &var_hash TSRMLS_CC); + php_var_unserialize(&session_vars, (const unsigned char **)&val, endptr, &var_hash TSRMLS_CC); PHP_VAR_UNSERIALIZE_DESTROY(var_hash); if (!Z_ISUNDEF(PS(http_session_vars))) { zval_ptr_dtor(&PS(http_session_vars)); @@ -861,7 +861,7 @@ PS_SERIALIZER_DECODE_FUNC(php_serialize) /* {{{ */ ZVAL_NEW_REF(&PS(http_session_vars), &session_vars); Z_ADDREF_P(&PS(http_session_vars)); zend_hash_update_ind(&EG(symbol_table).ht, var_name, &PS(http_session_vars)); - STR_RELEASE(var_name); + zend_string_release(var_name); return SUCCESS; } /* }}} */ @@ -918,7 +918,7 @@ PS_SERIALIZER_DECODE_FUNC(php_binary) /* {{{ */ has_value = *p & PS_BIN_UNDEF ? 0 : 1; - name = STR_INIT(p + 1, namelen, 0); + name = zend_string_init(p + 1, namelen, 0); p += namelen + 1; @@ -939,7 +939,7 @@ PS_SERIALIZER_DECODE_FUNC(php_binary) /* {{{ */ } } PS_ADD_VARL(name); - STR_RELEASE(name); + zend_string_release(name); } PHP_VAR_UNSERIALIZE_DESTROY(var_hash); @@ -1010,7 +1010,7 @@ PS_SERIALIZER_DECODE_FUNC(php) /* {{{ */ } namelen = q - p; - name = STR_INIT(p, namelen, 0); + name = zend_string_init(p, namelen, 0); q++; if ((tmp = zend_hash_find(&EG(symbol_table).ht, name))) { @@ -1030,7 +1030,7 @@ PS_SERIALIZER_DECODE_FUNC(php) /* {{{ */ } PS_ADD_VARL(name); skip: - STR_RELEASE(name); + zend_string_release(name); p = q; } @@ -1148,7 +1148,7 @@ static inline void strcpy_gmt(char *ubuf, time_t *when) /* {{{ */ static inline void last_modified(TSRMLS_D) /* {{{ */ { const char *path; - php_stat_t sb; + zend_stat_t sb; char buf[MAX_STR + 1]; path = SG(request_info).path_translated; @@ -1178,7 +1178,7 @@ CACHE_LIMITER_FUNC(public) /* {{{ */ 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 */ + snprintf(buf, sizeof(buf) , "Cache-Control: public, max-age=" ZEND_LONG_FMT, PS(cache_expire) * 60); /* SAFE */ ADD_HEADER(buf); last_modified(TSRMLS_C); @@ -1189,7 +1189,7 @@ 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 */ + snprintf(buf, sizeof(buf), "Cache-Control: private, max-age=" ZEND_LONG_FMT ", pre-check=" ZEND_LONG_FMT, PS(cache_expire) * 60, PS(cache_expire) * 60); /* SAFE */ ADD_HEADER(buf); last_modified(TSRMLS_C); @@ -1268,11 +1268,12 @@ static void php_session_remove_cookie(TSRMLS_D) { zend_llist_element *current; char *session_cookie; zend_string *e_session_name; - int session_cookie_len, len = sizeof("Set-Cookie")-1; + int session_cookie_len; + uint len = sizeof("Set-Cookie")-1; e_session_name = php_url_encode(PS(session_name), strlen(PS(session_name))); spprintf(&session_cookie, 0, "Set-Cookie: %s=", e_session_name->val); - STR_FREE(e_session_name); + zend_string_free(e_session_name); session_cookie_len = strlen(session_cookie); current = l->head; @@ -1327,8 +1328,8 @@ static void php_session_send_cookie(TSRMLS_D) /* {{{ */ smart_str_appendc(&ncookie, '='); smart_str_appendl(&ncookie, e_id->val, e_id->len); - STR_RELEASE(e_session_name); - STR_RELEASE(e_id); + zend_string_release(e_session_name); + zend_string_release(e_id); if (PS(cookie_lifetime) > 0) { struct timeval tv; @@ -1341,10 +1342,10 @@ static void php_session_send_cookie(TSRMLS_D) /* {{{ */ 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_appendl(&ncookie, date_fmt->val, date_fmt->len); - STR_RELEASE(date_fmt); + zend_string_release(date_fmt); smart_str_appends(&ncookie, COOKIE_MAX_AGE); - smart_str_append_int(&ncookie, PS(cookie_lifetime)); + smart_str_append_long(&ncookie, PS(cookie_lifetime)); } } @@ -1413,7 +1414,7 @@ static void ppid2sid(zval *ppid TSRMLS_DC) { PS(send_cookie) = 1; } else { convert_to_string(ppid); - PS(id) = STR_INIT(Z_STRVAL_P(ppid), Z_STRSIZE_P(ppid), 0); + PS(id) = zend_string_init(Z_STRVAL_P(ppid), Z_STRLEN_P(ppid), 0); PS(send_cookie) = 0; } } @@ -1547,7 +1548,7 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */ p += lensess + 1; if ((q = strpbrk(p, "/?\\"))) { - PS(id) = STR_INIT(p, q - p, 0); + PS(id) = zend_string_init(p, q - p, 0); PS(send_cookie) = 0; } } @@ -1560,10 +1561,10 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */ !Z_ISUNDEF(PG(http_globals)[TRACK_VARS_SERVER]) && (data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_REFERER", sizeof("HTTP_REFERER") - 1)) && Z_TYPE_P(data) == IS_STRING && - Z_STRSIZE_P(data) != 0 && + Z_STRLEN_P(data) != 0 && strstr(Z_STRVAL_P(data), PS(extern_referer_chk)) == NULL ) { - STR_RELEASE(PS(id)); + zend_string_release(PS(id)); PS(id) = NULL; PS(send_cookie) = 1; if (PS(use_trans_sid) && !PS(use_only_cookies)) { @@ -1574,7 +1575,7 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */ /* Finally check session id for dangerous characters * Security note: session id may be embedded in HTML pages.*/ if (PS(id) && strpbrk(PS(id)->val, "\r\n\t <>'\"\\")) { - STR_RELEASE(PS(id)); + zend_string_release(PS(id)); PS(id) = NULL; } @@ -1643,42 +1644,42 @@ PHPAPI void session_adapt_url(const char *url, size_t urllen, char **new, size_t static PHP_FUNCTION(session_set_cookie_params) { zval *lifetime; - char *path = NULL, *domain = NULL; - int path_len, domain_len, argc = ZEND_NUM_ARGS(); + zend_string *path = NULL, *domain = NULL; + int argc = ZEND_NUM_ARGS(); zend_bool secure = 0, httponly = 0; zend_string *ini_name; if (!PS(use_cookies) || - zend_parse_parameters(argc TSRMLS_CC, "z|ssbb", &lifetime, &path, &path_len, &domain, &domain_len, &secure, &httponly) == FAILURE) { + zend_parse_parameters(argc TSRMLS_CC, "z|SSbb", &lifetime, &path, &domain, &secure, &httponly) == FAILURE) { return; } convert_to_string_ex(lifetime); - ini_name = STR_INIT("session.cookie_lifetime", sizeof("session.cookie_lifetime") - 1, 0); - zend_alter_ini_entry(ini_name, Z_STRVAL_P(lifetime), Z_STRSIZE_P(lifetime), PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.cookie_lifetime", sizeof("session.cookie_lifetime") - 1, 0); + zend_alter_ini_entry(ini_name, Z_STR_P(lifetime), PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_name); if (path) { - ini_name = STR_INIT("session.cookie_path", sizeof("session.cookie_path") - 1, 0); - zend_alter_ini_entry(ini_name, path, path_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.cookie_path", sizeof("session.cookie_path") - 1, 0); + zend_alter_ini_entry(ini_name, path, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_name); } if (domain) { - ini_name = STR_INIT("session.cookie_domain", sizeof("session.cookie_domain") - 1, 0); - zend_alter_ini_entry(ini_name, domain, domain_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.cookie_domain", sizeof("session.cookie_domain") - 1, 0); + zend_alter_ini_entry(ini_name, domain, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_name); } if (argc > 3) { - ini_name = STR_INIT("session.cookie_secure", sizeof("session.cookie_secure") - 1, 0); - zend_alter_ini_entry(ini_name, secure ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.cookie_secure", sizeof("session.cookie_secure") - 1, 0); + zend_alter_ini_entry_chars(ini_name, secure ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_name); } if (argc > 4) { - ini_name = STR_INIT("session.cookie_httponly", sizeof("session.cookie_httponly") - 1, 0); - zend_alter_ini_entry(ini_name, httponly ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.cookie_httponly", sizeof("session.cookie_httponly") - 1, 0); + zend_alter_ini_entry_chars(ini_name, httponly ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_name); } } /* }}} */ @@ -1693,7 +1694,7 @@ static PHP_FUNCTION(session_get_cookie_params) array_init(return_value); - add_assoc_int(return_value, "lifetime", PS(cookie_lifetime)); + add_assoc_long(return_value, "lifetime", PS(cookie_lifetime)); add_assoc_string(return_value, "path", PS(cookie_path)); add_assoc_string(return_value, "domain", PS(cookie_domain)); add_assoc_bool(return_value, "secure", PS(cookie_secure)); @@ -1705,20 +1706,19 @@ static PHP_FUNCTION(session_get_cookie_params) 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; + zend_string *name = NULL; zend_string *ini_name; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|S", &name) == FAILURE) { return; } RETVAL_STRING(PS(session_name)); if (name) { - ini_name = STR_INIT("session.name", sizeof("session.name") - 1, 0); - zend_alter_ini_entry(ini_name, name, name_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.name", sizeof("session.name") - 1, 0); + zend_alter_ini_entry(ini_name, name, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_name); } } /* }}} */ @@ -1727,11 +1727,10 @@ static PHP_FUNCTION(session_name) 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; + zend_string *name = NULL; zend_string *ini_name; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|S", &name) == FAILURE) { return; } @@ -1743,8 +1742,8 @@ static PHP_FUNCTION(session_module_name) } 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); + if (!_php_find_ps_module(name->val TSRMLS_CC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find named PHP session module (%s)", name->val); zval_dtor(return_value); RETURN_FALSE; @@ -1754,9 +1753,9 @@ static PHP_FUNCTION(session_module_name) } PS(mod_data) = NULL; - ini_name = STR_INIT("session.save_handler", sizeof("session.save_handler") - 1, 0); - zend_alter_ini_entry(ini_name, name, name_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.save_handler", sizeof("session.save_handler") - 1, 0); + zend_alter_ini_entry(ini_name, name, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_name); } } /* }}} */ @@ -1768,7 +1767,7 @@ static PHP_FUNCTION(session_set_save_handler) zval *args = NULL; int i, num_args, argc = ZEND_NUM_ARGS(); zend_string *name; - zend_string *ini_name; + zend_string *ini_name, *ini_val; if (PS(session_status) != php_session_none) { RETURN_FALSE; @@ -1777,10 +1776,7 @@ static PHP_FUNCTION(session_set_save_handler) if (argc > 0 && argc <= 2) { zval *obj = NULL; zend_string *func_name; - HashPosition pos; - zend_function *default_mptr, *current_mptr; - php_uint_t func_index; - php_shutdown_function_entry shutdown_function_entry; + zend_function *current_mptr; zend_bool register_shutdown = 1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &obj, php_session_iface_entry, ®ister_shutdown) == FAILURE) { @@ -1788,11 +1784,8 @@ static PHP_FUNCTION(session_set_save_handler) } /* Find implemented methods - SessionHandlerInterface */ - zend_hash_internal_pointer_reset_ex(&php_session_iface_entry->function_table, &pos); i = 0; - while ((default_mptr = zend_hash_get_current_data_ptr_ex(&php_session_iface_entry->function_table, &pos))) { - zend_hash_get_current_key_ex(&php_session_iface_entry->function_table, &func_name, &func_index, 0, &pos); - + ZEND_HASH_FOREACH_STR_KEY(&php_session_iface_entry->function_table, func_name) { if ((current_mptr = zend_hash_find_ptr(&Z_OBJCE_P(obj)->function_table, func_name))) { if (!Z_ISUNDEF(PS(mod_user_names).names[i])) { zval_ptr_dtor(&PS(mod_user_names).names[i]); @@ -1801,21 +1794,17 @@ static PHP_FUNCTION(session_set_save_handler) array_init_size(&PS(mod_user_names).names[i], 2); Z_ADDREF_P(obj); add_next_index_zval(&PS(mod_user_names).names[i], obj); - add_next_index_str(&PS(mod_user_names).names[i], func_name); + add_next_index_str(&PS(mod_user_names).names[i], zend_string_copy(func_name)); } 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_iface_entry->function_table, &pos); ++i; - } + } ZEND_HASH_FOREACH_END(); /* Find implemented methods - SessionIdInterface (optional) */ - zend_hash_internal_pointer_reset_ex(&php_session_id_iface_entry->function_table, &pos); - while ((default_mptr = zend_hash_get_current_data_ptr_ex(&php_session_id_iface_entry->function_table, &pos))) { - zend_hash_get_current_key_ex(&php_session_id_iface_entry->function_table, &func_name, &func_index, 0, &pos); - + ZEND_HASH_FOREACH_STR_KEY(&php_session_id_iface_entry->function_table, func_name) { if ((current_mptr = zend_hash_find_ptr(&Z_OBJCE_P(obj)->function_table, func_name))) { if (!Z_ISUNDEF(PS(mod_user_names).names[i])) { zval_ptr_dtor(&PS(mod_user_names).names[i]); @@ -1824,15 +1813,15 @@ static PHP_FUNCTION(session_set_save_handler) array_init_size(&PS(mod_user_names).names[i], 2); Z_ADDREF_P(obj); add_next_index_zval(&PS(mod_user_names).names[i], obj); - add_next_index_str(&PS(mod_user_names).names[i], func_name); + add_next_index_str(&PS(mod_user_names).names[i], zend_string_copy(func_name)); } - zend_hash_move_forward_ex(&php_session_id_iface_entry->function_table, &pos); ++i; - } + } ZEND_HASH_FOREACH_END(); if (register_shutdown) { /* create shutdown function */ + php_shutdown_function_entry shutdown_function_entry; shutdown_function_entry.arg_count = 1; shutdown_function_entry.arguments = (zval *) safe_emalloc(sizeof(zval), 1, 0); @@ -1851,9 +1840,11 @@ static PHP_FUNCTION(session_set_save_handler) } if (PS(mod) && PS(session_status) == php_session_none && PS(mod) != &ps_mod_user) { - ini_name = STR_INIT("session.save_handler", sizeof("session.save_handler") - 1, 0); - zend_alter_ini_entry(ini_name, "user", sizeof("user") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.save_handler", sizeof("session.save_handler") - 1, 0); + ini_val = zend_string_init("user", sizeof("user") - 1, 0); + zend_alter_ini_entry(ini_name, ini_val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_val); + zend_string_release(ini_name); } RETURN_TRUE; @@ -1874,16 +1865,18 @@ static PHP_FUNCTION(session_set_save_handler) for (i = 0; i < argc; i++) { if (!zend_is_callable(&args[i], 0, &name TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument %d is not a valid callback", i+1); - STR_RELEASE(name); + zend_string_release(name); RETURN_FALSE; } - STR_RELEASE(name); + zend_string_release(name); } if (PS(mod) && PS(mod) != &ps_mod_user) { - ini_name = STR_INIT("session.save_handler", sizeof("session.save_handler") - 1, 0); - zend_alter_ini_entry(ini_name, "user", sizeof("user")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.save_handler", sizeof("session.save_handler") - 1, 0); + ini_val = zend_string_init("user", sizeof("user") - 1, 0); + zend_alter_ini_entry(ini_name, ini_val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_val); + zend_string_release(ini_name); } for (i = 0; i < argc; i++) { @@ -1901,25 +1894,24 @@ static PHP_FUNCTION(session_set_save_handler) 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; + zend_string *name = NULL; zend_string *ini_name; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|S", &name) == FAILURE) { return; } RETVAL_STRING(PS(save_path)); if (name) { - if (memchr(name, '\0', name_len) != NULL) { + if (memchr(name->val, '\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; } - ini_name = STR_INIT("session.save_path", sizeof("session.save_path") - 1, 0); - zend_alter_ini_entry(ini_name, name, name_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.save_path", sizeof("session.save_path") - 1, 0); + zend_alter_ini_entry(ini_name, name, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_name); } } /* }}} */ @@ -1940,9 +1932,9 @@ static PHP_FUNCTION(session_id) * see: ext/session/tests/session_id_error3.phpt */ int len = strlen(PS(id)->val); if (UNEXPECTED(len != PS(id)->len)) { - RETVAL_STR(STR_INIT(PS(id)->val, len, 0)); + RETVAL_STR(zend_string_init(PS(id)->val, len, 0)); } else { - RETVAL_STR(STR_COPY(PS(id))); + RETVAL_STR(zend_string_copy(PS(id))); } } else { RETVAL_EMPTY_STRING(); @@ -1950,9 +1942,9 @@ static PHP_FUNCTION(session_id) if (name) { if (PS(id)) { - STR_RELEASE(PS(id)); + zend_string_release(PS(id)); } - PS(id) = STR_COPY(name); + PS(id) = zend_string_copy(name); } } /* }}} */ @@ -1978,7 +1970,7 @@ static PHP_FUNCTION(session_regenerate_id) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session object destruction failed"); RETURN_FALSE; } - STR_RELEASE(PS(id)); + zend_string_release(PS(id)); memset(PS(session_data_hash),'\0', 16); } @@ -1999,20 +1991,19 @@ static PHP_FUNCTION(session_regenerate_id) 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; + zend_string *limiter = NULL; zend_string *ini_name; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &limiter, &limiter_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|S", &limiter) == FAILURE) { return; } RETVAL_STRING(PS(cache_limiter)); if (limiter) { - ini_name = STR_INIT("session.cache_limiter", sizeof("session.cache_limiter") - 1, 0); - zend_alter_ini_entry(ini_name, limiter, limiter_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.cache_limiter", sizeof("session.cache_limiter") - 1, 0); + zend_alter_ini_entry(ini_name, limiter, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(ini_name); } } /* }}} */ @@ -2028,13 +2019,13 @@ static PHP_FUNCTION(session_cache_expire) return; } - RETVAL_INT(PS(cache_expire)); + RETVAL_LONG(PS(cache_expire)); if (expires) { convert_to_string_ex(expires); - ini_name = STR_INIT("session.cache_expire", sizeof("session.cache_expire") - 1, 0); - zend_alter_ini_entry(ini_name, Z_STRVAL_P(expires), Z_STRSIZE_P(expires), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); - STR_RELEASE(ini_name); + ini_name = zend_string_init("session.cache_expire", sizeof("session.cache_expire") - 1, 0); + zend_alter_ini_entry(ini_name, Z_STR_P(expires), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); + zend_string_release(ini_name); } } /* }}} */ @@ -2063,7 +2054,7 @@ static PHP_FUNCTION(session_encode) static PHP_FUNCTION(session_decode) { char *str; - int str_len; + size_t str_len; if (PS(session_status) == php_session_none) { RETURN_FALSE; @@ -2114,10 +2105,7 @@ static PHP_FUNCTION(session_unset) } IF_SESSION_VARS() { - HashTable *ht_sess_var; - - SEPARATE_ZVAL_IF_NOT_REF(&PS(http_session_vars)); - ht_sess_var = Z_ARRVAL_P(Z_REFVAL(PS(http_session_vars))); + HashTable *ht_sess_var = Z_ARRVAL_P(Z_REFVAL(PS(http_session_vars))); /* Clean $_SESSION. */ zend_hash_clean(ht_sess_var); @@ -2157,7 +2145,7 @@ static PHP_FUNCTION(session_status) return; } - RETURN_INT(PS(session_status)); + RETURN_LONG(PS(session_status)); } /* }}} */ @@ -2432,7 +2420,7 @@ static PHP_MINIT_FUNCTION(session) /* {{{ */ { zend_class_entry ce; - zend_register_auto_global(STR_INIT("_SESSION", sizeof("_SESSION") - 1, 1), 0, NULL TSRMLS_CC); + zend_register_auto_global(zend_string_init("_SESSION", sizeof("_SESSION") - 1, 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! */ @@ -2460,9 +2448,9 @@ static PHP_MINIT_FUNCTION(session) /* {{{ */ zend_class_implements(php_session_class_entry TSRMLS_CC, 1, php_session_iface_entry); zend_class_implements(php_session_class_entry TSRMLS_CC, 1, php_session_id_iface_entry); - REGISTER_INT_CONSTANT("PHP_SESSION_DISABLED", php_session_disabled, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PHP_SESSION_NONE", php_session_none, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PHP_SESSION_ACTIVE", php_session_active, CONST_CS | CONST_PERSISTENT); + 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; } @@ -2603,7 +2591,7 @@ static zend_bool php_check_cancel_upload(php_session_rfc1867_progress *progress static void php_session_rfc1867_update(php_session_rfc1867_progress *progress, int force_update TSRMLS_DC) /* {{{ */ { if (!force_update) { - if (Z_IVAL_P(progress->post_bytes_processed) < progress->next_update) { + if (Z_LVAL_P(progress->post_bytes_processed) < progress->next_update) { return; } #ifdef HAVE_GETTIMEOFDAY @@ -2618,7 +2606,7 @@ static void php_session_rfc1867_update(php_session_rfc1867_progress *progress, i progress->next_update_time = dtv + PS(rfc1867_min_freq); } #endif - progress->next_update = Z_IVAL_P(progress->post_bytes_processed) + progress->update_step; + progress->next_update = Z_LVAL_P(progress->post_bytes_processed) + progress->update_step; } php_session_initialize(TSRMLS_C); @@ -2720,16 +2708,16 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo array_init(&progress->data); array_init(&progress->files); - add_assoc_int_ex(&progress->data, "start_time", sizeof("start_time") - 1, (php_int_t)sapi_get_request_time(TSRMLS_C)); - add_assoc_int_ex(&progress->data, "content_length", sizeof("content_length") - 1, progress->content_length); - add_assoc_int_ex(&progress->data, "bytes_processed", sizeof("bytes_processed") - 1, data->post_bytes_processed); + add_assoc_long_ex(&progress->data, "start_time", sizeof("start_time") - 1, (zend_long)sapi_get_request_time(TSRMLS_C)); + add_assoc_long_ex(&progress->data, "content_length", sizeof("content_length") - 1, progress->content_length); + add_assoc_long_ex(&progress->data, "bytes_processed", sizeof("bytes_processed") - 1, data->post_bytes_processed); add_assoc_bool_ex(&progress->data, "done", sizeof("done") - 1, 0); add_assoc_zval_ex(&progress->data, "files", sizeof("files") - 1, &progress->files); progress->post_bytes_processed = zend_hash_str_find(Z_ARRVAL(progress->data), "bytes_processed", sizeof("bytes_processed") - 1); php_rinit_session(0 TSRMLS_CC); - PS(id) = STR_INIT(Z_STRVAL(progress->sid), Z_STRSIZE(progress->sid), 0); + PS(id) = zend_string_init(Z_STRVAL(progress->sid), Z_STRLEN(progress->sid), 0); PS(apply_trans_sid) = progress->apply_trans_sid; PS(send_cookie) = 0; } @@ -2740,17 +2728,17 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo add_assoc_string_ex(&progress->current_file, "field_name", sizeof("field_name") - 1, data->name); add_assoc_string_ex(&progress->current_file, "name", sizeof("name") - 1, *data->filename); add_assoc_null_ex(&progress->current_file, "tmp_name", sizeof("tmp_name") - 1); - add_assoc_int_ex(&progress->current_file, "error", sizeof("error") - 1, 0); + add_assoc_long_ex(&progress->current_file, "error", sizeof("error") - 1, 0); add_assoc_bool_ex(&progress->current_file, "done", sizeof("done") - 1, 0); - add_assoc_int_ex(&progress->current_file, "start_time", sizeof("start_time") - 1, (php_int_t)time(NULL)); - add_assoc_int_ex(&progress->current_file, "bytes_processed", sizeof("bytes_processed") - 1, 0); + add_assoc_long_ex(&progress->current_file, "start_time", sizeof("start_time") - 1, (zend_long)time(NULL)); + add_assoc_long_ex(&progress->current_file, "bytes_processed", sizeof("bytes_processed") - 1, 0); add_next_index_zval(&progress->files, &progress->current_file); progress->current_file_bytes_processed = zend_hash_str_find(Z_ARRVAL(progress->current_file), "bytes_processed", sizeof("bytes_processed") - 1); - Z_IVAL_P(progress->current_file_bytes_processed) = data->post_bytes_processed; + Z_LVAL_P(progress->current_file_bytes_processed) = data->post_bytes_processed; php_session_rfc1867_update(progress, 0 TSRMLS_CC); } break; @@ -2761,8 +2749,8 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo break; } - Z_IVAL_P(progress->current_file_bytes_processed) = data->offset + data->length; - Z_IVAL_P(progress->post_bytes_processed) = data->post_bytes_processed; + 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); } @@ -2778,10 +2766,10 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo add_assoc_string_ex(&progress->current_file, "tmp_name", sizeof("tmp_name") - 1, data->temp_filename); } - add_assoc_int_ex(&progress->current_file, "error", sizeof("error") - 1, data->cancel_upload); + add_assoc_long_ex(&progress->current_file, "error", sizeof("error") - 1, data->cancel_upload); add_assoc_bool_ex(&progress->current_file, "done", sizeof("done") - 1, 1); - Z_IVAL_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); } @@ -2794,7 +2782,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo php_session_rfc1867_cleanup(progress TSRMLS_CC); } else { add_assoc_bool_ex(&progress->data, "done", sizeof("done") - 1, 1); - Z_IVAL_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, 1 TSRMLS_CC); } php_rshutdown_session_globals(TSRMLS_C); |