summaryrefslogtreecommitdiff
path: root/ext/session/php_session.h
blob: 005b451295544db30f35ddf1744328f9e6138c72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* 
   +----------------------------------------------------------------------+
   | PHP HTML Embedded Scripting Language Version 4.0                     |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997,1998 PHP Development Team (See Credits file)      |
   +----------------------------------------------------------------------+
   | This program is free software; you can redistribute it and/or modify |
   | it under the terms of one of the following licenses:                 |
   |                                                                      |
   |  A) the GNU General Public License as published by the Free Software |
   |     Foundation; either version 2 of the License, or (at your option) |
   |     any later version.                                               |
   |                                                                      |
   |  B) the PHP License as published by the PHP Development Team and     |
   |     included in the distribution in the file: LICENSE                |
   |                                                                      |
   | This program is distributed in the hope that it will be useful,      |
   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
   | GNU General Public License for more details.                         |
   |                                                                      |
   | You should have received a copy of both licenses referred to here.   |
   | If you did not, or have any questions about PHP licensing, please    |
   | contact core@php.net.                                                |
   +----------------------------------------------------------------------+
   | Authors: Sascha Schumann <ss@2ns.de>                                 |
   +----------------------------------------------------------------------+
 */

#ifndef PHP_SESSION_H
#define PHP_SESSION_H

#define PS_OPEN_ARGS void **mod_data, const char *save_path, const char *session_name
#define PS_CLOSE_ARGS void **mod_data
#define PS_READ_ARGS void **mod_data, const char *key, char **val, int *vallen
#define PS_WRITE_ARGS void **mod_data, const char *key, const char *val, const int vallen
#define PS_DESTROY_ARGS void **mod_data, const char *key
#define PS_GC_ARGS void **mod_data, int maxlifetime

typedef struct ps_module_struct {
	const char *name;
	int (*open)(PS_OPEN_ARGS);
	int (*close)(PS_CLOSE_ARGS);
	int (*read)(PS_READ_ARGS);
	int (*write)(PS_WRITE_ARGS);
	int (*destroy)(PS_DESTROY_ARGS);
	int (*gc)(PS_GC_ARGS);
} ps_module;

#define PS_GET_MOD_DATA() *mod_data
#define PS_SET_MOD_DATA(a) *mod_data = (a)

#define PS_OPEN_FUNC(x) 	int _ps_open_##x(PS_OPEN_ARGS)
#define PS_CLOSE_FUNC(x) 	int _ps_close_##x(PS_CLOSE_ARGS)
#define PS_READ_FUNC(x) 	int _ps_read_##x(PS_READ_ARGS)
#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_FUNCS(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)


#define PS_MOD(x) \
	#x, _ps_open_##x, _ps_close_##x, _ps_read_##x, _ps_write_##x, \
	 _ps_delete_##x, _ps_gc_##x 

typedef struct {
	char *save_path;
	char *session_name;
	char *id;
	char *extern_referer_chk;
	char *entropy_file;
	char *cache_limiter;
	int entropy_length;
	int cookie_lifetime;
	char *cookie_path;
	char *cookie_domain;
	zend_bool define_sid;
	zend_bool use_cookies;
	ps_module *mod;
	void *mod_data;
	HashTable vars;
	int nr_open_sessions;
	int gc_probability;
	int gc_maxlifetime;
	int module_number;
	int cache_expire;
	const struct ps_serializer_struct *serializer;
	zval *http_state_vars;
} php_ps_globals;

extern zend_module_entry session_module_entry;
#define phpext_session_ptr &session_module_entry

PHP_FUNCTION(session_name);
PHP_FUNCTION(session_module_name);
PHP_FUNCTION(session_save_path);
PHP_FUNCTION(session_id);
PHP_FUNCTION(session_decode);
PHP_FUNCTION(session_register);
PHP_FUNCTION(session_unregister);
PHP_FUNCTION(session_is_registered);
PHP_FUNCTION(session_encode);
PHP_FUNCTION(session_start);
PHP_FUNCTION(session_destroy);
PHP_FUNCTION(session_unset);
PHP_FUNCTION(session_set_save_handler);

#ifdef ZTS
#define PSLS_D php_ps_globals *ps_globals
#define PSLS_DC , PSLS_D
#define PSLS_C ps_globals
#define PSLS_CC , PSLS_C
#define PS(v) (ps_globals->v)
#define PSLS_FETCH() php_ps_globals *ps_globals = ts_resource(ps_globals_id)
#else
#define PSLS_D	void
#define PSLS_DC
#define PSLS_C
#define PSLS_CC
#define PS(v) (ps_globals.v)
#define PSLS_FETCH()
#endif

#define PS_SERIALIZER_ENCODE_ARGS char **newstr, int *newlen PSLS_DC
#define PS_SERIALIZER_DECODE_ARGS const char *val, int vallen PSLS_DC

typedef struct ps_serializer_struct {
	const char *name;
	int (*encode)(PS_SERIALIZER_ENCODE_ARGS);
	int (*decode)(PS_SERIALIZER_DECODE_ARGS);
} ps_serializer;

#define PS_SERIALIZER_ENCODE_FUNC(x) \
	int _ps_srlzr_encode_##x(PS_SERIALIZER_ENCODE_ARGS)
#define PS_SERIALIZER_DECODE_FUNC(x) \
	int _ps_srlzr_decode_##x(PS_SERIALIZER_DECODE_ARGS)

#define PS_SERIALIZER_FUNCS(x) \
	PS_SERIALIZER_ENCODE_FUNC(x); \
	PS_SERIALIZER_DECODE_FUNC(x)

#define PS_SERIALIZER_ENTRY(x) \
	{ #x, _ps_srlzr_encode_##x, _ps_srlzr_decode_##x }

#ifdef TRANS_SID
void session_adapt_uris(const char *, uint, char **, uint *);
#else
#define session_adapt_uris(a,b,c,d) do { } while(0)
#endif

void _php_session_auto_start(void *data);

#if HAVE_WDDX
#define WDDX_SERIALIZER
#include "ext/wddx/php_wddx_api.h"
#endif

#endif