jani            Wed Aug  6 05:34:55 2008 UTC

  Modified files:              
    /php-src/ext/session        session.c 
    /php-src/ext/session/tests  session_decode_variation3.phpt 
                                session_encode_variation3.phpt 
                                session_encode_variation4.phpt 
                                session_encode_variation5.phpt 
                                session_encode_variation7.phpt 
                                session_encode_variation8.phpt 
  Log:
  - Fixed some inconsistencies with the behaviour of sessions. Changed 
session_start() to return false when session start fails.
  
http://cvs.php.net/viewvc.cgi/php-src/ext/session/session.c?r1=1.491&r2=1.492&diff_format=u
Index: php-src/ext/session/session.c
diff -u php-src/ext/session/session.c:1.491 php-src/ext/session/session.c:1.492
--- php-src/ext/session/session.c:1.491 Wed Aug  6 04:48:39 2008
+++ php-src/ext/session/session.c       Wed Aug  6 05:34:55 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: session.c,v 1.491 2008/08/06 04:48:39 jani Exp $ */
+/* $Id: session.c,v 1.492 2008/08/06 05:34:55 jani Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -508,7 +508,10 @@
                        err_type = E_ERROR;
                }
 
-               php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find save 
handler %s", new_value);
+               /* Do not output error when restoring ini options. */
+               if (stage != ZEND_INI_STAGE_DEACTIVATE) {
+                       php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find 
save handler '%s'", new_value);
+               }
                return FAILURE;
        }
        PS(mod) = tmp;
@@ -517,20 +520,6 @@
 }
 /* }}} */
 
-static PHP_INI_MH(OnUpdateTransSid) /* {{{ */
-{
-       SESSION_CHECK_ACTIVE_STATE;
-
-       if (!strncasecmp(new_value, "on", sizeof("on"))) {
-               PS(use_trans_sid) = (zend_bool) 1;
-       } else {
-               PS(use_trans_sid) = (zend_bool) atoi(new_value);
-       }
-
-       return SUCCESS;
-}
-/* }}} */
-
 static PHP_INI_MH(OnUpdateSerializer) /* {{{ */
 {
        const ps_serializer *tmp;
@@ -547,7 +536,10 @@
                        err_type = E_ERROR;
                }
 
-               php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find 
serialization handler '%s'", new_value);
+               /* Do not output error when restoring ini options. */
+               if (stage != ZEND_INI_STAGE_DEACTIVATE) {
+                       php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find 
serialization handler '%s'", new_value);
+               }
                return FAILURE;
        }
        PS(serializer) = tmp;
@@ -556,6 +548,20 @@
 }
 /* }}} */
 
