moved wsf_extension inside wsf/extension as wsf/wsf_extension.ecf

added wsf/session as wsf/wsf_session.ecf
In descendants of WSF_HANDLER , we can keep the result of new_mapping as WSF_ROUTER_MAPPING
This commit is contained in:
Jocelyn Fiat
2012-09-28 14:42:31 +02:00
parent 80c1cc1c0d
commit 291bb3a33b
20 changed files with 573 additions and 20 deletions

View File

@@ -18,9 +18,9 @@ feature -- Execution
feature {WSF_ROUTER} -- Mapping
new_mapping (a_uri: READABLE_STRING_8): WSF_STARTS_WITH_MAPPING
new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING
do
create Result.make (a_uri, Current)
create {WSF_STARTS_WITH_MAPPING} Result.make (a_uri, Current)
end
note

View File

@@ -18,9 +18,9 @@ feature -- Execution
feature {WSF_ROUTER} -- Mapping
new_mapping (a_uri: READABLE_STRING_8): WSF_URI_MAPPING
new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING
do
create Result.make (a_uri, Current)
create {WSF_URI_MAPPING} Result.make (a_uri, Current)
end
note

View File

@@ -18,9 +18,9 @@ feature -- Execution
feature {WSF_ROUTER} -- Mapping
new_mapping (a_tpl: READABLE_STRING_8): WSF_URI_TEMPLATE_MAPPING
new_mapping (a_tpl: READABLE_STRING_8): WSF_ROUTER_MAPPING
do
create Result.make (a_tpl, Current)
create {WSF_URI_TEMPLATE_MAPPING} Result.make (a_tpl, Current)
end
note

View File

@@ -12,9 +12,9 @@ inherit
feature {WSF_ROUTER} -- Mapping
new_mapping (a_tpl: READABLE_STRING_8): WSF_URI_TEMPLATE_CONTEXT_MAPPING [C]
new_mapping (a_tpl: READABLE_STRING_8): WSF_ROUTER_MAPPING
do
create Result.make (a_tpl, Current)
create {WSF_URI_TEMPLATE_CONTEXT_MAPPING [C]} Result.make (a_tpl, Current)
end
note

View File

@@ -0,0 +1,193 @@
note
description: "Summary description for {WSF_SESSION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_COOKIE_SESSION
inherit
WSF_SESSION
create
make,
make_new
feature {NONE} -- Initialization
make (req: WSF_REQUEST; a_cookie_name: detachable like cookie_name; a_manager: WSF_SESSION_MANAGER)
local
l_uuid: detachable READABLE_STRING_32
do
manager := a_manager
initialize (a_cookie_name)
if attached {WSF_STRING} req.cookie (cookie_name) as c_uuid then
l_uuid := c_uuid.value
elseif attached {WSF_STRING} req.query_parameter (cookie_name) as q_uuid then
l_uuid := q_uuid.value
end
if l_uuid /= Void and then session_exists (l_uuid) then
uuid := l_uuid
load
else
is_pending := True
build
end
end
make_new (a_cookie_name: detachable like cookie_name; a_manager: WSF_SESSION_MANAGER)
do
manager := a_manager
initialize (a_cookie_name)
is_pending := True
build
end
initialize (a_cookie_name: detachable like cookie_name)
do
if a_cookie_name = Void or else a_cookie_name.is_empty then
cookie_name := "_EWF_SESSION_ID"
else
cookie_name := a_cookie_name
end
end
feature -- Cookie
apply_to (h: HTTP_HEADER; a_request: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
local
dt: detachable DATE_TIME
l_domain: detachable READABLE_STRING_8
do
l_domain := a_request.server_name
if l_domain.same_string ("localhost") then
-- Due to limitation of specific handling of local cookies
-- it is recommended to use Void or IP instead of "localhost"
l_domain := Void
end
if is_destroyed then
h.put_cookie (cookie_name, "deleted", "Thu, 01 Jan 1970 00:00:00 GMT", a_path, l_domain, False, True)
else
dt := expiration
if dt = Void then
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)
end
end
cookie_name: READABLE_STRING_8
feature -- Access
uuid: READABLE_STRING_8
data: WSF_SESSION_DATA
expiration: detachable DATE_TIME
feature -- status
is_pending: BOOLEAN
is_destroyed: BOOLEAN
feature -- Control
destroy
do
is_destroyed := True
data.wipe_out
delete
end
commit
do
save
end
set_expiration (dt: like expiration)
do
expiration := dt
end
feature {NONE} -- Storage
manager: WSF_SESSION_MANAGER
session_exists (a_uuid: like uuid): BOOLEAN
do
Result := manager.session_exists (a_uuid)
end
init_data
do
create data.make (0)
data.compare_objects
end
sessions_folder_name: READABLE_STRING_8
local
dn: DIRECTORY_NAME
once
create dn.make_from_string ((create {EXECUTION_ENVIRONMENT}).current_working_directory)
dn.extend ("_sessions_")
Result := dn.string
end
load
do
if manager.session_exists (uuid) then
if attached manager.session_data (uuid) as d then
data := d
set_expiration (data.expiration)
else
init_data
save
end
else
build
end
rescue
print ("ouch")
end
build
do
uuid := uuid_generator.generate_uuid.out
init_data
save
end
save
do
manager.save_session (Current)
end
delete
do
manager.delete_session (Current)
end
feature {NONE} -- Implementation
uuid_generator: UUID_GENERATOR
once
create Result
end
note
copyright: "Copyright (c) 1984-2012, 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

