From: Mark L. Woodward Date: Fri, 29 Mar 2002 16:00:27 +0000 (+0000) Subject: Added field to ps_module structure to hold function pointer for the creation X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~967 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=346d74a1464ecfb6bc7b8f7a273774ecf913f45c;p=php Added field to ps_module structure to hold function pointer for the creation 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. --- diff --git a/ext/session/php_session.h b/ext/session/php_session.h index c3e31d0570..ae26ba17fd 100644 --- a/ext/session/php_session.h +++ b/ext/session/php_session.h @@ -30,6 +30,12 @@ #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, diff --git a/ext/session/session.c b/ext/session/session.c index 9e0993dbf6..21480fc2b9 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -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;