mongrel 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. data.tar.gz.sig +2 -0
  2. data/CHANGELOG +2 -0
  3. data/Manifest +68 -0
  4. data/bin/mongrel_rails +55 -22
  5. data/examples/camping/README +3 -0
  6. data/examples/httpd.conf +474 -0
  7. data/examples/mime.yaml +3 -0
  8. data/examples/mongrel.conf +9 -0
  9. data/examples/monitrc +57 -0
  10. data/ext/http11/http11.c +25 -12
  11. data/ext/http11/http11_parser.c +456 -331
  12. data/ext/http11/http11_parser.h +1 -0
  13. data/ext/http11/http11_parser.java.rl +170 -0
  14. data/ext/http11/http11_parser.rl +8 -48
  15. data/ext/http11/http11_parser_common.rl +54 -0
  16. data/ext/http11/tst.h +2 -2
  17. data/ext/http11/tst_cleanup.c +0 -1
  18. data/ext/http11/tst_insert.c +29 -3
  19. data/ext/http11/tst_search.c +60 -55
  20. data/lib/mongrel.rb +68 -53
  21. data/lib/mongrel/cgi.rb +3 -3
  22. data/lib/mongrel/command.rb +1 -1
  23. data/lib/mongrel/configurator.rb +41 -31
  24. data/lib/mongrel/debug.rb +2 -5
  25. data/lib/mongrel/handlers.rb +23 -9
  26. data/lib/mongrel/mime_types.yml +2 -1
  27. data/lib/mongrel/rails.rb +7 -15
  28. data/mongrel-public_cert.pem +20 -0
  29. data/mongrel.gemspec +211 -0
  30. data/test/jruby_socket.rb +39 -0
  31. data/test/test_cgi_wrapper.rb +26 -0
  32. data/test/test_command.rb +1 -4
  33. data/test/test_conditional.rb +6 -18
  34. data/test/test_configurator.rb +5 -8
  35. data/test/test_debug.rb +3 -11
  36. data/test/test_handlers.rb +8 -10
  37. data/test/test_http11.rb +24 -5
  38. data/test/test_redirect_handler.rb +2 -6
  39. data/test/test_request_progress.rb +5 -9
  40. data/test/test_response.rb +24 -3
  41. data/test/test_stats.rb +1 -3
  42. data/test/test_uriclassifier.rb +170 -81
  43. data/test/test_ws.rb +25 -24
  44. data/test/testhelp.rb +26 -3
  45. data/tools/trickletest.rb +2 -2
  46. metadata +138 -333
  47. metadata.gz.sig +0 -0
  48. data/Rakefile +0 -117
  49. data/doc/rdoc/classes/IO.html +0 -170
  50. data/doc/rdoc/classes/IO.src/M000003.html +0 -19
  51. data/doc/rdoc/classes/IO.src/M000004.html +0 -19
  52. data/doc/rdoc/classes/Kernel.html +0 -159
  53. data/doc/rdoc/classes/Kernel.src/M000012.html +0 -19
  54. data/doc/rdoc/classes/Kernel.src/M000013.html +0 -23
  55. data/doc/rdoc/classes/Mongrel.html +0 -204
  56. data/doc/rdoc/classes/Mongrel/CGIWrapper.html +0 -404
  57. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000115.html +0 -25
  58. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000116.html +0 -47
  59. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000117.html +0 -34
  60. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000118.html +0 -32
  61. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000119.html +0 -25
  62. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000120.html +0 -18
  63. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000121.html +0 -18
  64. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000122.html +0 -18
  65. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000123.html +0 -19
  66. data/doc/rdoc/classes/Mongrel/Camping.html +0 -177
  67. data/doc/rdoc/classes/Mongrel/Camping.src/M000041.html +0 -22
  68. data/doc/rdoc/classes/Mongrel/Camping/CampingHandler.html +0 -184
  69. data/doc/rdoc/classes/Mongrel/Camping/CampingHandler.src/M000042.html +0 -20
  70. data/doc/rdoc/classes/Mongrel/Camping/CampingHandler.src/M000043.html +0 -58
  71. data/doc/rdoc/classes/Mongrel/Command.html +0 -132
  72. data/doc/rdoc/classes/Mongrel/Command/Base.html +0 -384
  73. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000018.html +0 -24
  74. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000019.html +0 -42
  75. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000020.html +0 -18
  76. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000021.html +0 -18
  77. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000022.html +0 -18
  78. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000023.html +0 -18
  79. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000024.html +0 -22
  80. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000025.html +0 -18
  81. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000026.html +0 -18
  82. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000027.html +0 -18
  83. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000028.html +0 -24
  84. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000029.html +0 -24
  85. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000030.html +0 -18
  86. data/doc/rdoc/classes/Mongrel/Command/Registry.html +0 -192
  87. data/doc/rdoc/classes/Mongrel/Command/Registry.src/M000031.html +0 -20
  88. data/doc/rdoc/classes/Mongrel/Command/Registry.src/M000032.html +0 -29
  89. data/doc/rdoc/classes/Mongrel/Command/Registry.src/M000033.html +0 -58
  90. data/doc/rdoc/classes/Mongrel/Configurator.html +0 -716
  91. data/doc/rdoc/classes/Mongrel/Configurator.src/M000093.html +0 -27
  92. data/doc/rdoc/classes/Mongrel/Configurator.src/M000094.html +0 -31
  93. data/doc/rdoc/classes/Mongrel/Configurator.src/M000095.html +0 -18
  94. data/doc/rdoc/classes/Mongrel/Configurator.src/M000096.html +0 -21
  95. data/doc/rdoc/classes/Mongrel/Configurator.src/M000097.html +0 -20
  96. data/doc/rdoc/classes/Mongrel/Configurator.src/M000098.html +0 -23
  97. data/doc/rdoc/classes/Mongrel/Configurator.src/M000099.html +0 -18
  98. data/doc/rdoc/classes/Mongrel/Configurator.src/M000100.html +0 -38
  99. data/doc/rdoc/classes/Mongrel/Configurator.src/M000101.html +0 -19
  100. data/doc/rdoc/classes/Mongrel/Configurator.src/M000102.html +0 -39
  101. data/doc/rdoc/classes/Mongrel/Configurator.src/M000103.html +0 -33
  102. data/doc/rdoc/classes/Mongrel/Configurator.src/M000104.html +0 -18
  103. data/doc/rdoc/classes/Mongrel/Configurator.src/M000105.html +0 -24
  104. data/doc/rdoc/classes/Mongrel/Configurator.src/M000106.html +0 -19
  105. data/doc/rdoc/classes/Mongrel/Configurator.src/M000107.html +0 -18
  106. data/doc/rdoc/classes/Mongrel/Configurator.src/M000108.html +0 -22
  107. data/doc/rdoc/classes/Mongrel/Configurator.src/M000109.html +0 -22
  108. data/doc/rdoc/classes/Mongrel/Configurator.src/M000110.html +0 -18
  109. data/doc/rdoc/classes/Mongrel/Configurator.src/M000111.html +0 -34
  110. data/doc/rdoc/classes/Mongrel/Configurator.src/M000112.html +0 -18
  111. data/doc/rdoc/classes/Mongrel/Configurator.src/M000113.html +0 -36
  112. data/doc/rdoc/classes/Mongrel/Configurator.src/M000114.html +0 -18
  113. data/doc/rdoc/classes/Mongrel/Const.html +0 -337
  114. data/doc/rdoc/classes/Mongrel/DeflateFilter.html +0 -188
  115. data/doc/rdoc/classes/Mongrel/DeflateFilter.src/M000124.html +0 -19
  116. data/doc/rdoc/classes/Mongrel/DeflateFilter.src/M000125.html +0 -23
  117. data/doc/rdoc/classes/Mongrel/DirHandler.html +0 -303
  118. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000051.html +0 -21
  119. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000052.html +0 -42
  120. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000053.html +0 -38
  121. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000054.html +0 -65
  122. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000055.html +0 -39
  123. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000056.html +0 -18
  124. data/doc/rdoc/classes/Mongrel/Error404Handler.html +0 -171
  125. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000126.html +0 -18
  126. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000127.html +0 -18
  127. data/doc/rdoc/classes/Mongrel/HeaderOut.html +0 -190
  128. data/doc/rdoc/classes/Mongrel/HeaderOut.src/M000066.html +0 -21
  129. data/doc/rdoc/classes/Mongrel/HeaderOut.src/M000067.html +0 -21
  130. data/doc/rdoc/classes/Mongrel/HttpHandler.html +0 -215
  131. data/doc/rdoc/classes/Mongrel/HttpHandler.src/M000072.html +0 -17
  132. data/doc/rdoc/classes/Mongrel/HttpHandler.src/M000073.html +0 -17
  133. data/doc/rdoc/classes/Mongrel/HttpHandler.src/M000074.html +0 -17
  134. data/doc/rdoc/classes/Mongrel/HttpHandlerPlugin.html +0 -210
  135. data/doc/rdoc/classes/Mongrel/HttpHandlerPlugin.src/M000014.html +0 -17
  136. data/doc/rdoc/classes/Mongrel/HttpHandlerPlugin.src/M000015.html +0 -17
  137. data/doc/rdoc/classes/Mongrel/HttpHandlerPlugin.src/M000016.html +0 -19
  138. data/doc/rdoc/classes/Mongrel/HttpHandlerPlugin.src/M000017.html +0 -17
  139. data/doc/rdoc/classes/Mongrel/HttpParams.html +0 -131
  140. data/doc/rdoc/classes/Mongrel/HttpParser.html +0 -278
  141. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000044.html +0 -28
  142. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000045.html +0 -29
  143. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000046.html +0 -29
  144. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000047.html +0 -59
  145. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000048.html +0 -27
  146. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000049.html +0 -27
  147. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000050.html +0 -28
  148. data/doc/rdoc/classes/Mongrel/HttpParserError.html +0 -111
  149. data/doc/rdoc/classes/Mongrel/HttpRequest.html +0 -284
  150. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000133.html +0 -50
  151. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000134.html +0 -41
  152. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000135.html +0 -29
  153. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000136.html +0 -20
  154. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000137.html +0 -20
  155. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000138.html +0 -32
  156. data/doc/rdoc/classes/Mongrel/HttpResponse.html +0 -443
  157. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000075.html +0 -25
  158. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000076.html +0 -20
  159. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000077.html +0 -26
  160. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000078.html +0 -22
  161. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000079.html +0 -22
  162. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000080.html +0 -22
  163. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000081.html +0 -31
  164. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000082.html +0 -21
  165. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000083.html +0 -20
  166. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000084.html +0 -20
  167. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000085.html +0 -20
  168. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000086.html +0 -18
  169. data/doc/rdoc/classes/Mongrel/HttpServer.html +0 -402
  170. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000057.html +0 -25
  171. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000058.html +0 -100
  172. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000059.html +0 -32
  173. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000060.html +0 -21
  174. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000061.html +0 -29
  175. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000062.html +0 -65
  176. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000063.html +0 -34
  177. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000064.html +0 -18
  178. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000065.html +0 -22
  179. data/doc/rdoc/classes/Mongrel/Rails.html +0 -112
  180. data/doc/rdoc/classes/Mongrel/Rails/RailsConfigurator.html +0 -225
  181. data/doc/rdoc/classes/Mongrel/Rails/RailsConfigurator.src/M000034.html +0 -37
  182. data/doc/rdoc/classes/Mongrel/Rails/RailsConfigurator.src/M000035.html +0 -25
  183. data/doc/rdoc/classes/Mongrel/Rails/RailsConfigurator.src/M000036.html +0 -26
  184. data/doc/rdoc/classes/Mongrel/Rails/RailsHandler.html +0 -263
  185. data/doc/rdoc/classes/Mongrel/Rails/RailsHandler.src/M000037.html +0 -23
  186. data/doc/rdoc/classes/Mongrel/Rails/RailsHandler.src/M000038.html +0 -56
  187. data/doc/rdoc/classes/Mongrel/Rails/RailsHandler.src/M000039.html +0 -20
  188. data/doc/rdoc/classes/Mongrel/Rails/RailsHandler.src/M000040.html +0 -25
  189. data/doc/rdoc/classes/Mongrel/RedirectHandler.html +0 -187
  190. data/doc/rdoc/classes/Mongrel/RedirectHandler.src/M000131.html +0 -22
  191. data/doc/rdoc/classes/Mongrel/RedirectHandler.src/M000132.html +0 -27
  192. data/doc/rdoc/classes/Mongrel/StatisticsFilter.html +0 -211
  193. data/doc/rdoc/classes/Mongrel/StatisticsFilter.src/M000128.html +0 -24
  194. data/doc/rdoc/classes/Mongrel/StatisticsFilter.src/M000129.html +0 -24
  195. data/doc/rdoc/classes/Mongrel/StatisticsFilter.src/M000130.html +0 -18
  196. data/doc/rdoc/classes/Mongrel/Stats.html +0 -309
  197. data/doc/rdoc/classes/Mongrel/Stats.src/M000139.html +0 -19
  198. data/doc/rdoc/classes/Mongrel/Stats.src/M000140.html +0 -23
  199. data/doc/rdoc/classes/Mongrel/Stats.src/M000141.html +0 -26
  200. data/doc/rdoc/classes/Mongrel/Stats.src/M000142.html +0 -18
  201. data/doc/rdoc/classes/Mongrel/Stats.src/M000143.html +0 -18
  202. data/doc/rdoc/classes/Mongrel/Stats.src/M000144.html +0 -18
  203. data/doc/rdoc/classes/Mongrel/Stats.src/M000145.html +0 -23
  204. data/doc/rdoc/classes/Mongrel/Stats.src/M000146.html +0 -20
  205. data/doc/rdoc/classes/Mongrel/StatusHandler.html +0 -194
  206. data/doc/rdoc/classes/Mongrel/StatusHandler.src/M000068.html +0 -18
  207. data/doc/rdoc/classes/Mongrel/StatusHandler.src/M000069.html +0 -24
  208. data/doc/rdoc/classes/Mongrel/StatusHandler.src/M000070.html +0 -42
  209. data/doc/rdoc/classes/Mongrel/StatusHandler.src/M000071.html +0 -20
  210. data/doc/rdoc/classes/Mongrel/StopServer.html +0 -117
  211. data/doc/rdoc/classes/Mongrel/TimeoutError.html +0 -117
  212. data/doc/rdoc/classes/Mongrel/URIClassifier.html +0 -317
  213. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000087.html +0 -18
  214. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000088.html +0 -18
  215. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000089.html +0 -39
  216. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000090.html +0 -51
  217. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000091.html +0 -36
  218. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000092.html +0 -83
  219. data/doc/rdoc/classes/MongrelDbg.html +0 -209
  220. data/doc/rdoc/classes/MongrelDbg.src/M000007.html +0 -24
  221. data/doc/rdoc/classes/MongrelDbg.src/M000008.html +0 -20
  222. data/doc/rdoc/classes/MongrelDbg.src/M000009.html +0 -22
  223. data/doc/rdoc/classes/MongrelDbg.src/M000010.html +0 -21
  224. data/doc/rdoc/classes/MongrelDbg.src/M000011.html +0 -18
  225. data/doc/rdoc/classes/Mutex.html +0 -158
  226. data/doc/rdoc/classes/Mutex.src/M000001.html +0 -24
  227. data/doc/rdoc/classes/Mutex.src/M000002.html +0 -32
  228. data/doc/rdoc/classes/RequestLog.html +0 -115
  229. data/doc/rdoc/classes/RequestLog/Access.html +0 -151
  230. data/doc/rdoc/classes/RequestLog/Access.src/M000147.html +0 -19
  231. data/doc/rdoc/classes/RequestLog/Files.html +0 -144
  232. data/doc/rdoc/classes/RequestLog/Files.src/M000148.html +0 -19
  233. data/doc/rdoc/classes/RequestLog/Objects.html +0 -150
  234. data/doc/rdoc/classes/RequestLog/Objects.src/M000150.html +0 -51
  235. data/doc/rdoc/classes/RequestLog/Params.html +0 -144
  236. data/doc/rdoc/classes/RequestLog/Params.src/M000151.html +0 -19
  237. data/doc/rdoc/classes/RequestLog/Threads.html +0 -144
  238. data/doc/rdoc/classes/RequestLog/Threads.src/M000149.html +0 -34
  239. data/doc/rdoc/classes/TCPServer.html +0 -173
  240. data/doc/rdoc/classes/TCPServer.src/M000005.html +0 -19
  241. data/doc/rdoc/created.rid +0 -1
  242. data/doc/rdoc/files/COPYING.html +0 -168
  243. data/doc/rdoc/files/LICENSE.html +0 -168
  244. data/doc/rdoc/files/README.html +0 -213
  245. data/doc/rdoc/files/ext/http11/http11_c.html +0 -101
  246. data/doc/rdoc/files/lib/mongrel/camping_rb.html +0 -120
  247. data/doc/rdoc/files/lib/mongrel/cgi_rb.html +0 -120
  248. data/doc/rdoc/files/lib/mongrel/command_rb.html +0 -123
  249. data/doc/rdoc/files/lib/mongrel/configurator_rb.html +0 -111
  250. data/doc/rdoc/files/lib/mongrel/debug_rb.html +0 -122
  251. data/doc/rdoc/files/lib/mongrel/handlers_rb.html +0 -122
  252. data/doc/rdoc/files/lib/mongrel/init_rb.html +0 -121
  253. data/doc/rdoc/files/lib/mongrel/rails_rb.html +0 -123
  254. data/doc/rdoc/files/lib/mongrel/stats_rb.html +0 -113
  255. data/doc/rdoc/files/lib/mongrel/tcphack_rb.html +0 -113
  256. data/doc/rdoc/files/lib/mongrel_rb.html +0 -135
  257. data/doc/rdoc/files/lib/mutex_fix_rb.html +0 -108
  258. data/doc/rdoc/fr_class_index.html +0 -68
  259. data/doc/rdoc/fr_file_index.html +0 -42
  260. data/doc/rdoc/fr_method_index.html +0 -177
  261. data/doc/rdoc/index.html +0 -24
  262. data/doc/rdoc/rdoc-style.css +0 -208
  263. data/tools/rakehelp.rb +0 -117
