From 496daab2f37436dde375ede903a0778c13de67a4 Mon Sep 17 00:00:00 2001 From: evanweaver Date: Wed, 17 Oct 2007 06:56:33 +0000 Subject: ragel task does java too git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@670 19e92222-5c0b-0410-8929-a290d50e31e9 --- ext/http11/http11_parser.c | 138 +++++++------- ext/http11_java/http11_parser.rl | 209 +++++++++++++++++++++ .../org/jruby/mongrel/Http11Parser.java | 38 ++-- ext/http11_java/org/jruby/mongrel/http11_parser.rl | 209 --------------------- 4 files changed, 297 insertions(+), 297 deletions(-) create mode 100644 ext/http11_java/http11_parser.rl delete mode 100644 ext/http11_java/org/jruby/mongrel/http11_parser.rl (limited to 'ext') diff --git a/ext/http11/http11_parser.c b/ext/http11/http11_parser.c index 7d139fc..d099cdc 100644 --- a/ext/http11/http11_parser.c +++ b/ext/http11/http11_parser.c @@ -1,4 +1,4 @@ -#line 1 "ext/http11/http11_parser.rl" +#line 1 "http11_parser.rl" /** * Copyright (c) 2005 Zed A. Shaw * You can redistribute it and/or modify it under the same terms as Ruby. @@ -15,28 +15,28 @@ #define PTR_TO(F) (buffer + parser->F) /** machine **/ -#line 119 "ext/http11/http11_parser.rl" +#line 119 "http11_parser.rl" /** Data **/ -#line 24 "ext/http11/http11_parser.c" +#line 24 "http11_parser.c" static const int http_parser_start = 1; static const int http_parser_first_final = 57; static const int http_parser_error = 0; static const int http_parser_en_main = 1; -#line 123 "ext/http11/http11_parser.rl" +#line 123 "http11_parser.rl" int http_parser_init(http_parser *parser) { int cs = 0; -#line 36 "ext/http11/http11_parser.c" +#line 36 "http11_parser.c" { cs = http_parser_start; } -#line 127 "ext/http11/http11_parser.rl" +#line 127 "http11_parser.rl" parser->cs = cs; parser->body_start = 0; parser->content_len = 0; @@ -64,7 +64,7 @@ size_t http_parser_execute(http_parser *parser, const char *buffer, size_t len, -#line 68 "ext/http11/http11_parser.c" +#line 68 "http11_parser.c" { if ( p == pe ) goto _out; @@ -87,14 +87,14 @@ case 1: st0: goto _out0; tr0: -#line 20 "ext/http11/http11_parser.rl" +#line 20 "http11_parser.rl" {MARK(mark, p); } goto st2; st2: if ( ++p == pe ) goto _out2; case 2: -#line 98 "ext/http11/http11_parser.c" +#line 98 "http11_parser.c" switch( (*p) ) { case 32: goto tr2; case 36: goto st38; @@ -110,7 +110,7 @@ case 2: goto st38; goto st0; tr2: -#line 34 "ext/http11/http11_parser.rl" +#line 34 "http11_parser.rl" { if(parser->request_method != NULL) parser->request_method(parser->data, PTR_TO(mark), LEN(mark, p)); @@ -120,7 +120,7 @@ st3: if ( ++p == pe ) goto _out3; case 3: -#line 124 "ext/http11/http11_parser.c" +#line 124 "http11_parser.c" switch( (*p) ) { case 42: goto tr4; case 43: goto tr5; @@ -137,66 +137,66 @@ case 3: goto tr5; goto st0; tr4: -#line 20 "ext/http11/http11_parser.rl" +#line 20 "http11_parser.rl" {MARK(mark, p); } goto st4; st4: if ( ++p == pe ) goto _out4; case 4: -#line 148 "ext/http11/http11_parser.c" +#line 148 "http11_parser.c" switch( (*p) ) { case 32: goto tr8; case 35: goto tr9; } goto st0; tr8: -#line 38 "ext/http11/http11_parser.rl" +#line 38 "http11_parser.rl" { if(parser->request_uri != NULL) parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, p)); } goto st5; tr30: -#line 42 "ext/http11/http11_parser.rl" +#line 42 "http11_parser.rl" { if(parser->fragment != NULL) parser->fragment(parser->data, PTR_TO(mark), LEN(mark, p)); } goto st5; tr40: -#line 58 "ext/http11/http11_parser.rl" +#line 58 "http11_parser.rl" { if(parser->request_path != NULL) parser->request_path(parser->data, PTR_TO(mark), LEN(mark,p)); } -#line 38 "ext/http11/http11_parser.rl" +#line 38 "http11_parser.rl" { if(parser->request_uri != NULL) parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, p)); } goto st5; tr51: -#line 47 "ext/http11/http11_parser.rl" +#line 47 "http11_parser.rl" {MARK(query_start, p); } -#line 48 "ext/http11/http11_parser.rl" +#line 48 "http11_parser.rl" { if(parser->query_string != NULL) parser->query_string(parser->data, PTR_TO(query_start), LEN(query_start, p)); } -#line 38 "ext/http11/http11_parser.rl" +#line 38 "http11_parser.rl" { if(parser->request_uri != NULL) parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, p)); } goto st5; tr55: -#line 48 "ext/http11/http11_parser.rl" +#line 48 "http11_parser.rl" { if(parser->query_string != NULL) parser->query_string(parser->data, PTR_TO(query_start), LEN(query_start, p)); } -#line 38 "ext/http11/http11_parser.rl" +#line 38 "http11_parser.rl" { if(parser->request_uri != NULL) parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, p)); @@ -206,19 +206,19 @@ st5: if ( ++p == pe ) goto _out5; case 5: -#line 210 "ext/http11/http11_parser.c" +#line 210 "http11_parser.c" if ( (*p) == 72 ) goto tr10; goto st0; tr10: -#line 20 "ext/http11/http11_parser.rl" +#line 20 "http11_parser.rl" {MARK(mark, p); } goto st6; st6: if ( ++p == pe ) goto _out6; case 6: -#line 222 "ext/http11/http11_parser.c" +#line 222 "http11_parser.c" if ( (*p) == 84 ) goto st7; goto st0; @@ -276,14 +276,14 @@ case 13: goto st13; goto st0; tr18: -#line 53 "ext/http11/http11_parser.rl" +#line 53 "http11_parser.rl" { if(parser->http_version != NULL) parser->http_version(parser->data, PTR_TO(mark), LEN(mark, p)); } goto st14; tr26: -#line 29 "ext/http11/http11_parser.rl" +#line 29 "http11_parser.rl" { if(parser->http_field != NULL) { parser->http_field(parser->data, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p)); @@ -294,7 +294,7 @@ st14: if ( ++p == pe ) goto _out14; case 14: -#line 298 "ext/http11/http11_parser.c" +#line 298 "http11_parser.c" if ( (*p) == 10 ) goto st15; goto st0; @@ -334,7 +334,7 @@ case 16: goto tr22; goto st0; tr22: -#line 63 "ext/http11/http11_parser.rl" +#line 63 "http11_parser.rl" { parser->body_start = p - buffer + 1; if(parser->header_done != NULL) @@ -346,17 +346,17 @@ st57: if ( ++p == pe ) goto _out57; case 57: -#line 350 "ext/http11/http11_parser.c" +#line 350 "http11_parser.c" goto st0; tr21: -#line 23 "ext/http11/http11_parser.rl" +#line 23 "http11_parser.rl" { MARK(field_start, p); } goto st17; st17: if ( ++p == pe ) goto _out17; case 17: -#line 360 "ext/http11/http11_parser.c" +#line 360 "http11_parser.c" switch( (*p) ) { case 33: goto st17; case 58: goto tr24; @@ -382,77 +382,77 @@ case 17: goto st17; goto st0; tr24: -#line 24 "ext/http11/http11_parser.rl" +#line 24 "http11_parser.rl" { parser->field_len = LEN(field_start, p); } goto st18; tr27: -#line 28 "ext/http11/http11_parser.rl" +#line 28 "http11_parser.rl" { MARK(mark, p); } goto st18; st18: if ( ++p == pe ) goto _out18; case 18: -#line 399 "ext/http11/http11_parser.c" +#line 399 "http11_parser.c" switch( (*p) ) { case 13: goto tr26; case 32: goto tr27; } goto tr25; tr25: -#line 28 "ext/http11/http11_parser.rl" +#line 28 "http11_parser.rl" { MARK(mark, p); } goto st19; st19: if ( ++p == pe ) goto _out19; case 19: -#line 413 "ext/http11/http11_parser.c" +#line 413 "http11_parser.c" if ( (*p) == 13 ) goto tr26; goto st19; tr9: -#line 38 "ext/http11/http11_parser.rl" +#line 38 "http11_parser.rl" { if(parser->request_uri != NULL) parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, p)); } goto st20; tr41: -#line 58 "ext/http11/http11_parser.rl" +#line 58 "http11_parser.rl" { if(parser->request_path != NULL) parser->request_path(parser->data, PTR_TO(mark), LEN(mark,p)); } -#line 38 "ext/http11/http11_parser.rl" +#line 38 "http11_parser.rl" { if(parser->request_uri != NULL) parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, p)); } goto st20; tr52: -#line 47 "ext/http11/http11_parser.rl" +#line 47 "http11_parser.rl" {MARK(query_start, p); } -#line 48 "ext/http11/http11_parser.rl" +#line 48 "http11_parser.rl" { if(parser->query_string != NULL) parser->query_string(parser->data, PTR_TO(query_start), LEN(query_start, p)); } -#line 38 "ext/http11/http11_parser.rl" +#line 38 "http11_parser.rl" { if(parser->request_uri != NULL) parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, p)); } goto st20; tr56: -#line 48 "ext/http11/http11_parser.rl" +#line 48 "http11_parser.rl" { if(parser->query_string != NULL) parser->query_string(parser->data, PTR_TO(query_start), LEN(query_start, p)); } -#line 38 "ext/http11/http11_parser.rl" +#line 38 "http11_parser.rl" { if(parser->request_uri != NULL) parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, p)); @@ -462,7 +462,7 @@ st20: if ( ++p == pe ) goto _out20; case 20: -#line 466 "ext/http11/http11_parser.c" +#line 466 "http11_parser.c" switch( (*p) ) { case 32: goto tr30; case 37: goto tr31; @@ -477,14 +477,14 @@ case 20: goto st0; goto tr29; tr29: -#line 20 "ext/http11/http11_parser.rl" +#line 20 "http11_parser.rl" {MARK(mark, p); } goto st21; st21: if ( ++p == pe ) goto _out21; case 21: -#line 488 "ext/http11/http11_parser.c" +#line 488 "http11_parser.c" switch( (*p) ) { case 32: goto tr30; case 37: goto st22; @@ -499,14 +499,14 @@ case 21: goto st0; goto st21; tr31: -#line 20 "ext/http11/http11_parser.rl" +#line 20 "http11_parser.rl" {MARK(mark, p); } goto st22; st22: if ( ++p == pe ) goto _out22; case 22: -#line 510 "ext/http11/http11_parser.c" +#line 510 "http11_parser.c" if ( (*p) < 65 ) { if ( 48 <= (*p) && (*p) <= 57 ) goto st23; @@ -530,14 +530,14 @@ case 23: goto st21; goto st0; tr5: -#line 20 "ext/http11/http11_parser.rl" +#line 20 "http11_parser.rl" {MARK(mark, p); } goto st24; st24: if ( ++p == pe ) goto _out24; case 24: -#line 541 "ext/http11/http11_parser.c" +#line 541 "http11_parser.c" switch( (*p) ) { case 43: goto st24; case 58: goto st25; @@ -555,14 +555,14 @@ case 24: goto st24; goto st0; tr7: -#line 20 "ext/http11/http11_parser.rl" +#line 20 "http11_parser.rl" {MARK(mark, p); } goto st25; st25: if ( ++p == pe ) goto _out25; case 25: -#line 566 "ext/http11/http11_parser.c" +#line 566 "http11_parser.c" switch( (*p) ) { case 32: goto tr8; case 34: goto st0; @@ -602,14 +602,14 @@ case 27: goto st25; goto st0; tr6: -#line 20 "ext/http11/http11_parser.rl" +#line 20 "http11_parser.rl" {MARK(mark, p); } goto st28; st28: if ( ++p == pe ) goto _out28; case 28: -#line 613 "ext/http11/http11_parser.c" +#line 613 "http11_parser.c" switch( (*p) ) { case 32: goto tr40; case 34: goto st0; @@ -651,7 +651,7 @@ case 30: goto st28; goto st0; tr43: -#line 58 "ext/http11/http11_parser.rl" +#line 58 "http11_parser.rl" { if(parser->request_path != NULL) parser->request_path(parser->data, PTR_TO(mark), LEN(mark,p)); @@ -661,7 +661,7 @@ st31: if ( ++p == pe ) goto _out31; case 31: -#line 665 "ext/http11/http11_parser.c" +#line 665 "http11_parser.c" switch( (*p) ) { case 32: goto tr8; case 34: goto st0; @@ -702,7 +702,7 @@ case 33: goto st31; goto st0; tr44: -#line 58 "ext/http11/http11_parser.rl" +#line 58 "http11_parser.rl" { if(parser->request_path != NULL) parser->request_path(parser->data, PTR_TO(mark), LEN(mark,p)); @@ -712,7 +712,7 @@ st34: if ( ++p == pe ) goto _out34; case 34: -#line 716 "ext/http11/http11_parser.c" +#line 716 "http11_parser.c" switch( (*p) ) { case 32: goto tr51; case 34: goto st0; @@ -726,14 +726,14 @@ case 34: goto st0; goto tr50; tr50: -#line 47 "ext/http11/http11_parser.rl" +#line 47 "http11_parser.rl" {MARK(query_start, p); } goto st35; st35: if ( ++p == pe ) goto _out35; case 35: -#line 737 "ext/http11/http11_parser.c" +#line 737 "http11_parser.c" switch( (*p) ) { case 32: goto tr55; case 34: goto st0; @@ -747,14 +747,14 @@ case 35: goto st0; goto st35; tr53: -#line 47 "ext/http11/http11_parser.rl" +#line 47 "http11_parser.rl" {MARK(query_start, p); } goto st36; st36: if ( ++p == pe ) goto _out36; case 36: -#line 758 "ext/http11/http11_parser.c" +#line 758 "http11_parser.c" if ( (*p) < 65 ) { if ( 48 <= (*p) && (*p) <= 57 ) goto st37; @@ -1169,7 +1169,7 @@ case 56: _out: {} } -#line 154 "ext/http11/http11_parser.rl" +#line 154 "http11_parser.rl" parser->cs = cs; parser->nread += p - (buffer + off); @@ -1184,8 +1184,8 @@ case 56: if(parser->body_start) { /* final \r\n combo encountered so stop right here */ -#line 1188 "ext/http11/http11_parser.c" -#line 168 "ext/http11/http11_parser.rl" +#line 1188 "http11_parser.c" +#line 168 "http11_parser.rl" parser->nread++; } @@ -1197,8 +1197,8 @@ int http_parser_finish(http_parser *parser) int cs = parser->cs; -#line 1201 "ext/http11/http11_parser.c" -#line 179 "ext/http11/http11_parser.rl" +#line 1201 "http11_parser.c" +#line 179 "http11_parser.rl" parser->cs = cs; diff --git a/ext/http11_java/http11_parser.rl b/ext/http11_java/http11_parser.rl new file mode 100644 index 0000000..5136993 --- /dev/null +++ b/ext/http11_java/http11_parser.rl @@ -0,0 +1,209 @@ +package org.jruby.mongrel; + +import org.jruby.util.ByteList; + +public class Http11Parser { + +/** machine **/ +%%{ + machine http_parser; + + action mark {parser.mark = fpc; } + + action start_field { parser.field_start = fpc; } + action write_field { + parser.field_len = fpc-parser.field_start; + } + + action start_value { parser.mark = fpc; } + action write_value { + if(parser.http_field != null) { + parser.http_field.call(parser.data, parser.field_start, parser.field_len, parser.mark, fpc-parser.mark); + } + } + action request_method { + if(parser.request_method != null) + parser.request_method.call(parser.data, parser.mark, fpc-parser.mark); + } + action request_uri { + if(parser.request_uri != null) + parser.request_uri.call(parser.data, parser.mark, fpc-parser.mark); + } + + action start_query {parser.query_start = fpc; } + action query_string { + if(parser.query_string != null) + parser.query_string.call(parser.data, parser.query_start, fpc-parser.query_start); + } + + action http_version { + if(parser.http_version != null) + parser.http_version.call(parser.data, parser.mark, fpc-parser.mark); + } + + action request_path { + if(parser.request_path != null) + parser.request_path.call(parser.data, parser.mark, fpc-parser.mark); + } + + action done { + parser.body_start = fpc + 1; + if(parser.header_done != null) + parser.header_done.call(parser.data, fpc + 1, pe - fpc - 1); + fbreak; + } + + +#### HTTP PROTOCOL GRAMMAR +# line endings + CRLF = "\r\n"; + +# character types + CTL = (cntrl | 127); + safe = ("$" | "-" | "_" | "."); + extra = ("!" | "*" | "'" | "(" | ")" | ","); + reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+"); + unsafe = (CTL | " " | "\"" | "#" | "%" | "<" | ">"); + national = any -- (alpha | digit | reserved | extra | safe | unsafe); + unreserved = (alpha | digit | safe | extra | national); + escape = ("%" xdigit xdigit); + uchar = (unreserved | escape); + pchar = (uchar | ":" | "@" | "&" | "=" | "+"); + tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t"); + +# elements + token = (ascii -- (CTL | tspecials)); + +# URI schemes and absolute paths + scheme = ( alpha | digit | "+" | "-" | "." )* ; + absolute_uri = (scheme ":" (uchar | reserved )*); + + path = (pchar+ ( "/" pchar* )*) ; + query = ( uchar | reserved )* %query_string ; + param = ( pchar | "/" )* ; + params = (param ( ";" param )*) ; + rel_path = (path? %request_path (";" params)?) ("?" %start_query query)?; + absolute_path = ("/"+ rel_path); + + Request_URI = ("*" | absolute_uri | absolute_path) >mark %request_uri; + Method = (upper | digit | safe){1,20} >mark %request_method; + + http_number = (digit+ "." digit+) ; + HTTP_Version = ("HTTP/" http_number) >mark %http_version ; + Request_Line = (Method " " Request_URI " " HTTP_Version CRLF) ; + + field_name = (token -- ":")+ >start_field %write_field; + + field_value = any* >start_value %write_value; + + message_header = field_name ":" " "* field_value :> CRLF; + + Request = Request_Line (message_header)* ( CRLF @done); + +main := Request; +}%% + +/** Data **/ +%% write data; + + public static interface ElementCB { + public void call(Object data, int at, int length); + } + + public static interface FieldCB { + public void call(Object data, int field, int flen, int value, int vlen); + } + + public static class HttpParser { + int cs; + int body_start; + int content_len; + int nread; + int mark; + int field_start; + int field_len; + int query_start; + + Object data; + ByteList buffer; + + public FieldCB http_field; + public ElementCB request_method; + public ElementCB request_uri; + public ElementCB request_path; + public ElementCB query_string; + public ElementCB http_version; + public ElementCB header_done; + + public void init() { + cs = 0; + + %% write init; + + body_start = 0; + content_len = 0; + mark = 0; + nread = 0; + field_len = 0; + field_start = 0; + } + } + + public final HttpParser parser = new HttpParser(); + + public int execute(ByteList buffer, int off) { + int p, pe; + int cs = parser.cs; + int len = buffer.realSize; + assert off<=len : "offset past end of buffer"; + + p = off; + pe = len; + byte[] data = buffer.bytes; + parser.buffer = buffer; + + %% write exec; + + parser.cs = cs; + parser.nread += (p - off); + + assert p <= pe : "buffer overflow after parsing execute"; + assert parser.nread <= len : "nread longer than length"; + assert parser.body_start <= len : "body starts after buffer end"; + assert parser.mark < len : "mark is after buffer end"; + assert parser.field_len <= len : "field has length longer than whole buffer"; + assert parser.field_start < len : "field starts after buffer end"; + + if(parser.body_start>0) { + /* final \r\n combo encountered so stop right here */ + %%write eof; + parser.nread++; + } + + return parser.nread; + } + + public int finish() { + int cs = parser.cs; + + %%write eof; + + parser.cs = cs; + + if(has_error()) { + return -1; + } else if(is_finished()) { + return 1; + } else { + return 0; + } + } + + public boolean has_error() { + return parser.cs == http_parser_error; + } + + public boolean is_finished() { + return parser.cs == http_parser_first_final; + } +} diff --git a/ext/http11_java/org/jruby/mongrel/Http11Parser.java b/ext/http11_java/org/jruby/mongrel/Http11Parser.java index 5a173d9..3aa26b1 100644 --- a/ext/http11_java/org/jruby/mongrel/Http11Parser.java +++ b/ext/http11_java/org/jruby/mongrel/Http11Parser.java @@ -1,4 +1,4 @@ -// line 1 "org/jruby/mongrel/http11_parser.rl" +// line 1 "http11_parser.rl" package org.jruby.mongrel; import org.jruby.util.ByteList; @@ -6,7 +6,7 @@ import org.jruby.util.ByteList; public class Http11Parser { /** machine **/ -// line 104 "org/jruby/mongrel/http11_parser.rl" +// line 104 "http11_parser.rl" /** Data **/ @@ -275,7 +275,7 @@ static final int http_parser_error = 0; static final int http_parser_en_main = 1; -// line 108 "org/jruby/mongrel/http11_parser.rl" +// line 108 "http11_parser.rl" public static interface ElementCB { public void call(Object data, int at, int length); @@ -314,7 +314,7 @@ static final int http_parser_en_main = 1; { cs = http_parser_start; } -// line 142 "org/jruby/mongrel/http11_parser.rl" +// line 142 "http11_parser.rl" body_start = 0; content_len = 0; @@ -413,25 +413,25 @@ static final int http_parser_en_main = 1; switch ( _http_parser_actions[_acts++] ) { case 0: -// line 11 "org/jruby/mongrel/http11_parser.rl" +// line 11 "http11_parser.rl" {parser.mark = p; } break; case 1: -// line 13 "org/jruby/mongrel/http11_parser.rl" +// line 13 "http11_parser.rl" { parser.field_start = p; } break; case 2: -// line 14 "org/jruby/mongrel/http11_parser.rl" +// line 14 "http11_parser.rl" { parser.field_len = p-parser.field_start; } break; case 3: -// line 18 "org/jruby/mongrel/http11_parser.rl" +// line 18 "http11_parser.rl" { parser.mark = p; } break; case 4: -// line 19 "org/jruby/mongrel/http11_parser.rl" +// line 19 "http11_parser.rl" { if(parser.http_field != null) { parser.http_field.call(parser.data, parser.field_start, parser.field_len, parser.mark, p-parser.mark); @@ -439,46 +439,46 @@ static final int http_parser_en_main = 1; } break; case 5: -// line 24 "org/jruby/mongrel/http11_parser.rl" +// line 24 "http11_parser.rl" { if(parser.request_method != null) parser.request_method.call(parser.data, parser.mark, p-parser.mark); } break; case 6: -// line 28 "org/jruby/mongrel/http11_parser.rl" +// line 28 "http11_parser.rl" { if(parser.request_uri != null) parser.request_uri.call(parser.data, parser.mark, p-parser.mark); } break; case 7: -// line 33 "org/jruby/mongrel/http11_parser.rl" +// line 33 "http11_parser.rl" {parser.query_start = p; } break; case 8: -// line 34 "org/jruby/mongrel/http11_parser.rl" +// line 34 "http11_parser.rl" { if(parser.query_string != null) parser.query_string.call(parser.data, parser.query_start, p-parser.query_start); } break; case 9: -// line 39 "org/jruby/mongrel/http11_parser.rl" +// line 39 "http11_parser.rl" { if(parser.http_version != null) parser.http_version.call(parser.data, parser.mark, p-parser.mark); } break; case 10: -// line 44 "org/jruby/mongrel/http11_parser.rl" +// line 44 "http11_parser.rl" { if(parser.request_path != null) parser.request_path.call(parser.data, parser.mark, p-parser.mark); } break; case 11: -// line 49 "org/jruby/mongrel/http11_parser.rl" +// line 49 "http11_parser.rl" { parser.body_start = p + 1; if(parser.header_done != null) @@ -498,7 +498,7 @@ static final int http_parser_en_main = 1; } } } } -// line 166 "org/jruby/mongrel/http11_parser.rl" +// line 166 "http11_parser.rl" parser.cs = cs; parser.nread += (p - off); @@ -514,7 +514,7 @@ static final int http_parser_en_main = 1; /* final \r\n combo encountered so stop right here */ // line 517 "org/jruby/mongrel/Http11Parser.java" -// line 180 "org/jruby/mongrel/http11_parser.rl" +// line 180 "http11_parser.rl" parser.nread++; } @@ -526,7 +526,7 @@ static final int http_parser_en_main = 1; // line 529 "org/jruby/mongrel/Http11Parser.java" -// line 190 "org/jruby/mongrel/http11_parser.rl" +// line 190 "http11_parser.rl" parser.cs = cs; diff --git a/ext/http11_java/org/jruby/mongrel/http11_parser.rl b/ext/http11_java/org/jruby/mongrel/http11_parser.rl deleted file mode 100644 index 5136993..0000000 --- a/ext/http11_java/org/jruby/mongrel/http11_parser.rl +++ /dev/null @@ -1,209 +0,0 @@ -package org.jruby.mongrel; - -import org.jruby.util.ByteList; - -public class Http11Parser { - -/** machine **/ -%%{ - machine http_parser; - - action mark {parser.mark = fpc; } - - action start_field { parser.field_start = fpc; } - action write_field { - parser.field_len = fpc-parser.field_start; - } - - action start_value { parser.mark = fpc; } - action write_value { - if(parser.http_field != null) { - parser.http_field.call(parser.data, parser.field_start, parser.field_len, parser.mark, fpc-parser.mark); - } - } - action request_method { - if(parser.request_method != null) - parser.request_method.call(parser.data, parser.mark, fpc-parser.mark); - } - action request_uri { - if(parser.request_uri != null) - parser.request_uri.call(parser.data, parser.mark, fpc-parser.mark); - } - - action start_query {parser.query_start = fpc; } - action query_string { - if(parser.query_string != null) - parser.query_string.call(parser.data, parser.query_start, fpc-parser.query_start); - } - - action http_version { - if(parser.http_version != null) - parser.http_version.call(parser.data, parser.mark, fpc-parser.mark); - } - - action request_path { - if(parser.request_path != null) - parser.request_path.call(parser.data, parser.mark, fpc-parser.mark); - } - - action done { - parser.body_start = fpc + 1; - if(parser.header_done != null) - parser.header_done.call(parser.data, fpc + 1, pe - fpc - 1); - fbreak; - } - - -#### HTTP PROTOCOL GRAMMAR -# line endings - CRLF = "\r\n"; - -# character types - CTL = (cntrl | 127); - safe = ("$" | "-" | "_" | "."); - extra = ("!" | "*" | "'" | "(" | ")" | ","); - reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+"); - unsafe = (CTL | " " | "\"" | "#" | "%" | "<" | ">"); - national = any -- (alpha | digit | reserved | extra | safe | unsafe); - unreserved = (alpha | digit | safe | extra | national); - escape = ("%" xdigit xdigit); - uchar = (unreserved | escape); - pchar = (uchar | ":" | "@" | "&" | "=" | "+"); - tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t"); - -# elements - token = (ascii -- (CTL | tspecials)); - -# URI schemes and absolute paths - scheme = ( alpha | digit | "+" | "-" | "." )* ; - absolute_uri = (scheme ":" (uchar | reserved )*); - - path = (pchar+ ( "/" pchar* )*) ; - query = ( uchar | reserved )* %query_string ; - param = ( pchar | "/" )* ; - params = (param ( ";" param )*) ; - rel_path = (path? %request_path (";" params)?) ("?" %start_query query)?; - absolute_path = ("/"+ rel_path); - - Request_URI = ("*" | absolute_uri | absolute_path) >mark %request_uri; - Method = (upper | digit | safe){1,20} >mark %request_method; - - http_number = (digit+ "." digit+) ; - HTTP_Version = ("HTTP/" http_number) >mark %http_version ; - Request_Line = (Method " " Request_URI " " HTTP_Version CRLF) ; - - field_name = (token -- ":")+ >start_field %write_field; - - field_value = any* >start_value %write_value; - - message_header = field_name ":" " "* field_value :> CRLF; - - Request = Request_Line (message_header)* ( CRLF @done); - -main := Request; -}%% - -/** Data **/ -%% write data; - - public static interface ElementCB { - public void call(Object data, int at, int length); - } - - public static interface FieldCB { - public void call(Object data, int field, int flen, int value, int vlen); - } - - public static class HttpParser { - int cs; - int body_start; - int content_len; - int nread; - int mark; - int field_start; - int field_len; - int query_start; - - Object data; - ByteList buffer; - - public FieldCB http_field; - public ElementCB request_method; - public ElementCB request_uri; - public ElementCB request_path; - public ElementCB query_string; - public ElementCB http_version; - public ElementCB header_done; - - public void init() { - cs = 0; - - %% write init; - - body_start = 0; - content_len = 0; - mark = 0; - nread = 0; - field_len = 0; - field_start = 0; - } - } - - public final HttpParser parser = new HttpParser(); - - public int execute(ByteList buffer, int off) { - int p, pe; - int cs = parser.cs; - int len = buffer.realSize; - assert off<=len : "offset past end of buffer"; - - p = off; - pe = len; - byte[] data = buffer.bytes; - parser.buffer = buffer; - - %% write exec; - - parser.cs = cs; - parser.nread += (p - off); - - assert p <= pe : "buffer overflow after parsing execute"; - assert parser.nread <= len : "nread longer than length"; - assert parser.body_start <= len : "body starts after buffer end"; - assert parser.mark < len : "mark is after buffer end"; - assert parser.field_len <= len : "field has length longer than whole buffer"; - assert parser.field_start < len : "field starts after buffer end"; - - if(parser.body_start>0) { - /* final \r\n combo encountered so stop right here */ - %%write eof; - parser.nread++; - } - - return parser.nread; - } - - public int finish() { - int cs = parser.cs; - - %%write eof; - - parser.cs = cs; - - if(has_error()) { - return -1; - } else if(is_finished()) { - return 1; - } else { - return 0; - } - } - - public boolean has_error() { - return parser.cs == http_parser_error; - } - - public boolean is_finished() { - return parser.cs == http_parser_first_final; - } -} -- cgit v1.2.3-24-ge0c7