REORG: buffers: split buffers into chunk,buffer,channel

Many parts of the channel definition still make use of the "buffer" word.
diff --git a/include/types/arg.h b/include/types/arg.h
index 2762674..666a51f 100644
--- a/include/types/arg.h
+++ b/include/types/arg.h
@@ -24,7 +24,8 @@
 
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <types/buffers.h>
+
+#include <common/chunk.h>
 
 enum {
 	ARGT_STOP = 0, /* end of the arg list */
diff --git a/include/types/buffers.h b/include/types/channel.h
similarity index 89%
rename from include/types/buffers.h
rename to include/types/channel.h
index 200e26c..cd16d9c 100644
--- a/include/types/buffers.h
+++ b/include/types/channel.h
@@ -1,8 +1,8 @@
 /*
- * include/types/buffers.h
- * Buffer management definitions, macros and inline functions.
+ * include/types/channel.h
+ * Channel management definitions, macros and inline functions.
  *
- * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
+ * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,15 +19,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef _TYPES_BUFFERS_H
-#define _TYPES_BUFFERS_H
+#ifndef _TYPES_CHANNEL_H
+#define _TYPES_CHANNEL_H
 
 #include <common/config.h>
-#include <common/memory.h>
+#include <common/chunk.h>
+#include <common/buffer.h>
 #include <types/stream_interface.h>
 
-/* The BF_* macros designate Buffer Flags, which may be ORed in the bit field
- * member 'flags' in struct channel. Here we have several types of flags :
+/* The BF_* macros designate Channel Flags (originally "Buffer Flags"), which
+ * may be ORed in the bit field member 'flags' in struct channel. Here we have
+ * several types of flags :
  *
  *   - pure status flags, reported by the lower layer, which must be cleared
  *     before doing further I/O :
@@ -47,8 +49,8 @@
  *
  * The flags have been arranged for readability, so that the read and write
  * bits have the same position in a byte (read being the lower byte and write
- * the second one). All flag names are relative to the buffer. For instance,
- * 'write' indicates the direction from the buffer to the stream interface.
+ * the second one). All flag names are relative to the channel. For instance,
+ * 'write' indicates the direction from the channel to the stream interface.
  */
 
 #define BF_READ_NULL      0x000001  /* last read detected on producer side */
@@ -57,7 +59,7 @@
 #define BF_READ_ERROR     0x000008  /* unrecoverable error on producer side */
 #define BF_READ_ACTIVITY  (BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR)
 
-#define BF_FULL           0x000010  /* buffer cannot accept any more data (l >= max len) */
+#define BF_FULL           0x000010  /* channel cannot accept any more data (l >= max len) */
 #define BF_SHUTR          0x000020  /* producer has already shut down */
 #define BF_SHUTR_NOW      0x000040  /* the producer must shut down for reads ASAP */
 #define BF_READ_NOEXP     0x000080  /* producer should not expire */
@@ -107,7 +109,7 @@
 #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 */
-#define BF_KERN_SPLICING  0x200000  /* kernel splicing desired for this buffer */
+#define BF_KERN_SPLICING  0x200000  /* kernel splicing desired for this channel */
 #define BF_READ_DONTWAIT  0x400000  /* wake the task up after every read (eg: HTTP request) */
 #define BF_AUTO_CONNECT   0x800000  /* consumer may attempt to establish a new connection */
 
@@ -116,7 +118,7 @@
 #define BF_SEND_DONTWAIT 0x4000000  /* don't wait for sending data (one-shoot) */
 #define BF_NEVER_WAIT    0x8000000  /* never wait for sending data (permanent) */
 
-#define BF_WAKE_ONCE    0x10000000  /* pretend there is activity on this buffer (one-shoot) */
+#define BF_WAKE_ONCE    0x10000000  /* pretend there is activity on this channel (one-shoot) */
 
 /* Use these masks to clear the flags before going back to lower layers */
 #define BF_CLEAR_READ     (~(BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR|BF_READ_ATTACHED))
@@ -130,7 +132,7 @@
 #define BF_MASK_STATIC          (BF_OUT_EMPTY|BF_FULL|BF_SHUTR|BF_SHUTW|BF_SHUTR_NOW|BF_SHUTW_NOW)
 
 
-/* Analysers (buffer->analysers).
+/* Analysers (channel->analysers).
  * Those bits indicate that there are some processing to do on the buffer
  * contents. It will probably evolve into a linked list later. Those
  * analysers could be compared to higher level processors.
@@ -164,24 +166,9 @@
 /* Magic value to forward infinite size (TCP, ...), used with ->to_forward */
 #define BUF_INFINITE_FORWARD    MAX_RANGE(int)
 
-/* describes a chunk of string */
-struct chunk {
-	char *str;	/* beginning of the string itself. Might not be 0-terminated */
-	int size;	/* total size of the buffer, 0 if the *str is read-only */
-	int len;	/* current size of the string from first to last char. <0 = uninit. */
-};
-
 /* needed for a declaration below */
 struct session;
 
-struct buffer {
-	char *p;                        /* buffer's start pointer, separates in and out data */
-	unsigned int size;              /* buffer size in bytes */
-	unsigned int i;                 /* number of input bytes pending for analysis in the buffer */
-	unsigned int o;                 /* number of out bytes the sender can consume from this buffer */
-	char data[0];                   /* <size> bytes */
-};
-
 struct channel {
 	unsigned int flags;             /* BF_* */
 	int rex;                        /* expiration date for a read, in ticks */
@@ -189,14 +176,14 @@
 	int rto;                        /* read timeout, in ticks */
 	int wto;                        /* write timeout, in ticks */
 	unsigned int to_forward;        /* number of bytes to forward after out without a wake-up */
-	unsigned int analysers;         /* bit field indicating what to do on the buffer */
+	unsigned int analysers;         /* bit field indicating what to do on the channel */
 	int analyse_exp;                /* expiration date for current analysers (if set) */
 	void (*hijacker)(struct session *, struct channel *); /* 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 */
-	struct stream_interface *prod;  /* producer attached to this buffer */
-	struct stream_interface *cons;  /* consumer attached to this buffer */
+	struct stream_interface *prod;  /* producer attached to this channel */
+	struct stream_interface *cons;  /* consumer attached to this channel */
 	struct pipe *pipe;		/* non-NULL only when data present */
 	struct buffer buf;		/* embedded buffer for now, will move */
 };
@@ -291,7 +278,7 @@
        long.
  */
 
-#endif /* _TYPES_BUFFERS_H */
+#endif /* _TYPES_CHANNEL_H */
 
 /*
  * Local variables:
diff --git a/include/types/global.h b/include/types/global.h
index b4fa23e..b55481b 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -25,6 +25,7 @@
 #include <netinet/in.h>
 
 #include <common/config.h>
+#include <types/freq_ctr.h>
 #include <types/log.h>
 #include <types/protocols.h>
 #include <types/proxy.h>
diff --git a/include/types/log.h b/include/types/log.h
index 2086860..ac985fc 100644
--- a/include/types/log.h
+++ b/include/types/log.h
@@ -26,6 +26,7 @@
 #include <sys/un.h>
 #include <netinet/in.h>
 #include <common/config.h>
+#include <common/mini-clist.h>
 
 #define MAX_SYSLOG_LEN          1024
 #define NB_LOG_FACILITIES       24
diff --git a/include/types/proto_http.h b/include/types/proto_http.h
index 158f094..665ec75 100644
--- a/include/types/proto_http.h
+++ b/include/types/proto_http.h
@@ -22,9 +22,9 @@
 #ifndef _TYPES_PROTO_HTTP_H
 #define _TYPES_PROTO_HTTP_H
 
+#include <common/chunk.h>
 #include <common/config.h>
 
-#include <types/buffers.h>
 #include <types/hdr_idx.h>
 
 /* These are the flags that are found in txn->flags */
diff --git a/include/types/proxy.h b/include/types/proxy.h
index c93edd2..13a08a5 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -28,6 +28,7 @@
 #include <arpa/inet.h>
 
 #include <common/appsession.h>
+#include <common/chunk.h>
 #include <common/config.h>
 #include <common/mini-clist.h>
 #include <common/regex.h>
@@ -37,7 +38,6 @@
 
 #include <types/acl.h>
 #include <types/backend.h>
-#include <types/buffers.h>
 #include <types/counters.h>
 #include <types/freq_ctr.h>
 #include <types/log.h>
diff --git a/include/types/sample.h b/include/types/sample.h
index b806a12..2f5ce86 100644
--- a/include/types/sample.h
+++ b/include/types/sample.h
@@ -25,8 +25,9 @@
 
 #include <sys/socket.h>
 #include <netinet/in.h>
+
+#include <common/chunk.h>
 #include <types/arg.h>
-#include <types/buffers.h>
 
 /* input and output sample types */
 enum {
@@ -78,6 +79,9 @@
 	SMP_F_VOLATILE   = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */
 };
 
+/* needed below */
+struct session;
+
 /* a sample context might be used by any sample fetch function in order to
  * store information needed across multiple calls (eg: restart point for a
  * next occurrence). By definition it may store up to 8 pointers, or any
diff --git a/include/types/server.h b/include/types/server.h
index c952885..689441c 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -29,7 +29,6 @@
 #include <common/mini-clist.h>
 #include <eb32tree.h>
 
-#include <types/buffers.h>
 #include <types/connection.h>
 #include <types/counters.h>
 #include <types/freq_ctr.h>
diff --git a/include/types/session.h b/include/types/session.h
index 9180a94..cce55a4 100644
--- a/include/types/session.h
+++ b/include/types/session.h
@@ -31,7 +31,7 @@
 #include <common/config.h>
 #include <common/mini-clist.h>
 
-#include <types/buffers.h>
+#include <types/channel.h>
 #include <types/proto_http.h>
 #include <types/proxy.h>
 #include <types/queue.h>
diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h
index 5985619..87f951e 100644
--- a/include/types/stream_interface.h
+++ b/include/types/stream_interface.h
@@ -25,7 +25,7 @@
 #include <stdlib.h>
 #include <sys/socket.h>
 
-#include <types/buffers.h>
+#include <types/channel.h>
 #include <types/connection.h>
 #include <common/config.h>