View File

@@ -0,0 +1,160 @@
note
description: "Summary description for {WSF_FS_SESSION_MANAGER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_FS_SESSION_MANAGER
inherit
WSF_SESSION_MANAGER
create
make,
make_with_folder
feature {NONE} -- Initialization
make
do
make_with_folder ("_WSF_SESSIONS_")
end
make_with_folder (a_folder: like sessions_folder_name)
do
sessions_folder_name := a_folder
end
sessions_folder_name: STRING_8
feature -- Access
session_exists (a_session_uuid: like {WSF_SESSION}.uuid): BOOLEAN
local
f: RAW_FILE
do
create f.make (file_name (a_session_uuid))
Result := f.exists and then f.is_readable
end
session_data (a_session_uuid: like {WSF_SESSION}.uuid): detachable like {WSF_SESSION}.data
local
f: RAW_FILE
do
create f.make (file_name (a_session_uuid))
if f.exists and then f.is_readable then
f.open_read
if attached data_from_file (f) as d then
Result := d
end
f.close
end
rescue
debug
print ("Error occurred in " + generator)
end
end
feature -- Persistence
save_session (a_session: WSF_SESSION)
local
f: RAW_FILE
rescued: BOOLEAN
do
if not rescued then
if a_session.is_destroyed then
delete_session (a_session)
else
ensure_session_folder_exists
create f.make (file_name (a_session.uuid))
if not f.exists or else f.is_writable then
f.create_read_write
a_session.data.set_expiration (a_session.expiration)
f.general_store (a_session.data)
f.close
end
end
end
rescue
debug
io.error.put_string (generator + ": trouble saving session")
end
rescued := True
retry
end
delete_session (a_session: WSF_SESSION)
local
f: RAW_FILE
rescued: BOOLEAN
do
if not rescued then
create f.make (file_name (a_session.uuid))
if f.exists then
f.delete
end
end
rescue
debug
io.error.put_string (generator + ": trouble deleting session")
end
rescued := True
retry
end
feature {NONE} -- Implementation
data_from_file (f: FILE): detachable like session_data
require
f.is_open_read and f.is_readable
local
rescued: BOOLEAN
do
if
not rescued and then
attached {like session_data} f.retrieved as d
then
Result := d
end
rescue
debug
--FIXME
io.error.put_string (generator + ": incompatible session content")
end
rescued := True
retry
end
ensure_session_folder_exists
local
d: DIRECTORY
once
create d.make (sessions_folder_name)
if not d.exists then
d.recursive_create_dir
end
ensure
sessions_folder_exists_and_writable: sessions_folder_exists_and_writable
end
sessions_folder_exists_and_writable: BOOLEAN
local
d: DIRECTORY
do
create d.make (sessions_folder_name)
Result := d.exists and then d.is_writable
end
file_name (a_uuid: like {WSF_SESSION}.uuid): READABLE_STRING_8
local
fn: FILE_NAME
do
create fn.make_from_string (sessions_folder_name)
fn.set_file_name (a_uuid.out)
fn.add_extension ("session")
Result := fn.string
end
end

View File

