Replaced notion of session uuid by session id which is more generic (could be a uuid, or something else).

Use STRING_TABLE for the implementation of session data container.
Added a few missing comments.
This commit is contained in:
2014-05-14 09:45:15 +02:00
parent 02f5a09689
commit d158579bdc
4 changed files with 67 additions and 13 deletions

View File

@@ -60,7 +60,8 @@ feature {NONE} -- Initialization
feature -- Cookie
apply_to (h: HTTP_HEADER_BUILDER; a_request: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
apply_to (h: HTTP_HEADER_MODIFIER; a_request: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
-- <Precursor>
local
dt: detachable DATE_TIME
l_domain: detachable READABLE_STRING_8
@@ -79,13 +80,18 @@ feature -- Cookie
create dt.make_now_utc
dt.day_add (40)
end
h.put_cookie_with_expiration_date (cookie_name, uuid, dt, a_path, l_domain, False, True)
h.put_cookie_with_expiration_date (cookie_name, id, dt, a_path, l_domain, False, True)
end
end
cookie_name: READABLE_STRING_8
feature -- Access
feature -- Access
id: READABLE_STRING_8
do
Result := uuid
end
uuid: READABLE_STRING_8
@@ -135,8 +141,8 @@ feature {NONE} -- Storage
load
do
if manager.session_exists (uuid) then
if attached manager.session_data (uuid) as d then
if manager.session_exists (id) then
if attached manager.session_data (id) as d then
data := d
set_expiration (data.expiration)
else

View File

@@ -68,7 +68,7 @@ feature -- Persistence
delete_session (a_session)
else
ensure_session_folder_exists
create f.make_with_path (file_name (a_session.uuid))
create f.make_with_path (file_name (a_session.id))
if not f.exists or else f.is_writable then
f.create_read_write
a_session.data.set_expiration (a_session.expiration)
@@ -91,7 +91,7 @@ feature -- Persistence
rescued: BOOLEAN
do
if not rescued then
create f.make_with_path (file_name (a_session.uuid))
create f.make_with_path (file_name (a_session.id))
if f.exists then
f.delete
end

View File

@@ -7,26 +7,43 @@ note
deferred class
WSF_SESSION
feature -- Access
feature -- Access
id: READABLE_STRING_8
-- Session identifier.
deferred
end
uuid: READABLE_STRING_8
obsolete
"Use `id' which is more general [2014-03]"
deferred
end
data: WSF_SESSION_DATA
-- Data associated with current session.
deferred
end
expiration: detachable DATE_TIME
-- Expiration date for current session, if any.
deferred
end
expired: BOOLEAN
-- Is current session expired now?
do
Result := expired_at (create {DATE_TIME}.make_now_utc)
end
expired_at (dt: DATE_TIME): BOOLEAN
-- Is current session expired at date and time `dt'?
do
if attached expiration as e then
Result := e < (create {DATE_TIME}.make_now_utc)
Result := e < (dt)
end
end
feature -- status
is_pending: BOOLEAN
@@ -36,27 +53,32 @@ feature -- status
end
is_destroyed: BOOLEAN
-- Is current session in destroyed state?
deferred
end
feature -- Entries
table: TABLE_ITERABLE [detachable ANY, READABLE_STRING_32]
table: TABLE_ITERABLE [detachable ANY, READABLE_STRING_GENERAL]
-- Table of session data indexed by key
do
Result := data
end
item (k: READABLE_STRING_GENERAL): detachable ANY
item alias "[]" (k: READABLE_STRING_GENERAL): detachable ANY assign remember
-- Session value associated with key `k'.
do
Result := data.item (table_key (k))
end
remember (v: detachable ANY; k: READABLE_STRING_GENERAL)
-- Remember value `v' in association with key `k'.
do
data.force (v, table_key (k))
end
forget (k: READABLE_STRING_GENERAL)
-- Forget about value associated with key `k'.
do
data.remove (table_key (k))
end
@@ -71,14 +93,16 @@ feature {NONE} -- Implementation
feature -- Control
destroy
-- Destroy current session.
deferred
end
commit
-- Commit current session, including data associated.
deferred
end
apply_to (h: HTTP_HEADER_BUILDER; req: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
apply_to (h: HTTP_HEADER_MODIFIER; req: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
-- Apply current session to header `h' for request `req' and optional path `a_path'.
-- note: either use `apply_to' or `apply', not both.
deferred

View File

@@ -8,7 +8,13 @@ class
WSF_SESSION_DATA
inherit
HASH_TABLE [detachable ANY, READABLE_STRING_32]
STRING_TABLE [detachable ANY]
rename
make as old_make,
make_caseless as make
redefine
empty_duplicate
end
create
make
@@ -24,4 +30,22 @@ feature -- Element change
expiration := dt
end
feature {NONE} -- Duplication
empty_duplicate (n: INTEGER): like Current
-- Create an empty copy of Current that can accommodate `n' items
do
create Result.make (n)
end
note
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end