thin 1.2.3-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of thin might be problematic. Click here for more details.

Files changed (137) hide show
  1. data/CHANGELOG +263 -0
  2. data/COPYING +18 -0
  3. data/README +69 -0
  4. data/Rakefile +36 -0
  5. data/benchmark/abc +51 -0
  6. data/benchmark/benchmarker.rb +80 -0
  7. data/benchmark/runner +82 -0
  8. data/bin/thin +6 -0
  9. data/example/adapter.rb +32 -0
  10. data/example/async_app.ru +126 -0
  11. data/example/async_chat.ru +247 -0
  12. data/example/async_tailer.ru +100 -0
  13. data/example/config.ru +22 -0
  14. data/example/monit_sockets +20 -0
  15. data/example/monit_unixsock +20 -0
  16. data/example/myapp.rb +1 -0
  17. data/example/ramaze.ru +12 -0
  18. data/example/thin.god +80 -0
  19. data/example/thin_solaris_smf.erb +36 -0
  20. data/example/thin_solaris_smf.readme.txt +150 -0
  21. data/example/vlad.rake +64 -0
  22. data/ext/thin_parser/common.rl +55 -0
  23. data/ext/thin_parser/ext_help.h +14 -0
  24. data/ext/thin_parser/extconf.rb +6 -0
  25. data/ext/thin_parser/parser.c +452 -0
  26. data/ext/thin_parser/parser.h +49 -0
  27. data/ext/thin_parser/parser.rl +157 -0
  28. data/ext/thin_parser/thin.c +433 -0
  29. data/lib/rack/adapter/loader.rb +79 -0
  30. data/lib/rack/adapter/rails.rb +181 -0
  31. data/lib/thin.rb +46 -0
  32. data/lib/thin/backends/base.rb +141 -0
  33. data/lib/thin/backends/swiftiply_client.rb +56 -0
  34. data/lib/thin/backends/tcp_server.rb +29 -0
  35. data/lib/thin/backends/unix_server.rb +51 -0
  36. data/lib/thin/command.rb +53 -0
  37. data/lib/thin/connection.rb +222 -0
  38. data/lib/thin/controllers/cluster.rb +127 -0
  39. data/lib/thin/controllers/controller.rb +183 -0
  40. data/lib/thin/controllers/service.rb +75 -0
  41. data/lib/thin/controllers/service.sh.erb +39 -0
  42. data/lib/thin/daemonizing.rb +174 -0
  43. data/lib/thin/headers.rb +39 -0
  44. data/lib/thin/logging.rb +54 -0
  45. data/lib/thin/request.rb +153 -0
  46. data/lib/thin/response.rb +101 -0
  47. data/lib/thin/runner.rb +209 -0
  48. data/lib/thin/server.rb +247 -0
  49. data/lib/thin/stats.html.erb +216 -0
  50. data/lib/thin/stats.rb +52 -0
  51. data/lib/thin/statuses.rb +43 -0
  52. data/lib/thin/version.rb +32 -0
  53. data/lib/thin_parser.so +0 -0
  54. data/spec/backends/swiftiply_client_spec.rb +66 -0
  55. data/spec/backends/tcp_server_spec.rb +33 -0
  56. data/spec/backends/unix_server_spec.rb +37 -0
  57. data/spec/command_spec.rb +25 -0
  58. data/spec/configs/cluster.yml +9 -0
  59. data/spec/configs/single.yml +9 -0
  60. data/spec/connection_spec.rb +106 -0
  61. data/spec/controllers/cluster_spec.rb +235 -0
  62. data/spec/controllers/controller_spec.rb +129 -0
  63. data/spec/controllers/service_spec.rb +50 -0
  64. data/spec/daemonizing_spec.rb +192 -0
  65. data/spec/headers_spec.rb +40 -0
  66. data/spec/logging_spec.rb +46 -0
  67. data/spec/perf/request_perf_spec.rb +50 -0
  68. data/spec/perf/response_perf_spec.rb +19 -0
  69. data/spec/perf/server_perf_spec.rb +39 -0
  70. data/spec/rack/loader_spec.rb +29 -0
  71. data/spec/rack/rails_adapter_spec.rb +106 -0
  72. data/spec/rails_app/app/controllers/application.rb +10 -0
  73. data/spec/rails_app/app/controllers/simple_controller.rb +19 -0
  74. data/spec/rails_app/app/helpers/application_helper.rb +3 -0
  75. data/spec/rails_app/app/views/simple/index.html.erb +15 -0
  76. data/spec/rails_app/config/boot.rb +109 -0
  77. data/spec/rails_app/config/environment.rb +64 -0
  78. data/spec/rails_app/config/environments/development.rb +18 -0
  79. data/spec/rails_app/config/environments/production.rb +19 -0
  80. data/spec/rails_app/config/environments/test.rb +22 -0
  81. data/spec/rails_app/config/initializers/inflections.rb +10 -0
  82. data/spec/rails_app/config/initializers/mime_types.rb +5 -0
  83. data/spec/rails_app/config/routes.rb +35 -0
  84. data/spec/rails_app/public/404.html +30 -0
  85. data/spec/rails_app/public/422.html +30 -0
  86. data/spec/rails_app/public/500.html +30 -0
  87. data/spec/rails_app/public/dispatch.cgi +10 -0
  88. data/spec/rails_app/public/dispatch.fcgi +24 -0
  89. data/spec/rails_app/public/dispatch.rb +10 -0
  90. data/spec/rails_app/public/favicon.ico +0 -0
  91. data/spec/rails_app/public/images/rails.png +0 -0
  92. data/spec/rails_app/public/index.html +277 -0
  93. data/spec/rails_app/public/javascripts/application.js +2 -0
  94. data/spec/rails_app/public/javascripts/controls.js +963 -0
  95. data/spec/rails_app/public/javascripts/dragdrop.js +972 -0
  96. data/spec/rails_app/public/javascripts/effects.js +1120 -0
  97. data/spec/rails_app/public/javascripts/prototype.js +4225 -0
  98. data/spec/rails_app/public/robots.txt +5 -0
  99. data/spec/rails_app/script/about +3 -0
  100. data/spec/rails_app/script/console +3 -0
  101. data/spec/rails_app/script/destroy +3 -0
  102. data/spec/rails_app/script/generate +3 -0
  103. data/spec/rails_app/script/performance/benchmarker +3 -0
  104. data/spec/rails_app/script/performance/profiler +3 -0
  105. data/spec/rails_app/script/performance/request +3 -0
  106. data/spec/rails_app/script/plugin +3 -0
  107. data/spec/rails_app/script/process/inspector +3 -0
  108. data/spec/rails_app/script/process/reaper +3 -0
  109. data/spec/rails_app/script/process/spawner +3 -0
  110. data/spec/rails_app/script/runner +3 -0
  111. data/spec/rails_app/script/server +3 -0
  112. data/spec/request/mongrel_spec.rb +39 -0
  113. data/spec/request/parser_spec.rb +215 -0
  114. data/spec/request/persistent_spec.rb +35 -0
  115. data/spec/request/processing_spec.rb +45 -0
  116. data/spec/response_spec.rb +91 -0
  117. data/spec/runner_spec.rb +168 -0
  118. data/spec/server/builder_spec.rb +44 -0
  119. data/spec/server/pipelining_spec.rb +110 -0
  120. data/spec/server/robustness_spec.rb +34 -0
  121. data/spec/server/stopping_spec.rb +55 -0
  122. data/spec/server/swiftiply.yml +6 -0
  123. data/spec/server/swiftiply_spec.rb +32 -0
  124. data/spec/server/tcp_spec.rb +57 -0
  125. data/spec/server/threaded_spec.rb +27 -0
  126. data/spec/server/unix_socket_spec.rb +26 -0
  127. data/spec/server_spec.rb +96 -0
  128. data/spec/spec_helper.rb +219 -0
  129. data/tasks/announce.rake +22 -0
  130. data/tasks/deploy.rake +13 -0
  131. data/tasks/email.erb +30 -0
  132. data/tasks/gem.rake +74 -0
  133. data/tasks/rdoc.rake +25 -0
  134. data/tasks/site.rake +15 -0
  135. data/tasks/spec.rake +49 -0
  136. data/tasks/stats.rake +28 -0
  137. metadata +246 -0
