]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: http: add a pointer to the buffer in http_msg
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Mar 2012 10:32:30 +0000 (11:32 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 May 2012 10:28:12 +0000 (12:28 +0200)
ACLs and patterns only rely on a struct http_msg and don't know the pointer
to the actual data. struct http_msg will soon only hold relative references
so that's not possible. We need http_msg to hold a reference to the struct
buffer before having relative pointers everywhere.

It is likely that doing so will also result in opportunities to simplify
a number of functions arguments. The following functions are already
candidate :

http_buffer_heavy_realign
http_capture_bad_message
http_change_connection_header
http_forward_trailers
http_header_add_tail
http_header_add_tail2
http_msg_analyzer
http_parse_chunk_size
http_parse_connection_header
http_remove_header2
http_send_name_header
http_skip_chunk_crlf
http_upgrade_v09_to_v10

include/types/proto_http.h
src/proto_http.c
src/session.c

index 5df00bda3e684a55d3ece8417832a568f01ef81e..2c8b876c7f661df799c82a86513326a405291121 100644 (file)
@@ -307,6 +307,7 @@ enum {
 struct http_msg {
        unsigned int msg_state;                /* where we are in the current message parsing */
        unsigned int flags;                    /* flags describing the message (HTTP version, ...) */
+       struct buffer *buf;                    /* pointer to the buffer which holds the message */
        unsigned int next;                     /* pointer to next byte to parse, relative to buf->p */
        unsigned int sov;                      /* current header: start of value */
        unsigned int eoh;                      /* End Of Headers, relative to buffer */
index 0f5a509d2666317e1a44fb6deab4c9664cab2de0..5fbf68f80acdde70537c943df387df23f8cf3d42 100644 (file)
@@ -951,10 +951,11 @@ void capture_headers(char *som, struct hdr_idx *idx,
  * labels and variable names. Note that msg->sol is left unchanged.
  */
 const char *http_parse_stsline(struct http_msg *msg, const char *msg_buf,
-                              const char *msg_start,
                               unsigned int state, const char *ptr, const char *end,
                               unsigned int *ret_ptr, unsigned int *ret_state)
 {
+       const char *msg_start = msg->buf->p;
+
        switch (state)  {
        case HTTP_MSG_RPVER:
        http_msg_rpver:
@@ -1060,10 +1061,11 @@ const char *http_parse_stsline(struct http_msg *msg, const char *msg_buf,
  * labels and variable names. Note that msg->sol is left unchanged.
  */
 const char *http_parse_reqline(struct http_msg *msg, const char *msg_buf,
-                              const char *msg_start,
                               unsigned int state, const char *ptr, const char *end,
                               unsigned int *ret_ptr, unsigned int *ret_state)
 {
+       const char *msg_start = msg->buf->p;
+
        switch (state)  {
        case HTTP_MSG_RQMETH:
        http_msg_rqmeth:
@@ -1334,7 +1336,7 @@ void http_msg_analyzer(struct buffer *buf, struct http_msg *msg, struct hdr_idx
        case HTTP_MSG_RPCODE:
        case HTTP_MSG_RPCODE_SP:
        case HTTP_MSG_RPREASON:
-               ptr = (char *)http_parse_stsline(msg, buf->data, buf->p,
+               ptr = (char *)http_parse_stsline(msg, buf->data,
                                                 state, ptr, end,
                                                 &msg->next, &msg->msg_state);
                if (unlikely(!ptr))
@@ -1404,7 +1406,7 @@ void http_msg_analyzer(struct buffer *buf, struct http_msg *msg, struct hdr_idx
        case HTTP_MSG_RQURI:
        case HTTP_MSG_RQURI_SP:
        case HTTP_MSG_RQVER:
-               ptr = (char *)http_parse_reqline(msg, buf->data, buf->p,
+               ptr = (char *)http_parse_reqline(msg, buf->data,
                                                 state, ptr, end,
                                                 &msg->next, &msg->msg_state);
                if (unlikely(!ptr))
@@ -1608,7 +1610,7 @@ static int http_upgrade_v09_to_v10(struct buffer *req, struct http_msg *msg, str
        delta = buffer_replace2(req, cur_end, cur_end, " HTTP/1.0\r\n", 11);
        http_msg_move_end(msg, delta);
        cur_end += delta;
-       cur_end = (char *)http_parse_reqline(msg, req->data, req->p,
+       cur_end = (char *)http_parse_reqline(msg, req->data,
                                             HTTP_MSG_RQMETH,
                                             msg->sol, cur_end + 1,
                                             NULL, NULL);
@@ -5679,7 +5681,7 @@ int apply_filter_to_req_line(struct session *t, struct buffer *req, struct hdr_e
 
                        http_msg_move_end(&txn->req, delta);
                        cur_end += delta;
-                       cur_end = (char *)http_parse_reqline(&txn->req, req->data, req->p,
+                       cur_end = (char *)http_parse_reqline(&txn->req, req->data,
                                                             HTTP_MSG_RQMETH,
                                                             cur_ptr, cur_end + 1,
                                                             NULL, NULL);
@@ -6518,7 +6520,7 @@ int apply_filter_to_sts_line(struct session *t, struct buffer *rtr, struct hdr_e
 
                        http_msg_move_end(&txn->rsp, delta);
                        cur_end += delta;
-                       cur_end = (char *)http_parse_stsline(&txn->rsp, rtr->data, rtr->p,
+                       cur_end = (char *)http_parse_stsline(&txn->rsp, rtr->data,
                                                             HTTP_MSG_RPVER,
                                                             cur_ptr, cur_end + 1,
                                                             NULL, NULL);
@@ -7353,6 +7355,8 @@ void http_init_txn(struct session *s)
        txn->rsp.body_len = 0LL;
        txn->req.msg_state = HTTP_MSG_RQBEFORE; /* at the very beginning of the request */
        txn->rsp.msg_state = HTTP_MSG_RPBEFORE; /* at the very beginning of the response */
+       txn->req.buf = s->req;
+       txn->rsp.buf = s->rep;
 
        txn->auth.method = HTTP_AUTH_UNKNOWN;
 
index 86aa28c7cbd444a94cf9fcae257eef0c13f62141..ac8a8cc7c63c8a1ad2c0abfb566a301c26a674b9 100644 (file)
@@ -217,22 +217,6 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
        if (unlikely(fcntl(cfd, F_SETFL, O_NONBLOCK) == -1))
                goto out_free_task;
 
-       txn = &s->txn;
-       /* Those variables will be checked and freed if non-NULL in
-        * session.c:session_free(). It is important that they are
-        * properly initialized.
-        */
-       txn->sessid = NULL;
-       txn->srv_cookie = NULL;
-       txn->cli_cookie = NULL;
-       txn->uri = NULL;
-       txn->req.cap = NULL;
-       txn->rsp.cap = NULL;
-       txn->hdr_idx.v = NULL;
-       txn->hdr_idx.size = txn->hdr_idx.used = 0;
-       txn->req.flags = 0;
-       txn->rsp.flags = 0;
-
        if (unlikely((s->req = pool_alloc2(pool2_buffer)) == NULL))
                goto out_free_task; /* no memory */
 
@@ -275,6 +259,25 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
        s->rep->wex = TICK_ETERNITY;
        s->rep->analyse_exp = TICK_ETERNITY;
 
+       txn = &s->txn;
+       /* Those variables will be checked and freed if non-NULL in
+        * session.c:session_free(). It is important that they are
+        * properly initialized.
+        */
+       txn->sessid = NULL;
+       txn->srv_cookie = NULL;
+       txn->cli_cookie = NULL;
+       txn->uri = NULL;
+       txn->req.cap = NULL;
+       txn->rsp.cap = NULL;
+       txn->hdr_idx.v = NULL;
+       txn->hdr_idx.size = txn->hdr_idx.used = 0;
+       txn->req.flags = 0;
+       txn->rsp.flags = 0;
+       /* the HTTP messages need to know what buffer they're associated with */
+       txn->req.buf = s->req;
+       txn->rsp.buf = s->rep;
+
        /* finish initialization of the accepted file descriptor */
        fd_insert(cfd);
        fdtab[cfd].owner = &s->si[0];