Index: libfdproto/fdproto-internal.h
===================================================================
--- libfdproto/fdproto-internal.h	(revision 1085)
+++ libfdproto/fdproto-internal.h	(revision 1088)
@@ -48,7 +48,4 @@
 void fd_sess_fini(void);
 
-/* Where debug messages are sent */
-extern FILE * fd_g_debug_fstr;
-
 /* Iterator on the rules of a parent object */
 int fd_dict_iterate_rules ( struct dict_object *parent, void * data, int (*cb)(void *, struct dict_rule_data *) );
Index: libfdproto/init.c
===================================================================
--- libfdproto/init.c	(revision 974)
+++ libfdproto/init.c	(revision 1088)
@@ -58,7 +58,4 @@
 	}
 	
-	/* Set the debug stream */
-	fd_g_debug_fstr = stdout;
-	
 	/* Initialize the modules that need it */
 	fd_msg_eteid_init();
Index: libfdproto/log.c
===================================================================
--- libfdproto/log.c	(revision 1085)
+++ libfdproto/log.c	(revision 1088)
@@ -38,9 +38,7 @@
 #include <stdarg.h>
 
-FILE * fd_g_debug_fstr;
-
 pthread_mutex_t fd_log_lock = PTHREAD_MUTEX_INITIALIZER;
 pthread_key_t	fd_log_thname;
-int fd_g_debug_lvl = INFO;
+int fd_g_debug_lvl = FD_LOG_NOTICE;
 
 static void fd_internal_logger( int, const char *, va_list );
@@ -88,14 +86,14 @@
 
 
-static void fd_internal_logger( int loglevel, const char *format, va_list ap )
+static void fd_internal_logger( int printlevel, const char *format, va_list ap )
 {
     char buf[25];
-    FILE *fstr = fd_g_debug_fstr ?: stdout;
-    int local_use_color = 0;
-
-    /* logging has been decided by macros outside already */
+
+    /* Do we need to trace this ? */
+    if (printlevel < fd_g_debug_lvl)
+    	return;
 
     /* add timestamp */
-    fprintf(fstr, "%s  ", fd_log_time(NULL, buf, sizeof(buf)));
+    printf("%s  ", fd_log_time(NULL, buf, sizeof(buf)));
     
     /* Use colors on stdout ? */
@@ -107,20 +105,18 @@
     }
     
-    /* now, this time log, do we use colors? */
-    if ((fstr == stdout) && (use_colors == 1))
-	    local_use_color = 1;
+    switch(printlevel) {
+	    case FD_LOG_ANNOYING:  printf("%s	A   ", (use_colors == 1) ? "\e[0;37m" : ""); break;
+	    case FD_LOG_DEBUG:     printf("%s DBG   ", (use_colors == 1) ? "\e[0;37m" : ""); break;
+	    case FD_LOG_NOTICE:    printf("%sNOTI   ", (use_colors == 1) ? "\e[1;37m" : ""); break;
+	    case FD_LOG_ERROR:     printf("%sERROR  ", (use_colors == 1) ? "\e[0;31m" : ""); break;
+	    case FD_LOG_FATAL:     printf("%sFATAL! ", (use_colors == 1) ? "\e[0;31m" : ""); break;
+	    default:               printf("%s ???   ", (use_colors == 1) ? "\e[0;31m" : "");
+    }
+    vprintf(format, ap);
+    if (use_colors == 1)
+	     printf("\e[00m");
+    printf("\n");
     
-    switch(loglevel) {
-	    case FD_LOG_DEBUG:  fprintf(fstr, "%s DBG   ", local_use_color ? "\e[0;37m" : ""); break;
-	    case FD_LOG_NOTICE: fprintf(fstr, "%sNOTI   ", local_use_color ? "\e[1;37m" : ""); break;
-	    case FD_LOG_ERROR:  fprintf(fstr, "%sERROR  ", local_use_color ? "\e[0;31m" : ""); break;
-	    default:            fprintf(fstr, "%s ???   ", local_use_color ? "\e[0;31m" : "");
-    }
-    vfprintf(fstr, format, ap);
-    if (local_use_color)
-	     fprintf(fstr, "\e[00m");
-    fprintf(fstr, "\n");
-    
-    fflush(fstr);
+    fflush(stdout);
 }
 
@@ -212,4 +208,16 @@
 
 
+static size_t sys_mempagesz = 0;
+
+static size_t get_mempagesz(void) {
+	if (!sys_mempagesz) {
+		sys_mempagesz = sysconf(_SC_PAGESIZE); /* We alloc buffer by memory pages for efficiency */
+		if (sys_mempagesz <= 0)
+			sys_mempagesz = 1024; /* default size if above call failed */
+	}
+	return sys_mempagesz;
+}
+
+
 /* Helper function for fd_*_dump. Prints the format string from 'offset' into '*buf', extends if needed. The location of buf can be updated by this function. */
 char * fd_dump_extend(char ** buf, size_t *len, size_t *offset, const char * format, ... )