+static PHP_INI_MH(OnUpdateTransSid) /* {{{ */
+{
+       SESSION_CHECK_ACTIVE_STATE;
+
+       if (!strncasecmp(new_value, "on", sizeof("on"))) {
+               PS(use_trans_sid) = (zend_bool) 1;
+       } else {
+               PS(use_trans_sid) = (zend_bool) atoi(new_value);
+       }
+
+       return SUCCESS;
+}
+/* }}} */
+
 static PHP_INI_MH(OnUpdateSaveDir) /* {{{ */
 {
        /* Only do the safemode/open_basedir check at runtime */
@@ -1236,30 +1242,42 @@
 {
        zval **ppid;
        zval **data;
-       char *p;
+       char *p, *value;
        int nrand;
        int lensess;
 
        PS(apply_trans_sid) = PS(use_trans_sid);
 
-       if (PS(session_status) != php_session_none) {
-               if (PS(session_status) == php_session_disabled) {
-                       char *value;
+       switch (PS(session_status)) {
+               case php_session_active:
+                       php_error(E_NOTICE, "A session had already been started 
- ignoring session_start()");
+                       return;
+                       break;
 
+               case php_session_disabled:
                        value = zend_ini_string("session.save_handler", 
sizeof("session.save_handler"), 0);
-
-                       if (value) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Cannot find save handler %s", value);
-                       } else {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Cannot find unknown save handler");
+                       if (!PS(mod) && value) {
+                               PS(mod) = _php_find_ps_module(value TSRMLS_CC);
+                               if (!PS(mod)) {
+                                       php_error_docref(NULL TSRMLS_CC, 
E_WARNING, "Cannot find save handler '%s' - session startup failed", value);
+                                       return;
+                               }
                        }
-                       return;
-               }
-               php_error(E_NOTICE, "A session had already been started - 
ignoring session_start()");
-               return;
-       } else {
-               PS(define_sid) = 1;
-               PS(send_cookie) = 1;
+                       value = zend_ini_string("session.serialize_handler", 
sizeof("session.serialize_handler"), 0);
+                       if (!PS(serializer) && value) {
+                               PS(serializer) = _php_find_ps_serializer(value 
TSRMLS_CC);
+                               if (!PS(serializer)) {
+                                       php_error_docref(NULL TSRMLS_CC, 
E_WARNING, "Cannot find serialization handler '%s' - session startup failed", 
value);
+                                       return;
+                               }
+                       }
+                       PS(session_status) = php_session_none;
+                       /* fallthrough */
+
+               default:
+               case php_session_none:
+                       PS(define_sid) = 1;
+                       PS(send_cookie) = 1;
        }
 
        lensess = strlen(PS(session_name));
@@ -1560,7 +1578,6 @@
        if (name) {
                if (memchr(name, '\0', name_len) != NULL) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "The 
save_path cannot contain NULL characters");
-
                        zval_dtor(return_value);
                        RETURN_FALSE;
                }
@@ -1762,6 +1779,10 @@
 {
        /* skipping check for non-zero args for performance reasons here ?*/
        php_session_start(TSRMLS_C);
+
+       if (PS(session_status) != php_session_active) {
+               RETURN_FALSE;
+       }
        RETURN_TRUE;
 }
 /* }}} */
@@ -1778,7 +1799,6 @@
 }
 /* }}} */
 
-
 /* {{{ proto void session_unset(void) U
    Unset all registered variables */
 static PHP_FUNCTION(session_unset)
@@ -1968,7 +1988,7 @@
        }
        ps_globals->http_session_vars = NULL;
 }
-/* }}}*/
+/* }}} */
 
 static PHP_MINIT_FUNCTION(session) /* {{{ */
 {
@@ -2048,7 +2068,7 @@
 
        DISPLAY_INI_ENTRIES();
 }
-/* }}} */ 
+/* }}} */
 
 zend_module_entry session_module_entry = {
        STANDARD_MODULE_HEADER,
http://cvs.php.net/viewvc.cgi/php-src/ext/session/tests/session_decode_variation3.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/session/tests/session_decode_variation3.phpt
diff -u php-src/ext/session/tests/session_decode_variation3.phpt:1.3 
php-src/ext/session/tests/session_decode_variation3.phpt:1.4
--- php-src/ext/session/tests/session_decode_variation3.phpt:1.3        Tue May 
27 12:17:39 2008
+++ php-src/ext/session/tests/session_decode_variation3.phpt    Wed Aug  6 
05:34:55 2008
@@ -23,8 +23,8 @@
 $_SESSION["bar"] = "Blah!";
 $_SESSION["guff"] = 123.456;
 var_dump($_SESSION);
-$encoded = "A2Zvb2k6MTIzNDU2Nzg5MDs=";
-var_dump(session_decode(base64_decode($encoded)));
+$encoded = "foo|i:1234567890;";
+var_dump(session_decode($encoded));
 var_dump($_SESSION);
 var_dump(session_destroy());
 
@@ -34,10 +34,11 @@
 --EXPECTF--
 *** Testing session_decode() : variation ***
 
-Warning: session_start(): Unknown session.serialize_handler. Failed to decode 
session object in %s on line %d
-bool(true)
-array(0) {
-}
+Warning: session_start(): Cannot find serialization handler 'blah' - session 
startup failed in %s on line %d
+bool(false)
+
+Notice: Undefined variable: _SESSION in %s on line %d
+NULL
 array(3) {
   [u"foo"]=>
   int(1234567890)
@@ -49,14 +50,8 @@
 
 Warning: session_decode(): Unknown session.serialize_handler. Failed to decode 
session object in %s on line %d
 bool(true)
-array(3) {
-  [u"foo"]=>
-  int(1234567890)
-  [u"bar"]=>
-  unicode(5) "Blah!"
-  [u"guff"]=>
-  float(123.456)
-}
-bool(true)
-Done
+unicode(17) "foo|i:1234567890;"
 
+Warning: session_destroy(): Trying to destroy uninitialized session in %s on 
line %d
+bool(false)
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/session/tests/session_encode_variation3.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/session/tests/session_encode_variation3.phpt
diff -u php-src/ext/session/tests/session_encode_variation3.phpt:1.3 
php-src/ext/session/tests/session_encode_variation3.phpt:1.4
--- php-src/ext/session/tests/session_encode_variation3.phpt:1.3        Tue May 
27 12:17:39 2008
+++ php-src/ext/session/tests/session_encode_variation3.phpt    Wed Aug  6 
05:34:55 2008
@@ -31,4 +31,3 @@
 unicode(34) "foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}"
 bool(true)
 Done
-
http://cvs.php.net/viewvc.cgi/php-src/ext/session/tests/session_encode_variation4.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/session/tests/session_encode_variation4.phpt
diff -u php-src/ext/session/tests/session_encode_variation4.phpt:1.3 
php-src/ext/session/tests/session_encode_variation4.phpt:1.4
--- php-src/ext/session/tests/session_encode_variation4.phpt:1.3        Tue May 
27 12:17:39 2008
+++ php-src/ext/session/tests/session_encode_variation4.phpt    Wed Aug  6 
05:34:55 2008
@@ -33,4 +33,3 @@
 unicode(52) "foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}guff|R:1;blah|R:1;"
 bool(true)
 Done
-
http://cvs.php.net/viewvc.cgi/php-src/ext/session/tests/session_encode_variation5.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/session/tests/session_encode_variation5.phpt
diff -u php-src/ext/session/tests/session_encode_variation5.phpt:1.3 
php-src/ext/session/tests/session_encode_variation5.phpt:1.4
--- php-src/ext/session/tests/session_encode_variation5.phpt:1.3        Tue May 
27 12:17:39 2008
+++ php-src/ext/session/tests/session_encode_variation5.phpt    Wed Aug  6 
05:34:55 2008
@@ -33,4 +33,3 @@
 unicode(64) "data|a:5:{i:0;i:1;i:1;i:2;i:2;i:3;U:3:"foo";R:1;U:4:"blah";R:1;}"
 bool(true)
 Done
-
http://cvs.php.net/viewvc.cgi/php-src/ext/session/tests/session_encode_variation7.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/session/tests/session_encode_variation7.phpt
diff -u php-src/ext/session/tests/session_encode_variation7.phpt:1.3 
php-src/ext/session/tests/session_encode_variation7.phpt:1.4
--- php-src/ext/session/tests/session_encode_variation7.phpt:1.3        Tue May 
27 12:17:39 2008
+++ php-src/ext/session/tests/session_encode_variation7.phpt    Wed Aug  6 
05:34:55 2008
@@ -32,4 +32,3 @@
 string(0) ""
 bool(true)
 Done
-
http://cvs.php.net/viewvc.cgi/php-src/ext/session/tests/session_encode_variation8.phpt?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/session/tests/session_encode_variation8.phpt
diff -u php-src/ext/session/tests/session_encode_variation8.phpt:1.2 
php-src/ext/session/tests/session_encode_variation8.phpt:1.3
--- php-src/ext/session/tests/session_encode_variation8.phpt:1.2        Tue Apr 
29 08:57:10 2008
+++ php-src/ext/session/tests/session_encode_variation8.phpt    Wed Aug  6 
05:34:55 2008
@@ -29,11 +29,12 @@
 --EXPECTF--
 *** Testing session_encode() : variation ***
 
-Warning: session_start(): Unknown session.serialize_handler. Failed to decode 
session object in %s on line %d
-bool(true)
+Warning: session_start(): Cannot find serialization handler 'blah' - session 
startup failed in %s on line 13
+bool(false)
 
-Warning: session_encode(): Unknown session.serialize_handler. Failed to encode 
session object in %s on line %d
+Warning: session_encode(): Cannot encode non-existent session in %s on line 15
 string(0) ""
-bool(true)
-Done
 
+Warning: session_destroy(): Trying to destroy uninitialized session in %s on 
line 17
+bool(false)
+Done

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to