[MAJOR] remove files distributed under an obscure license

src/chtbl.c, src/hashpjw.c and src/list.c are distributed under
an obscure license. While Aleks and I believe that this license
is OK for haproxy, other people think it is not compatible with
the GPL.

Whether it is or not is not the problem. The fact that it rises
a doubt is sufficient for this problem to be addressed. Arnaud
Cornet rewrote the unclear parts with clean GPLv2 and LGPL code.
The hash algorithm has changed too and the code has been slightly
simplified in the process. A lot of care has been taken in order
to respect the original API as much as possible, including the
LGPL for the exportable parts.

The new code has not been thoroughly tested but it looks OK now.
diff --git a/include/common/appsession.h b/include/common/appsession.h
index 4687298..e77396c 100644
--- a/include/common/appsession.h
+++ b/include/common/appsession.h
@@ -1,15 +1,14 @@
 #ifndef _COMMON_APPSESS_H
 #define _COMMON_APPSESS_H
 
-#define TBLSIZ 10
-#define TBLCHKINT 5000 /* The time between two calls of appsession_refresh in ms */
+/*
+ * The time between two calls of appsession_refresh in ms.
+ */
+#define TBLCHKINT 5000
 
 #include <sys/time.h>
 
-#include <common/chtbl.h>
 #include <common/config.h>
-#include <common/hashpjw.h>
-#include <common/list.h>
 #include <common/memory.h>
 
 #include <types/task.h>
@@ -19,6 +18,7 @@
 	char *serverid;
 	struct timeval expire;		/* next expiration time for this application session */
 	unsigned long int request_count;
+	struct list hash_list;
 } appsess;
 
 extern struct pool_head *pool2_appsess;
@@ -36,11 +36,7 @@
 int match_str(const void *key1, const void *key2);
 
 /* Callback for destroy */
-void destroy(void *data);
-
-#if defined(DEBUG_HASH)
-static void print_table(const CHTbl *htbl);
-#endif
+void destroy(appsess *data);
 
 void appsession_refresh(struct task *t, struct timeval *next);
 int appsession_task_init(void);
