You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
7.6 KiB

25 years ago
25 years ago
25 years ago
25 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2006 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Sascha Schumann <sascha@schumann.cx> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #ifndef PHP_SESSION_H
  20. #define PHP_SESSION_H
  21. #include "ext/standard/php_var.h"
  22. #define PHP_SESSION_API 20020330
  23. #define PS_OPEN_ARGS void **mod_data, const char *save_path, const char *session_name TSRMLS_DC
  24. #define PS_CLOSE_ARGS void **mod_data TSRMLS_DC
  25. #define PS_READ_ARGS void **mod_data, const char *key, char **val, int *vallen TSRMLS_DC
  26. #define PS_WRITE_ARGS void **mod_data, const char *key, const char *val, const int vallen TSRMLS_DC
  27. #define PS_DESTROY_ARGS void **mod_data, const char *key TSRMLS_DC
  28. #define PS_GC_ARGS void **mod_data, int maxlifetime, int *nrdels TSRMLS_DC
  29. #define PS_CREATE_SID_ARGS void **mod_data, int *newlen TSRMLS_DC
  30. /* default create id function */
  31. PHPAPI char *php_session_create_id(PS_CREATE_SID_ARGS);
  32. typedef struct ps_module_struct {
  33. const char *s_name;
  34. int (*s_open)(PS_OPEN_ARGS);
  35. int (*s_close)(PS_CLOSE_ARGS);
  36. int (*s_read)(PS_READ_ARGS);
  37. int (*s_write)(PS_WRITE_ARGS);
  38. int (*s_destroy)(PS_DESTROY_ARGS);
  39. int (*s_gc)(PS_GC_ARGS);
  40. char *(*s_create_sid)(PS_CREATE_SID_ARGS);
  41. } ps_module;
  42. #define PS_GET_MOD_DATA() *mod_data
  43. #define PS_SET_MOD_DATA(a) *mod_data = (a)
  44. #define PS_OPEN_FUNC(x) int ps_open_##x(PS_OPEN_ARGS)
  45. #define PS_CLOSE_FUNC(x) int ps_close_##x(PS_CLOSE_ARGS)
  46. #define PS_READ_FUNC(x) int ps_read_##x(PS_READ_ARGS)
  47. #define PS_WRITE_FUNC(x) int ps_write_##x(PS_WRITE_ARGS)
  48. #define PS_DESTROY_FUNC(x) int ps_delete_##x(PS_DESTROY_ARGS)
  49. #define PS_GC_FUNC(x) int ps_gc_##x(PS_GC_ARGS)
  50. #define PS_CREATE_SID_FUNC(x) char *ps_create_sid_##x(PS_CREATE_SID_ARGS)
  51. #define PS_FUNCS(x) \
  52. PS_OPEN_FUNC(x); \
  53. PS_CLOSE_FUNC(x); \
  54. PS_READ_FUNC(x); \
  55. PS_WRITE_FUNC(x); \
  56. PS_DESTROY_FUNC(x); \
  57. PS_GC_FUNC(x); \
  58. PS_CREATE_SID_FUNC(x)
  59. #define PS_MOD(x) \
  60. #x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
  61. ps_delete_##x, ps_gc_##x, php_session_create_id
  62. /* SID enabled module handler definitions */
  63. #define PS_FUNCS_SID(x) \
  64. PS_OPEN_FUNC(x); \
  65. PS_CLOSE_FUNC(x); \
  66. PS_READ_FUNC(x); \
  67. PS_WRITE_FUNC(x); \
  68. PS_DESTROY_FUNC(x); \
  69. PS_GC_FUNC(x); \
  70. PS_CREATE_SID_FUNC(x)
  71. #define PS_MOD_SID(x) \
  72. #x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
  73. ps_delete_##x, ps_gc_##x, ps_create_sid_##x
  74. typedef enum {
  75. php_session_disabled,
  76. php_session_none,
  77. php_session_active
  78. } php_session_status;
  79. typedef struct _php_ps_globals {
  80. char *save_path;
  81. char *session_name;
  82. char *id;
  83. char *extern_referer_chk;
  84. char *entropy_file;
  85. char *cache_limiter;
  86. long entropy_length;
  87. long cookie_lifetime;
  88. char *cookie_path;
  89. char *cookie_domain;
  90. zend_bool cookie_secure;
  91. ps_module *mod;
  92. void *mod_data;
  93. php_session_status session_status;
  94. long gc_probability;
  95. long gc_divisor;
  96. long gc_maxlifetime;
  97. int module_number;
  98. long cache_expire;
  99. const struct ps_serializer_struct *serializer;
  100. zval *http_session_vars;
  101. zend_bool auto_start;
  102. zend_bool use_cookies;
  103. zend_bool use_only_cookies;
  104. zend_bool use_trans_sid; /* contains the INI value of whether to use trans-sid */
  105. zend_bool apply_trans_sid; /* whether or not to enable trans-sid for the current request */
  106. long hash_func;
  107. long hash_bits_per_character;
  108. int send_cookie;
  109. int define_sid;
  110. } php_ps_globals;
  111. typedef php_ps_globals zend_ps_globals;
  112. extern zend_module_entry session_module_entry;
  113. #define phpext_session_ptr &session_module_entry
  114. PHP_FUNCTION(session_name);
  115. PHP_FUNCTION(session_module_name);
  116. PHP_FUNCTION(session_save_path);
  117. PHP_FUNCTION(session_id);
  118. PHP_FUNCTION(session_regenerate_id);
  119. PHP_FUNCTION(session_decode);
  120. PHP_FUNCTION(session_encode);
  121. PHP_FUNCTION(session_start);
  122. PHP_FUNCTION(session_destroy);
  123. PHP_FUNCTION(session_unset);
  124. PHP_FUNCTION(session_set_save_handler);
  125. PHP_FUNCTION(session_cache_expire);
  126. PHP_FUNCTION(session_cache_limiter);
  127. PHP_FUNCTION(session_set_cookie_params);
  128. PHP_FUNCTION(session_get_cookie_params);
  129. PHP_FUNCTION(session_write_close);
  130. #ifdef ZTS
  131. #define PS(v) TSRMG(ps_globals_id, php_ps_globals *, v)
  132. #else
  133. #define PS(v) (ps_globals.v)
  134. #endif
  135. #define PS_SERIALIZER_ENCODE_ARGS char **newstr, int *newlen TSRMLS_DC
  136. #define PS_SERIALIZER_DECODE_ARGS const char *val, int vallen TSRMLS_DC
  137. typedef struct ps_serializer_struct {
  138. const char *name;
  139. int (*encode)(PS_SERIALIZER_ENCODE_ARGS);
  140. int (*decode)(PS_SERIALIZER_DECODE_ARGS);
  141. } ps_serializer;
  142. #define PS_SERIALIZER_ENCODE_NAME(x) ps_srlzr_encode_##x
  143. #define PS_SERIALIZER_DECODE_NAME(x) ps_srlzr_decode_##x
  144. #define PS_SERIALIZER_ENCODE_FUNC(x) \
  145. int PS_SERIALIZER_ENCODE_NAME(x)(PS_SERIALIZER_ENCODE_ARGS)
  146. #define PS_SERIALIZER_DECODE_FUNC(x) \
  147. int PS_SERIALIZER_DECODE_NAME(x)(PS_SERIALIZER_DECODE_ARGS)
  148. #define PS_SERIALIZER_FUNCS(x) \
  149. PS_SERIALIZER_ENCODE_FUNC(x); \
  150. PS_SERIALIZER_DECODE_FUNC(x)
  151. #define PS_SERIALIZER_ENTRY(x) \
  152. { #x, PS_SERIALIZER_ENCODE_NAME(x), PS_SERIALIZER_DECODE_NAME(x) }
  153. PHPAPI void session_adapt_url(const char *, size_t, char **, size_t * TSRMLS_DC);
  154. PHPAPI void php_add_session_var(char *name, size_t namelen TSRMLS_DC);
  155. PHPAPI void php_set_session_var(char *name, size_t namelen, zval *state_val, php_unserialize_data_t *var_hash TSRMLS_DC);
  156. PHPAPI int php_get_session_var(char *name, size_t namelen, zval ***state_var TSRMLS_DC);
  157. PHPAPI int php_session_register_module(ps_module *);
  158. PHPAPI int php_session_register_serializer(const char *name,
  159. int (*encode)(PS_SERIALIZER_ENCODE_ARGS),
  160. int (*decode)(PS_SERIALIZER_DECODE_ARGS));
  161. PHPAPI void php_session_set_id(char *id TSRMLS_DC);
  162. PHPAPI void php_session_start(TSRMLS_D);
  163. #define PS_ADD_VARL(name,namelen) do { \
  164. php_add_session_var(name, namelen TSRMLS_CC); \
  165. } while (0)
  166. #define PS_ADD_VAR(name) PS_ADD_VARL(name, strlen(name))
  167. #define PS_DEL_VARL(name,namelen) do { \
  168. if (PS(http_session_vars)) { \
  169. zend_hash_del(Z_ARRVAL_P(PS(http_session_vars)), name, namelen+1); \
  170. } \
  171. } while (0)
  172. #define PS_ENCODE_VARS \
  173. zstr key; \
  174. uint key_length; \
  175. ulong num_key; \
  176. zval **struc;
  177. #define PS_ENCODE_LOOP(code) do { \
  178. HashTable *_ht = Z_ARRVAL_P(PS(http_session_vars)); \
  179. \
  180. for (zend_hash_internal_pointer_reset(_ht); \
  181. zend_hash_get_current_key_ex(_ht, &key, &key_length, &num_key, 0, NULL) == HASH_KEY_IS_STRING; \
  182. zend_hash_move_forward(_ht)) { \
  183. key_length--; \
  184. if (php_get_session_var(key.s, key_length, &struc TSRMLS_CC) == SUCCESS) { \
  185. code; \
  186. } \
  187. } \
  188. } while(0)
  189. PHPAPI ZEND_EXTERN_MODULE_GLOBALS(ps)
  190. void php_session_auto_start(void *data);
  191. void php_session_shutdown(void *data);
  192. #endif