;;; session.mhtml: -*- Meta-HTML -*-
;;;
;;;  Copyright (c) 1996 Brian J. Fox
;;;  Author: Brian J. Fox (bfox@ai.mit.edu) Wed May 29 08:10:02 1996.
;;;
;;; The tag <session::initialize> creates or resumes a session for the
;;; current user.  To use this tag, you should place the following in
;;; a file which is executed for each page fetch:
;;;
;;;     <include session.mhtml>
;;;	<session::initialize>
;;;
<defun session::initialize timeout timeout-page>
  <if <not <get-var timeout>>
      <set-var timeout = 200>>

  ;;; Hair to handle non-cookie compatible browsers.

  <set-var mhtml::sid-prefix="/">
  <set-var sid=<get-var default::sid>>
  <set-session-timeout <get-var timeout>>
  <if <not <get-var session::no-session-required>>
      <require-session
       missing = <prog
		   <set-var site::new-arrival=true>
		   <set-var anonymous=anonymous>
		   <create-session anonymous allow-multiple>
		   <set-session-timeout <get-var timeout>>
		   <set-session-var client=<get-var env::remote_host>>
		   <set-session-var user-agent=<get-var env::http_user_agent>>
		   <when <not <get-var mhtml::cookie-compatible>>>
		   <redirect <concat
			      <get-var mhtml::http-to-host>/
			      <get-var default::sid mhtml::relative-prefix>/
			      <get-var mhtml::current-doc>>>
		   </when>>

       timeout = <prog
		   <if <get-var timeout-page>
		       <redirect <get-var timeout-page>>>
		   <set-var
		     default::sid=<get-var sid>>>>>
</defun>
