You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rob Hartill <ro...@imdb.com> on 1997/10/17 21:03:52 UTC

per-directory support for mod_usertrack (fwd)

not acked

---------- Forwarded message ----------
Date: Thu, 16 Oct 1997 18:52:22 -0400 (EDT)
From: "David J. MacKenzie" <dj...@va.pubnix.com>
To: apache-bugs@apache.org
Cc: djm@va.pubnix.com
Subject: per-directory support for mod_usertrack

From: David MacKenzie <dj...@va.pubnix.com>
Subject: per-directory support for mod_usertrack
Affects: src/mod_usertrack.c, htdocs/manual/mod/mod_usertrack.html
ChangeLog: mod_usertrack.c: Add active and path members to state structure.
Keep the state per-directory instead of per-server.  Use the path from
the CookieTracking directive as the cookie path, so cookies set in
subdirectories don't affect the whole server.  Allow CookieExpires to
be called in .htaccess files.

Comments: The usertrack module has incomplete support for
per-directory configuration.  This patch adds the missing pieces:
1. Per-directory support for the CookieExpires directive, rather than
having it global.
2. Set the path= in the generated cookies to the path where the
"CookieTracking on" directive was given, with the document root removed.

Here are the patches.  These are against apache 1.2.4, but the file
hasn't changed a lot in 1.3a1.

--- mod_usertrack.c	1997/09/08 21:04:17	1.1
+++ mod_usertrack.c	1997/10/16 22:49:49
@@ -96,14 +96,20 @@
 
 #include "httpd.h"
 #include "http_config.h"
+#define CORE_PRIVATE /* Ick-the only way to get the doc root w/o a request? */
 #include "http_core.h"
 #include <sys/time.h>
 
 module usertrack_module;
 
+#define ACTIVE_ON 	1
+#define ACTIVE_OFF 	0
+#define ACTIVE_DONTCARE 2
+
 typedef struct {
-    int always;
+    int active;
     time_t expires;
+    char *path;
 } cookie_log_state;
 
 /* Define this to allow post-2000 cookies. Cookies use two-digit dates,
@@ -116,10 +122,8 @@
 
 #define COOKIE_NAME "Apache="
 
-void make_cookie(request_rec *r)
+void make_cookie(request_rec *r, cookie_log_state *cls)
 {
-    cookie_log_state *cls = get_module_config (r->server->module_config,
-					       &usertrack_module);
 #ifdef MPE
     clock_t mpe_times;
     struct tms mpe_tms;
@@ -172,14 +176,15 @@
 
       /* Cookie with date; as strftime '%a, %d-%h-%y %H:%M:%S GMT' */
       ap_snprintf(new_cookie, 1024,
-	   "%s%s; path=/; expires=%s, %.2d-%s-%.2d %.2d:%.2d:%.2d GMT",
-	      COOKIE_NAME, cookiebuf, days[tms->tm_wday],
+	   "%s%s; path=%s; expires=%s, %.2d-%s-%.2d %.2d:%.2d:%.2d GMT",
+	      COOKIE_NAME, cookiebuf, cls->path, days[tms->tm_wday],
 	      tms->tm_mday, month_snames[tms->tm_mon],
 	      (tms->tm_year >= 100) ? tms->tm_year - 100 : tms->tm_year,
 	      tms->tm_hour, tms->tm_min, tms->tm_sec);
     }
     else
-      ap_snprintf(new_cookie, 1024, "%s%s; path=/", COOKIE_NAME, cookiebuf);
+      ap_snprintf(new_cookie, 1024, "%s%s; path=%s", COOKIE_NAME, cookiebuf,
+		  cls->path);
 
     table_set(r->headers_out,"Set-Cookie",new_cookie);
     table_set(r->notes, "cookie", cookiebuf); /* log first time */
@@ -188,12 +193,13 @@
 
 int spot_cookie(request_rec *r)
 {
-    int *enable = (int *)get_module_config(r->per_dir_config,
-					    &usertrack_module);
+    cookie_log_state *cls =
+      (cookie_log_state *)get_module_config (r->per_dir_config, &usertrack_module); 
     char *cookie;
     char *value;
 
-    if (!*enable) return DECLINED;
+    if (cls->active != ACTIVE_ON)
+	return DECLINED;
 
     if ((cookie = table_get (r->headers_in, "Cookie")))
       if ((value=strstr(cookie,COOKIE_NAME))) {
@@ -209,34 +215,61 @@
 
 	return DECLINED;          /* Theres already a cookie, no new one */
       }
-    make_cookie(r);
+    make_cookie(r, cls);
     return OK;                        /* We set our cookie */
 }
 
-void *make_cookie_log_state (pool *p, server_rec *s)
+void *create_cookie_dir_config (pool *p, char *dummy)
 {
     cookie_log_state *cls =
-      (cookie_log_state *)palloc (p, sizeof (cookie_log_state));
-
-    cls->expires = 0;
-
+      (cookie_log_state *)pcalloc (p, sizeof (cookie_log_state));
+    cls->active = ACTIVE_DONTCARE;
     return (void *)cls;
 }
 
