MEDIUM: shctx: separate ssl and shctx

This patch reorganize the shctx API in a generic storage API, separating
the shared SSL session handling from its core.

The shctx API only handles the generic data part, it does not know what
kind of data you use with it.

A shared_context is a storage structure allocated in a shared memory,
allowing its usage in a multithread or a multiprocess context.

The structure use 2 linked list, one containing the available blocks,
and another for the hot locked blocks. At initialization the available
list is filled with <maxblocks> blocks of size <blocksize>. An <extra>
space is initialized outside the list in case you need some specific
storage.

+-----------------------+--------+--------+--------+--------+----
| struct shared_context | extra  | block1 | block2 | block3 | ...
+-----------------------+--------+--------+--------+--------+----
                                 <--------  maxblocks  --------->
                                            * blocksize

The API allows to store content on several linked blocks. For example,
if you allocated blocks of 16 bytes, and you want to store an object of
60 bytes, the object will be allocated in a row of 4 blocks.

The API was made for LRU usage, each time you get an object, it pushes
the object at the end of the list. When it needs more space, it discards

The functions name have been renamed in a more logical way, the part
regarding shctx have been prefixed by shctx_ and the functions for the
shared ssl session cache have been prefixed by sh_ssl_sess_.
diff --git a/include/types/shctx.h b/include/types/shctx.h
index 6ab6460..afef1a1 100644
--- a/include/types/shctx.h
+++ b/include/types/shctx.h
@@ -1,8 +1,6 @@
 #ifndef __TYPES_SHCTX
 #define __TYPES_SHCTX
 
-#include <openssl/ssl.h> /* shared session depend of openssl */
-
 #ifndef SHSESS_BLOCK_MIN_SIZE
 #define SHSESS_BLOCK_MIN_SIZE 128
 #endif
@@ -18,20 +16,15 @@
 #define SHCTX_E_ALLOC_CACHE -1
 #define SHCTX_E_INIT_LOCK   -2
 
-struct shared_session {
-	struct ebmb_node key;
-	unsigned char key_data[SSL_MAX_SSL_SESSION_ID_LENGTH];
-	unsigned char data[SHSESS_BLOCK_MIN_SIZE];
-};
+#define SHCTX_F_REMOVING 0x1      /* Removing flag, does not accept new */
 
+/* generic shctx struct */
 struct shared_block {
-	union {
-		struct shared_session session;
-		unsigned char data[sizeof(struct shared_session)];
-	} data;
-	short int data_len;
-	struct shared_block *p;
-	struct shared_block *n;
+	struct list list;
+	short int len;          /* data length for the row */
+	short int block_count;  /* number of blocks */
+	unsigned int refcount;
+	unsigned char data[0];
 };
 
 struct shared_context {
@@ -42,10 +35,12 @@
 	unsigned int waiters;
 #endif
 #endif
-	struct shared_block active;
-	struct shared_block free;
+	struct list avail;  /* list for active and free blocks */
+	struct list hot;     /* list for locked blocks */
+	unsigned int nbav;  /* number of available blocks */
+	void (*free_block)(struct shared_block *first, struct shared_block *block);
+	short int block_size;
+	unsigned char data[0];
 };
 
-extern struct shared_context *ssl_shctx;
-
 #endif