@@ -30,6 +30,7 @@ typedef struct http_parser {
30
30
  field_cb http_field;
31
31
  element_cb request_method;
32
32
  element_cb request_uri;
33
+ element_cb fragment;
33
34
  element_cb request_path;
34
35
  element_cb query_string;
35
36
  element_cb http_version;
@@ -0,0 +1,170 @@
1
+ package org.jruby.mongrel;
2
+
3
+ import org.jruby.util.ByteList;
4
+
5
+ public class Http11Parser {
6
+
7
+ /** Machine **/
8
+
9
+ %%{
10
+
11
+ machine http_parser;
12
+
13
+ action mark {parser.mark = fpc; }
14
+
15
+ action start_field { parser.field_start = fpc; }
16
+ action write_field {
17
+ parser.field_len = fpc-parser.field_start;
18
+ }
19
+
20
+ action start_value { parser.mark = fpc; }
21
+ action write_value {
22
+ if(parser.http_field != null) {
23
+ parser.http_field.call(parser.data, parser.field_start, parser.field_len, parser.mark, fpc-parser.mark);
24
+ }
25
+ }
26
+ action request_method {
27
+ if(parser.request_method != null)
28
+ parser.request_method.call(parser.data, parser.mark, fpc-parser.mark);
29
+ }
30
+ action request_uri {
31
+ if(parser.request_uri != null)
32
+ parser.request_uri.call(parser.data, parser.mark, fpc-parser.mark);
33
+ }
34
+ action fragment {
35
+ if(parser.fragment != null)
36
+ parser.fragment.call(parser.data, parser.mark, fpc-parser.mark);
37
+ }
38
+
39
+ action start_query {parser.query_start = fpc; }
40
+ action query_string {
41
+ if(parser.query_string != null)
42
+ parser.query_string.call(parser.data, parser.query_start, fpc-parser.query_start);
43
+ }
44
+
45
+ action http_version {
46
+ if(parser.http_version != null)
47
+ parser.http_version.call(parser.data, parser.mark, fpc-parser.mark);
48
+ }
49
+
50
+ action request_path {
51
+ if(parser.request_path != null)
52
+ parser.request_path.call(parser.data, parser.mark, fpc-parser.mark);
53
+ }
54
+
55
+ action done {
56
+ parser.body_start = fpc + 1;
57
+ if(parser.header_done != null)
58
+ parser.header_done.call(parser.data, fpc + 1, pe - fpc - 1);
59
+ fbreak;
60
+ }
61
+
62
+ include http_parser_common "http11_parser_common.rl";
63
+
64
+ }%%
65
+
66
+ /** Data **/
67
+ %% write data;
68
+
69
+ public static interface ElementCB {
70
+ public void call(Object data, int at, int length);
71
+ }
72
+
73
+ public static interface FieldCB {
74
+ public void call(Object data, int field, int flen, int value, int vlen);
75
+ }
76
+
77
+ public static class HttpParser {
78
+ int cs;
79
+ int body_start;
80
+ int content_len;
81
+ int nread;
82
+ int mark;
83
+ int field_start;
84
+ int field_len;
85
+ int query_start;
86
+
87
+ Object data;
88
+ ByteList buffer;
89
+
90
+ public FieldCB http_field;
91
+ public ElementCB request_method;
92
+ public ElementCB request_uri;
93
+ public ElementCB fragment;
94
+ public ElementCB request_path;
95
+ public ElementCB query_string;
96
+ public ElementCB http_version;
97
+ public ElementCB header_done;
98
+
99
+ public void init() {
100
+ cs = 0;
101
+
102
+ %% write init;
103
+
104
+ body_start = 0;
105
+ content_len = 0;
106
+ mark = 0;
107
+ nread = 0;
108
+ field_len = 0;
109
+ field_start = 0;
110
+ }
111
+ }
112
+
113
+ public final HttpParser parser = new HttpParser();
114
+
115
+ public int execute(ByteList buffer, int off) {
116
+ int p, pe;
117
+ int cs = parser.cs;
118
+ int len = buffer.realSize;
119
+ assert off<=len : "offset past end of buffer";
120
+
121
+ p = off;
122
+ pe = len;
123
+ byte[] data = buffer.bytes;
124
+ parser.buffer = buffer;
125
+
126
+ %% write exec;
127
+
128
+ parser.cs = cs;
129
+ parser.nread += (p - off);
130
+
131
+ assert p <= pe : "buffer overflow after parsing execute";
132
+ assert parser.nread <= len : "nread longer than length";
133
+ assert parser.body_start <= len : "body starts after buffer end";
134
+ assert parser.mark < len : "mark is after buffer end";
135
+ assert parser.field_len <= len : "field has length longer than whole buffer";
136
+ assert parser.field_start < len : "field starts after buffer end";
137
+
138
+ if(parser.body_start>0) {
139
+ /* final \r\n combo encountered so stop right here */
140
+ %%write eof;
141
+ parser.nread++;
142
+ }
143
+
144
+ return parser.nread;
145
+ }
146
+
147
+ public int finish() {
148
+ int cs = parser.cs;
149
+
150
+ %%write eof;
151
+
152
+ parser.cs = cs;
153
+
154
+ if(has_error()) {
155
+ return -1;
156
+ } else if(is_finished()) {
157
+ return 1;
158
+ } else {
159
+ return 0;
160
+ }
161
+ }
162
+
163
+ public boolean has_error() {
164
+ return parser.cs == http_parser_error;
165
+ }
166
+
167
+ public boolean is_finished() {
168
+ return parser.cs == http_parser_first_final;
169
+ }
170
+ }
@@ -13,8 +13,10 @@
13
13
  #define MARK(M,FPC) (parser->M = (FPC) - buffer)
14
14
  #define PTR_TO(F) (buffer + parser->F)
15
15
 
16
- /** machine **/
16
+ /** Machine **/
17
+
17
18
  %%{
19
+
18
20
  machine http_parser;
19
21
 
20
22
  action mark {MARK(mark, fpc); }
@@ -39,6 +41,10 @@
39
41
  if(parser->request_uri != NULL)
40
42
  parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, fpc));
