/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

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