CVS update: php4/ext/session

From: Date: Thu, 01 Jul 1999 05:45:50 +0000
Subject: CVS update: php4/ext/session
Groups: php.version4 
Request: Send a blank email to php-version4+get-1769@lists.php.net to get a copy of this message
Date: Thursday July 1, 1999 @ 1:45 Author: sas Update of /repository/php4/ext/session In directory php:/tmp/cvs-serv22517 Modified Files: php_session.h session.c Log Message: implement a simple API in the case someone wants to define his/her own serialization stuff Index: php4/ext/session/php_session.h diff -u php4/ext/session/php_session.h:1.6 php4/ext/session/php_session.h:1.7 --- php4/ext/session/php_session.h:1.6 Tue Jun 29 11:39:59 1999 +++ php4/ext/session/php_session.h Thu Jul 1 01:45:48 1999 @@ -30,6 +30,11 @@ #ifndef PHP_SESSION_H #define PHP_SESSION_H +/* + * some relict. ignore it, unless you want to build locking + * functionality into the session code + */ + typedef enum { LOCK, UNLOCK @@ -43,7 +48,7 @@ #define PS_GC_ARGS void **mod_data, int maxlifetime typedef struct ps_module_struct { - char *name; + const char *name; int (*open)(PS_OPEN_ARGS); int (*close)(PS_CLOSE_ARGS); int (*read)(PS_READ_ARGS); @@ -85,6 +90,7 @@ int nr_open_sessions; int gc_probability; int gc_maxlifetime; + const struct ps_serializer_struct *serializer; } php_ps_globals; extern zend_module_entry session_module_entry; @@ -118,5 +124,25 @@ #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 } #endif Index: php4/ext/session/session.c diff -u php4/ext/session/session.c:1.21 php4/ext/session/session.c:1.22 --- php4/ext/session/session.c:1.21 Tue Jun 29 18:08:07 1999 +++ php4/ext/session/session.c Thu Jul 1 01:45:48 1999 @@ -81,9 +81,16 @@ PHP_INI_ENTRY("session_gc_probability", "1", PHP_INI_ALL, NULL) PHP_INI_ENTRY("session_gc_maxlifetime", "1440", PHP_INI_ALL, NULL) PHP_INI_ENTRY("session_lifetime", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("session_serializer", "php", PHP_INI_ALL, NULL) PHP_INI_END() +PS_SERIALIZER_FUNCS(php); +const static ps_serializer ps_serializers[] = { + PS_SERIALIZER_ENTRY(php), + {0} +}; + static int php_minit_session(INIT_FUNC_ARGS); static int php_rinit_session(INIT_FUNC_ARGS); static int php_mshutdown_session(SHUTDOWN_FUNC_ARGS); @@ -117,12 +124,11 @@ #define STD_FMT "%s|" #define NOTFOUND_FMT "!%s|" -static char *_php_session_encode(int *newlen PSLS_DC) +PS_SERIALIZER_ENCODE_FUNC(php) { pval *buf; pval **struc; char *key; - char *ret = NULL; char strbuf[MAX_STR + 1]; ELS_FETCH(); @@ -146,10 +152,10 @@ } if(newlen) *newlen = buf->value.str.len; - ret = buf->value.str.val; + *newstr = buf->value.str.val; efree(buf); - return ret; + return SUCCESS; } #define PS_ADD_VARL(name,namelen) \ @@ -158,16 +164,15 @@ #define PS_ADD_VAR(name) PS_ADD_VARL(name, strlen(name)) #define PS_DEL_VARL(name,namelen) \ - zend_hash_del(&PS(vars), name, namelen); + zend_hash_del(&PS(vars), name, namelen + 1); #define PS_DEL_VAR(name) PS_DEL_VARL(name, strlen(name)) - -static void _php_session_decode(char *val, int vallen PSLS_DC) +PS_SERIALIZER_DECODE_FUNC(php) { - char *p, *q; + const char *p, *q; char *name; - char *endptr = val + vallen; + const char *endptr = val + vallen; pval *current; int namelen; int has_value; @@ -197,8 +202,24 @@ PS_ADD_VAR(name); efree(name); } + + return SUCCESS; } +static char *_php_session_encode(int *newlen PSLS_DC) +{ + char *ret = NULL; + + PS(serializer)->encode(&ret, newlen PSLS_CC); + + return ret; +} + +static void _php_session_decode(const char *val, int vallen PSLS_DC) +{ + PS(serializer)->decode(val, vallen PSLS_CC); +} + static char *_php_create_id(int *newlen) { PHP3_MD5_CTX context; @@ -295,6 +316,21 @@ return ret; } +static const ps_serializer *_php_find_ps_serializer(char *name PSLS_DC) +{ + const ps_serializer *ret = NULL; + const ps_serializer *mod; + + for(mod = ps_serializers; mod->name; mod++) { + if(!strcasecmp(name, mod->name)) { + ret = mod; + break; + } + } + + return ret; +} + static void _php_session_start(PSLS_D) { pval **ppid; @@ -565,6 +601,8 @@ static void php_rinit_session_globals(PSLS_D) { PS(mod) = _php_find_ps_module(INI_STR("session_module_name") PSLS_CC); + PS(serializer) = \ + _php_find_ps_serializer(INI_STR("session_serializer") PSLS_CC); zend_hash_init(&PS(vars), 0, NULL, NULL, 0); PS(save_path) = estrdup(INI_STR("session_save_path"));

« previous php.version4 (#1769) next »