diff options
author | Dmitry Stogov <dmitry@zend.com> | 2014-04-26 00:32:51 +0400 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2014-04-26 00:32:51 +0400 |
commit | f9927a6c97208c60d922f9a4e98feb8079c57d1f (patch) | |
tree | 35815b69d1bf7d47fb41e857ff8d2b024ddac153 /ext/session/session.c | |
parent | 4e7cbf3f5842abe6688c11ce3cc11d2eabf0695f (diff) | |
parent | b82d077f988606580e5c06a9da18fe4f60ddb7cb (diff) | |
download | php-git-f9927a6c97208c60d922f9a4e98feb8079c57d1f.tar.gz |
Merge mainstream 'master' branch into refactoring
During merge I had to revert:
Nikita's patch for php_splice() (it probably needs to be applyed again)
Bob Weinand's patches related to constant expression handling (we need to review them carefully)
I also reverted all our attempts to support sapi/phpdbg (we didn't test it anyway)
Conflicts:
Zend/zend.h
Zend/zend_API.c
Zend/zend_ast.c
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_constants.c
Zend/zend_exceptions.c
Zend/zend_execute.c
Zend/zend_execute.h
Zend/zend_execute_API.c
Zend/zend_hash.c
Zend/zend_highlight.c
Zend/zend_language_parser.y
Zend/zend_language_scanner.c
Zend/zend_language_scanner_defs.h
Zend/zend_variables.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h
ext/date/php_date.c
ext/dom/documenttype.c
ext/hash/hash.c
ext/iconv/iconv.c
ext/mbstring/tests/zend_multibyte-10.phpt
ext/mbstring/tests/zend_multibyte-11.phpt
ext/mbstring/tests/zend_multibyte-12.phpt
ext/mysql/php_mysql.c
ext/mysqli/mysqli.c
ext/mysqlnd/mysqlnd_reverse_api.c
ext/mysqlnd/php_mysqlnd.c
ext/opcache/ZendAccelerator.c
ext/opcache/zend_accelerator_util_funcs.c
ext/opcache/zend_persist.c
ext/opcache/zend_persist_calc.c
ext/pcre/php_pcre.c
ext/pdo/pdo_dbh.c
ext/pdo/pdo_stmt.c
ext/pdo_pgsql/pgsql_driver.c
ext/pgsql/pgsql.c
ext/reflection/php_reflection.c
ext/session/session.c
ext/spl/spl_array.c
ext/spl/spl_observer.c
ext/standard/array.c
ext/standard/basic_functions.c
ext/standard/html.c
ext/standard/mail.c
ext/standard/php_array.h
ext/standard/proc_open.c
ext/standard/streamsfuncs.c
ext/standard/user_filters.c
ext/standard/var_unserializer.c
ext/standard/var_unserializer.re
main/php_variables.c
sapi/phpdbg/phpdbg.c
sapi/phpdbg/phpdbg_bp.c
sapi/phpdbg/phpdbg_frame.c
sapi/phpdbg/phpdbg_help.c
sapi/phpdbg/phpdbg_list.c
sapi/phpdbg/phpdbg_print.c
sapi/phpdbg/phpdbg_prompt.c
Diffstat (limited to 'ext/session/session.c')
-rw-r--r-- | ext/session/session.c | 117 |
1 files changed, 45 insertions, 72 deletions
diff --git a/ext/session/session.c b/ext/session/session.c index 6982449af4..8784016db6 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1262,6 +1262,49 @@ static int php_session_cache_limiter(TSRMLS_D) /* {{{ */ #define COOKIE_SECURE "; secure" #define COOKIE_HTTPONLY "; HttpOnly" +/* + * Remove already sent session ID cookie. + * It must be directly removed from SG(sapi_header) because sapi_add_header_ex() + * removes all of matching cookie. i.e. It deletes all of Set-Cookie headers. + */ +static void php_session_remove_cookie(TSRMLS_D) { + sapi_header_struct *header; + zend_llist *l = &SG(sapi_headers).headers; + zend_llist_element *next; + zend_llist_element *current; + char *session_cookie, *e_session_name; + int session_cookie_len, 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); + efree(e_session_name); + + session_cookie_len = strlen(session_cookie); + current = l->head; + while (current) { + header = (sapi_header_struct *)(current->data); + next = current->next; + if (header->header_len > len && header->header[len] == ':' + && !strncmp(header->header, session_cookie, session_cookie_len)) { + if (current->prev) { + current->prev->next = next; + } else { + l->head = next; + } + if (next) { + next->prev = current->prev; + } else { + l->tail = current->prev; + } + sapi_free_header(header); + efree(current); + --l->count; + } + current = next; + } + efree(session_cookie); +} + static void php_session_send_cookie(TSRMLS_D) /* {{{ */ { smart_str ncookie = {0}; @@ -1330,6 +1373,7 @@ static void php_session_send_cookie(TSRMLS_D) /* {{{ */ smart_str_0(&ncookie); + php_session_remove_cookie(TSRMLS_C); /* remove already sent session ID cookie */ /* 'replace' must be 0 here, else a previous Set-Cookie header, probably sent with setcookie() will be replaced! */ sapi_add_header_ex(estrndup(ncookie.s->val, ncookie.s->len), ncookie.s->len, 0, 0 TSRMLS_CC); @@ -1718,34 +1762,6 @@ static PHP_FUNCTION(session_module_name) } /* }}} */ -/* {{{ proto mixed session_serializer_name([string newname]) - Return the current serializer name used for encode/decode session data. If newname is given, the serialzer name is replaced with newname and return bool */ -static PHP_FUNCTION(session_serializer_name) -{ - char *name = NULL; - int name_len; - zend_string *ini_name; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) { - return; - } - - /* Return serializer name */ - if (!name) { - RETURN_STRING(zend_ini_string("session.serialize_handler", sizeof("session.serialize_handler") - 1, 0)); - } - - ini_name = STR_INIT("session.serialize_handler", sizeof("session.serialize_handler") - 1, 0); - /* Set serializer name */ - if (zend_alter_ini_entry(ini_name, name, name_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == SUCCESS) { - RETVAL_TRUE; - } else { - RETVAL_FALSE; - } - STR_RELEASE(ini_name); -} -/* }}} */ - /* {{{ proto void session_set_save_handler(string open, string close, string read, string write, string destroy, string gc, string create_sid) Sets user-level functions */ static PHP_FUNCTION(session_set_save_handler) @@ -1914,7 +1930,7 @@ static PHP_FUNCTION(session_save_path) static PHP_FUNCTION(session_id) { zend_string *name = NULL; - int name_len, argc = ZEND_NUM_ARGS(); + int argc = ZEND_NUM_ARGS(); if (zend_parse_parameters(argc TSRMLS_CC, "|S", &name) == FAILURE) { return; @@ -2146,39 +2162,6 @@ static PHP_FUNCTION(session_status) } /* }}} */ -/* {{{ proto int session_gc([int maxlifetime]) - Execute garbage collection returns number of deleted data */ -static PHP_FUNCTION(session_gc) -{ - int nrdels = -1; - long maxlifetime = PS(gc_maxlifetime); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &maxlifetime) == FAILURE) { - return; - } - - /* Session must be active to have PS(mod) */ - if (PS(session_status) != php_session_active) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Trying to garbage collect without active session"); - RETURN_FALSE; - } - - if (!PS(mod) || !PS(mod)->s_gc) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session save handler does not have gc()"); - RETURN_FALSE; - } - PS(mod)->s_gc(&PS(mod_data), maxlifetime, &nrdels TSRMLS_CC); - - if (nrdels < 0) { - /* Files save handler return -1 if there is not a permission to remove. - Save handlder should return negative nrdels when something wrong. */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session gc failed. Check permission or session storage"); - RETURN_FALSE; - } - RETURN_LONG((long)nrdels); -} -/* }}} */ - /* {{{ proto void session_register_shutdown(void) Registers session_write_close() as a shutdown function */ static PHP_FUNCTION(session_register_shutdown) @@ -2222,10 +2205,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_session_module_name, 0, 0, 0) ZEND_ARG_INFO(0, module) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_session_serializer_name, 0, 0, 0) - ZEND_ARG_INFO(0, module) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_session_save_path, 0, 0, 0) ZEND_ARG_INFO(0, path) ZEND_END_ARG_INFO() @@ -2271,10 +2250,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_session_set_cookie_params, 0, 0, 1) ZEND_ARG_INFO(0, httponly) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_session_gc, 0) - ZEND_ARG_INFO(0, maxlifetime) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO(arginfo_session_class_open, 0) ZEND_ARG_INFO(0, save_path) ZEND_ARG_INFO(0, session_name) @@ -2309,7 +2284,6 @@ ZEND_END_ARG_INFO() static const zend_function_entry session_functions[] = { PHP_FE(session_name, arginfo_session_name) PHP_FE(session_module_name, arginfo_session_module_name) - PHP_FE(session_serializer_name, arginfo_session_serializer_name) PHP_FE(session_save_path, arginfo_session_save_path) PHP_FE(session_id, arginfo_session_id) PHP_FE(session_regenerate_id, arginfo_session_regenerate_id) @@ -2327,7 +2301,6 @@ static const zend_function_entry session_functions[] = { PHP_FE(session_abort, arginfo_session_void) PHP_FE(session_reset, arginfo_session_void) PHP_FE(session_status, arginfo_session_void) - PHP_FE(session_gc, arginfo_session_gc) PHP_FE(session_register_shutdown, arginfo_session_void) PHP_FALIAS(session_commit, session_write_close, arginfo_session_void) PHP_FE_END |