*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 7 Jul 2005 18:11:24 +0000 (18:11 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 7 Jul 2005 18:11:24 +0000 (18:11 +0000)
tests/js-test/js/httpd/httpd.js

index e1df940..58d3d40 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: httpd.js,v 1.24 2005/07/07 17:09:54 mmondor Exp $ */
+/* $Id: httpd.js,v 1.25 2005/07/07 18:11:24 mmondor Exp $ */
 
 /*
  * Copyright (c) 2005, Matthew Mondor
@@ -83,7 +83,6 @@ function file_read(file)
 eval(file_read('options.js'));         /* Configuration */
 eval(file_read('ml.js'));              /* MLTag object for HTML generation */
 eval(file_read('root.js'));            /* Root object for virtual chroot(2) */
-eval(file_read('session.js'));         /* Sesssion object */
 
 
 
@@ -91,7 +90,7 @@ eval(file_read('session.js'));                /* Sesssion object */
  * Server identification
  */
 SERVER_VERSION                 = 'mmondor_js_httpd/0.0.1 (NetBSD)';
-SERVER_CVSID   = '$Id: httpd.js,v 1.24 2005/07/07 17:09:54 mmondor Exp $';
+SERVER_CVSID   = '$Id: httpd.js,v 1.25 2005/07/07 18:11:24 mmondor Exp $';
 
 
 
@@ -166,6 +165,55 @@ function VHost(o)
 
 
 /*
+ * The Session object allows to maintain persistent session variables among
+ * multiple client queries.  We are using a cookie with the unique session ID
+ * to link those queries together into a session.
+ */
+
+var o = new FD();
+o.set(FD.STDOUT_FILENO);
+
+var session_randfd = new FD();
+session_randfd.open('/dev/urandom', FD.O_RDONLY);
+
+var session_charlist = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
+                       'abcdefghijklmnopqrstuvwxyz' +
+                       '0123456789-_';
+
+var sessions_table = {};
+
+/*
+ * To be called at regular but spaced intervals,
+ * destroys expired session objects.
+ */
+function session_gc(time)
+{
+       var i;
+
+       for (i in sessions_table) {
+               if (sessions_table[i].expires >= time)
+                       delete sessions_table[i];
+       }
+}
+
+function Session(time, exp)
+{
+       var rval = session_randfd.read(64);
+       var i;
+
+       this.sessid = '';
+       for (i = 0; i < 64; i++)
+               this.sessid +=
+                   session_charlist.charAt(rval.charCodeAt(i) & 0x3f);
+
+       this.variables = {};
+       this.expires = time + exp;
+       sessions_table[this.sessid] = this;
+}
+
+
+
+/*
  * For the mime types database
  */