;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: July 2003
;;;;
-;;;; $Id: classes.lisp,v 1.1 2003/07/16 16:02:21 kevin Exp $
+;;;; $Id: classes.lisp,v 1.2 2003/07/16 16:40:35 kevin Exp $
;;;;
;;;; This file and Wol are Copyright (c) 2001-2003 by Kevin M. Rosenberg
;;;; *************************************************************************
(defclass websession ()
((key :initarg :key :accessor websession-key)
(lastref :initarg :lastref :accessor websession-lastref)
+ (lifetime :initarg :lifetime :initform nil
+ :accessor websession-lifetime)
(data :initform nil :accessor websession-data)
(method :initarg :method :accessor websession-method)
(variables :initform (make-hash-table :test 'equal)
--- /dev/null
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: wol -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name: log.lisp
+;;;; Purpose: Logging functions
+;;;; Programmer: Kevin M. Rosenberg
+;;;; Date Started: July 2003
+;;;;
+;;;; $Id: log.lisp,v 1.1 2003/07/16 16:40:35 kevin Exp $
+;;;;
+;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg
+;;;; *************************************************************************
+
+(in-package #:wol)
+
+(defun add-log-entry (project fmt &rest args)
+ (apply #'cmsg fmt args))
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: July 2003
;;;;
-;;;; $Id: sessions.lisp,v 1.1 2003/07/16 16:02:21 kevin Exp $
+;;;; $Id: sessions.lisp,v 1.2 2003/07/16 16:40:35 kevin Exp $
;;;;
;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg
;;;; *************************************************************************
(in-package #:wol)
-(defun start-reaper ()
- (process-run-function "wol-reaper"
- (lambda () (reap-sessions) (kmrcl::process-sleep *reap-interval*))))
-
-(defun reap-sessions ()
- (cmsg-c :debug "Reaping"))
(defun make-new-session-id ()
(random-string :length 24 :set :lower-alphanumeric))
(sess (make-instance 'websession
:key key
:lastref (get-universal-time)
+ :lifetime (lifetime (session-master (entity-project ent)))
:method method))
(hash (sessions (session-master (entity-project ent)))))
(when hash
(getf (request-plist req) :session-id))
(setf (websession-from-req req)
(ensure-websession it req ent :uri))))
+
+
+
+;;; Reap expired sessions
+
+
+(defun start-reaper ()
+ (process-run-function "wol-reaper"
+ (lambda () (reap-sessions) (kmrcl::process-sleep *reap-interval*))))
+
+(defun reap-sessions ()
+ (cmsg-c :debug "Reaping")
+ (dolist (expired (find-expired-sessions))
+ (flush-expired expired)))
+
+(defun find-expired-sessions ()
+ (loop for s in (all-sessions)
+ when (is-session-expired (car s))
+ collect s))
+
+(defun all-sessions (&aux s)
+ (dolist (p *active-projects* s)
+ (let ((sm (session-master p))
+ (sessions (when sm (sessions sm))))
+ (when sessions
+ (maphash
+ (lambda (k v)
+ (declare (ignore k))
+ (push (cons v p) s))
+ sessions)))))
+
+(defmethod flush-expired (s)
+ (let ((sessions (sessions (session-master (cdr s)))))
+ (remhash (car s) sessions)
+ (add-log-entry (cdr s) "flush expired session: key=~A" (websession-key (car s)))))
+
+(defun is-session-expired (ws)
+ (> (get-universal-time) (+ (websession-lastref ws)
+ (websession-lifetime ws))))
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: July 2003
;;;;
-;;;; $Id: wol.asd,v 1.1 2003/07/16 16:02:21 kevin Exp $
+;;;; $Id: wol.asd,v 1.2 2003/07/16 16:40:35 kevin Exp $
;;;;
;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg
;;;; *************************************************************************
(:file "project" :depends-on ("classes"))
(:file "sessions" :depends-on ("classes"))
(:file "uri" :depends-on ("classes"))
+ (:file "log" :depends-on ("classes"))
))