I am submitting a patch that will enable a session handler to override the default session id creation routine.
This will help extensions like srm and msession. It adds a new member to the ps_module structure and defines a default if it is not overridden. session.c is also changed in that the module is initialized before the creation of the sesson ID Mark
? session.sid.patch Index: php_session.h =================================================================== RCS file: /repository/php4/ext/session/php_session.h,v retrieving revision 1.73 diff -u -r1.73 php_session.h --- php_session.h 6 Mar 2002 11:49:51 -0000 1.73 +++ php_session.h 24 Mar 2002 17:00:13 -0000 @@ -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 @@ 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 @@ #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 @@ 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: session.c =================================================================== RCS file: /repository/php4/ext/session/session.c,v retrieving revision 1.294 diff -u -r1.294 session.c --- session.c 13 Mar 2002 13:08:49 -0000 1.294 +++ session.c 24 Mar 2002 17:00:14 -0000 @@ -495,7 +495,7 @@ 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 @@ { 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_save_current_state(TSRMLS_D) { char *val; @@ -918,8 +929,7 @@ 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 @@ } php_session_cache_limiter(TSRMLS_C); - php_session_initialize(TSRMLS_C); if (PS(mod_data) && PS(gc_probability) > 0) { int nrdels = -1;
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php