-/* $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
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 */
* 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 $';
/*
+ * 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
*/