41
43
  }
44
+ action fragment {
45
+ if(parser->fragment != NULL)
46
+ parser->fragment(parser->data, PTR_TO(mark), LEN(mark, fpc));
47
+ }
42
48
 
43
49
  action start_query {MARK(query_start, fpc); }
44
50
  action query_string {
@@ -63,54 +69,8 @@
63
69
  fbreak;
64
70
  }
65
71
 
72
+ include http_parser_common "http11_parser_common.rl";
66
73
 
67
- #### HTTP PROTOCOL GRAMMAR
68
- # line endings
69
- CRLF = "\r\n";
70
-
71
- # character types
72
- CTL = (cntrl | 127);
73
- safe = ("$" | "-" | "_" | ".");
74
- extra = ("!" | "*" | "'" | "(" | ")" | ",");
75
- reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+");
76
- unsafe = (CTL | " " | "\"" | "#" | "%" | "<" | ">");
77
- national = any -- (alpha | digit | reserved | extra | safe | unsafe);
78
- unreserved = (alpha | digit | safe | extra | national);
79
- escape = ("%" xdigit xdigit);
80
- uchar = (unreserved | escape);
81
- pchar = (uchar | ":" | "@" | "&" | "=" | "+");
82
- tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
83
-
84
- # elements
85
- token = (ascii -- (CTL | tspecials));
86
-
87
- # URI schemes and absolute paths
88
- scheme = ( alpha | digit | "+" | "-" | "." )* ;
89
- absolute_uri = (scheme ":" (uchar | reserved )*);
90
-
91
- path = (pchar+ ( "/" pchar* )*) ;
92
- query = ( uchar | reserved )* %query_string ;
93
- param = ( pchar | "/" )* ;
94
- params = (param ( ";" param )*) ;
95
- rel_path = (path? %request_path (";" params)?) ("?" %start_query query)?;
96
- absolute_path = ("/"+ rel_path);
97
-
98
- Request_URI = ("*" | absolute_uri | absolute_path) >mark %request_uri;
99
- Method = (upper | digit | safe){1,20} >mark %request_method;
100
-
101
- http_number = (digit+ "." digit+) ;
102
- HTTP_Version = ("HTTP/" http_number) >mark %http_version ;
103
- Request_Line = (Method " " Request_URI " " HTTP_Version CRLF) ;
104
-
105
- field_name = (token -- ":")+ >start_field %write_field;
106
-
107
- field_value = any* >start_value %write_value;
108
-
109
- message_header = field_name ":" " "* field_value :> CRLF;
110
-
111
- Request = Request_Line (message_header)* ( CRLF @done);
112
-
113
- main := Request;
114
74
  }%%
