/library/server/fcgi/implementation/windows/fcgi_imp.e

http://github.com/jocelyn/EiffelWebReloaded · Specman e · 267 lines · 83 code · 30 blank · 154 comment · 2 complexity · b70e64ea6df94e597028fc9075623dcb MD5 · raw file

  1. note
  2. description: "Implementation for the FCGI_I interface"
  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_IMP
  8. inherit
  9. FCGI_I
  10. feature {NONE} -- Initialization
  11. make
  12. -- Initialize FCGI interface
  13. do
  14. create fcgi
  15. end
  16. fcgi: FCGI_C_API
  17. -- FastCGI C API primitives
  18. feature -- Access
  19. fcgi_environ: POINTER
  20. do
  21. Result := fcgi.environ
  22. end
  23. -- updated_environ_variables: HASH_TABLE [STRING, STRING]
  24. -- local
  25. ---- n, l_size,
  26. -- i: INTEGER
  27. -- p, v, null: POINTER
  28. -- do
  29. ---- update_eif_environ
  30. ---- Result := starting_environment_variables
  31. --
  32. ---- p := environ_strings_pointer ($n)
  33. ---- from
  34. ---- i := 1
  35. ---- l_size := 0
  36. ---- create Result.make (n)
  37. ---- until
  38. ---- i > n
  39. ---- loop
  40. ---- create s.make_from_c (p.plus (l_size))
  41. ---- l_size := l_size + s.count + 1
  42. ---- if attached separated_variables (s) as t then
  43. ---- Result.force (t.value, t.key)
  44. ---- end
  45. ---- i := i + 1
  46. ---- end
  47. --
  48. -- p := fcgi.environ
  49. -- create Result.make (50)
  50. -- if p /= null then
  51. -- from
  52. -- i := 0
  53. -- v := fcgi_i_th_environ (i,p)
  54. -- until
  55. -- v = null
  56. -- loop
  57. -- if attached separated_variables (create {STRING}.make_from_c (v)) as t then
  58. -- Result.force (t.value, t.key)
  59. -- end
  60. -- i := i + 1
  61. -- v := fcgi_i_th_environ (i,p)
  62. -- end
  63. -- end
  64. -- end
  65. --
  66. -- fcgi_i_th_environ (i: INTEGER; p: POINTER): POINTER
  67. -- -- Environment variable at `i'-th position of `p'.
  68. -- require
  69. -- i_valid: i >=0
  70. -- external
  71. -- "C inline use <string.h>"
  72. -- alias
  73. -- "[
  74. -- return ((char **)$p)[$i];
  75. -- ]"
  76. -- end
  77. feature -- FCGI connection
  78. fcgi_listen: INTEGER
  79. -- Listen to the FCGI input stream
  80. -- Return 0 for successful calls, -1 otherwise.
  81. do
  82. Result := fcgi.accept
  83. end
  84. -- update_eif_environ
  85. -- external
  86. -- "C inline use <string.h>"
  87. -- alias
  88. -- "[
  89. -- #ifdef EIF_WINDOWS
  90. -- #ifndef GetEnvironmentStringsA
  91. -- extern LPVOID WINAPI GetEnvironmentStringsA(void);
  92. -- #endif
  93. --
  94. -- eif_environ = (char**) GetEnvironmentStringsA();
  95. -- #endif
  96. -- ]"
  97. -- end
  98. fcgi_finish
  99. -- Finish current request from HTTP server started from
  100. -- the most recent call to `fcgi_accept'.
  101. do
  102. fcgi.finish
  103. end
  104. set_fcgi_exit_status (v: INTEGER)
  105. do
  106. fcgi.set_exit_status (-2)
  107. end
  108. feature -- FCGI output
  109. put_string (a_str: STRING)
  110. -- Put `a_str' on the FastCGI stdout.
  111. local
  112. l_c_str: C_STRING
  113. do
  114. l_c_str := c_buffer
  115. l_c_str.set_string (a_str)
  116. fcgi.put_string (l_c_str.item, l_c_str.count)
  117. end
  118. feature -- FCGI input
  119. copy_from_stdin (n: INTEGER; f: FILE)
  120. -- Read up to n bytes from stdin and write to given file
  121. local
  122. l_c_str: C_STRING
  123. num, readsize, writecount: INTEGER
  124. done: BOOLEAN
  125. l_fcgi: like fcgi
  126. do
  127. --put_trace ("copy_from_stdin, n=" +n.out)
  128. readsize := n.min (K_input_bufsize)
  129. --put_trace ("copy_from_stdin, readsize=" +readsize.out)
  130. l_c_str := c_buffer
  131. from
  132. l_fcgi := fcgi
  133. until done or writecount >= n
  134. loop
  135. num := l_fcgi.read_content_into (l_c_str.item, readsize)
  136. --put_trace ("copy_from_stdin, num=" +num.out)
  137. if num = 0 then
  138. -- EOF
  139. done := True
  140. else
  141. f.put_managed_pointer (c_buffer.managed_data, 0, num)
  142. writecount := writecount + num
  143. end
  144. end
  145. end
  146. feature {NONE} -- Implementation: FCGI Input
  147. fill_pointer_from_stdin (p: POINTER; n: INTEGER): INTEGER
  148. -- Read up to `n' bytes from stdin and store in pointer `p'
  149. -- and return number of bytes read.
  150. do
  151. Result := fcgi.read_content_into (p, n)
  152. end
  153. feature -- I/O Routines
  154. --RFO read_stdin_into (a_str: STRING)
  155. --RFO -- Read a string from the `stdin' into `a_str'.
  156. --RFO require
  157. --RFO a_str_not_void: a_str /= Void
  158. --RFO local
  159. --RFO l_c_str: C_STRING
  160. --RFO n: INTEGER
  161. --RFO do
  162. --RFO l_c_str := c_buffer
  163. --RFO n := fcgi.read_content_into (l_c_str.item, l_c_str.capacity)
  164. --RFO a_str.set_count (n)
  165. --RFO l_c_str.read_substring_into (a_str, 1, n)
  166. --RFO end
  167. --RFO read_string_into (a_str: STRING)
  168. --RFO require
  169. --RFO exists: a_str /= Void
  170. --RFO local
  171. --RFO l_c_str: C_STRING
  172. --RFO p: POINTER
  173. --RFO do
  174. --RFO create l_c_str.make_empty (1024)
  175. --RFO p := fcgi.gets (l_c_str.item)
  176. --RFO-- if p /= default_pointer and p = l_c_str.item then
  177. --RFO a_str.resize (l_c_str.count)
  178. --RFO l_c_str.read_string_into (a_str)
  179. --RFO-- else
  180. --RFO-- put_error_line ("Bad pointer from gets")
  181. --RFO-- end
  182. --RFO end
  183. --RFO read_line
  184. --RFO -- Read up to the next end of line, or end of input
  185. --RFO -- Leave result in last_string
  186. --RFO -- Newline character is absent from result
  187. --RFO do
  188. --RFO if last_string = Void then
  189. --RFO create Result.make (K_input_bufsize)
  190. --RFO else
  191. --RFO last_string.wipe_out
  192. --RFO end
  193. --RFO-- if input_filename /= Void then
  194. --RFO-- io.read_line
  195. --RFO-- last_string.append (io.last_string)
  196. --RFO-- else
  197. --RFO read_string_into (last_string)
  198. --RFO-- end
  199. --RFO end
  200. feature {NONE} -- Implementation: environment
  201. -- environ_strings_pointer (p_nb: TYPED_POINTER [INTEGER]): POINTER
  202. -- -- Environment variable strings returned by `GetEnvironmentStringsA'
  203. -- -- `p_nb' return the count of environment variables.
  204. -- external
  205. -- "C inline use <string.h>"
  206. -- alias
  207. -- "[
  208. -- #ifdef EIF_WINDOWS
  209. -- #ifndef GetEnvironmentStringsA
  210. -- extern LPVOID WINAPI GetEnvironmentStringsA(void);
  211. -- #endif
  212. --
  213. -- int cnt = 0;
  214. -- LPSTR vars = GetEnvironmentStringsA();
  215. -- char** p = (char**) vars;
  216. --
  217. -- for (; *vars; vars++) {
  218. -- while (*vars) { vars++; }
  219. -- cnt++;
  220. -- }
  221. --
  222. -- *$p_nb = cnt;
  223. -- return (EIF_POINTER) p;
  224. -- #endif
  225. -- ]"
  226. -- end
  227. note
  228. copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
  229. license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
  230. source: "[
  231. Eiffel Software
  232. 5949 Hollister Ave., Goleta, CA 93117 USA
  233. Telephone 805-685-1006, Fax 805-685-6869
  234. Website http://www.eiffel.com
  235. Customer support http://support.eiffel.com
  236. ]"
  237. end