diff --git a/include/common/chtbl.h b/include/common/chtbl.h
deleted file mode 100644
index cddb207..0000000
--- a/include/common/chtbl.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
-  This File is copied from
-  
-  http://www.oreilly.com/catalog/masteralgoc/index.html
-  Mastering Algorithms with C
-  By Kyle Loudon
-  ISBN: 1-56592-453-3
-  Publishd by O'Reilly
-  
- */
-
-/*****************************************************************************
-*                                                                            *
-*  ------------------------------- chtbl.h --------------------------------  *
-*                                                                            *
-*****************************************************************************/
-
-#ifndef _COMMON_CHTBL_H
-#define _COMMON_CHTBL_H
-
-#include <stdlib.h>
-
-#include <common/config.h>
-#include <common/list.h>
-
-/*****************************************************************************
-*                                                                            *
-*  Define a structure for chained hash tables.                               *
-*                                                                            *
-*****************************************************************************/
-
-typedef struct CHTbl_ {
-
-  int                buckets;
-
-  int                (*h)(const void *key);
-  int                (*match)(const void *key1, const void *key2);
-  void               (*destroy)(void *data);
-
-  int                size;
-  List               *table;
-} CHTbl;
-
-/*****************************************************************************
- *                                                                            *
- *  --------------------------- Public Interface ---------------------------  *
- *                                                                            *
- *****************************************************************************/
-
-int chtbl_init(CHTbl *htbl, int buckets, int (*h)(const void *key), int
-	       (*match)(const void *key1, const void *key2), void (*destroy)(void *data));
-
-void chtbl_destroy(CHTbl *htbl);
-
-int chtbl_insert(CHTbl *htbl, const void *data);
-
-int chtbl_remove(CHTbl *htbl, void **data);
-
-int chtbl_lookup(const CHTbl *htbl, void **data);
-
-#define chtbl_size(htbl) ((htbl)->size)
-
-#endif /* _COMMON_CHTBL_H */
-
diff --git a/include/common/hashpjw.h b/include/common/hashpjw.h
deleted file mode 100644
index 8d3998c..0000000
--- a/include/common/hashpjw.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
-  This File is copied from
-  
-  http://www.oreilly.com/catalog/masteralgoc/index.html
-  Mastering Algorithms with C
-  By Kyle Loudon
-  ISBN: 1-56592-453-3
-  Publishd by O'Reilly
-
-  We have added our own struct to these function.
- */
-
-/*****************************************************************************
-*                                                                            *
-*  ------------------------------- hashpjw.h ------------------------------  *
-*                                                                            *
-*****************************************************************************/
-
-#ifndef _COMMON_HASHPJW_H
-#define _COMMON_HASHPJW_H
-
-#include <common/config.h>
-
-/*****************************************************************************
-*                                                                            *
-*  Define a table size for demonstration purposes only.                      *
-*                                                                            *
-*****************************************************************************/
-
-#define            PRIME_TBLSIZ       1699
-
-/*****************************************************************************
-*                                                                            *
-*  --------------------------- Public Interface ---------------------------  *
-*                                                                            *
-*****************************************************************************/
-
-int hashpjw(const void *key);
-
-#endif /* _COMMON_HASHPJW_H */
diff --git a/include/common/list.h b/include/common/list.h
deleted file mode 100644
index 91a5084..0000000
--- a/include/common/list.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
-  This File is copied from
-  
-  http://www.oreilly.com/catalog/masteralgoc/index.html
-  Mastering Algorithms with C
-  By Kyle Loudon
-  ISBN: 1-56592-453-3
-  Publishd by O'Reilly
-  
- */
-
-/*****************************************************************************
-*                                                                            *
-*  -------------------------------- list.h --------------------------------  *
-*                                                                            *
-*****************************************************************************/
-
-#ifndef _COMMON_LIST_H
-#define _COMMON_LIST_H
-
-#include <stdlib.h>
-#include <common/config.h>
-
-/*****************************************************************************
- *                                                                            *
- *  Define a structure for linked list elements.                              *
- *                                                                            *
- *****************************************************************************/
-
-typedef struct ListElmt_ {
-	void               *data;
-	struct ListElmt_   *next;
-} ListElmt;
-
-/*****************************************************************************
- *                                                                            *
- *  Define a structure for linked lists.                                      *
- *                                                                            *
- *****************************************************************************/
-
-typedef struct List_ {
-	int                size;
-	int                (*match)(const void *key1, const void *key2);
-	void               (*destroy)(void *data);
-  
-	ListElmt           *head;
-	ListElmt           *tail;
-} List;
-
-/*****************************************************************************
- *                                                                            *
- *  --------------------------- Public Interface ---------------------------  *
- *                                                                            *
- *****************************************************************************/
-
-void list_init(List *list, void (*destroy)(void *data));
-
-void list_destroy(List *list);
-
-int list_ins_next(List *list, ListElmt *element, const void *data);
-
-int list_rem_next(List *list, ListElmt *element, void **data);
-
-#define list_size(list) ((list)->size)
-
-#define list_head(list) ((list)->head)
-
-#define list_tail(list) ((list)->tail)
-
-#define list_is_head(list, element) ((element) == (list)->head ? 1 : 0)
-
-#define list_is_tail(element) ((element)->next == NULL ? 1 : 0)
-
-#define list_data(element) ((element)->data)
-
-#define list_next(element) ((element)->next)
-
-#endif /* _COMMON_LIST_H */
-
-/*
- * Local variables:
- *  c-indent-level: 8
- *  c-basic-offset: 8
- * End:
- */
diff --git a/include/common/sessionhash.h b/include/common/sessionhash.h
new file mode 100644
index 0000000..da5fde0
--- /dev/null
+++ b/include/common/sessionhash.h
@@ -0,0 +1,62 @@
+#ifndef SESSION_HASH_H
+#define SESSION_HASH_H
+
+/*
+ * HashTable functions.
+ *
+ * Copyright 2007 Arnaud Cornet
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License, version 2.1 as published by the Free Software Foundation.
+ *
+ */
+
+#include <common/appsession.h>
+
+#ifndef TABLESHIFT
+#define TABLESHIFT 11
+#endif
+#define TABLESIZE (1UL << TABLESHIFT)
+#define TABLEMASK (TABLESIZE - 1)
+
+/*
+ * quick and dirty AppSession hash table, using sessid as key
+ */
+
+struct appsession_hash
+{
+	struct list *table;
+	void (*destroy)(appsess *);
+};
+
+unsigned int appsession_hash_f(char *);
+int appsession_hash_init(struct appsession_hash *hash,
+		void(*destroy)(appsess*));
+void appsession_hash_insert(struct appsession_hash *hash,
+		struct appsessions *session);
+struct appsessions *appsession_hash_lookup(struct appsession_hash *hash,
+		char *key);
+void appsession_hash_remove(struct appsession_hash *hash,
+		struct appsessions *session);
+
+void appsession_hash_destroy(struct appsession_hash *hash);
+#if defined(DEBUG_HASH)
+void appsession_hash_dump(struct appsession_hash *hash);
+#endif
+
+/*
+ * Iterates <item> through a hashtable of items of type "typeof(*item)"
+ * A pointer to the appsession_hash is passed in <hash>. The hash table
+ * internaly uses <list_head> member of the struct. A temporary variable <back>
+ * of same type as <item> is needed so that <item> may safely be deleted if
+ * needed.  <idx> is a variable containing <item>'s current bucket index in the
+ * hash table.
+ * Example: as_hash_for_each_entry_safe(idx, item, tmp, &hash, hash_list)
+ * { ... }
+ */
+#define as_hash_for_each_entry_safe(idx, item, back, hash, member) \
+	 for (idx = 0; idx < TABLESIZE; idx++)                          \
+		list_for_each_entry_safe(item, back, &((hash)->table[idx]), member)
+
+#endif /* SESSION_HASH_H */