115
75
 
116
76
  /** Data **/
@@ -0,0 +1,54 @@
1
+ %%{
2
+
3
+ machine http_parser_common;
4
+
5
+ #### HTTP PROTOCOL GRAMMAR
6
+ # line endings
7
+ CRLF = "\r\n";
8
+
9
+ # character types
10
+ CTL = (cntrl | 127);
11
+ safe = ("$" | "-" | "_" | ".");
12
+ extra = ("!" | "*" | "'" | "(" | ")" | ",");
13
+ reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+");
14
+ unsafe = (CTL | " " | "\"" | "#" | "%" | "<" | ">");
15
+ national = any -- (alpha | digit | reserved | extra | safe | unsafe);
16
+ unreserved = (alpha | digit | safe | extra | national);
17
+ escape = ("%" xdigit xdigit);
18
+ uchar = (unreserved | escape);
19
+ pchar = (uchar | ":" | "@" | "&" | "=" | "+");
20
+ tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
21
+
22
+ # elements
23
+ token = (ascii -- (CTL | tspecials));
24
+
25
+ # URI schemes and absolute paths
26
+ scheme = ( alpha | digit | "+" | "-" | "." )* ;
27
+ absolute_uri = (scheme ":" (uchar | reserved )*);
28
+
29
+ path = ( pchar+ ( "/" pchar* )* ) ;
30
+ query = ( uchar | reserved )* %query_string ;
31
+ param = ( pchar | "/" )* ;
32
+ params = ( param ( ";" param )* ) ;
33
+ rel_path = ( path? %request_path (";" params)? ) ("?" %start_query query)?;
34
+ absolute_path = ( "/"+ rel_path );
35
+
36
+ Request_URI = ( "*" | absolute_uri | absolute_path ) >mark %request_uri;
37
+ Fragment = ( uchar | reserved )* >mark %fragment;
38
+ Method = ( upper | digit | safe ){1,20} >mark %request_method;
39
+
40
+ http_number = ( digit+ "." digit+ ) ;
41
+ HTTP_Version = ( "HTTP/" http_number ) >mark %http_version ;
42
+ Request_Line = ( Method " " Request_URI ("#" Fragment){0,1} " " HTTP_Version CRLF ) ;
43
+
44
+ field_name = ( token -- ":" )+ >start_field %write_field;
45
+
46
+ field_value = any* >start_value %write_value;
47
+
48
+ message_header = field_name ":" " "* field_value :> CRLF;
49
+
50
+ Request = Request_Line ( message_header )* ( CRLF @done );
51
+
52
+ main := Request;
53
+
54
+ }%%
@@ -24,14 +24,14 @@ struct node_lines
24
24
 
