[MEDIUM] reference the current hijack function in the buffer itself

Instead of calling a hard-coded function to produce data, let's
reference this function into the buffer and call it from there
when BF_HIJACK is set. This goes in the direction of more generic
session management code.
diff --git a/include/proto/buffers.h b/include/proto/buffers.h
index 536f5a1..bc472a0 100644
--- a/include/proto/buffers.h
+++ b/include/proto/buffers.h
@@ -126,13 +126,21 @@
 	buf->flags |= BF_SHUTR_NOW | BF_SHUTW_NOW;
 }
 
-/* set the buffer to hijacking mode */
-static inline void buffer_start_hijack(struct buffer *buf)
+/* Installs <func> as a hijacker on the buffer <b> for session <s>. The hijack
+ * flag is set, and the function called once. The function is responsible for
+ * clearing the hijack bit. It is possible that the function clears the flag
+ * during this first call.
+ */
+static inline void buffer_install_hijacker(struct session *s,
+					   struct buffer *b,
+					   void (*func)(struct session *, struct buffer *))
 {
-	buf->flags |= BF_HIJACK;
+	b->hijacker = func;
+	b->flags |= BF_HIJACK;
+	func(s, b);
 }
 
-/* releases the buffer from hijacking mode */
+/* Releases the buffer from hijacking mode. Often used by the hijack function */
 static inline void buffer_stop_hijack(struct buffer *buf)
 {
 	buf->flags &= ~BF_HIJACK;
diff --git a/include/proto/dumpstats.h b/include/proto/dumpstats.h
index a7c5ab4..bc6bdad 100644
--- a/include/proto/dumpstats.h
+++ b/include/proto/dumpstats.h
@@ -45,7 +45,7 @@
 #define STATS_ST_CLOSE 3
 
 int stats_dump_raw(struct session *s, struct uri_auth *uri);
-int stats_dump_raw_to_buffer(struct session *s, struct buffer *req);
+void stats_dump_raw_to_buffer(struct session *s, struct buffer *req);
 int stats_dump_http(struct session *s, struct uri_auth *uri);
 int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri);
 
diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h
index c723651..41f1922 100644
--- a/include/proto/proto_http.h
+++ b/include/proto/proto_http.h
@@ -66,7 +66,7 @@
 int http_process_request_body(struct session *s, struct buffer *req);
 int process_response(struct session *t);
 
-int produce_content(struct session *s);
+void produce_content(struct session *s, struct buffer *rep);
 int produce_content_stats(struct session *s);
 int produce_content_stats_proxy(struct session *s, struct proxy *px);
 void debug_hdr(const char *dir, struct session *t, const char *start, const char *end);
diff --git a/include/types/buffers.h b/include/types/buffers.h
index 665c75d..3c79a4e 100644
--- a/include/types/buffers.h
+++ b/include/types/buffers.h
@@ -80,7 +80,7 @@
  * it is strictly forbidden for the stream interface to send anything from the
  * buffer.
  */
-#define BF_HIJACK         0x040000  /* the producer is temporarily replaced */
+#define BF_HIJACK         0x040000  /* the producer is temporarily replaced by ->hijacker */
 #define BF_ANA_TIMEOUT    0x080000  /* the analyser timeout has expired */
 #define BF_READ_ATTACHED  0x100000  /* the read side is attached for the first time */
 
@@ -116,6 +116,9 @@
 	int len;	/* size of the string from first to last char. <0 = uninit. */
 };
 
+/* needed for a declaration below */
+struct session;
+
 struct buffer {
 	unsigned int flags;             /* BF_* */
 	int rex;                        /* expiration date for a read, in ticks */
@@ -128,6 +131,7 @@
 	char *rlim;                     /* read limit, used for header rewriting */
 	unsigned int analysers;         /* bit field indicating what to do on the buffer */
 	int analyse_exp;                /* expiration date for current analysers (if set) */
+	void (*hijacker)(struct session *, struct buffer *); /* alternative content producer */
 	unsigned char xfer_large;       /* number of consecutive large xfers */
 	unsigned char xfer_small;       /* number of consecutive small xfers */
 	unsigned long long total;       /* total data read */