@@ -0,0 +1,64 @@
1
+ # $GEM_HOME/gems/vlad-1.2.0/lib/vlad/thin.rb
2
+ # Thin tasks for Vlad the Deployer
3
+ # By cnantais
4
+ require 'vlad'
5
+
6
+ namespace :vlad do
7
+ ##
8
+ # Thin app server
9
+
10
+ set :thin_address, "127.0.0.1"
11
+ set :thin_command, 'thin'
12
+ set(:thin_conf) { "#{shared_path}/thin_cluster.conf" }
13
+ set :thin_environment, "production"
14
+ set :thin_group, nil
15
+ set :thin_log_file, nil
16
+ set :thin_pid_file, nil
17
+ set :thin_port, nil
18
+ set :thin_socket, nil
19
+ set :thin_prefix, nil
20
+ set :thin_servers, 2
21
+ set :thin_user, nil
22
+
23
+ desc "Prepares application servers for deployment. thin
24
+ configuration is set via the thin_* variables.".cleanup
25
+
26
+ remote_task :setup_app, :roles => :app do
27
+
28
+ raise(ArgumentError, "Please provide either thin_socket or thin_port") if thin_port.nil? && thin_socket.nil?
29
+
30
+ cmd = [
31
+ "#{thin_command} config",
32
+ "-s #{thin_servers}",
33
+ ("-S #{thin_socket}" if thin_socket),
34
+ "-e #{thin_environment}",
35
+ "-a #{thin_address}",
36
+ "-c #{current_path}",
37
+ "-C #{thin_conf}",
38
+ ("-P #{thin_pid_file}" if thin_pid_file),
39
+ ("-l #{thin_log_file}" if thin_log_file),
40
+ ("--user #{thin_user}" if thin_user),
41
+ ("--group #{thin_group}" if thin_group),
42
+ ("--prefix #{thin_prefix}" if thin_prefix),
43
+ ("-p #{thin_port}" if thin_port),
44
+ ].compact.join ' '
45
+
46
+ run cmd
47
+ end
48
+
49
+ def thin(cmd) # :nodoc:
50
+ "#{thin_command} #{cmd} -C #{thin_conf}"
51
+ end
52
+
53
+ desc "Restart the app servers"
54
+
55
+ remote_task :start_app, :roles => :app do
56
+ run thin("restart -s #{thin_servers}")
57
+ end
58
+
59
+ desc "Stop the app servers"
60
+
61
+ remote_task :stop_app, :roles => :app do
62
+ run thin("stop -s #{thin_servers}")
63
+ end
64
+ end
@@ -0,0 +1,55 @@
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
+ sorta_safe = ("\"" | "<" | ">");
15
+ unsafe = (CTL | " " | "#" | "%" | sorta_safe);
16
+ national = any -- (alpha | digit | reserved | extra | safe | unsafe);
17
+ unreserved = (alpha | digit | safe | extra | national);
18
+ escape = ("%" xdigit xdigit);
19
+ uchar = (unreserved | escape | sorta_safe);
20
+ pchar = (uchar | ":" | "@" | "&" | "=" | "+");
21
+ tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
22
+
23
+ # elements
24
+ token = (ascii -- (CTL | tspecials));
25
+
26
+ # URI schemes and absolute paths
27
+ scheme = ( alpha | digit | "+" | "-" | "." )* ;
28
+ absolute_uri = (scheme ":" (uchar | reserved )*);
29
+
30
+ path = ( pchar+ ( "/" pchar* )* ) ;
31
+ query = ( uchar | reserved )* %query_string ;
32
+ param = ( pchar | "/" )* ;
33
+ params = ( param ( ";" param )* ) ;
34
+ rel_path = ( path? %request_path (";" params)? ) ("?" %start_query query)?;
35
+ absolute_path = ( "/"+ rel_path );
36
+
37
+ Request_URI = ( "*" | absolute_uri | absolute_path ) >mark %request_uri;
38
+ Fragment = ( uchar | reserved )* >mark %fragment;
39
+ Method = ( upper | digit | safe ){1,20} >mark %request_method;
40
+
41
+ http_number = ( digit+ "." digit+ ) ;
42
+ HTTP_Version = ( "HTTP/" http_number ) >mark %http_version ;
43
+ Request_Line = ( Method " " Request_URI ("#" Fragment){0,1} " " HTTP_Version CRLF ) ;
44
+
45
+ field_name = ( token -- ":" )+ >start_field %write_field;
46
+
47
+ field_value = any* >start_value %write_value;
48
+
49
+ message_header = field_name ":" " "* field_value :> CRLF;
50
+
51
+ Request = Request_Line ( message_header )* ( CRLF @done );
52
+
53
+ main := Request;
54
+
55
+ }%%
@@ -0,0 +1,14 @@
1
+ #ifndef ext_help_h
2
+ #define ext_help_h
3
+
4
+ #define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "NULL found for " # T " when shouldn't be.");
5
+ #define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name);
6
+ #define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "Wrong argument type for " # V " required " # T);
7
+
8
+ #ifdef DEBUG
9
+ #define TRACE() fprintf(stderr, "> %s:%d:%s\n", __FILE__, __LINE__, __FUNCTION__)
10
+ #else
11
+ #define TRACE()
12
+ #endif
13
+
14
+ #endif
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("thin_parser")
4
+ have_library("c", "main")
5
+
6
+ create_makefile("thin_parser")
@@ -0,0 +1,452 @@
1
+ #line 1 "parser.rl"
2
+ /**
3
+ * Copyright (c) 2005 Zed A. Shaw
4
+ * You can redistribute it and/or modify it under the same terms as Ruby.
5
+ */
6
+ #include "parser.h"
7
+ #include <stdio.h>
8
+ #include <assert.h>
9
+ #include <stdlib.h>
10
+ #include <ctype.h>
11
+ #include <string.h>
12
+
13
+ #define LEN(AT, FPC) (FPC - buffer - parser->AT)
14
+ #define MARK(M,FPC) (parser->M = (FPC) - buffer)
15
+ #define PTR_TO(F) (buffer + parser->F)
16
+
17
+ /** Machine **/
18
+
19
+ #line 81 "parser.rl"
20
+
21
+
22
+ /** Data **/
23
+
24
+ #line 25 "parser.c"
25
+ static const char _http_parser_actions[] = {
26
+ 0, 1, 0, 1, 1, 1, 2, 1,
27
+ 3, 1, 4, 1, 5, 1, 6, 1,
28
+ 7, 1, 8, 1, 10, 1, 11, 1,
29
+ 12, 2, 0, 7, 2, 3, 4, 2,
30
+ 9, 6, 2, 11, 6, 3, 8, 9,
31
+ 6
32
+ };
33
+
34
+ static const short _http_parser_key_offsets[] = {
35
+ 0, 0, 8, 17, 27, 29, 30, 31,
36
+ 32, 33, 34, 36, 39, 41, 44, 45,
37
+ 61, 62, 78, 80, 81, 87, 93, 99,
38
+ 105, 115, 121, 127, 133, 141, 147, 153,
39
+ 160, 166, 172, 178, 184, 190, 196, 205,
40
+ 214, 223, 232, 241, 250, 259, 268, 277,
41
+ 286, 295, 304, 313, 322, 331, 340, 349,
42
+ 358, 359
43
+ };
44
+
45
+ static const char _http_parser_trans_keys[] = {
46
+ 36, 95, 45, 46, 48, 57, 65, 90,
47
+ 32, 36, 95, 45, 46, 48, 57, 65,
48
+ 90, 42, 43, 47, 58, 45, 57, 65,
49
+ 90, 97, 122, 32, 35, 72, 84, 84,
50
+ 80, 47, 48, 57, 46, 48, 57, 48,
51
+ 57, 13, 48, 57, 10, 13, 33, 124,
52
+ 126, 35, 39, 42, 43, 45, 46, 48,
53
+ 57, 65, 90, 94, 122, 10, 33, 58,
54
+ 124, 126, 35, 39, 42, 43, 45, 46,
55
+ 48, 57, 65, 90, 94, 122, 13, 32,
56
+ 13, 32, 35, 37, 127, 0, 31, 32,
57
+ 35, 37, 127, 0, 31, 48, 57, 65,
58
+ 70, 97, 102, 48, 57, 65, 70, 97,
59
+ 102, 43, 58, 45, 46, 48, 57, 65,
60
+ 90, 97, 122, 32, 35, 37, 127, 0,
61
+ 31, 48, 57, 65, 70, 97, 102, 48,
62
+ 57, 65, 70, 97, 102, 32, 35, 37,
63
+ 59, 63, 127, 0, 31, 48, 57, 65,
64
+ 70, 97, 102, 48, 57, 65, 70, 97,
65
+ 102, 32, 35, 37, 63, 127, 0, 31,
66
+ 48, 57, 65, 70, 97, 102, 48, 57,
67
+ 65, 70, 97, 102, 32, 35, 37, 127,
68
+ 0, 31, 32, 35, 37, 127, 0, 31,
69
+ 48, 57, 65, 70, 97, 102, 48, 57,
70
+ 65, 70, 97, 102, 32, 36, 95, 45,
71
+ 46, 48, 57, 65, 90, 32, 36, 95,
72
+ 45, 46, 48, 57, 65, 90, 32, 36,
73
+ 95, 45, 46, 48, 57, 65, 90, 32,
74
+ 36, 95, 45, 46, 48, 57, 65, 90,
75
+ 32, 36, 95, 45, 46, 48, 57, 65,
76
+ 90, 32, 36, 95, 45, 46, 48, 57,
77
+ 65, 90, 32, 36, 95, 45, 46, 48,
78
+ 57, 65, 90, 32, 36, 95, 45, 46,
79
+ 48, 57, 65, 90, 32, 36, 95, 45,
80
+ 46, 48, 57, 65, 90, 32, 36, 95,
81
+ 45, 46, 48, 57, 65, 90, 32, 36,
82
+ 95, 45, 46, 48, 57, 65, 90, 32,
83
+ 36, 95, 45, 46, 48, 57, 65, 90,
84
+ 32, 36, 95, 45, 46, 48, 57, 65,
85
+ 90, 32, 36, 95, 45, 46, 48, 57,
86
+ 65, 90, 32, 36, 95, 45, 46, 48,
87
+ 57, 65, 90, 32, 36, 95, 45, 46,
88
+ 48, 57, 65, 90, 32, 36, 95, 45,
89
+ 46, 48, 57, 65, 90, 32, 36, 95,
90
+ 45, 46, 48, 57, 65, 90, 32, 0
91
+ };
92
+
93
+ static const char _http_parser_single_lengths[] = {
94
+ 0, 2, 3, 4, 2, 1, 1, 1,
95
+ 1, 1, 0, 1, 0, 1, 1, 4,
96
+ 1, 4, 2, 1, 4, 4, 0, 0,
97
+ 2, 4, 0, 0, 6, 0, 0, 5,
98
+ 0, 0, 4, 4, 0, 0, 3, 3,
99
+ 3, 3, 3, 3, 3, 3, 3, 3,
100
+ 3, 3, 3, 3, 3, 3, 3, 3,
101
+ 1, 0
102
+ };
103
+
104
+ static const char _http_parser_range_lengths[] = {
105
+ 0, 3, 3, 3, 0, 0, 0, 0,
106
+ 0, 0, 1, 1, 1, 1, 0, 6,
107
+ 0, 6, 0, 0, 1, 1, 3, 3,
108
+ 4, 1, 3, 3, 1, 3, 3, 1,
109
+ 3, 3, 1, 1, 3, 3, 3, 3,
110
+ 3, 3, 3, 3, 3, 3, 3, 3,
111
+ 3, 3, 3, 3, 3, 3, 3, 3,
112
+ 0, 0
113
+ };
114
+
115
+ static const short _http_parser_index_offsets[] = {
116
+ 0, 0, 6, 13, 21, 24, 26, 28,
117
+ 30, 32, 34, 36, 39, 41, 44, 46,
118
+ 57, 59, 70, 73, 75, 81, 87, 91,
119
+ 95, 102, 108, 112, 116, 124, 128, 132,
120
+ 139, 143, 147, 153, 159, 163, 167, 174,
121
+ 181, 188, 195, 202, 209, 216, 223, 230,
122
+ 237, 244, 251, 258, 265, 272, 279, 286,
123
+ 293, 295
124
+ };
125
+
126
+ static const char _http_parser_indicies[] = {
127
+ 0, 0, 0, 0, 0, 1, 2, 3,
128
+ 3, 3, 3, 3, 1, 4, 5, 6,
129
+ 7, 5, 5, 5, 1, 8, 9, 1,
130
+ 10, 1, 11, 1, 12, 1, 13, 1,
131
+ 14, 1, 15, 1, 16, 15, 1, 17,
132
+ 1, 18, 17, 1, 19, 1, 20, 21,
133
+ 21, 21, 21, 21, 21, 21, 21, 21,
134
+ 1, 22, 1, 23, 24, 23, 23, 23,
135
+ 23, 23, 23, 23, 23, 1, 26, 27,
136
+ 25, 29, 28, 31, 1, 32, 1, 1,
137
+ 30, 34, 1, 35, 1, 1, 33, 36,
138
+ 36, 36, 1, 33, 33, 33, 1, 37,
139
+ 38, 37, 37, 37, 37, 1, 8, 9,
140
+ 39, 1, 1, 38, 40, 40, 40, 1,
141
+ 38, 38, 38, 1, 42, 43, 44, 45,
142
+ 46, 1, 1, 41, 47, 47, 47, 1,
143
+ 41, 41, 41, 1, 8, 9, 49, 50,
144
+ 1, 1, 48, 51, 51, 51, 1, 48,
145
+ 48, 48, 1, 53, 54, 55, 1, 1,
146
+ 52, 57, 58, 59, 1, 1, 56, 60,
147
+ 60, 60, 1, 56, 56, 56, 1, 2,
148
+ 61, 61, 61, 61, 61, 1, 2, 62,
149
+ 62, 62, 62, 62, 1, 2, 63, 63,
150
+ 63, 63, 63, 1, 2, 64, 64, 64,
151
+ 64, 64, 1, 2, 65, 65, 65, 65,
152
+ 65, 1, 2, 66, 66, 66, 66, 66,
153
+ 1, 2, 67, 67, 67, 67, 67, 1,
154
+ 2, 68, 68, 68, 68, 68, 1, 2,
155
+ 69, 69, 69, 69, 69, 1, 2, 70,
156
+ 70, 70, 70, 70, 1, 2, 71, 71,
157
+ 71, 71, 71, 1, 2, 72, 72, 72,
158
+ 72, 72, 1, 2, 73, 73, 73, 73,
159
+ 73, 1, 2, 74, 74, 74, 74, 74,
160
+ 1, 2, 75, 75, 75, 75, 75, 1,
161
+ 2, 76, 76, 76, 76, 76, 1, 2,
162
+ 77, 77, 77, 77, 77, 1, 2, 78,
163
+ 78, 78, 78, 78, 1, 2, 1, 1,
164
+ 0
165
+ };
166
+
167
+ static const char _http_parser_trans_targs[] = {
168
+ 2, 0, 3, 38, 4, 24, 28, 25,
169
+ 5, 20, 6, 7, 8, 9, 10, 11,
170
+ 12, 13, 14, 15, 16, 17, 57, 17,
171
+ 18, 19, 14, 18, 19, 14, 21, 5,
172
+ 22, 21, 5, 22, 23, 24, 25, 26,
173
+ 27, 28, 5, 20, 29, 31, 34, 30,
174
+ 31, 32, 34, 33, 35, 5, 20, 36,
175
+ 35, 5, 20, 36, 37, 39, 40, 41,
176
+ 42, 43, 44, 45, 46, 47, 48, 49,
177
+ 50, 51, 52, 53, 54, 55, 56
178
+ };
179
+
180
+ static const char _http_parser_trans_actions[] = {
181
+ 1, 0, 11, 0, 1, 1, 1, 1,
182
+ 13, 13, 1, 0, 0, 0, 0, 0,
183
+ 0, 0, 19, 0, 0, 3, 23, 0,
184
+ 5, 7, 28, 7, 0, 9, 1, 25,
185
+ 1, 0, 15, 0, 0, 0, 0, 0,
186
+ 0, 0, 34, 34, 0, 21, 21, 0,
187
+ 0, 0, 0, 0, 17, 37, 37, 17,
188
+ 0, 31, 31, 0, 0, 0, 0, 0,
189
+ 0, 0, 0, 0, 0, 0, 0, 0,
190
+ 0, 0, 0, 0, 0, 0, 0
191
+ };
192
+
193
+ static const int http_parser_start = 1;
194
+ static const int http_parser_first_final = 57;
195
+ static const int http_parser_error = 0;
196
+
197
+ static const int http_parser_en_main = 1;
198
+
199
+ #line 85 "parser.rl"
200
+
201
+ int thin_http_parser_init(http_parser *parser) {
202
+ int cs = 0;
203
+
204
+ #line 205 "parser.c"
205
+ {
206
+ cs = http_parser_start;
207
+ }
208
+ #line 89 "parser.rl"
209
+ parser->cs = cs;
210
+ parser->body_start = 0;
211
+ parser->content_len = 0;
212
+ parser->mark = 0;
213
+ parser->nread = 0;
214
+ parser->field_len = 0;
215
+ parser->field_start = 0;
216
+
217
+ return(1);
218
+ }
219
+
220
+
221
+ /** exec **/
222
+ size_t thin_http_parser_execute(http_parser *parser, const char *buffer, size_t len, size_t off) {
223
+ const char *p, *pe;
224
+ int cs = parser->cs;
225
+
226
+ assert(off <= len && "offset past end of buffer");
227
+
228
+ p = buffer+off;
229
+ pe = buffer+len;
230
+
231
+ assert(*pe == '\0' && "pointer does not end on NUL");
232
+ assert(pe - p == len - off && "pointers aren't same distance");
233
+
234
+
235
+
236
+ #line 237 "parser.c"
237
+ {
238
+ int _klen;
239
+ unsigned int _trans;
240
+ const char *_acts;
241
+ unsigned int _nacts;
242
+ const char *_keys;
243
+
244
+ if ( p == pe )
245
+ goto _test_eof;
246
+ if ( cs == 0 )
247
+ goto _out;
248
+ _resume:
249
+ _keys = _http_parser_trans_keys + _http_parser_key_offsets[cs];
250
+ _trans = _http_parser_index_offsets[cs];
251
+
252
+ _klen = _http_parser_single_lengths[cs];
253
+ if ( _klen > 0 ) {
254
+ const char *_lower = _keys;
255
+ const char *_mid;
256
+ const char *_upper = _keys + _klen - 1;
257
+ while (1) {
258
+ if ( _upper < _lower )
259
+ break;
260
+
261
+ _mid = _lower + ((_upper-_lower) >> 1);
262
+ if ( (*p) < *_mid )
263
+ _upper = _mid - 1;
264
+ else if ( (*p) > *_mid )
265
+ _lower = _mid + 1;
266
+ else {
267
+ _trans += (_mid - _keys);
268
+ goto _match;
269
+ }
270
+ }
271
+ _keys += _klen;
272
+ _trans += _klen;
273
+ }
274
+
275
+ _klen = _http_parser_range_lengths[cs];
276
+ if ( _klen > 0 ) {
277
+ const char *_lower = _keys;
278
+ const char *_mid;
279
+ const char *_upper = _keys + (_klen<<1) - 2;
280
+ while (1) {
281
+ if ( _upper < _lower )
282
+ break;
283
+
284
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
285
+ if ( (*p) < _mid[0] )
286
+ _upper = _mid - 2;
287
+ else if ( (*p) > _mid[1] )
288
+ _lower = _mid + 2;
289
+ else {
290
+ _trans += ((_mid - _keys)>>1);
291
+ goto _match;
292
+ }
293
+ }
294
+ _trans += _klen;
295
+ }
296
+
297
+ _match:
298
+ _trans = _http_parser_indicies[_trans];
299
+ cs = _http_parser_trans_targs[_trans];
300
+
301
+ if ( _http_parser_trans_actions[_trans] == 0 )
302
+ goto _again;
303
+
304
+ _acts = _http_parser_actions + _http_parser_trans_actions[_trans];
305
+ _nacts = (unsigned int) *_acts++;
306
+ while ( _nacts-- > 0 )
307
+ {
308
+ switch ( *_acts++ )
309
+ {
310
+ case 0:
311
+ #line 22 "parser.rl"
312
+ {MARK(mark, p); }
313
+ break;
314
+ case 1:
315
+ #line 25 "parser.rl"
316
+ { MARK(field_start, p); }
317
+ break;
318
+ case 2:
319
+ #line 26 "parser.rl"
320
+ {
321
+ parser->field_len = LEN(field_start, p);
322
+ }
323
+ break;
324
+ case 3:
325
+ #line 30 "parser.rl"
326
+ { MARK(mark, p); }
327
+ break;
328
+ case 4:
329
+ #line 31 "parser.rl"
330
+ {
331
+ if (parser->http_field != NULL) {
332
+ parser->http_field(parser->data, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
333
+ }
334
+ }
335
+ break;
336
+ case 5:
337
+ #line 36 "parser.rl"
338
+ {
339
+ if (parser->request_method != NULL) {
340
+ parser->request_method(parser->data, PTR_TO(mark), LEN(mark, p));
341
+ }
342
+ }
343
+ break;
344
+ case 6:
345
+ #line 41 "parser.rl"
346
+ {
347
+ if (parser->request_uri != NULL) {
348
+ parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, p));
349
+ }
350
+ }
351
+ break;
352
+ case 7:
353
+ #line 46 "parser.rl"
354
+ {
355
+ if (parser->fragment != NULL) {
356
+ parser->fragment(parser->data, PTR_TO(mark), LEN(mark, p));
357
+ }
358
+ }
359
+ break;
360
+ case 8:
361
+ #line 52 "parser.rl"
362
+ {MARK(query_start, p); }
363
+ break;
364
+ case 9:
365
+ #line 53 "parser.rl"
366
+ {
367
+ if (parser->query_string != NULL) {
368
+ parser->query_string(parser->data, PTR_TO(query_start), LEN(query_start, p));
369
+ }
370
+ }
371
+ break;
372
+ case 10:
373
+ #line 59 "parser.rl"
374
+ {
375
+ if (parser->http_version != NULL) {
376
+ parser->http_version(parser->data, PTR_TO(mark), LEN(mark, p));
377
+ }
378
+ }
379
+ break;
380
+ case 11:
381
+ #line 65 "parser.rl"
382
+ {
383
+ if (parser->request_path != NULL) {
384
+ parser->request_path(parser->data, PTR_TO(mark), LEN(mark,p));
385
+ }
386
+ }
387
+ break;
388
+ case 12:
389
+ #line 71 "parser.rl"
390
+ {
391
+ parser->body_start = p - buffer + 1;
392
+ if (parser->header_done != NULL) {
393
+ parser->header_done(parser->data, p + 1, pe - p - 1);
394
+ }
395
+ {p++; goto _out; }
396
+ }
397
+ break;
398
+ #line 399 "parser.c"
399
+ }
400
+ }
401
+
402
+ _again:
403
+ if ( cs == 0 )
404
+ goto _out;
405
+ if ( ++p != pe )
406
+ goto _resume;
407
+ _test_eof: {}
408
+ _out: {}
409
+ }
410
+ #line 116 "parser.rl"
411
+
412
+ parser->cs = cs;
413
+ parser->nread += p - (buffer + off);
414
+
415
+ assert(p <= pe && "buffer overflow after parsing execute");
416
+ assert(parser->nread <= len && "nread longer than length");
417
+ assert(parser->body_start <= len && "body starts after buffer end");
418
+ assert(parser->mark < len && "mark is after buffer end");
419
+ assert(parser->field_len <= len && "field has length longer than whole buffer");
420
+ assert(parser->field_start < len && "field starts after buffer end");
421
+
422
+ if(parser->body_start) {
423
+ /* final \r\n combo encountered so stop right here */
424
+ parser->nread++;
425
+ }
426
+
427
+ return(parser->nread);
428
+ }
429
+
430
+ int thin_http_parser_finish(http_parser *parser)
431
+ {
432
+ int cs = parser->cs;
433
+
434
+
435
+ parser->cs = cs;
436
+
437
+ if (thin_http_parser_has_error(parser) ) {
438
+ return -1;
439
+ } else if (thin_http_parser_is_finished(parser) ) {
440
+ return 1;
441
+ } else {
442
+ return 0;
443
+ }
444
+ }
445
+
446
+ int thin_http_parser_has_error(http_parser *parser) {
447
+ return parser->cs == http_parser_error;
448
+ }
449
+
450
+ int thin_http_parser_is_finished(http_parser *parser) {
451
+ return parser->cs == http_parser_first_final;
452
+ }