REORG: include: split buf.h into haproxy/buf-t.h and haproxy/buf.h

File buf.h is one common cause of pain in the dependencies. Many files in
the code need it to get the struct buffer definition, and a few also need
the inlined functions to manipulate a buffer, but the file used to depend
on a long chain only for BUG_ON() (addressed by last commit).

Now buf.h is split into buf-t.h which only contains the type definitions,
and buf.h for all inlined functions. Callers who don't care can continue
to use buf.h but files in types/ must only use buf-t.h. sys/types.h had
to be added to buf.h to get ssize_t as used by b_move(). It's worth noting
that ssize_t is only supposed to be a size_t supporting -1, so b_move()
ought to be rethought regarding this.

The files were moved to haproxy/ and all their users were updated
accordingly. A dependency issue was addressed on fcgi whose C file didn't
include buf.h.
diff --git a/include/common/buffer.h b/include/common/buffer.h
index d90b94e..6e7adf4 100644
--- a/include/common/buffer.h
+++ b/include/common/buffer.h
@@ -27,7 +27,7 @@
 #include <string.h>
 
 #include <haproxy/api.h>
-#include <common/buf.h>
+#include <haproxy/buf.h>
 #include <common/chunk.h>
 #include <import/ist.h>
 #include <common/istbuf.h>
diff --git a/include/common/chunk.h b/include/common/chunk.h
index d4f9ea2..46dfae7 100644
--- a/include/common/chunk.h
+++ b/include/common/chunk.h
@@ -26,7 +26,7 @@
 #include <string.h>
 
 #include <haproxy/api.h>
-#include <common/buf.h>
+#include <haproxy/buf-t.h>
 #include <import/ist.h>
 #include <common/memory.h>
 
diff --git a/include/common/fcgi.h b/include/common/fcgi.h
index 6d3c6eb..b822a2c 100644
--- a/include/common/fcgi.h
+++ b/include/common/fcgi.h
@@ -25,7 +25,7 @@
 #include <stdio.h>
 #include <haproxy/api.h>
 #include <common/standard.h>
-#include <common/buf.h>
+#include <haproxy/buf-t.h>
 #include <import/ist.h>
 
 /* FCGI protocol version */
diff --git a/include/common/hpack-enc.h b/include/common/hpack-enc.h
index f766063..7d73b35 100644
--- a/include/common/hpack-enc.h
+++ b/include/common/hpack-enc.h
@@ -30,7 +30,7 @@
 
 #include <string.h>
 #include <haproxy/api.h>
-#include <common/buf.h>
+#include <haproxy/buf-t.h>
 #include <common/http.h>
 #include <import/ist.h>
 
diff --git a/include/common/http.h b/include/common/http.h
index 86cf015..0173b7a 100644
--- a/include/common/http.h
+++ b/include/common/http.h
@@ -23,7 +23,7 @@
 #ifndef _COMMON_HTTP_H
 #define _COMMON_HTTP_H
 
