MEDIUM: http: add a pointer to the buffer in http_msg

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
diff --git a/include/types/proto_http.h b/include/types/proto_http.h
index 5df00bd..2c8b876 100644
--- a/include/types/proto_http.h
+++ b/include/types/proto_http.h
@@ -307,6 +307,7 @@
 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 */
diff --git a/src/proto_http.c b/src/proto_http.c
index 0f5a509..5fbf68f 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -951,10 +951,11 @@
  * 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 @@
  * 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 @@
 	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 @@
 	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 @@
 	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 @@
 
 			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 @@
 
 			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 @@
 	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;
 
diff --git a/src/session.c b/src/session.c
index 86aa28c..ac8a8cc 100644
--- a/src/session.c
+++ b/src/session.c
@@ -217,22 +217,6 @@
 	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 @@
 	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];