Made all libraries compilable in any mode (voidsafe or not)

Fixed related examples
This commit is contained in:
Jocelyn Fiat
2011-09-22 15:12:33 +02:00
parent d9ba97d33b
commit dae8e1d67d
10 changed files with 58 additions and 47 deletions

View File

@@ -7,7 +7,7 @@
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" void_safety="none" syntax="standard">
<option warning="true" full_class_checking="true" void_safety="none" syntax="provisional">
</option>
<library name="base" location="$ISE_LIBRARY/library/base/base.ecf"/>
<library name="cURL" location="$ISE_LIBRARY/library/cURL/cURL.ecf"/>

View File

@@ -69,7 +69,7 @@ feature -- Status setting
feature -- Header output operation
write_headers_string (a_headers: STRING)
write_headers_string (a_headers: READABLE_STRING_8)
require
status_set: status_is_set
header_not_committed: not header_committed
@@ -80,7 +80,7 @@ feature -- Header output operation
message_writable: message_writable
end
write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]])
write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: READABLE_STRING_8; value: READABLE_STRING_8]])
-- Send headers with status `a_status', and headers from `a_headers'
require
status_not_set: not status_is_set
@@ -94,21 +94,21 @@ feature -- Header output operation
feature -- Output operation
write_string (s: STRING)
write_string (s: READABLE_STRING_8)
-- Send the string `s'
require
message_writable: message_writable
deferred
end
write_substring (s: STRING; a_begin_index, a_end_index: INTEGER)
write_substring (s: READABLE_STRING_8; a_begin_index, a_end_index: INTEGER)
-- Send the substring `s[a_begin_index:a_end_index]'
require
message_writable: message_writable
deferred
end
write_file_content (fn: STRING)
write_file_content (fn: READABLE_STRING_8)
-- Send the content of file `fn'
require
message_writable: message_writable

View File

@@ -25,7 +25,14 @@ create
feature -- Status report
authentication_required: BOOLEAN
authentication_required (req: WGI_REQUEST): BOOLEAN
do
Result := internal_authentication_required
end
feature {NONE} -- Implementation
internal_authentication_required: BOOLEAN
feature -- Execution

View File

@@ -63,9 +63,9 @@ feature -- Execution
do
content_type_supported := <<{HTTP_CONSTANTS}.json_app, {HTTP_CONSTANTS}.xml_text, {HTTP_CONSTANTS}.plain_text>>
l_format_id := ctx.request_format_id ("format", content_type_supported)
if ctx.authenticated then
if authenticated (ctx) then
l_full := attached ctx.query_parameter ("details") as v and then v.is_case_insensitive_equal ("true")
if attached ctx.authenticated_identifier as log then
if attached authenticated_identifier (ctx) as log then
l_login := log.as_string_8
create h.make

View File

@@ -70,7 +70,7 @@ feature -- Execution
-- if attached ctx.http_authorization_login_password as t then
-- s.append_string ("Check login=" + t.login + "<br/>%N")
-- end
if ctx.authenticated and then attached ctx.authenticated_identifier as l_login then
if authenticated (ctx) and then attached authenticated_identifier (ctx) as l_login then
s.append_string ("Authenticated: login=" + l_login.as_string_8 + "<br/>%N")
end
end

View File

@@ -14,6 +14,9 @@ inherit
end
REST_REQUEST_AGENT_HANDLER [APP_REQUEST_HANDLER_CONTEXT]
undefine
authenticated
end
create
make

View File

@@ -8,6 +8,9 @@ deferred class
inherit
REST_REQUEST_HANDLER [APP_REQUEST_HANDLER_CONTEXT]
redefine
authenticated
end
APP_REQUEST_HELPER
@@ -38,6 +41,24 @@ feature {NONE} -- Implementation
end
end
feature -- Auth
authenticated (ctx: APP_REQUEST_HANDLER_CONTEXT): BOOLEAN
-- Is authenticated?
do
--| To redefine if needed
if attached ctx.request.http_authorization as l_http_authorization then
Result := True
end
end
authenticated_identifier (ctx: APP_REQUEST_HANDLER_CONTEXT): detachable READABLE_STRING_32
do
if attached ctx.request.http_authorization as l_http_authorization then
Result := "foo" -- Implement it as you want
end
end
feature -- Helpers
format_id (s: detachable STRING): INTEGER

View File

@@ -9,29 +9,10 @@ class
inherit
REST_REQUEST_URI_TEMPLATE_HANDLER_CONTEXT
redefine
authenticated,
authenticated_identifier
end
create
make
feature -- Auth
authenticated: BOOLEAN
do
if attached request.http_authorization as l_http_auth then
Result := True
end
end
authenticated_identifier: detachable READABLE_STRING_32
do
if authenticated then
Result := "foo"
end
end
feature -- Format

View File

@@ -10,12 +10,14 @@ class
inherit
APP_REQUEST_HANDLER
undefine
execute,
pre_execute,
post_execute
execute
end
REST_REQUEST_URI_TEMPLATE_ROUTING_HANDLER_I [APP_REQUEST_HANDLER, APP_REQUEST_HANDLER_CONTEXT]
undefine
authenticated,
pre_execute,
post_execute
redefine
router
end

View File

@@ -14,31 +14,28 @@ feature -- Helper
execute_content_type_not_allowed (req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER; a_content_types: detachable ARRAY [STRING]; a_uri_formats: detachable ARRAY [STRING])
local
s, uri_s: detachable STRING
accept_s, uri_s: detachable STRING
i, n: INTEGER
h: EWF_HEADER
do
create h.make
h.put_status ({HTTP_STATUS_CODE}.unsupported_media_type)
h.put_content_type_text_plain
if a_content_types /= Void then
create s.make (10)
create accept_s.make (10)
from
i := a_content_types.lower
n := a_content_types.upper
until
i > n
loop
s.append_string (a_content_types[i])
accept_s.append_string (a_content_types[i])
if i < n then
s.append_character (',')
s.append_character (' ')
accept_s.append_character (',')
accept_s.append_character (' ')
end
i := i + 1
end
h.put_header_key_value ("Accept", s)
else
accept_s := "*/*"
end
if a_uri_formats /= Void then
create uri_s.make (10)
from
@@ -56,9 +53,9 @@ feature -- Helper
end
end
res.set_status_code ({HTTP_STATUS_CODE}.unsupported_media_type)
res.write_headers_string (h.string)
if s /= Void then
res.write_string ("Unsupported request content-type, Accept: " + s + "%N")
res.write_header ({HTTP_STATUS_CODE}.unsupported_media_type, << ["Content-Type", "text/plain"], ["Accept", accept_s]>>)
if accept_s /= Void then
res.write_string ("Unsupported request content-type, Accept: " + accept_s + "%N")
end
if uri_s /= Void then
res.write_string ("Unsupported request format from the URI: " + uri_s + "%N")