-#include <common/buf.h>
+#include <haproxy/buf-t.h>
 #include <import/ist.h>
 
 /*
diff --git a/include/common/htx.h b/include/common/htx.h
index 1a87cde..197ffb6 100644
--- a/include/common/htx.h
+++ b/include/common/htx.h
@@ -24,7 +24,7 @@
 
 #include <stdio.h>
 #include <haproxy/api.h>
-#include <common/buf.h>
+#include <haproxy/buf.h>
 #include <import/ist.h>
 #include <common/http.h>
 #include <common/http-hdr.h>
diff --git a/include/common/istbuf.h b/include/common/istbuf.h
index f9bf0b1..074efe0 100644
--- a/include/common/istbuf.h
+++ b/include/common/istbuf.h
@@ -29,7 +29,7 @@
 #define _COMMON_ISTBUF_H
 
 #include <inttypes.h>
-#include <common/buf.h>
+#include <haproxy/buf.h>
 #include <import/ist.h>
 
 
diff --git a/include/haproxy/buf-t.h b/include/haproxy/buf-t.h
new file mode 100644
index 0000000..cb4310d
--- /dev/null
+++ b/include/haproxy/buf-t.h
@@ -0,0 +1,62 @@
+/*
+ * include/haproxy/buf-t.h
+ * Simple buffer handling - types definitions.
+ *
+ * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _HAPROXY_BUF_T_H
+#define _HAPROXY_BUF_T_H
+
+#include <stddef.h>
+
+/* Structure defining a buffer's head */
+struct buffer {
+	size_t size;                /* buffer size in bytes */
+	char  *area;                /* points to <size> bytes */
+	size_t data;                /* amount of data after head including wrapping */
+	size_t head;                /* start offset of remaining data relative to area */
+};
+
+/* A buffer may be in 3 different states :
+ *   - unallocated : size == 0, area == 0  (b_is_null() is true)
+ *   - waiting     : size == 0, area != 0  (b_is_null() is true)
+ *   - allocated   : size  > 0, area  > 0  (b_is_null() is false)
+ */
+
+/* initializers for certain buffer states. It is important that the NULL buffer
+ * remains the one with all fields initialized to zero so that a calloc() or a
+ * memset() on a struct automatically sets a NULL buffer.
+ */
+#define BUF_NULL   ((struct buffer){ })
+#define BUF_WANTED ((struct buffer){ .area = (char *)1 })
+#define BUF_RING   ((struct buffer){ .area = (char *)2 })
+
+#endif /* _HAPROXY_BUF_T_H */
+
+/*
+ * Local variables:
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ * End:
+ */
diff --git a/include/common/buf.h b/include/haproxy/buf.h
similarity index 95%
rename from include/common/buf.h
rename to include/haproxy/buf.h
index 6ae9a4e..a0e1cb8 100644
--- a/include/common/buf.h
+++ b/include/haproxy/buf.h
@@ -1,8 +1,8 @@
 /*
- * include/common/buf.h
- * Simple buffer handling.
+ * include/haproxy/buf.h
+ * Simple buffer handling - functions definitions.
  *
- * Copyright (C) 2000-2018 Willy Tarreau - w@1wt.eu
+ * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -25,35 +25,13 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-#ifndef _COMMON_BUF_H
-#define _COMMON_BUF_H
+#ifndef _HAPROXY_BUF_H
+#define _HAPROXY_BUF_H
 
+#include <sys/types.h>
 #include <string.h>
-#include <unistd.h>
 #include <haproxy/api.h>
-
-/* Structure defining a buffer's head */
-struct buffer {
-	size_t size;                /* buffer size in bytes */
-	char  *area;                /* points to <size> bytes */
-	size_t data;                /* amount of data after head including wrapping */
-	size_t head;                /* start offset of remaining data relative to area */
-};
-
-/* A buffer may be in 3 different states :
- *   - unallocated : size == 0, area == 0  (b_is_null() is true)
- *   - waiting     : size == 0, area != 0  (b_is_null() is true)
- *   - allocated   : size  > 0, area  > 0  (b_is_null() is false)
- */
-
-/* initializers for certain buffer states. It is important that the NULL buffer
- * remains the one with all fields initialized to zero so that a calloc() or a
- * memset() on a struct automatically sets a NULL buffer.
- */
-#define BUF_NULL   ((struct buffer){ })
-#define BUF_WANTED ((struct buffer){ .area = (char *)1 })
-#define BUF_RING   ((struct buffer){ .area = (char *)2 })
-
+#include <haproxy/buf-t.h>
 
 /***************************************************************************/
 /* Functions used to compute offsets and pointers. Most of them exist in   */
@@ -1034,7 +1012,7 @@
 	return br_head(r);
 }
 
-#endif /* _COMMON_BUF_H */
+#endif /* _HAPROXY_BUF_H */
 
 /*
  * Local variables:
diff --git a/include/proto/h1_htx.h b/include/proto/h1_htx.h
index 13ba394..02b9bdc 100644
--- a/include/proto/h1_htx.h
+++ b/include/proto/h1_htx.h
@@ -23,7 +23,7 @@
 #ifndef _PROTO_H1_HTX_H
 #define _PROTO_H1_HTX_H
 
-#include <common/buf.h>
+#include <haproxy/buf.h>
 #include <import/ist.h>
 #include <common/h1.h>
 
diff --git a/include/proto/http_htx.h b/include/proto/http_htx.h
index edbd8f1..77e4d67 100644
--- a/include/proto/http_htx.h
+++ b/include/proto/http_htx.h
@@ -23,7 +23,7 @@
 #ifndef _PROTO_HTTP_HTX_H
 #define _PROTO_HTTP_HTX_H
 
-#include <common/buf.h>
+#include <haproxy/buf.h>
 #include <import/ist.h>
 #include <common/regex.h>
 
diff --git a/include/types/checks.h b/include/types/checks.h
index 4b81770..6d07c9a 100644
--- a/include/types/checks.h
+++ b/include/types/checks.h
@@ -20,7 +20,7 @@
 #include <import/ist.h>
 #include <common/mini-clist.h>
 #include <common/regex.h>
-#include <common/buf.h>
+#include <haproxy/buf-t.h>
 
 #include <types/connection.h>
 #include <types/obj_type.h>
diff --git a/include/types/http_htx.h b/include/types/http_htx.h
index 02b6b3b..4123e7e 100644
--- a/include/types/http_htx.h
+++ b/include/types/http_htx.h
@@ -25,7 +25,7 @@
 
 #include <import/ebistree.h>
 
-#include <common/buf.h>
+#include <haproxy/buf-t.h>
 #include <common/http.h>
 #include <common/htx.h>
 #include <import/ist.h>
diff --git a/include/types/ring.h b/include/types/ring.h
index f3b3987..f508444 100644
--- a/include/types/ring.h
+++ b/include/types/ring.h
@@ -23,7 +23,7 @@
 #define _TYPES_RING_H
 
 #include <haproxy/api-t.h>
-#include <common/buf.h>
+#include <haproxy/buf-t.h>
 #include <import/ist.h>
 
 /* The code below handles circular buffers with single-producer and multiple
diff --git a/include/types/sample.h b/include/types/sample.h
index 2292b36..bb6b092 100644
--- a/include/types/sample.h
+++ b/include/types/sample.h
@@ -26,7 +26,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 
-#include <common/buf.h>
+#include <haproxy/buf-t.h>
 #include <common/http.h>
 #include <common/mini-clist.h>