]> granicus.if.org Git - php/commitdiff
Added field to ps_module structure to hold function pointer for the creation
authorMark L. Woodward <mlwmohawk@php.net>
Fri, 29 Mar 2002 16:00:27 +0000 (16:00 +0000)
committerMark L. Woodward <mlwmohawk@php.net>
Fri, 29 Mar 2002 16:00:27 +0000 (16:00 +0000)
of the session ID string. Default PS_MOD() macro sets this to be the default
creation routine. PS_MOD_SID() macro sets this to a handlers session ID
creation routine.

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

index c3e31d0570333a228df96072f6361a0ed45d8346..ae26ba17fdb4ec59271fc252d4d36746accfe040 100644 (file)
 #define PS_DESTROY_ARGS void **mod_data, const char *key TSRMLS_DC
 #define PS_GC_ARGS void **mod_data, int maxlifetime, int *nrdels TSRMLS_DC
 
+#define HAVE_PHP_SESSION_CREATESID
+#define PS_CREATESID_ARGS void **mod_data, int *newlen
+
+/* default create id function */
+char *php_session_create_id(PS_CREATESID_ARGS);
+
 typedef struct ps_module_struct {
        const char *name;
        int (*open)(PS_OPEN_ARGS);
@@ -38,6 +44,7 @@ typedef struct ps_module_struct {
        int (*write)(PS_WRITE_ARGS);
        int (*destroy)(PS_DESTROY_ARGS);
        int (*gc)(PS_GC_ARGS);
+       char *(*createsid)(PS_CREATESID_ARGS);
 } ps_module;
 
 #define PS_GET_MOD_DATA() *mod_data
@@ -49,6 +56,7 @@ typedef struct ps_module_struct {
 #define PS_WRITE_FUNC(x)       int ps_write_##x(PS_WRITE_ARGS)
 #define PS_DESTROY_FUNC(x)     int ps_delete_##x(PS_DESTROY_ARGS)
 #define PS_GC_FUNC(x)          int ps_gc_##x(PS_GC_ARGS)
+#define PS_CREATESID_FUNC(x)   char *ps_createsid_##x(PS_CREATESID_ARGS)
 
 #define PS_FUNCS(x) \
        PS_OPEN_FUNC(x); \
@@ -56,12 +64,26 @@ typedef struct ps_module_struct {
        PS_READ_FUNC(x); \
        PS_WRITE_FUNC(x); \
        PS_DESTROY_FUNC(x); \
-       PS_GC_FUNC(x)
-
+       PS_GC_FUNC(x);  \
+       PS_CREATESID_FUNC(x)
 
 #define PS_MOD(x) \
        #x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
-        ps_delete_##x, ps_gc_##x 
+        ps_delete_##x, ps_gc_##x, php_session_create_id
+
+/* SID enabled module handler definitions */
+#define PS_FUNCS_SID(x) \
+       PS_OPEN_FUNC(x); \
+       PS_CLOSE_FUNC(x); \
+       PS_READ_FUNC(x); \
+       PS_WRITE_FUNC(x); \
+       PS_DESTROY_FUNC(x); \
+       PS_GC_FUNC(x); \
+       PS_CREATESID_FUNC(x)
+
+#define PS_MOD_SID(x) \
+       #x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
+        ps_delete_##x, ps_gc_##x, ps_createsid_##x
 
 typedef enum {
        php_session_disabled,
index 9e0993dbf638926b18d7f9510958fb2925b5b533..21480fc2b9ffa576bb05aeaff2269c0f74b39d40 100644 (file)
@@ -495,7 +495,7 @@ static void php_session_decode(const char *val, int vallen TSRMLS_DC)
 
 static char hexconvtab[] = "0123456789abcdef";
 
-static char *_php_create_id(int *newlen TSRMLS_DC)
+char *php_session_create_id(PS_CREATESID_ARGS)
 {
        PHP_MD5_CTX context;
        unsigned char digest[16];
@@ -548,11 +548,23 @@ static void php_session_initialize(TSRMLS_D)
 {
        char *val;
        int vallen;
-       
+
+       /* Open session handler first */
        if (PS(mod)->open(&PS(mod_data), PS(save_path), PS(session_name) TSRMLS_CC) == FAILURE) {
                php_error(E_ERROR, "Failed to initialize session module");
                return;
        }
+       
+       /* If there is no ID, use session module to create one */
+       if (!PS(id))
+               PS(id) = PS(mod)->createsid(&PS(mod_data), NULL);
+       
+       /* Read data */
+       /* 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
+        */
        php_session_track_init(TSRMLS_C);
        if (PS(mod)->read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == SUCCESS) {
                php_session_decode(val, vallen TSRMLS_CC);
@@ -560,7 +572,6 @@ static void php_session_initialize(TSRMLS_D)
        }
 }
 
-
 static void php_session_save_current_state(TSRMLS_D)
 {
        char *val;
@@ -918,8 +929,7 @@ PHPAPI void php_session_start(TSRMLS_D)
                        PS(apply_trans_sid) = 1;
        }
        
-       if (!PS(id))
-               PS(id) = _php_create_id(NULL TSRMLS_CC);
+       php_session_initialize(TSRMLS_C);
        
        if (!PS(use_cookies) && send_cookie) {
                if (PS(use_trans_sid))
@@ -950,7 +960,6 @@ PHPAPI void php_session_start(TSRMLS_D)
        }
 
        php_session_cache_limiter(TSRMLS_C);
-       php_session_initialize(TSRMLS_C);
 
        if (PS(mod_data) && PS(gc_probability) > 0) {
                int nrdels = -1;