]> granicus.if.org Git - php/commitdiff
MFH general urlencoding
authorSascha Schumann <sas@php.net>
Thu, 20 Feb 2003 06:24:08 +0000 (06:24 +0000)
committerSascha Schumann <sas@php.net>
Thu, 20 Feb 2003 06:24:08 +0000 (06:24 +0000)
MFH session_regenerate_id, a change which is as important as the former one

ext/session/php_session.h
ext/session/session.c

index 5fff13acf05b24df06133aa15064a3b3a21160ea..598b2d4e99fcd17a5982d5ef16a266b2eeec128b 100644 (file)
@@ -118,6 +118,8 @@ typedef struct _php_ps_globals {
        zend_bool use_only_cookies;
        zend_bool use_trans_sid;        /* contains the INI value of whether to use trans-sid */
        zend_bool apply_trans_sid;      /* whether or not to enable trans-sid for the current request */
+       int send_cookie;
+       int define_sid;
 } php_ps_globals;
 
 typedef php_ps_globals zend_ps_globals;
@@ -129,6 +131,7 @@ PHP_FUNCTION(session_name);
 PHP_FUNCTION(session_module_name);
 PHP_FUNCTION(session_save_path);
 PHP_FUNCTION(session_id);
+PHP_FUNCTION(session_regenerate_id);
 PHP_FUNCTION(session_decode);
 PHP_FUNCTION(session_register);
 PHP_FUNCTION(session_unregister);
index f570ed995f56548d7a3f4a905555236f6c91b2fd..28235943a8d08c042e9420bf35424ec89eb2bdff 100644 (file)
@@ -60,6 +60,7 @@ function_entry session_functions[] = {
        PHP_FE(session_module_name,       NULL)
        PHP_FE(session_save_path,         NULL)
        PHP_FE(session_id,                NULL)
+       PHP_FE(session_regenerate_id,     NULL)
        PHP_FE(session_decode,            NULL)
        PHP_FE(session_register,          NULL)
        PHP_FE(session_unregister,        NULL)
@@ -918,19 +919,47 @@ static const ps_serializer *_php_find_ps_serializer(char *name TSRMLS_DC)
                convert_to_string((*ppid)); \
                PS(id) = estrndup(Z_STRVAL_PP(ppid), Z_STRLEN_PP(ppid))
 
+static void php_session_reset_id(TSRMLS_D)
+{
+       int module_number = PS(module_number);
+       
+       if (PS(send_cookie)) {
+               php_session_send_cookie(TSRMLS_C);
+       }
+
+       /* if the SID constant exists, destroy it. */
+       zend_hash_del(EG(zend_constants), "sid", sizeof("sid"));
+       
+       if (PS(define_sid)) {
+               smart_str var = {0};
+
+               smart_str_appends(&var, PS(session_name));
+               smart_str_appendc(&var, '=');
+               smart_str_appends(&var, PS(id));
+               smart_str_0(&var);
+               REGISTER_STRINGL_CONSTANT("SID", var.c, var.len, 0);
+       } else {
+               REGISTER_STRINGL_CONSTANT("SID", empty_string, 0, 0);
+       }
+
+       if (PS(apply_trans_sid)) {
+               php_url_scanner_reset_vars(TSRMLS_C);
+               php_url_scanner_add_var(PS(session_name), strlen(PS(session_name)), PS(id), strlen(PS(id)), 1 TSRMLS_CC);
+       }
+}
+       
 PHPAPI void php_session_start(TSRMLS_D)
 {
        zval **ppid;
        zval **data;
        char *p;
-       int send_cookie = 1;
-       int define_sid = 1;
-       int module_number = PS(module_number);
        int nrand;
        int lensess;
 
        PS(apply_trans_sid) = PS(use_trans_sid);
 
+       PS(define_sid) = 1;
+       PS(send_cookie) = 1;
        if (PS(session_status) != php_session_none) 
                return;
 
@@ -950,8 +979,8 @@ PHPAPI void php_session_start(TSRMLS_D)
                                        lensess + 1, (void **) &ppid) == SUCCESS) {
                        PPID2SID;
                        PS(apply_trans_sid) = 0;
-                       send_cookie = 0;
-                       define_sid = 0;
+                       PS(send_cookie) = 0;
+                       PS(define_sid) = 0;
                }
 
                if (!PS(use_only_cookies) && !PS(id) &&
@@ -961,7 +990,7 @@ PHPAPI void php_session_start(TSRMLS_D)
                                zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
                                        lensess + 1, (void **) &ppid) == SUCCESS) {
                        PPID2SID;
-                       send_cookie = 0;
+                       PS(send_cookie) = 0;
                }
 
                if (!PS(use_only_cookies) && !PS(id) &&
@@ -971,7 +1000,7 @@ PHPAPI void php_session_start(TSRMLS_D)
                                zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
                                        lensess + 1, (void **) &ppid) == SUCCESS) {
                        PPID2SID;
-                       send_cookie = 0;
+                       PS(send_cookie) = 0;
                }
        }
 
