REORG: h1: create a new h1m_state
This is the *parsing* state of an HTTP/1 message. Currently the h1_state
is composite as it's made both of parsing and control (100SENT, BODY,
DONE, TUNNEL, ENDING etc). The purpose here is to have a purely H1 state
that can be used by H1 parsers. For now it's equivalent to h1_state.
diff --git a/include/proto/h1.h b/include/proto/h1.h
index 2997383..22b5c6e 100644
--- a/include/proto/h1.h
+++ b/include/proto/h1.h
@@ -74,7 +74,7 @@
} \
} while (0)
-/* for debugging, reports the HTTP/1 message state name */
+/* for debugging, reports the HTTP/1 message state name (legacy version) */
static inline const char *h1_msg_state_str(enum h1_state msg_state)
{
switch (msg_state) {
@@ -120,6 +120,52 @@
}
}
+/* for debugging, reports the HTTP/1 message state name */
+static inline const char *h1m_state_str(enum h1_state msg_state)
+{
+ switch (msg_state) {
+ case H1_MSG_RQBEFORE: return "MSG_RQBEFORE";
+ case H1_MSG_RQBEFORE_CR: return "MSG_RQBEFORE_CR";
+ case H1_MSG_RQMETH: return "MSG_RQMETH";
+ case H1_MSG_RQMETH_SP: return "MSG_RQMETH_SP";
+ case H1_MSG_RQURI: return "MSG_RQURI";
+ case H1_MSG_RQURI_SP: return "MSG_RQURI_SP";
+ case H1_MSG_RQVER: return "MSG_RQVER";
+ case H1_MSG_RQLINE_END: return "MSG_RQLINE_END";
+ case H1_MSG_RPBEFORE: return "MSG_RPBEFORE";
+ case H1_MSG_RPBEFORE_CR: return "MSG_RPBEFORE_CR";
+ case H1_MSG_RPVER: return "MSG_RPVER";
+ case H1_MSG_RPVER_SP: return "MSG_RPVER_SP";
+ case H1_MSG_RPCODE: return "MSG_RPCODE";
+ case H1_MSG_RPCODE_SP: return "MSG_RPCODE_SP";
+ case H1_MSG_RPREASON: return "MSG_RPREASON";
+ case H1_MSG_RPLINE_END: return "MSG_RPLINE_END";
+ case H1_MSG_HDR_FIRST: return "MSG_HDR_FIRST";
+ case H1_MSG_HDR_NAME: return "MSG_HDR_NAME";
+ case H1_MSG_HDR_COL: return "MSG_HDR_COL";
+ case H1_MSG_HDR_L1_SP: return "MSG_HDR_L1_SP";
+ case H1_MSG_HDR_L1_LF: return "MSG_HDR_L1_LF";
+ case H1_MSG_HDR_L1_LWS: return "MSG_HDR_L1_LWS";
+ case H1_MSG_HDR_VAL: return "MSG_HDR_VAL";
+ case H1_MSG_HDR_L2_LF: return "MSG_HDR_L2_LF";
+ case H1_MSG_HDR_L2_LWS: return "MSG_HDR_L2_LWS";
+ case H1_MSG_LAST_LF: return "MSG_LAST_LF";
+ case H1_MSG_ERROR: return "MSG_ERROR";
+ case H1_MSG_BODY: return "MSG_BODY";
+ case H1_MSG_100_SENT: return "MSG_100_SENT";
+ case H1_MSG_CHUNK_SIZE: return "MSG_CHUNK_SIZE";
+ case H1_MSG_DATA: return "MSG_DATA";
+ case H1_MSG_CHUNK_CRLF: return "MSG_CHUNK_CRLF";
+ case H1_MSG_TRAILERS: return "MSG_TRAILERS";
+ case H1_MSG_ENDING: return "MSG_ENDING";
+ case H1_MSG_DONE: return "MSG_DONE";
+ case H1_MSG_CLOSING: return "MSG_CLOSING";
+ case H1_MSG_CLOSED: return "MSG_CLOSED";
+ case H1_MSG_TUNNEL: return "MSG_TUNNEL";
+ default: return "MSG_??????";
+ }
+}
+
/* This function may be called only in HTTP_MSG_CHUNK_CRLF. It reads the CRLF or
* a possible LF alone at the end of a chunk. The caller should adjust msg->next
* in order to include this part into the next forwarding phase. Note that the
@@ -262,7 +308,7 @@
/* initializes an H1 message */
static inline struct h1m *h1m_init(struct h1m *h1m)
{
- h1m->state = HTTP_MSG_RQBEFORE;
+ h1m->state = H1_MSG_RQBEFORE;
h1m->status = 0;
h1m->flags = 0;
h1m->curr_len = 0;
diff --git a/include/types/h1.h b/include/types/h1.h
index 3956b6e..8587608 100644
--- a/include/types/h1.h
+++ b/include/types/h1.h
@@ -22,7 +22,9 @@
#ifndef _TYPES_H1_H
#define _TYPES_H1_H
-/* Possible states while parsing HTTP/1 messages (request|response) */
+/* Legacy version of the HTTP/1 message state, used by the channels, should
+ * ultimately be removed.
+ */
enum h1_state {
HTTP_MSG_RQBEFORE = 0, // request: leading LF, before start line
HTTP_MSG_RQBEFORE_CR = 1, // request: leading CRLF, before start line
@@ -82,6 +84,66 @@
} __attribute__((packed));
+/* Possible states while parsing HTTP/1 messages (request|response) */
+enum h1m_state {
+ H1_MSG_RQBEFORE = 0, // request: leading LF, before start line
+ H1_MSG_RQBEFORE_CR = 1, // request: leading CRLF, before start line
+ /* these ones define a request start line */
+ H1_MSG_RQMETH = 2, // parsing the Method
+ H1_MSG_RQMETH_SP = 3, // space(s) after the Method
+ H1_MSG_RQURI = 4, // parsing the Request URI
+ H1_MSG_RQURI_SP = 5, // space(s) after the Request URI
+ H1_MSG_RQVER = 6, // parsing the Request Version
+ H1_MSG_RQLINE_END = 7, // end of request line (CR or LF)
+
+ H1_MSG_RPBEFORE = 8, // response: leading LF, before start line
+ H1_MSG_RPBEFORE_CR = 9, // response: leading CRLF, before start line
+
+ /* these ones define a response start line */
+ H1_MSG_RPVER = 10, // parsing the Response Version
+ H1_MSG_RPVER_SP = 11, // space(s) after the Response Version
+ H1_MSG_RPCODE = 12, // response code
+ H1_MSG_RPCODE_SP = 13, // space(s) after the response code
+ H1_MSG_RPREASON = 14, // response reason
+ H1_MSG_RPLINE_END = 15, // end of response line (CR or LF)
+
+ /* common header processing */
+ H1_MSG_HDR_FIRST = 16, // waiting for first header or last CRLF (no LWS possible)
+ H1_MSG_HDR_NAME = 17, // parsing header name
+ H1_MSG_HDR_COL = 18, // parsing header colon
+ H1_MSG_HDR_L1_SP = 19, // parsing header LWS (SP|HT) before value
+ H1_MSG_HDR_L1_LF = 20, // parsing header LWS (LF) before value
+ H1_MSG_HDR_L1_LWS = 21, // checking whether it's a new header or an LWS
+ H1_MSG_HDR_VAL = 22, // parsing header value
+ H1_MSG_HDR_L2_LF = 23, // parsing header LWS (LF) inside/after value
+ H1_MSG_HDR_L2_LWS = 24, // checking whether it's a new header or an LWS
+
+ H1_MSG_LAST_LF = 25, // parsing last LF
+
+ /* error state : must be before H1_MSG_BODY so that (>=BODY) always indicates
+ * that data are being processed.
+ */
+ H1_MSG_ERROR = 26, // an error occurred
+ /* Body processing.
+ * The state H1_MSG_BODY is a delimiter to know if we're waiting for headers
+ * or body. All the sub-states below also indicate we're processing the body,
+ * with some additional information.
+ */
+ H1_MSG_BODY = 27, // parsing body at end of headers
+ H1_MSG_100_SENT = 28, // parsing body after a 100-Continue was sent
+ H1_MSG_CHUNK_SIZE = 29, // parsing the chunk size (RFC7230 #4.1)
+ H1_MSG_DATA = 30, // skipping data chunk / content-length data
+ H1_MSG_CHUNK_CRLF = 31, // skipping CRLF after data chunk
+ H1_MSG_TRAILERS = 32, // trailers (post-data entity headers)
+ /* we enter this state when we've received the end of the current message */
+ H1_MSG_ENDING = 33, // message end received, wait that the filters end too
+ H1_MSG_DONE = 34, // message end received, waiting for resync or close
+ H1_MSG_CLOSING = 35, // shutdown_w done, not all bytes sent yet
+ H1_MSG_CLOSED = 36, // shutdown_w done, all bytes sent
+ H1_MSG_TUNNEL = 37, // tunneled data after DONE
+} __attribute__((packed));
+
+
/* HTTP/1 message flags (32 bit), for use in h1m->flags only */
#define H1_MF_NONE 0x00000000
#define H1_MF_CLEN 0x00000001 // content-length present
@@ -90,7 +152,7 @@
/* basic HTTP/1 message state for use in parsers */
struct h1m {
- enum h1_state state; // H1 message state (HTTP_MSG_*)
+ enum h1m_state state; // H1 message state (H1_MSG_*)
/* 8 bits available here */
uint16_t status; // HTTP status code
uint32_t flags; // H1 message flags (H1_MF_*)