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 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 local
dt: detachable DATE_TIME dt: detachable DATE_TIME
l_domain: detachable READABLE_STRING_8 l_domain: detachable READABLE_STRING_8
@@ -79,7 +80,7 @@ feature -- Cookie
create dt.make_now_utc create dt.make_now_utc
dt.day_add (40) dt.day_add (40)
end 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
end end
@@ -87,6 +88,11 @@ feature -- Cookie
feature -- Access feature -- Access
id: READABLE_STRING_8
do
Result := uuid
end
uuid: READABLE_STRING_8 uuid: READABLE_STRING_8
data: WSF_SESSION_DATA data: WSF_SESSION_DATA
@@ -135,8 +141,8 @@ feature {NONE} -- Storage
load load
do do
if manager.session_exists (uuid) then if manager.session_exists (id) then
if attached manager.session_data (uuid) as d then if attached manager.session_data (id) as d then
data := d data := d
set_expiration (data.expiration) set_expiration (data.expiration)
else else

View File

@@ -68,7 +68,7 @@ feature -- Persistence
delete_session (a_session) delete_session (a_session)
else else
ensure_session_folder_exists 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 if not f.exists or else f.is_writable then
f.create_read_write f.create_read_write
a_session.data.set_expiration (a_session.expiration) a_session.data.set_expiration (a_session.expiration)
@@ -91,7 +91,7 @@ feature -- Persistence
rescued: BOOLEAN rescued: BOOLEAN
do do
if not rescued then 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 if f.exists then
f.delete f.delete
end end

View File

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

View File

@@ -8,7 +8,13 @@ class
WSF_SESSION_DATA WSF_SESSION_DATA
inherit 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 create
make make
@@ -24,4 +30,22 @@ feature -- Element change
expiration := dt expiration := dt
end 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 end