@@ -0,0 +1,97 @@
note
description: "Summary description for {WSF_SESSION}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_SESSION
feature -- Access
uuid: READABLE_STRING_8
deferred
end
data: WSF_SESSION_DATA
deferred
end
expiration: detachable DATE_TIME
deferred
end
expired: BOOLEAN
do
if attached expiration as e then
Result := e < (create {DATE_TIME}.make_now_utc)
end
end
feature -- status
is_pending: BOOLEAN
-- New session pending to be applied?
-- i.e: sent back to the client
deferred
end
is_destroyed: BOOLEAN
deferred
end
feature -- Entries
table: TABLE_ITERABLE [detachable ANY, READABLE_STRING_32]
do
Result := data
end
item (k: READABLE_STRING_GENERAL): detachable ANY
do
Result := data.item (table_key (k))
end
remember (v: detachable ANY; k: READABLE_STRING_GENERAL)
do
data.force (v, table_key (k))
end
forget (k: READABLE_STRING_GENERAL)
do
data.remove (table_key (k))
end
feature {NONE} -- Implementation
table_key (k: READABLE_STRING_GENERAL): STRING_32
do
Result := k.as_string_32
end
feature -- Control
destroy
deferred
end
commit
deferred
end
apply_to (h: HTTP_HEADER; a_request: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
deferred
end
note
copyright: "Copyright (c) 1984-2012, 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

View File

@@ -0,0 +1,27 @@
note
description: "Summary description for {WSF_SESSION_DATA}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_SESSION_DATA
inherit
HASH_TABLE [detachable ANY, READABLE_STRING_32]
create
make
feature -- Access
expiration: detachable DATE_TIME
feature -- Element change
set_expiration (dt: like expiration)
do
expiration := dt
end
end

View File

@@ -0,0 +1,16 @@
note
description: "Summary description for {WSF_SESSION_FACTORY}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_SESSION_FACTORY [G -> WSF_SESSION]
feature -- Access
new_session (req: WSF_REQUEST; a_reuse: BOOLEAN; m: WSF_SESSION_MANAGER): G
deferred
end
end

View File

@@ -0,0 +1,30 @@
note
description: "Summary description for {WSF_SESSION_MANAGER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_SESSION_MANAGER
feature -- Access
session_exists (a_uuid: like {WSF_SESSION}.uuid): BOOLEAN
deferred
end
session_data (a_uuid: like {WSF_SESSION}.uuid): detachable like {WSF_SESSION}.data
deferred
end
feature -- Persistence
save_session (a_session: WSF_SESSION)
deferred
end
delete_session (a_session: WSF_SESSION)
deferred
end
end

View File

@@ -13,6 +13,6 @@
<library name="http" location="../../network/protocol/http/http-safe.ecf"/>
<library name="ewsgi" location="..\ewsgi\ewsgi-safe.ecf"/>
<library name="wsf-safe" location="..\wsf\wsf-safe.ecf"/>
<cluster name="src" location="./src" recursive="true"/>
<cluster name="extension" location=".extension" recursive="true"/>
</target>
</system>

View File

@@ -13,6 +13,6 @@
<library name="http" location="../../network/protocol/http/http.ecf"/>
<library name="ewsgi" location="..\ewsgi\ewsgi.ecf"/>
<library name="wsf" location="..\wsf\wsf.ecf"/>
<cluster name="src" location="./src" recursive="true"/>
<cluster name="extension" location="./extension" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="wsf_session" uuid="C41D0367-9852-4AA7-9E7E-DEA162A4CBB0" library_target="wsf_session">
<target name="wsf_session">
<root all_classes="true"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard">
</option>
<library name="base" location="$ISE_LIBRARY/library/base/base-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY/library/time/time-safe.ecf"/>
<library name="uuid" location="$ISE_LIBRARY/library/uuid/uuid-safe.ecf"/>
<library name="http" location="../../network/protocol/http/http-safe.ecf"/>
<library name="ewsgi" location="..\ewsgi\ewsgi-safe.ecf"/>
<library name="wsf-safe" location="..\wsf\wsf-safe.ecf"/>
<cluster name="session" location="./session" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="wsf_session" uuid="C41D0367-9852-4AA7-9E7E-DEA162A4CBB0" library_target="wsf_session">
<target name="wsf_session">
<root all_classes="true"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" void_safety="none" syntax="standard">
</option>
<library name="base" location="$ISE_LIBRARY/library/base/base.ecf"/>
<library name="time" location="$ISE_LIBRARY/library/time/time.ecf"/>
<library name="uuid" location="$ISE_LIBRARY/library/uuid/uuid.ecf"/>
<library name="http" location="../../network/protocol/http/http.ecf"/>
<library name="ewsgi" location="..\ewsgi\ewsgi.ecf"/>
<library name="wsf" location="..\wsf\wsf.ecf"/>
<cluster name="session" location="./session" recursive="true"/>
</target>
</system>

View File

@@ -1,10 +0,0 @@
${NOTE_KEYWORD}
copyright: "2011-${YEAR}, Jocelyn Fiat, Javier Velilla, 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
]"