diff options
Diffstat (limited to 'chunk_parser.rl')
-rw-r--r-- | chunk_parser.rl | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/chunk_parser.rl b/chunk_parser.rl index 9234f71..926db26 100644 --- a/chunk_parser.rl +++ b/chunk_parser.rl @@ -26,69 +26,69 @@ static inline off_t hexchar2off(int xdigit) off_t buf_remain; size_t wr_len; - if (http->content_len == 0) { /* final chunk */ - http->chunk_state = MOG_CHUNK_STATE_TRAILER; + if (http->_p.content_len == 0) { /* final chunk */ + http->_p.chunk_state = MOG_CHUNK_STATE_TRAILER; fhold; /* XXX this feels wrong ... */ if (fpc >= buf) { assert(fc == '\n' && "bad chunk end"); - http->line_end = to_u16(fpc - buf); + http->_p.line_end = to_u16(fpc - buf); } fgoto more_trailers; } - assert(http->content_len > 0 && "impossible content_len"); + assert(http->_p.content_len > 0 && "impossible content_len"); buf_remain = len - (fpc - buf); if (buf_remain == 0) fbreak; assert(buf_remain > 0 && "impossible buf_remain"); - wr_len = MIN((size_t)http->content_len, (size_t)buf_remain); + wr_len = MIN((size_t)http->_p.content_len, (size_t)buf_remain); assert(wr_len != 0 && "invalid wr_len"); if (! mog_http_write_full(http->forward, fpc, wr_len)) fbreak; - http->content_len -= wr_len; + http->_p.content_len -= wr_len; p += wr_len - 1; assert(p < pe && "buffer overrun"); - if (http->content_len > 0) { + if (http->_p.content_len > 0) { really_done = 1; /* let caller handle reading the rest of the body */ fbreak; } /* next chunk header */ - http->chunk_state = MOG_CHUNK_STATE_SIZE; + http->_p.chunk_state = MOG_CHUNK_STATE_SIZE; if (wr_len == buf_remain) { - if (http->content_len == 0) + if (http->_p.content_len == 0) fgoto main; really_done = 1; fbreak; } /* more chunks in this buffer */ - assert(http->content_len == 0 && + assert(http->_p.content_len == 0 && "bad content_len at chunk end"); fgoto main; }; chunk = "\r\n"? # account for trailing CRLF in previous chunk (xdigit+) $ { - off_t prev = http->content_len; + off_t prev = http->_p.content_len; - http->content_len *= 16; - http->content_len += hexchar2off(fc); - if (http->content_len < prev) { + http->_p.content_len *= 16; + http->_p.content_len += hexchar2off(fc); + if (http->_p.content_len < prev) { errno = ERANGE; - http->content_len = -1; + http->_p.content_len = -1; fbreak; } } (any -- [\r\n])* - '\r' '\n' @ { http->chunk_state = MOG_CHUNK_STATE_DATA; } + '\r' '\n' @ { http->_p.chunk_state = MOG_CHUNK_STATE_DATA; } chunk_data; main := chunk+; }%% @@ -100,12 +100,12 @@ void mog_chunk_init(struct mog_http *http) int cs; %% write init; - assert(http->chunked && "not chunked"); + assert(http->_p.chunked && "not chunked"); http->cs = cs; - http->line_end = 0; - http->content_len = 0; - http->offset = 0; - http->chunk_state = MOG_CHUNK_STATE_SIZE; + http->_p.line_end = 0; + http->_p.content_len = 0; + http->_p.offset = 0; + http->_p.chunk_state = MOG_CHUNK_STATE_SIZE; } enum mog_parser_state @@ -114,7 +114,7 @@ mog_chunk_parse(struct mog_http *http, char *buf, size_t len) char *p, *pe, *eof = NULL; int cs = http->cs; int really_done = 0; - size_t off = http->offset; + size_t off = http->_p.offset; assert(http->wbuf == NULL && "unwritten data in buffer"); assert(off <= len && "http offset past end of buffer"); @@ -132,13 +132,13 @@ mog_chunk_parse(struct mog_http *http, char *buf, size_t len) cs = chunk_parser_first_final; http->cs = cs; - http->offset = p - buf; + http->_p.offset = p - buf; if (cs == chunk_parser_error || errno) return MOG_PARSER_ERROR; assert(p <= pe && "buffer overflow after chunk parse"); - assert(http->offset <= len && "offset longer than len"); + assert(http->_p.offset <= len && "offset longer than len"); if (http->cs == chunk_parser_first_final) return MOG_PARSER_DONE; return MOG_PARSER_CONTINUE; |