Browse Source

Add cache_limiter and cache_expire options. Rename extern_referer_check

to referer_check.
experimental/RETURN_REF
Sascha Schumann 27 years ago
parent
commit
996216b499
  1. 2
      ext/session/php_session.h
  2. 118
      ext/session/session.c

2
ext/session/php_session.h

@ -76,6 +76,7 @@ typedef struct {
char *id; char *id;
char *extern_referer_chk; char *extern_referer_chk;
char *entropy_file; char *entropy_file;
char *cache_limiter;
int entropy_length; int entropy_length;
int cookie_lifetime; int cookie_lifetime;
char *cookie_path; char *cookie_path;
@ -89,6 +90,7 @@ typedef struct {
int gc_probability; int gc_probability;
int gc_maxlifetime; int gc_maxlifetime;
int module_number; int module_number;
int cache_expire;
const struct ps_serializer_struct *serializer; const struct ps_serializer_struct *serializer;
zval *http_state_vars; zval *http_state_vars;
} php_ps_globals; } php_ps_globals;

118
ext/session/session.c

@ -23,6 +23,7 @@
#include "win32/time.h" #include "win32/time.h"
#endif #endif
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "php.h" #include "php.h"
@ -73,9 +74,11 @@ PHP_INI_BEGIN()
PHP_INI_ENTRY("session.cookie_path", "/", PHP_INI_ALL, NULL) PHP_INI_ENTRY("session.cookie_path", "/", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("session.cookie_domain", "", PHP_INI_ALL, NULL) PHP_INI_ENTRY("session.cookie_domain", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("session.use_cookies", "1", PHP_INI_ALL, NULL) PHP_INI_ENTRY("session.use_cookies", "1", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("session.extern_referer_check", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("session.referer_check", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("session.entropy_file", "", PHP_INI_ALL, NULL) PHP_INI_ENTRY("session.entropy_file", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("session.entropy_length", "0", PHP_INI_ALL, NULL) PHP_INI_ENTRY("session.entropy_length", "0", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("session.cache_limiter", "nocache", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("session.cache_expire", "180", PHP_INI_ALL, NULL)
/* Commented out until future discussion */ /* Commented out until future discussion */
/* PHP_INI_ENTRY("session.encode_sources", "globals,track", PHP_INI_ALL, NULL) */ /* PHP_INI_ENTRY("session.encode_sources", "globals,track", PHP_INI_ALL, NULL) */
PHP_INI_END() PHP_INI_END()
@ -112,6 +115,16 @@ zend_module_entry session_module_entry = {
STANDARD_MODULE_PROPERTIES, STANDARD_MODULE_PROPERTIES,
}; };
typedef struct {
char *name;
void (*func)(PSLS_D);
} php_session_cache_limiter;
#define CACHE_LIMITER_FUNC(name) void _php_cache_limiter_##name(PSLS_D)
#define CACHE_LIMITER(name) { #name, _php_cache_limiter_##name },
#define ADD_COOKIE(a) sapi_add_header(estrdup(a), strlen(a));
#define STR_CAT(P,S,I) {\ #define STR_CAT(P,S,I) {\
pval *__p = (P);\ pval *__p = (P);\
ulong __i = __p->value.str.len;\ ulong __i = __p->value.str.len;\
@ -422,6 +435,103 @@ static void _php_session_save_current_state(PSLS_D)
PS(mod)->close(&PS(mod_data)); PS(mod)->close(&PS(mod_data));
} }
static char *month_names[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
static char *week_days[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
};
static void strcat_gmt(char *ubuf, time_t *when)
{
char buf[MAX_STR];
struct tm tm;
gmtime_r(when, &tm);
/* we know all components, thus it is safe to use sprintf */
sprintf(buf, "%s, %d %s %d %02d:%02d:%02d GMT", week_days[tm.tm_wday], tm.tm_mday, month_names[tm.tm_mon], tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
strcat(ubuf, buf);
}
static void last_modified(void)
{
char *path;
struct stat sb;
char buf[MAX_STR + 1];
SLS_FETCH();
path = SG(request_info).path_translated;
if (path) {
if (stat(path, &sb) == -1) {
return;
}
strcpy(buf, "Last-Modified: ");
strcat_gmt(buf, &sb.st_mtime);
ADD_COOKIE(buf);
}
}
CACHE_LIMITER_FUNC(public)
{
char buf[MAX_STR + 1];
time_t now;
time(&now);
now += PS(cache_expire) * 60;
strcpy(buf, "Expires: ");
strcat_gmt(buf, &now);
ADD_COOKIE(buf);
sprintf(buf, "Cache-Control: public, max-age=%d", PS(cache_expire) * 60);
ADD_COOKIE(buf);
last_modified();
}
CACHE_LIMITER_FUNC(private)
{
char buf[MAX_STR + 1];
ADD_COOKIE("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
sprintf(buf, "Cache-Control: private, max-age=%d", PS(cache_expire) * 60);
ADD_COOKIE(buf);
last_modified();
}
CACHE_LIMITER_FUNC(nocache)
{
ADD_COOKIE("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
/* For HTTP/1.1 conforming clients */
ADD_COOKIE("Cache-Control: no-cache");
/* For HTTP/1.0 conforming clients */
ADD_COOKIE("Pragma: no-cache");
}
static php_session_cache_limiter php_session_cache_limiters[] = {
CACHE_LIMITER(public)
CACHE_LIMITER(private)
CACHE_LIMITER(nocache)
{0}
};
static void _php_session_cache_limiter(PSLS_D)
{
php_session_cache_limiter *lim;
for (lim = php_session_cache_limiters; lim->name; lim++) {
if (!strcasecmp(lim->name, PS(cache_limiter))) {
lim->func(PSLS_C);
break;
}
}
}
#define COOKIE_FMT "Set-Cookie: %s=%s" #define COOKIE_FMT "Set-Cookie: %s=%s"
#define COOKIE_EXPIRES "; expires=" #define COOKIE_EXPIRES "; expires="
#define COOKIE_PATH "; path=" #define COOKIE_PATH "; path="
@ -604,6 +714,7 @@ static void _php_session_start(PSLS_D)
PS(nr_open_sessions)++; PS(nr_open_sessions)++;
_php_session_cache_limiter(PSLS_C);
_php_session_initialize(PSLS_C); _php_session_initialize(PSLS_C);
if(PS(mod_data) && PS(gc_probability) > 0) { if(PS(mod_data) && PS(gc_probability) > 0) {
@ -981,11 +1092,13 @@ static void php_rinit_session_globals(PSLS_D)
PS(entropy_length) = INI_INT("session.entropy_length"); PS(entropy_length) = INI_INT("session.entropy_length");
PS(gc_probability) = INI_INT("session.gc_probability"); PS(gc_probability) = INI_INT("session.gc_probability");
PS(gc_maxlifetime) = INI_INT("session.gc_maxlifetime"); PS(gc_maxlifetime) = INI_INT("session.gc_maxlifetime");
PS(extern_referer_chk) = estrdup(INI_STR("session.extern_referer_check"));
PS(extern_referer_chk) = estrdup(INI_STR("session.referer_check"));
PS(id) = NULL; PS(id) = NULL;
PS(cookie_lifetime) = INI_INT("session.cookie_lifetime"); PS(cookie_lifetime) = INI_INT("session.cookie_lifetime");
PS(cookie_path) = estrdup(INI_STR("session.cookie_path")); PS(cookie_path) = estrdup(INI_STR("session.cookie_path"));
PS(cookie_domain) = estrdup(INI_STR("session.cookie_domain")); PS(cookie_domain) = estrdup(INI_STR("session.cookie_domain"));
PS(cache_limiter) = estrdup(INI_STR("session.cache_limiter"));
PS(cache_expire) = INI_INT("session.cache_expire");
PS(nr_open_sessions) = 0; PS(nr_open_sessions) = 0;
PS(mod_data) = NULL; PS(mod_data) = NULL;
} }
@ -999,6 +1112,7 @@ static void php_rshutdown_session_globals(PSLS_D)
if(PS(save_path)) efree(PS(save_path)); if(PS(save_path)) efree(PS(save_path));
if(PS(session_name)) efree(PS(session_name)); if(PS(session_name)) efree(PS(session_name));
if(PS(id)) efree(PS(id)); if(PS(id)) efree(PS(id));
efree(PS(cache_limiter));
efree(PS(cookie_path)); efree(PS(cookie_path));
efree(PS(cookie_domain)); efree(PS(cookie_domain));
zend_hash_destroy(&PS(vars)); zend_hash_destroy(&PS(vars));

Loading…
Cancel
Save