[MINOR] store HTTP error messages into a chunk array

HTTP error messages were all specific cases handled by an IF.
Now they are all in an array so that it will be easier to add
new ones. Also, the return functions now use chunks as inputs
so that it should be easier to provide alternative return
messages if needed.
diff --git a/include/proto/buffers.h b/include/proto/buffers.h
index a5ad208..ca88b16 100644
--- a/include/proto/buffers.h
+++ b/include/proto/buffers.h
@@ -22,6 +22,8 @@
 #ifndef _PROTO_BUFFERS_H
 #define _PROTO_BUFFERS_H
 
+#include <stdlib.h>
+
 #include <common/config.h>
 #include <types/buffers.h>
 
@@ -84,6 +86,21 @@
 int buffer_replace(struct buffer *b, char *pos, char *end, char *str);
 int buffer_replace2(struct buffer *b, char *pos, char *end, char *str, int len);
 
+/*
+ * frees the destination chunk if already allocated, allocates a new string,
+ * and copies the source into it. The pointer to the destination string is
+ * returned, or NULL if the allocation fails or if any pointer is NULL..
+ */
+static inline char *chunk_dup(struct chunk *dst, const struct chunk *src) {
+	if (!dst || !src || !src->str)
+		return NULL;
+	if (dst->str)
+		free(dst->str);
+	dst->len = src->len;
+	dst->str = (char *)malloc(dst->len);
+	memcpy(dst->str, src->str, dst->len);
+	return dst->str;
+}
 
 #endif /* _PROTO_BUFFERS_H */
 
diff --git a/include/proto/httperr.h b/include/proto/httperr.h
new file mode 100644
index 0000000..24a0cd1
--- /dev/null
+++ b/include/proto/httperr.h
@@ -0,0 +1,41 @@
+/*
+  include/proto/httperr.h
+  This file contains declarations for HTTP responses and errors.
+
+  Copyright (C) 2000-2006 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
+  License as published by the Free Software Foundation, version 2.1
+  exclusively.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef _PROTO_HTTPERR_H
+#define _PROTO_HTTPERR_H
+
+#include <types/httperr.h>
+
+extern const int http_err_codes[HTTP_ERR_SIZE];
+extern const char *http_err_msgs[HTTP_ERR_SIZE];
+extern const char *HTTP_200;
+extern const char *HTTP_302;
+extern const char *HTTP_303;
+extern const char *HTTP_401_fmt;
+
+#endif /* _PROTO_HTTPERR_H */
+
+/*
+ * Local variables:
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ * End:
+ */
diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h
index 61d58c2..5ee3a53 100644
--- a/include/proto/proto_http.h
+++ b/include/proto/proto_http.h
@@ -40,10 +40,10 @@
 int process_cli(struct session *t);
 int process_srv(struct session *t);
 
-void client_retnclose(struct session *s, int len, const char *msg);
-void client_return(struct session *s, int len, const char *msg);
+void client_retnclose(struct session *s, const struct chunk *msg);
+void client_return(struct session *s, const struct chunk *msg);
 void srv_close_with_err(struct session *t, int err, int finst,
-			int status, int msglen, const char *msg);
+			int status, const struct chunk *msg);
 
 int produce_content(struct session *s);
 void debug_hdr(const char *dir, struct session *t, const char *start, const char *end);
diff --git a/include/types/httperr.h b/include/types/httperr.h
index c594048..c466328 100644
--- a/include/types/httperr.h
+++ b/include/types/httperr.h
@@ -32,6 +32,19 @@
 #define DATA_ST_INIT	0
 #define DATA_ST_DATA	1
 
+/*
+ * All implemented return codes
+ */
+enum {
+	HTTP_ERR_400 = 0,
+	HTTP_ERR_403,
+	HTTP_ERR_408,
+	HTTP_ERR_500,
+	HTTP_ERR_502,
+	HTTP_ERR_503,
+	HTTP_ERR_504,
+	HTTP_ERR_SIZE
+};
 
 
 #endif /* _TYPES_HTTPERR_H */
diff --git a/include/types/proxy.h b/include/types/proxy.h
index a82f195..8480143 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -34,6 +34,7 @@
 #include <common/regex.h>
 
 #include <types/buffers.h>
+#include <types/httperr.h>
 #include <types/session.h>
 #include <types/server.h>
 
@@ -125,22 +126,7 @@
 	int grace;				/* grace time after stop request */
 	char *check_req;			/* HTTP or SSL request to use for PR_O_HTTP_CHK|PR_O_SSL3_CHK */
 	int check_len;				/* Length of the HTTP or SSL3 request */
-	struct {
-		char *msg400;			/* message for error 400 */
-		int len400;			/* message length for error 400 */
-		char *msg403;			/* message for error 403 */
-		int len403;			/* message length for error 403 */
-		char *msg408;			/* message for error 408 */
-		int len408;			/* message length for error 408 */
-		char *msg500;			/* message for error 500 */
-		int len500;			/* message length for error 500 */
-		char *msg502;			/* message for error 502 */
-		int len502;			/* message length for error 502 */
-		char *msg503;			/* message for error 503 */
-		int len503;			/* message length for error 503 */
-		char *msg504;			/* message for error 504 */
-		int len504;			/* message length for error 504 */
-	} errmsg;
+	struct chunk errmsg[HTTP_ERR_SIZE];	/* default or customized error messages for known errors */
 };
 
 extern struct proxy *proxy;