PageRenderTime 38ms CodeModel.GetById 31ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/library/server/httpd/interface/variable/httpd_request_variables.e

http://github.com/jocelyn/EiffelWebReloaded
Specman e | 137 lines | 108 code | 22 blank | 7 comment | 5 complexity | 5482e182a2821d9749aab528dcb1b0b2 MD5 | raw file
  1note
  2	description: "[
  3				Variables/field related to the current request.
  4			]"
  5	legal: "See notice at end of class."
  6	status: "See notice at end of class."
  7	date: "$Date$"
  8	revision: "$Revision$"
  9
 10class
 11	HTTPD_REQUEST_VARIABLES
 12
 13inherit
 14	HTTPD_VARIABLES
 15
 16	ITERABLE [STRING_32]
 17
 18create
 19	make,
 20	make_from_urlencoded
 21
 22feature -- Initialization
 23
 24	make (n: INTEGER)
 25		do
 26			create variables.make (n)
 27			variables.compare_objects
 28		end
 29
 30	make_from_urlencoded (a_content: STRING; decoding: BOOLEAN)
 31		do
 32			make (a_content.occurrences ('&') + 1)
 33			import_urlencoded (a_content, decoding)
 34		end
 35
 36feature -- Status report
 37
 38	count: INTEGER
 39			-- Variables count
 40		do
 41			Result := variables.count
 42		end
 43
 44	variable (a_name: STRING): detachable STRING_32
 45		do
 46			Result := variables.item (a_name)
 47		end
 48
 49	has_variable (a_name: STRING): BOOLEAN
 50		do
 51			Result := variables.has (a_name)
 52		end
 53
 54feature -- Import urlencoded
 55
 56	import_urlencoded (a_content: STRING; decoding: BOOLEAN)
 57			-- Import `a_content'
 58		local
 59			n, p, i, j: INTEGER
 60			s: STRING
 61			l_name,l_value: STRING_32
 62		do
 63			n := a_content.count
 64			if n > 0 then
 65				from
 66					p := 1
 67				until
 68					p = 0
 69				loop
 70					i := a_content.index_of ('&', p)
 71					if i = 0 then
 72						s := a_content.substring (p, n)
 73						p := 0
 74					else
 75						s := a_content.substring (p, i - 1)
 76						p := i + 1
 77					end
 78					if not s.is_empty then
 79						j := s.index_of ('=', 1)
 80						if j > 0 then
 81							l_name := s.substring (1, j - 1)
 82							l_value := s.substring (j + 1, s.count)
 83							if decoding then
 84								l_name := url_encoder.decoded_string (l_name)
 85								l_value := url_encoder.decoded_string (l_value)
 86							end
 87							add_variable (l_value, l_name)
 88						end
 89					end
 90				end
 91			end
 92		end
 93
 94feature -- Access: table
 95
 96	new_cursor: HASH_TABLE_ITERATION_CURSOR [STRING_32, STRING_32]
 97			-- Fresh cursor associated with current structure
 98		do
 99			create Result.make (variables)
100		end
101
102feature {HTTPD_REQUEST_CONTEXT} -- Element change
103
104	add_variable (v: STRING_32; k: STRING_32)
105			-- Added `k,v' to variables table
106			-- Not exported to common client
107			-- Simulate Read Only Access
108		require
109			k_attached: k /= Void
110			v_attached: v /= Void
111		do
112			variables.force (v, k)
113		end
114
115feature {HTTPD_REQUEST_CONTEXT} -- Element change		
116
117	variables: HASH_TABLE [STRING_32, STRING_32]
118			-- Variables table
119
120feature {NONE} -- Implementation
121
122	url_encoder: URL_ENCODER
123		once
124			create Result
125		end
126
127note
128	copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
129	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
130	source: "[
131			Eiffel Software
132			5949 Hollister Ave., Goleta, CA 93117 USA
133			Telephone 805-685-1006, Fax 805-685-6869
134			Website http://www.eiffel.com
135			Customer support http://support.eiffel.com
136		]"
137end