-void *make_cookie_dir (pool *p, char *d) {
-    return (void *)pcalloc(p, sizeof(int));
-}
+void *merge_cookie_dir_configs (pool *p, void *basev, void *addv) 
+{
+    cookie_log_state *base = (cookie_log_state *)basev;
+    cookie_log_state *add = (cookie_log_state *)addv; 
+    cookie_log_state *new =
+      (cookie_log_state *)palloc (p, sizeof(cookie_log_state));
+
+    new->active = add->active == ACTIVE_DONTCARE ? base->active : add->active;
+    new->expires = add->expires ? add->expires : base->expires;
+    new->path = add->path ? add->path : base->path;
+
+    return new;
+}   
 
-const char *set_cookie_enable (cmd_parms *cmd, int *c, int arg)
+const char *set_cookie_enable (cmd_parms *parms, cookie_log_state *cls, int arg)
 {
-    *c = arg;
+    cls->active = arg ? ACTIVE_ON : ACTIVE_OFF;
+    if (arg && parms->path) {
+      char *dr, *s;
+      size_t drlen;
+      core_server_config *conf = 
+	(core_server_config *)get_module_config(parms->server->module_config,
+						&core_module); 
+      dr = conf->document_root;
+      drlen = strlen(dr);
+      if (!strncmp(parms->path, dr, drlen)) {
+	/* Remove the document root from the front of the path.  */
+	while (dr[drlen - 1] == '/')
+	  drlen--;
+	cls->path = pstrdup(parms->pool, parms->path + drlen);
+	s = strrchr(cls->path, '/');
+	while (s > cls->path && *s == '/')
+	  --s;
+	s[1] = '\0';
+      } else {
+	cls->path = "/";
+      }
+    }
     return NULL;
 }
 
-const char *set_cookie_exp (cmd_parms *parms, void *dummy, const char *arg)
+const char *set_cookie_exp (cmd_parms *parms, cookie_log_state *cls, const char *arg)
 {
-    cookie_log_state *cls = get_module_config (parms->server->module_config,
-                           &usertrack_module);
     time_t factor, modifier = 0;
     time_t num = 0;
     char *word;
@@ -299,7 +332,7 @@
 }
 
 command_rec cookie_log_cmds[] = {
-{ "CookieExpires", set_cookie_exp, NULL, RSRC_CONF, TAKE1,
+{ "CookieExpires", set_cookie_exp, NULL, OR_FILEINFO, TAKE1,
     "an expiry date code" },
 { "CookieTracking", set_cookie_enable, NULL, OR_FILEINFO, FLAG,
     "whether or not to enable cookies" },
@@ -309,9 +342,9 @@
 module usertrack_module = {
    STANDARD_MODULE_STUFF,
    NULL,                   /* initializer */
-   make_cookie_dir,    	   /* dir config creater */
-   NULL,	      	   /* dir merger --- default is to override */
-   make_cookie_log_state,  /* server config */
+   create_cookie_dir_config,/* dir config creater */
+   merge_cookie_dir_configs,/* dir merger --- default is to override */
+   NULL,		   /* server config */
    NULL,		   /* merge server configs */
    cookie_log_cmds,	   /* command table */
    NULL,		   /* handlers */
--- mod_usertrack.html	1997/09/08 21:04:23	1.1.1.1
+++ mod_usertrack.html	1997/10/16 15:18:17
@@ -57,7 +57,7 @@
 
 <h2><a name="cookieexpires">CookieExpires</A></h2>
 <strong>Syntax:</strong> CookieExpires <em>expiry-period</em><br>
-<strong>Context:</strong> server config, virtual host<br>
+<strong>Context:</strong> server config, virtual host, directory, .htaccess<br>
 <strong>Status:</strong> optional<br>
 <strong>Module:</strong> mod_usertrack<p>
 


Re: per-directory support for mod_usertrack (fwd)

Posted by Marc Slemko <ma...@worldgate.com>.
The reason they probably didn't want to is because it is a pain to put
patches in.  We should document how to do that.

Or just have them fill out the form, then I can append the patches they
submitted via mail to it...

On Fri, 17 Oct 1997, Rob Hartill wrote:

> On Fri, 17 Oct 1997, Ben Laurie wrote:
> 
> > Rob Hartill wrote:
> > > 
> > > not acked
> > 
> > y'know, Rob, it'd be a lot better if you put these in the bug db. Or
> > even just pointed them at it.
> 
> okey dokey, I'll try the latter.
> 
> 


Re: per-directory support for mod_usertrack (fwd)

Posted by Rob Hartill <ro...@imdb.com>.
On Fri, 17 Oct 1997, Ben Laurie wrote:

> Rob Hartill wrote:
> > 
> > not acked
> 
> y'know, Rob, it'd be a lot better if you put these in the bug db. Or
> even just pointed them at it.

okey dokey, I'll try the latter.



Re: per-directory support for mod_usertrack (fwd)

Posted by Ben Laurie <be...@algroup.co.uk>.
Rob Hartill wrote:
> 
> not acked

y'know, Rob, it'd be a lot better if you put these in the bug db. Or
even just pointed them at it.

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686|Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |Apache-SSL author
A.L. Digital Ltd,     |http://www.algroup.co.uk/Apache-SSL
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache