X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sessions.lisp;fp=sessions.lisp;h=b5bc55944f226c25ccee4cb1bb18073e249c501b;hb=155f1c55e5b3cfb5efc0fa3a87aca4843b418415;hp=227483bab3dabc19313794702c6a80d9db9bb87c;hpb=de82da84115f8e2a6ad7add24cb73e7876c89a3b;p=wol.git diff --git a/sessions.lisp b/sessions.lisp index 227483b..b5bc559 100644 --- a/sessions.lisp +++ b/sessions.lisp @@ -7,19 +7,13 @@ ;;;; 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)) @@ -48,6 +42,7 @@ (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 @@ -60,3 +55,42 @@ (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))))