25
25
  enum tst_constants
26
26
  {
27
- TST_OK, TST_ERROR, TST_NULL_KEY, TST_DUPLICATE_KEY, TST_REPLACE
27
+ TST_OK, TST_ERROR, TST_NULL_KEY, TST_DUPLICATE_KEY, TST_REPLACE, TST_LONGEST_MATCH
28
28
  };
29
29
 
30
30
  struct tst *tst_init(int node_line_width);
31
31
 
32
32
  int tst_insert(unsigned char *key, void *data, struct tst *tst, int option, void **exist_ptr);
33
33
 
34
- void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len);
34
+ void *tst_search(const unsigned char *key, struct tst *tst, int option, unsigned int *match_len);
35
35
 
36
36
  void *tst_delete(unsigned char *key, struct tst *tst);
37
37
 
@@ -21,4 +21,3 @@ void tst_cleanup(struct tst *tst)
21
21
 
22
22
  free(tst);
23
23
  }
24
-
@@ -2,16 +2,16 @@
2
2
  #include "tst.h"
3
3
  #include <stdio.h>
4
4
  #include <stdlib.h>
5
-
5
+ #include <string.h>
6
6
 
7
7
  int tst_grow_node_free_list(struct tst *tst);
8
8
  int tst_insert(unsigned char *key, void *data, struct tst *tst, int option, void **exist_ptr)
