cvs: /php4/ext/session session.c php_session.h
| From: | Sascha Schumann | Date: | Sun, 12 Dec 1999 14:17:25 +0000 |
| Subject: | cvs: /php4/ext/session session.c php_session.h | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-7821@lists.php.net to get a copy of this message | ||
sas Sun Dec 12 09:17:25 1999 EDT
Modified files:
/php4/ext/session session.c php_session.h
Log:
Add cache_limiter and cache_expire options. Rename extern_referer_check
to referer_check.
Index: php4/ext/session/session.c
diff -u php4/ext/session/session.c:1.80 php4/ext/session/session.c:1.81
--- php4/ext/session/session.c:1.80 Thu Dec 9 13:57:57 1999
+++ php4/ext/session/session.c Sun Dec 12 09:16:55 1999
@@ -23,6 +23,7 @@
#include "win32/time.h"
#endif
+#include <sys/stat.h>
#include <fcntl.h>
#include "php.h"
@@ -73,9 +74,11 @@
PHP_INI_ENTRY("session.cookie_path", "/", 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.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_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 */
/* PHP_INI_ENTRY("session.encode_sources", "globals,track", PHP_INI_ALL, NULL)
*/
PHP_INI_END()
@@ -112,6 +115,16 @@
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) {\
pval *__p = (P);\
ulong __i = __p->value.str.len;\
@@ -422,6 +435,103 @@
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_EXPIRES "; expires="
#define COOKIE_PATH "; path="
@@ -604,6 +714,7 @@
PS(nr_open_sessions)++;
+ _php_session_cache_limiter(PSLS_C);
_php_session_initialize(PSLS_C);
if(PS(mod_data) && PS(gc_probability) > 0) {
@@ -981,11 +1092,13 @@
PS(entropy_length) = INI_INT("session.entropy_length");
PS(gc_probability) = INI_INT("session.gc_probability");
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(cookie_lifetime) = INI_INT("session.cookie_lifetime");
PS(cookie_path) = estrdup(INI_STR("session.cookie_path"));
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(mod_data) = NULL;
}
@@ -999,6 +1112,7 @@
if(PS(save_path)) efree(PS(save_path));
if(PS(session_name)) efree(PS(session_name));
if(PS(id)) efree(PS(id));
+ efree(PS(cache_limiter));
efree(PS(cookie_path));
efree(PS(cookie_domain));
zend_hash_destroy(&PS(vars));
Index: php4/ext/session/php_session.h
diff -u php4/ext/session/php_session.h:1.23 php4/ext/session/php_session.h:1.24
--- php4/ext/session/php_session.h:1.23 Sun Dec 5 05:29:05 1999
+++ php4/ext/session/php_session.h Sun Dec 12 09:16:55 1999
@@ -76,6 +76,7 @@
char *id;
char *extern_referer_chk;
char *entropy_file;
+ char *cache_limiter;
int entropy_length;
int cookie_lifetime;
char *cookie_path;
@@ -89,6 +90,7 @@
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;