/library/server/fcgi/interface/fcgi_i.e

http://github.com/jocelyn/EiffelWebReloaded · Specman e · 236 lines · 176 code · 37 blank · 23 comment · 5 complexity · d8265c441fe20fb50d67c5f3cd6070c2 MD5 · raw file

  1. note
  2. description: "Abstract interface to FCGI C library"
  3. legal: "See notice at end of class."
  4. status: "See notice at end of class."
  5. date: "$Date$"
  6. revision: "$Revision$"
  7. deferred class FCGI_I
  8. inherit
  9. STRING_HANDLER
  10. feature {NONE} -- Initialization
  11. make
  12. -- Initialize FCGI interface
  13. deferred
  14. end
  15. feature -- Access
  16. updated_environ_variables: HASH_TABLE [STRING, STRING]
  17. local
  18. i: INTEGER
  19. p, v, null: POINTER
  20. do
  21. p := fcgi_environ
  22. create Result.make (50)
  23. if p /= null then
  24. from
  25. i := 0
  26. v := fcgi_i_th_environ (i,p)
  27. until
  28. v = null
  29. loop
  30. if attached separated_variables (create {STRING}.make_from_c (v)) as t then
  31. Result.force (t.value, t.key)
  32. end
  33. i := i + 1
  34. v := fcgi_i_th_environ (i,p)
  35. end
  36. end
  37. end
  38. feature -- FCGI interface
  39. fcgi_listen: INTEGER
  40. -- Listen to the FCGI input stream
  41. -- Return 0 for successful calls, -1 otherwise.
  42. deferred
  43. end
  44. fcgi_environ: POINTER
  45. -- Get the (char**) environ variable from the DLL.
  46. deferred
  47. end
  48. fcgi_finish
  49. -- Finish current request from HTTP server started from
  50. -- the most recent call to `fcgi_accept'.
  51. deferred
  52. end
  53. set_fcgi_exit_status (v: INTEGER)
  54. deferred
  55. end
  56. feature -- Status
  57. is_interactive: BOOLEAN
  58. -- Is execution interactive? (for debugging)
  59. do
  60. end
  61. feature -- Input
  62. fill_string_from_stdin (s: STRING; n: INTEGER)
  63. -- Read up to `n' bytes from stdin and store in string `s'
  64. local
  65. new_count: INTEGER
  66. str_area: ANY
  67. do
  68. s.grow (n)
  69. str_area := s.area
  70. new_count := fill_pointer_from_stdin ($str_area, n)
  71. s.set_count (new_count)
  72. end
  73. read_from_stdin (n: INTEGER)
  74. -- Read up to n bytes from stdin and store in input buffer
  75. require
  76. small_enough: n <= buffer_capacity
  77. local
  78. l_c_str: C_STRING
  79. l_count: INTEGER
  80. do
  81. last_read_is_empty_ref.set_item (False)
  82. l_c_str := c_buffer
  83. l_count := fill_pointer_from_stdin (l_c_str.item, n)
  84. last_read_count_ref.set_item (l_count)
  85. if l_count <= 0 then
  86. last_read_is_empty_ref.set_item (True)
  87. end
  88. end
  89. fill_pointer_from_stdin (p: POINTER; n: INTEGER): INTEGER
  90. -- Read up to `n' bytes from stdin and store in pointer `p'
  91. -- and return number of bytes read.
  92. deferred
  93. end
  94. copy_from_stdin (n: INTEGER; f: FILE)
  95. -- Read up to n bytes from stdin and write to given file
  96. require
  97. -- small_enough: n <= buffer_capacity
  98. file_exists: f /= Void
  99. file_open: f.is_open_write or f.is_open_append
  100. deferred
  101. end
  102. feature -- Output
  103. put_string (a_str: STRING)
  104. -- Put `a_str' on the FastCGI stdout.
  105. require
  106. a_str_not_void: a_str /= Void
  107. deferred
  108. end
  109. feature -- Implementation
  110. buffer_contents: STRING
  111. local
  112. n: like last_read_count
  113. do
  114. n := last_read_count
  115. create Result.make (n)
  116. Result.set_count (n)
  117. c_buffer.read_substring_into (Result, 1, n)
  118. end
  119. buffer_capacity: INTEGER
  120. do
  121. Result := c_buffer.capacity
  122. end
  123. --RFO last_string: STRING
  124. --RFO once
  125. --RFO create Result.make (K_input_bufsize)
  126. --RFO end
  127. last_read_count: INTEGER
  128. do
  129. Result := last_read_count_ref.item
  130. end
  131. last_read_is_empty: BOOLEAN
  132. do
  133. Result := last_read_is_empty_ref.item
  134. end
  135. feature {NONE} -- Shared buffer
  136. c_buffer: C_STRING
  137. -- Buffer for Eiffel to C and C to Eiffel string conversions.
  138. once
  139. create Result.make_empty (K_input_bufsize)
  140. ensure
  141. c_buffer_not_void: Result /= Void
  142. end
  143. feature {NONE} -- Constants
  144. last_read_count_ref: INTEGER_REF
  145. once
  146. create Result
  147. end
  148. last_read_is_empty_ref: BOOLEAN_REF
  149. once
  150. create Result
  151. end
  152. K_input_bufsize: INTEGER = 1024_000
  153. feature {NONE} -- Implementation: Environment
  154. fcgi_i_th_environ (i: INTEGER; p: POINTER): POINTER
  155. -- Environment variable at `i'-th position of `p'.
  156. require
  157. i_valid: i >=0
  158. external
  159. "C inline use <string.h>"
  160. alias
  161. "return ((char **)$p)[$i];"
  162. end
  163. separated_variables (a_var: STRING): detachable TUPLE [value: STRING; key: STRING]
  164. -- Given an environment variable `a_var' in form of "key=value",
  165. -- return separated key and value.
  166. -- Return Void if `a_var' is in incorrect format.
  167. require
  168. a_var_attached: a_var /= Void
  169. local
  170. i, j: INTEGER
  171. done: BOOLEAN
  172. do
  173. j := a_var.count
  174. from
  175. i := 1
  176. until
  177. i > j or done
  178. loop
  179. if a_var.item (i) = '=' then
  180. done := True
  181. else
  182. i := i + 1
  183. end
  184. end
  185. if i > 1 and then i < j then
  186. Result := [a_var.substring (i + 1, j), a_var.substring (1, i - 1)]
  187. end
  188. end
  189. note
  190. copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
  191. license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
  192. source: "[
  193. Eiffel Software
  194. 5949 Hollister Ave., Goleta, CA 93117 USA
  195. Telephone 805-685-1006, Fax 805-685-6869
  196. Website http://www.eiffel.com
  197. Customer support http://support.eiffel.com
  198. ]"
  199. end