9
9
  {
10
10
  struct node *current_node;
11
11
  struct node *new_node_tree_begin = NULL;
12
+ struct node *new_node;
12
13
  int key_index;
13
14
  int perform_loop = 1;
14
-
15
15
 
16
16
  if (key == NULL)
17
17
  return TST_NULL_KEY;
@@ -91,7 +91,33 @@ int tst_insert(unsigned char *key, void *data, struct tst *tst, int option, void
91
91
  }
92
92
  }
93
93
  }
94
-
94
+ if(key[key_index] == 0)
95
+ {
96
+ if(tst->free_list == NULL)
97
+ {
98
+ if(tst_grow_node_free_list(tst) != 1)
99
+ return TST_ERROR;
100
+ }
101
+ new_node = tst->free_list;
102
+ tst->free_list = tst->free_list->middle;
103
+
104
+ memcpy((void*)new_node, (void*)current_node, sizeof(struct node));
105
+ current_node->value = 0;
106
+ if(new_node->value < 64)
107
+ {
108
+ current_node->left = new_node;
109
+ current_node->right = '\0';
110
+ }
111
+ else
112
+ {
113
+ current_node->left = '\0';
114
+ current_node->right = new_node;
115
+ }
116
+
117
+ current_node->middle = data;
118
+ return TST_OK;
119
+ }
120
+
95
121
  if( ((current_node->value == 0) && (key[key_index] < 64)) ||
96
122
  ((current_node->value != 0) && (key[key_index] <
97
123
  current_node->value)) )
