-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
state.lisp
36 lines (31 loc) · 1.02 KB
/
state.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(in-package :cl-user)
(defpackage lack.middleware.session.state
(:nicknames :lack.session.state)
(:use :cl)
(:import-from :lack.util
:generate-random-id)
(:import-from :cl-ppcre
:scan)
(:export :state
:make-state
:generate-sid
:extract-sid
:expire-state
:finalize-state))
(in-package :lack.middleware.session.state)
(defstruct state
(sid-generator (lambda (env)
(declare (ignore env))
(generate-random-id)))
(sid-validator (lambda (sid)
(not (null (ppcre:scan "\\A[0-9a-f]{40}\\Z" sid))))))
(defun generate-sid (state env)
(funcall (state-sid-generator state) env))
(defgeneric extract-sid (state env))
(defmethod extract-sid :around ((state state) env)
(let ((sid (call-next-method)))
(when (and sid
(funcall (state-sid-validator state) sid))
sid)))
(defgeneric expire-state (state sid res options))
(defgeneric finalize-state (state sid res options))