@@ -218,11 +226,5 @@
 	int to_write;
 	size_t o = 0;
-	static size_t mempagesz = 0;
-	
-	if (!mempagesz) {
-		mempagesz = sysconf(_SC_PAGESIZE); /* We alloc buffer by memory pages for efficiency */
-		if (mempagesz <= 0)
-			mempagesz = 1024; /* default size if above call failed */
-	}
+	size_t mempagesz = get_mempagesz();
 	
 	/* we do not TRACE_ENTRY this one on purpose */
@@ -258,2 +260,60 @@
 	return *buf;
 }
+
+char * fd_dump_extend_hexdump(char ** buf, size_t *len, size_t *offset, uint8_t *data, size_t datalen, size_t trunc, size_t wrap )
+{
+	int truncated = 0;
+	size_t towrite = 0;
+	size_t o = 0;
+	int i;
+	char * p;
+	size_t mempagesz = get_mempagesz();
+#define TRUNK_MARK "[...]"
+
+	CHECK_PARAMS_DO(buf && len && data, return NULL);
+	
+	if (trunc && (datalen > trunc)) {
+		datalen = trunc;
+		truncated = 1;
+	}
+	
+	towrite = datalen * 2;
+	
+	if (wrap)
+		towrite += datalen / wrap; /* add 1 '\n' every wrap byte */
+	
+	if (truncated)
+		towrite += CONSTSTRLEN(TRUNK_MARK);
+	
+	
+	if (offset)
+		o = *offset;
+	
+	if (*buf == NULL) {
+		/* Directly allocate the size we need */
+		*len = (((towrite + o) / mempagesz) + 1 ) * mempagesz;
+		CHECK_MALLOC_DO(*buf = malloc(*len), return NULL);
+	} else if ((towrite + o) >= *len) {
+		/* There is no room in the buffer, we extend and redo */
+		size_t new_len = (((towrite + o) / mempagesz) + 1) * mempagesz;
+		CHECK_MALLOC_DO(*buf = realloc(*buf, new_len), return NULL);
+		*len = new_len;
+	}
+	
+	p = *buf + o;
+	for (i = 0; i < datalen; i++) {
+		sprintf(p, "%2hhX", data[i]);
+		p+=2;
+		if ((wrap) && ((i+1) % wrap == 0)) {
+			*p++='\n'; *p ='\0'; /* we want to ensure the buffer is always 0-terminated */
+		}
+	}
+	
+	if (truncated)
+		memcpy(p, TRUNK_MARK, CONSTSTRLEN(TRUNK_MARK));
+		
+	if (offset)
+		*offset += towrite;
+	
+	return *buf;
+}
Index: libfdproto/sessions.c
===================================================================
--- libfdproto/sessions.c	(revision 1085)
+++ libfdproto/sessions.c	(revision 1088)
@@ -69,6 +69,6 @@
 	int		  eyec;	/* An eye catcher also used to ensure the object is valid, must be SH_EYEC */
 	int		  id;	/* A unique integer to identify this handler */
-	void 		(*cleanup)(session_state *, os0_t, void *); /* The cleanup function to be called for cleaning a state */
-	session_state_dump *state_dump; /* dumper function */
+	void 		(*cleanup)(struct sess_state *, os0_t, void *); /* The cleanup function to be called for cleaning a state */
+	session_state_dump state_dump; /* dumper function */
 	void             *opaque; /* a value that is passed as is to the cleanup callback */
 };
@@ -81,5 +81,5 @@
 struct state {
 	int			 eyec;	/* Must be SD_EYEC */
-	session_state		*state;	/* The state registered by the application, never NULL (or the whole object is deleted) */
+	struct sess_state	*state;	/* The state registered by the application, never NULL (or the whole object is deleted) */
 	struct fd_list		 chain;	/* Chaining in the list of session's states ordered by hdl->id */
 	union {
@@ -274,5 +274,5 @@
 
 /* Create a new handler */
-int fd_sess_handler_create_internal ( struct session_handler ** handler, void (*cleanup)(session_state *, os0_t, void *), session_state_dump dumper, void * opaque )
+int fd_sess_handler_create ( struct session_handler ** handler, void (*cleanup)(struct sess_state *, os0_t, void *), session_state_dump dumper, void * opaque )
 {
 	struct session_handler *new;
@@ -720,5 +720,5 @@
 
 /* Save a state information with a session */
-int fd_sess_state_store_internal ( struct session_handler * handler, struct session * session, session_state ** state )
+int fd_sess_state_store ( struct session_handler * handler, struct session * session, struct sess_state ** state )
 {
 	struct state *new;
@@ -773,5 +773,5 @@
 
 /* Get the data back */
-int fd_sess_state_retrieve_internal ( struct session_handler * handler, struct session * session, session_state ** state )
+int fd_sess_state_retrieve ( struct session_handler * handler, struct session * session, struct sess_state ** state )
 {
 	struct fd_list * li;