@@ -4,65 +4,70 @@
4
4
  #include <stdlib.h>
5
5
  #include <assert.h>
6
6
 
7
- void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len)
7
+
8
+ void *tst_search(const unsigned char *key, struct tst *tst, int option,
9
+ unsigned int *match_len)
8
10
  {
9
- struct node *current_node;
10
- void *longest_match = NULL;
11
- int key_index;
12
-
13
- assert(key != NULL && "key can't be NULL");
14
- assert(tst != NULL && "tst can't be NULL");
15
-
16
- if(key[0] == 0)
17
- return NULL;
18
-
19
- if(tst->head[(int)key[0]] == NULL)
20
- return NULL;
11
+ struct node *current_node;
12
+ struct node *longest_match = NULL;
13
+ unsigned int longest_match_len = 0;
14
+ int key_index;
15
+
16
+ assert(key != NULL && "key can't be NULL");
17
+ assert(tst != NULL && "tst can't be NULL");
18
+
19
+ if (key[0] == 0)
20
+ return NULL;
21
+
22
+ if (tst->head[(int) key[0]] == NULL)
23
+ return NULL;
24
+
25
+ if (match_len)
26
+ *match_len = 0;
27
+
28
+ current_node = tst->head[(int) key[0]];
29
+ key_index = 1;
21
30
 
22
-
23
- if(prefix_len) *prefix_len = 0;
24
- current_node = tst->head[(int)key[0]];
25
- key_index = 1;
26
-
27
- while (current_node != NULL)
28
- {
29
- if(key[key_index] == current_node->value)
30
- {
31
- if(current_node->value == 0) {
32
- if(prefix_len) *prefix_len = key_index;
33
- return current_node->middle;
34
- } else {
35
- current_node = current_node->middle;
36
- if(current_node && current_node->value == 0) {
37
- if(prefix_len) *prefix_len = key_index+1;
38
- longest_match = current_node->middle;
31
+ while (current_node != NULL) {
32
+ if (key[key_index] == current_node->value) {
33
+ if (current_node->value == 0) {
34
+ if (match_len)
35
+ *match_len = key_index;
36
+ return current_node->middle;
37
+ } else {
38
+ current_node = current_node->middle;
39
+ key_index++;
40
+ continue;
39
41
  }
42
+ } else {
43
+ if (current_node->value == 0) {
44
+ if (option & TST_LONGEST_MATCH) {
45
+ longest_match = current_node->middle;
46
+ longest_match_len = key_index;
47
+ }
40
48
 
41
- key_index++;
42
- continue;
43
- }
44
- }
45
- else if( ((current_node->value == 0) && (key[key_index] < 64)) ||
46
- ((current_node->value != 0) && (key[key_index] <
47
- current_node->value)) )
48
- {
49
- if(current_node->value == 0) {
50
- if(prefix_len) *prefix_len = key_index;
51
- longest_match = current_node->middle;
52
- }
53
- current_node = current_node->left;
54
- continue;
55
- }
56
- else
57
- {
58
- if(current_node->value == 0) {
59
- if(prefix_len) *prefix_len = key_index;
60
- longest_match = current_node->middle;
61
- }
62
- current_node = current_node->right;
63
- continue;
49
+ if (key[key_index] < 64) {
50
+ current_node = current_node->left;
51
+ continue;
52
+ } else {
53
+ current_node = current_node->right;
54
+ continue;
55
+ }
56
+ } else {
57
+ if (key[key_index] < current_node->value) {
58
+ current_node = current_node->left;
59
+ continue;
60
+ } else {
61
+ current_node = current_node->right;
62
+ continue;
63
+ }
64
+ }
64
65
  }
65
66
  }
66
-
67
- return longest_match;
67
+
68
+ if (match_len)
69
+ *match_len = longest_match_len;
70
+
71
+ return longest_match;
72
+
68
73
  }