@@ -1004,42 +1033,22 @@ PHPAPI void php_session_start(TSRMLS_D)
                        strstr(Z_STRVAL_PP(data), PS(extern_referer_chk)) == NULL) {
                efree(PS(id));
                PS(id) = NULL;
-               send_cookie = 1;
+               PS(send_cookie) = 1;
                if (PS(use_trans_sid))
                        PS(apply_trans_sid) = 1;
        }
        
        php_session_initialize(TSRMLS_C);
        
-       if (!PS(use_cookies) && send_cookie) {
+       if (!PS(use_cookies) && PS(send_cookie)) {
                if (PS(use_trans_sid))
                        PS(apply_trans_sid) = 1;
-               send_cookie = 0;
-       }
-       
-       if (send_cookie) {
-               php_session_send_cookie(TSRMLS_C);
+               PS(send_cookie) = 0;
        }
 
-       /* if the SID constant exists, destroy it. */
-       zend_hash_del(EG(zend_constants), "sid", sizeof("sid"));
+       php_session_reset_id(TSRMLS_C);
        
-       if (define_sid) {
-               smart_str var = {0};
-
-               smart_str_appendl(&var, PS(session_name), lensess);
-               smart_str_appendc(&var, '=');
-               smart_str_appends(&var, PS(id));
-               smart_str_0(&var);
-               REGISTER_STRINGL_CONSTANT("SID", var.c, var.len, 0);
-       } else {
-               REGISTER_STRINGL_CONSTANT("SID", empty_string, 0, 0);
-       }
-
        PS(session_status) = php_session_active;
-       if (PS(apply_trans_sid)) {
-               php_url_scanner_add_var(PS(session_name), strlen(PS(session_name)), PS(id), strlen(PS(id)), 0 TSRMLS_CC);
-       }
 
        php_session_cache_limiter(TSRMLS_C);
 
@@ -1262,6 +1271,23 @@ PHP_FUNCTION(session_id)
 }
 /* }}} */
 
+/* {{{ proto string session_regenerate_id()
+   Update the current session id with a newly generated one. */
+PHP_FUNCTION(session_regenerate_id)
+{
+       if (PS(session_status) == php_session_active) {
+               if (PS(id)) efree(PS(id));
+       
+               PS(id) = PS(mod)->s_create_sid(&PS(mod_data), NULL TSRMLS_CC);
+
+               php_session_reset_id(TSRMLS_C);
+               
+               RETURN_TRUE;
+       }
+       RETURN_FALSE;
+}
+/* }}} */
+
 /* {{{ proto string session_cache_limiter([string new_cache_limiter])
    Return the current cache limiter. If new_cache_limited is given, the current cache_limiter is replaced with new_cache_limiter */
 PHP_FUNCTION(session_cache_limiter)