#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);
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
#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); \
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,
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];
{
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);
}
}
-
static void php_session_save_current_state(TSRMLS_D)
{
char *val;
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))
}
php_session_cache_limiter(TSRMLS_C);
- php_session_initialize(TSRMLS_C);
if (PS(mod_data) && PS(gc_probability) > 0) {
int nrdels = -1;