about summary refs log tree commit homepage
path: root/http_parser.rl
diff options
context:
space:
mode:
Diffstat (limited to 'http_parser.rl')
-rw-r--r--http_parser.rl76
1 files changed, 38 insertions, 38 deletions
diff --git a/http_parser.rl b/http_parser.rl
index d84d0ce..a643862 100644
--- a/http_parser.rl
+++ b/http_parser.rl
@@ -30,69 +30,69 @@ static bool length_incr(off_t *len, unsigned c)
         };
 
         mog_path = '/'[a-zA-Z0-9/\.\-]{0,36}; # only stuff MogileFS will use
-        GET = "GET "> { http->http_method = MOG_HTTP_METHOD_GET; };
-        HEAD = "HEAD "> { http->http_method = MOG_HTTP_METHOD_HEAD; };
-        PUT = "PUT "> { http->http_method = MOG_HTTP_METHOD_PUT; };
-        DELETE = "DELETE "> { http->http_method = MOG_HTTP_METHOD_DELETE; };
-        MKCOL = "MKCOL "> { http->http_method = MOG_HTTP_METHOD_MKCOL; };
+        GET = "GET "> { http->_p.http_method = MOG_HTTP_METHOD_GET; };
+        HEAD = "HEAD "> { http->_p.http_method = MOG_HTTP_METHOD_HEAD; };
+        PUT = "PUT "> { http->_p.http_method = MOG_HTTP_METHOD_PUT; };
+        DELETE = "DELETE "> { http->_p.http_method = MOG_HTTP_METHOD_DELETE; };
+        MKCOL = "MKCOL "> { http->_p.http_method = MOG_HTTP_METHOD_MKCOL; };
 
         # no HTTP/0.9 for now, sorry (not :P)
         req_line = (HEAD|GET|PUT|DELETE|MKCOL)
                 ("http://" [^/]+)?
-                '/'*(mog_path) > { http->path_tip = to_u8(fpc - buf); }
+                '/'*(mog_path) > { http->_p.path_tip = to_u8(fpc - buf); }
                 # TODO: maybe folks use query string/fragments for logging...
-                (" HTTP/1.") > { http->path_end = to_u8(fpc - buf); }
-                ('0'|'1'> { http->persistent = 1; }) '\r'LF;
+                (" HTTP/1.") > { http->_p.path_end = to_u8(fpc - buf); }
+                ('0'|'1'> { http->_p.persistent = 1; }) '\r'LF;
 
         content_length = "Content-Length:"i sep
                 (digit+) $ {
-                        if (!length_incr(&http->content_len, fc))
+                        if (!length_incr(&http->_p.content_len, fc))
                                 fbreak;
                 }
                 $! { errno = EINVAL; fbreak; }
                 eor;
         content_range = "Content-Range:"i sep "bytes"LWS+
                 (digit+) $ {
-                        if (!length_incr(&http->range_beg, fc))
+                        if (!length_incr(&http->_p.range_beg, fc))
                                 fbreak;
                 }
                 $! { errno = EINVAL; fbreak; }
                 "-"
                 (digit+) $ {
-                        if (!length_incr(&http->range_end, fc))
+                        if (!length_incr(&http->_p.range_end, fc))
                                 fbreak;
                 }
                 $! { errno = EINVAL; fbreak; }
                 "/*"
-                eor > { http->has_content_range = 1; };
+                eor > { http->_p.has_content_range = 1; };
         range = "Range:"i sep (
                         "bytes=" > {
-                                http->range_beg = http->range_end = -1;
+                                http->_p.range_beg = http->_p.range_end = -1;
                         }
                         (digit*) $ {
-                                if (http->range_beg < 0)
-                                        http->range_beg = 0;
-                                if (!length_incr(&http->range_beg, fc))
+                                if (http->_p.range_beg < 0)
+                                        http->_p.range_beg = 0;
+                                if (!length_incr(&http->_p.range_beg, fc))
                                         fbreak;
                         }
                         '-'
                         (digit*) $ {
-                                if (http->range_end < 0)
-                                        http->range_end = 0;
-                                if (!length_incr(&http->range_end, fc))
+                                if (http->_p.range_end < 0)
+                                        http->_p.range_end = 0;
+                                if (!length_incr(&http->_p.range_end, fc))
                                         fbreak;
                         }
                 ) $! { errno = EINVAL; fbreak; }
-                eor @ { http->has_range = 1; };
+                eor @ { http->_p.has_range = 1; };
         transfer_encoding_chunked = "Transfer-Encoding:"i sep
-                "chunked"i eor > { http->chunked = 1; };
+                "chunked"i eor > { http->_p.chunked = 1; };
         trailer = "Trailer:"i sep
-                (("Content-MD5"i @ { http->has_trailer_md5 = 1; })
+                (("Content-MD5"i @ { http->_p.has_trailer_md5 = 1; })
                  | header_name | ',')
                 eor;
         connection = "Connection:"i sep
-                (("close"i @ { http->persistent = 0; }) |
-                 ("keep-alive"i @ { http->persistent = 1; })) eor;
+                (("close"i @ { http->_p.persistent = 0; }) |
+                 ("keep-alive"i @ { http->_p.persistent = 1; })) eor;
         header_line =
                 ( content_length |
                   transfer_encoding_chunked |
@@ -102,11 +102,11 @@ static bool length_incr(off_t *len, unsigned c)
                   content_md5 |
                   connection ) $!
                 {
-                        assert(http->line_end > 0 &&
+                        assert(http->_p.line_end > 0 &&
                                "no previous request/header line");
-                        assert(buf[http->line_end] == '\n' &&
-                               "bad http->line_end");
-                        p = buf + http->line_end + 1;
+                        assert(buf[http->_p.line_end] == '\n' &&
+                               "bad http->_p.line_end");
+                        p = buf + http->_p.line_end + 1;
                         assert(p <= pe && "overflow");
                         fgoto ignored_header;
                 };
@@ -120,21 +120,21 @@ static bool length_incr(off_t *len, unsigned c)
 void mog_http_reset_parser(struct mog_http *http)
 {
         int cs;
-        struct mog_rbuf *rbuf = http->rbuf;
-        struct mog_svc *svc = http->svc;
 
         %% write init;
-        memset(http, 0, sizeof(struct mog_http));
         http->cs = cs;
-        http->rbuf = rbuf;
-        http->svc = svc;
+        memset(&http->_p, 0, sizeof(http->_p));
+
+        /* these should probably be in mog_http_init */
+        http->forward = NULL;
+        http->wbuf = NULL;
 }
 
 void mog_http_init(struct mog_http *http, struct mog_svc *svc)
 {
-        http->svc = svc;
-        http->rbuf = NULL;
         mog_http_reset_parser(http);
+        http->rbuf = NULL;
+        http->svc = svc;
 }
 
 enum mog_parser_state
@@ -143,7 +143,7 @@ mog_http_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");
@@ -161,13 +161,13 @@ mog_http_parse(struct mog_http *http, char *buf, size_t len)
                 cs = http_parser_first_final;
 
         http->cs = cs;
-        http->offset = p - buf;
+        http->_p.offset = p - buf;
 
         if (cs == http_parser_error || errno)
                 return MOG_PARSER_ERROR;
 
         assert(p <= pe && "buffer overflow after http parse");
-        assert(http->offset <= len && "offset longer than len");
+        assert(http->_p.offset <= len && "offset longer than len");
 
         if (http->cs == http_parser_first_final) return MOG_PARSER_DONE;
         return MOG_PARSER_CONTINUE;