Basic ragel suport
parent
3c05dca97a
commit
503e8d7859
@ -0,0 +1,19 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Thomas Nagy, 2006 (ita)
|
||||
|
||||
"Ragel: '.rl' files are converted into .c files using 'ragel': {.rl -> .c -> .o}"
|
||||
|
||||
import TaskGen
|
||||
|
||||
TaskGen.declare_chain(
|
||||
name = 'ragel',
|
||||
action = '${RAGEL} -o ${TGT} ${SRC}',
|
||||
ext_in = '.rl',
|
||||
ext_out = '.c',
|
||||
before = 'c',
|
||||
)
|
||||
|
||||
def detect(conf):
|
||||
dang = conf.find_program('ragel', var='RAGEL')
|
||||
if not dang: conf.fatal('cannot find the program "ragel"')
|
@ -0,0 +1,26 @@
|
||||
#ifndef _LIGHTTPD_HTTP_REQUEST_PARSER_H_
|
||||
#define _LIGHTTPD_HTTP_REQUEST_PARSER_H_
|
||||
|
||||
struct http_request_ctx;
|
||||
typedef struct http_request_ctx http_request_ctx;
|
||||
|
||||
#include "chunks.h"
|
||||
|
||||
struct http_request_ctx {
|
||||
chunkqueue *cq;
|
||||
|
||||
goffset bytes_in;
|
||||
|
||||
/* current position
|
||||
* buf is curi[start..start+length)
|
||||
*/
|
||||
chunkiter curi;
|
||||
off_t start, length;
|
||||
char *buf;
|
||||
|
||||
int cs;
|
||||
|
||||
chunk_parser_mark mark;
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,55 @@
|
||||
|
||||
#include "http_request_parser.h"
|
||||
|
||||
static chunk_parser_mark getmark(http_request_ctx *ctx, const char *fpc) {
|
||||
chunk_parser_mark m;
|
||||
m.ci = ctx->curi;
|
||||
m.pos = ctx->start + fpc - ctx->buf;
|
||||
return m;
|
||||
}
|
||||
|
||||
/** Machine **/
|
||||
|
||||
%%{
|
||||
|
||||
machine http_request_parser;
|
||||
|
||||
CRLF = "\r\n";
|
||||
|
||||
action mark { ctx->mark = getmark(ctx, fpc); }
|
||||
|
||||
main := CRLF ;
|
||||
}%%
|
||||
|
||||
%% write data;
|
||||
|
||||
void http_request_parse(server *srv, connection *con, http_request_ctx *ctx) {
|
||||
int cs = ctx->cs;
|
||||
while (cs != http_request_parser_error && cs != http_request_parser_first_final) {
|
||||
char *p, *pe;
|
||||
off_t l;
|
||||
|
||||
l = chunkiter_length(ctx->curi);
|
||||
if (ctx->start >= l) {
|
||||
chunkiter_next(&ctx->curi);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (HANDLER_GO_ON != chunkiter_read(srv, con, ctx->curi, ctx->start, l - ctx->start, &ctx->buf, &ctx->length)) {
|
||||
return;
|
||||
}
|
||||
|
||||
p = ctx->buf;
|
||||
pe = ctx->buf + ctx->length;
|
||||
|
||||
%% write exec;
|
||||
|
||||
ctx->start += pe - p;
|
||||
ctx->bytes_in += pe - p;
|
||||
if (ctx->start >= l) {
|
||||
chunkiter_next(&ctx->curi);
|
||||
ctx->start = 0;
|
||||
}
|
||||
}
|
||||
ctx->cs = cs;
|
||||
}
|
Loading…
Reference in New Issue