Back to index

php5  5.3.10
php_session.h
Go to the documentation of this file.
00001 /* 
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author: Sascha Schumann <sascha@schumann.cx>                         |
00016    +----------------------------------------------------------------------+
00017  */
00018 
00019 /* $Id: php_session.h 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifndef PHP_SESSION_H
00022 #define PHP_SESSION_H
00023 
00024 #include "ext/standard/php_var.h"
00025 
00026 #if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
00027 # include "ext/hash/php_hash.h"
00028 #endif
00029 
00030 #define PHP_SESSION_API 20020330
00031 
00032 #define PS_OPEN_ARGS void **mod_data, const char *save_path, const char *session_name TSRMLS_DC
00033 #define PS_CLOSE_ARGS void **mod_data TSRMLS_DC
00034 #define PS_READ_ARGS void **mod_data, const char *key, char **val, int *vallen TSRMLS_DC
00035 #define PS_WRITE_ARGS void **mod_data, const char *key, const char *val, const int vallen TSRMLS_DC
00036 #define PS_DESTROY_ARGS void **mod_data, const char *key TSRMLS_DC
00037 #define PS_GC_ARGS void **mod_data, int maxlifetime, int *nrdels TSRMLS_DC
00038 #define PS_CREATE_SID_ARGS void **mod_data, int *newlen TSRMLS_DC
00039 
00040 /* default create id function */
00041 PHPAPI char *php_session_create_id(PS_CREATE_SID_ARGS);
00042 
00043 typedef struct ps_module_struct {
00044        const char *s_name;
00045        int (*s_open)(PS_OPEN_ARGS);
00046        int (*s_close)(PS_CLOSE_ARGS);
00047        int (*s_read)(PS_READ_ARGS);
00048        int (*s_write)(PS_WRITE_ARGS);
00049        int (*s_destroy)(PS_DESTROY_ARGS);
00050        int (*s_gc)(PS_GC_ARGS);
00051        char *(*s_create_sid)(PS_CREATE_SID_ARGS);
00052 } ps_module;
00053 
00054 #define PS_GET_MOD_DATA() *mod_data
00055 #define PS_SET_MOD_DATA(a) *mod_data = (a)
00056 
00057 #define PS_OPEN_FUNC(x)     int ps_open_##x(PS_OPEN_ARGS)
00058 #define PS_CLOSE_FUNC(x)    int ps_close_##x(PS_CLOSE_ARGS)
00059 #define PS_READ_FUNC(x)     int ps_read_##x(PS_READ_ARGS)
00060 #define PS_WRITE_FUNC(x)    int ps_write_##x(PS_WRITE_ARGS)
00061 #define PS_DESTROY_FUNC(x)  int ps_delete_##x(PS_DESTROY_ARGS)
00062 #define PS_GC_FUNC(x)              int ps_gc_##x(PS_GC_ARGS)
00063 #define PS_CREATE_SID_FUNC(x)      char *ps_create_sid_##x(PS_CREATE_SID_ARGS)
00064 
00065 #define PS_FUNCS(x) \
00066        PS_OPEN_FUNC(x); \
00067        PS_CLOSE_FUNC(x); \
00068        PS_READ_FUNC(x); \
00069        PS_WRITE_FUNC(x); \
00070        PS_DESTROY_FUNC(x); \
00071        PS_GC_FUNC(x);       \
00072        PS_CREATE_SID_FUNC(x)
00073 
00074 #define PS_MOD(x) \
00075        #x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
00076         ps_delete_##x, ps_gc_##x, php_session_create_id
00077 
00078 /* SID enabled module handler definitions */
00079 #define PS_FUNCS_SID(x) \
00080        PS_OPEN_FUNC(x); \
00081        PS_CLOSE_FUNC(x); \
00082        PS_READ_FUNC(x); \
00083        PS_WRITE_FUNC(x); \
00084        PS_DESTROY_FUNC(x); \
00085        PS_GC_FUNC(x); \
00086        PS_CREATE_SID_FUNC(x)
00087 
00088 #define PS_MOD_SID(x) \
00089        #x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
00090         ps_delete_##x, ps_gc_##x, ps_create_sid_##x
00091 
00092 typedef enum {
00093        php_session_disabled,
00094        php_session_none,
00095        php_session_active
00096 } php_session_status;
00097 
00098 typedef struct _php_ps_globals {
00099        char *save_path;
00100        char *session_name;
00101        char *id;
00102        char *extern_referer_chk;
00103        char *entropy_file;
00104        char *cache_limiter;
00105        long entropy_length;
00106        long cookie_lifetime;
00107        char *cookie_path;
00108        char *cookie_domain;
00109        zend_bool  cookie_secure;
00110        zend_bool  cookie_httponly;
00111        ps_module *mod;
00112        void *mod_data;
00113        php_session_status session_status;
00114        long gc_probability;
00115        long gc_divisor;
00116        long gc_maxlifetime;
00117        int module_number;
00118        long cache_expire;
00119        union {
00120               zval *names[6];
00121               struct {
00122                      zval *ps_open;
00123                      zval *ps_close;
00124                      zval *ps_read;
00125                      zval *ps_write;
00126                      zval *ps_destroy;
00127                      zval *ps_gc;
00128               } name;
00129        } mod_user_names;
00130        zend_bool bug_compat; /* Whether to behave like PHP 4.2 and earlier */
00131        zend_bool bug_compat_warn; /* Whether to warn about it */
00132        const struct ps_serializer_struct *serializer;
00133        zval *http_session_vars;
00134        zend_bool auto_start;
00135        zend_bool use_cookies;
00136        zend_bool use_only_cookies;
00137        zend_bool use_trans_sid;    /* contains the INI value of whether to use trans-sid */
00138        zend_bool apply_trans_sid;  /* whether or not to enable trans-sid for the current request */
00139 
00140        long hash_func;
00141 #if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
00142        php_hash_ops *hash_ops;
00143 #endif
00144        long hash_bits_per_character;
00145        int send_cookie;
00146        int define_sid;
00147        zend_bool invalid_session_id;      /* allows the driver to report about an invalid session id and request id regeneration */
00148 } php_ps_globals;
00149 
00150 typedef php_ps_globals zend_ps_globals;
00151 
00152 extern zend_module_entry session_module_entry;
00153 #define phpext_session_ptr &session_module_entry
00154 
00155 #ifdef ZTS
00156 #define PS(v) TSRMG(ps_globals_id, php_ps_globals *, v)
00157 #else
00158 #define PS(v) (ps_globals.v)
00159 #endif
00160 
00161 #define PS_SERIALIZER_ENCODE_ARGS char **newstr, int *newlen TSRMLS_DC
00162 #define PS_SERIALIZER_DECODE_ARGS const char *val, int vallen TSRMLS_DC
00163 
00164 typedef struct ps_serializer_struct {
00165        const char *name;
00166        int (*encode)(PS_SERIALIZER_ENCODE_ARGS);
00167        int (*decode)(PS_SERIALIZER_DECODE_ARGS);
00168 } ps_serializer;
00169 
00170 #define PS_SERIALIZER_ENCODE_NAME(x) ps_srlzr_encode_##x
00171 #define PS_SERIALIZER_DECODE_NAME(x) ps_srlzr_decode_##x
00172 
00173 #define PS_SERIALIZER_ENCODE_FUNC(x) \
00174        int PS_SERIALIZER_ENCODE_NAME(x)(PS_SERIALIZER_ENCODE_ARGS)
00175 #define PS_SERIALIZER_DECODE_FUNC(x) \
00176        int PS_SERIALIZER_DECODE_NAME(x)(PS_SERIALIZER_DECODE_ARGS)
00177 
00178 #define PS_SERIALIZER_FUNCS(x) \
00179        PS_SERIALIZER_ENCODE_FUNC(x); \
00180        PS_SERIALIZER_DECODE_FUNC(x)
00181 
00182 #define PS_SERIALIZER_ENTRY(x) \
00183        { #x, PS_SERIALIZER_ENCODE_NAME(x), PS_SERIALIZER_DECODE_NAME(x) }
00184 
00185 PHPAPI void session_adapt_url(const char *, size_t, char **, size_t * TSRMLS_DC);
00186 
00187 PHPAPI void php_add_session_var(char *name, size_t namelen TSRMLS_DC);
00188 PHPAPI void php_set_session_var(char *name, size_t namelen, zval *state_val, php_unserialize_data_t *var_hash TSRMLS_DC);
00189 PHPAPI int php_get_session_var(char *name, size_t namelen, zval ***state_var TSRMLS_DC);
00190 
00191 PHPAPI int php_session_register_module(ps_module *);
00192 
00193 PHPAPI int php_session_register_serializer(const char *name,
00194                int (*encode)(PS_SERIALIZER_ENCODE_ARGS),
00195                int (*decode)(PS_SERIALIZER_DECODE_ARGS));
00196 
00197 PHPAPI void php_session_set_id(char *id TSRMLS_DC);
00198 PHPAPI void php_session_start(TSRMLS_D);
00199 
00200 PHPAPI ps_module *_php_find_ps_module(char *name TSRMLS_DC);
00201 PHPAPI const ps_serializer *_php_find_ps_serializer(char *name TSRMLS_DC);
00202 
00203 #define PS_ADD_VARL(name,namelen) do {                                                                   \
00204        php_add_session_var(name, namelen TSRMLS_CC);                                              \
00205 } while (0)
00206 
00207 #define PS_ADD_VAR(name) PS_ADD_VARL(name, strlen(name))
00208 
00209 #define PS_DEL_VARL(name,namelen) do {                                                                   \
00210        if (PS(http_session_vars)) {                                                                             \
00211               zend_hash_del(Z_ARRVAL_P(PS(http_session_vars)), name, namelen+1);    \
00212        }                                                                                                                             \
00213 } while (0)
00214 
00215 
00216 #define PS_ENCODE_VARS                                                                            \
00217        char *key;                                                                                        \
00218        uint key_length;                                                                           \
00219        ulong num_key;                                                                                    \
00220        zval **struc;
00221 
00222 #define PS_ENCODE_LOOP(code) do {                                                          \
00223               HashTable *_ht = Z_ARRVAL_P(PS(http_session_vars));                   \
00224               int key_type;                                                                              \
00225                                                                                                                        \
00226               for (zend_hash_internal_pointer_reset(_ht);                                  \
00227                             (key_type = zend_hash_get_current_key_ex(_ht, &key, &key_length, &num_key, 0, NULL)) != HASH_KEY_NON_EXISTANT; \
00228                                    zend_hash_move_forward(_ht)) {                                 \
00229                      if (key_type == HASH_KEY_IS_LONG) {                                          \
00230                             php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Skipping numeric key %ld", num_key);    \
00231                             continue;                                                                           \
00232                      }                                                                                                 \
00233                      key_length--;                                                                       \
00234                      if (php_get_session_var(key, key_length, &struc TSRMLS_CC) == SUCCESS) {     \
00235                             code;                                                                               \
00236                      }                                                                                                 \
00237               }                                                                                                        \
00238        } while(0)
00239 
00240 PHPAPI ZEND_EXTERN_MODULE_GLOBALS(ps)
00241 
00242 void php_session_auto_start(void *data);
00243 void php_session_shutdown(void *data);
00244 
00245 #endif