Index: include/freeDiameter/CMakeLists.txt
===================================================================
--- include/freeDiameter/CMakeLists.txt	(revision 1)
+++ include/freeDiameter/CMakeLists.txt	(revision 8)
@@ -72,4 +72,7 @@
 CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
 
+# signalent.h ? -- found in strace distrib; just for nice signal names...
+CHECK_INCLUDE_FILES (signalent.h HAVE_SIGNALENT_H)
+
 # The default configuration file name
 IF (NOT DEFAULT_CONF_FILE)
Index: include/freeDiameter/extension.h
===================================================================
--- include/freeDiameter/extension.h	(revision 8)
+++ include/freeDiameter/extension.h	(revision 8)
@@ -0,0 +1,63 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
+*													 *
+* Copyright (c) 2009, WIDE Project and NICT								 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the WIDE Project or NICT nor the 						 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of WIDE Project and 						 *
+*   NICT.												 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+
+#ifndef _EXTENSION_H
+#define _EXTENSION_H
+
+/* Include definition of freeDiameter API */
+#include <freeDiameter/freeDiameter-host.h>
+#include <freeDiameter/freeDiameter.h>
+
+/* Macro that define the entry point of the extension */
+#define EXTENSION_ENTRY(_name, _function)						\
+static int extension_loaded = 0;							\
+int fd_ext_init(int major, int minor, char * conffile) {				\
+	if ((major != FD_PROJECT_VERSION_MAJOR)						\
+		|| (minor != FD_PROJECT_VERSION_MINOR)) {				\
+		fprintf(stderr, "This extension (" _name ") was compiled for a different version of freeDiameter.\n");	\
+		TRACE_DEBUG(INFO, "daemon %d.%d != ext %d.%d",				\
+			major, minor,							\
+			FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR);		\
+		return EINVAL;								\
+	}										\
+	if (extension_loaded) {								\
+		fprintf(stderr, "Extension (" _name ") cannot be loaded twice!\n");	\
+		return ENOTSUP;								\
+	}										\
+	extension_loaded++;								\
+	return (_function)(conffile);							\
+}														
+
+#endif /* _EXTENSION_H */
Index: include/freeDiameter/freeDiameter-host.h.in
===================================================================
--- include/freeDiameter/freeDiameter-host.h.in	(revision 1)
+++ include/freeDiameter/freeDiameter-host.h.in	(revision 8)
@@ -40,4 +40,5 @@
 #cmakedefine HAVE_NTOHLL
 #cmakedefine HAVE_MALLOC_H
+#cmakedefine HAVE_SIGNALENT_H
 
 #cmakedefine HOST_BIG_ENDIAN @HOST_BIG_ENDIAN@
@@ -45,10 +46,24 @@
 #cmakedefine DISABLE_SCTP
 
-#cmakedefine PROJECT_NAME "@PROJECT_NAME@"
-#cmakedefine CMAKE_PROJECT_NAME "@CMAKE_PROJECT_NAME@"
-#cmakedefine PROJECT_VERSION "@PROJECT_VERSION@"
-#cmakedefine PROJECT_COPYRIGHT "@PROJECT_COPYRIGHT@"
+#cmakedefine FD_PROJECT_BINARY "@FD_PROJECT_BINARY@"
+#cmakedefine FD_PROJECT_NAME "@FD_PROJECT_NAME@"
+#cmakedefine FD_PROJECT_VERSION_MAJOR @FD_PROJECT_VERSION_MAJOR@
+#ifndef FD_PROJECT_VERSION_MAJOR
+# define FD_PROJECT_VERSION_MAJOR 0
+#endif /*FD_PROJECT_VERSION_MAJOR*/
+#cmakedefine FD_PROJECT_VERSION_MINOR @FD_PROJECT_VERSION_MINOR@
+#ifndef FD_PROJECT_VERSION_MINOR
+# define FD_PROJECT_VERSION_MINOR 0
+#endif /*FD_PROJECT_VERSION_MINOR*/
+#cmakedefine FD_PROJECT_VERSION_REV   @FD_PROJECT_VERSION_REV@
+#ifndef FD_PROJECT_VERSION_REV
+# define FD_PROJECT_VERSION_REV 0
+#endif /*FD_PROJECT_VERSION_REV*/
+/* HG_VERSION */
+/* PACKAGE_HG_REVISION */
+#cmakedefine FD_PROJECT_COPYRIGHT "@FD_PROJECT_COPYRIGHT@"
 
 #cmakedefine DEFAULT_CONF_FILE "@DEFAULT_CONF_FILE@"
 
+
 #endif /* FD_IS_CONFIG */
Index: include/freeDiameter/freeDiameter.h
===================================================================
--- include/freeDiameter/freeDiameter.h	(revision 7)
+++ include/freeDiameter/freeDiameter.h	(revision 8)
@@ -41,7 +41,75 @@
 
 
-/* The global dictionary */
-extern struct dictionary * fd_g_dict;
-
+/* Structure to hold the configuration of the freeDiameter daemon */
+struct fd_config {
+	int		 eyec;		/* Eye catcher: EYEC_CONFIG */
+	char		*conf_file;	/* Configuration file to parse, default is DEFAULT_CONF_FILE */
+	
+	char   		*diam_id;	/* Diameter Identity of the local peer (FQDN -- UTF-8) */
+	size_t		 diam_id_len;	/* length of the previous string */
+	char		*diam_realm;	/* Diameter realm of the local peer, default to realm part of diam_id */
+	size_t		 diam_realm_len;/* length of the previous string */
+	
+	uint16_t	 loc_port;	/* the local port for legacy Diameter (default: 3868) in host byte order */
+	uint16_t	 loc_port_tls;	/* the local port for Diameter/TLS (default: 3869) in host byte order */
+	uint16_t	 loc_sctp_str;	/* default max number of streams for SCTP associations (def: 30) */
+	struct fd_list	 loc_endpoints;	/* the local endpoints to bind the server to. list of struct fd_endpoint. default is empty (bind all) */
+	struct {
+		unsigned no_ip4 : 1;	/* disable IP */
+		unsigned no_ip6 : 1;	/* disable IPv6 */
+		unsigned no_tcp : 1;	/* disable use of TCP */
+		unsigned no_sctp: 1;	/* disable the use of SCTP */
+		unsigned pr_tcp	: 1;	/* prefer TCP over SCTP */
+		unsigned tls_alg: 1;	/* TLS algorithm for initiated cnx. 0: separate port. 1: inband-security (old) */
+		unsigned no_fwd : 1;	/* the peer does not relay messages (0xffffff app id) */
+	} 		 flags;
+	
+	unsigned int	 timer_tc;	/* The value in seconds of the default Tc timer */
+	unsigned int 	 timer_tw;	/* The value in seconds of the default Tw timer */
+	
+	uint32_t	 or_state_id;	/* The value to use in Origin-State-Id, default to random value */
+	struct dictionary *g_dict;	/* pointer to the global dictionary */
+	struct fifo	  *g_fifo_main;	/* FIFO queue of events in the daemon main (struct fd_event items) */
+};
+
+#define	EYEC_CONFIG	0xC011F16
+
+/* The pointer to access the global configuration, initalized in main */
+extern struct fd_config *fd_g_config;
+
+/* Endpoints */
+struct fd_endpoint {
+	struct fd_list  chain;	/* link in loc_endpoints list */
+	sSS		ss;	/* the socket information. */
+};
+
+/* Events */
+struct fd_event {
+	int	 code; /* codespace depends on the queue */
+	void    *data;
+};
+
+/* send an event */
+static __inline__ int fd_event_send(struct fifo *queue, int code, void * data)
+{
+	struct fd_event * ev;
+	CHECK_MALLOC( ev = malloc(sizeof(struct fd_event)) );
+	ev->code = code;
+	ev->data = data;
+	CHECK_FCT( fd_fifo_post(queue, &ev) );
+	return 0;
+}
+/* receive an event */
+static __inline__ int fd_event_get(struct fifo *queue, int *code, void ** data)
+{
+	struct fd_event * ev;
+	CHECK_FCT( fd_fifo_get(queue, &ev) );
+	if (code)
+		*code = ev->code;
+	if (data)
+		*data = ev->data;
+	free(ev);
+	return 0;
+}
 
 /***************************************/
Index: include/freeDiameter/libfreeDiameter.h
===================================================================
--- include/freeDiameter/libfreeDiameter.h	(revision 7)
+++ include/freeDiameter/libfreeDiameter.h	(revision 8)
@@ -37,8 +37,17 @@
  *
  * This library is meant to be used by both the freeDiameter daemon and its extensions.
- *
  * It provides the tools to manipulate Diameter messages and related data.
- *
  * This file should always be included as #include <freeDiameter/libfreeDiameter.h>
+ *
+ * The file contains the following parts:
+ *	DEBUG
+ *	MACROS
+ *	THREADS
+ *	LISTS
+ *	DICTIONARY
+ *	SESSIONS
+ *	MESSAGES
+ *	DISPATCH
+ *	QUEUES
  */
 
@@ -297,8 +306,8 @@
 #define sSA6	struct sockaddr_in6
 
-/* Dump one sockaddr */
-#define sSA_DUMP( level, text, sa ) {				\
+/* Dump one sockaddr Node information */
+#define sSA_DUMP_NODE( sa, flag ) {				\
 	sSA * __sa = (sSA *)(sa);				\
-	char *__str, __addrbuf[INET6_ADDRSTRLEN];		\
+	char __addrbuf[INET6_ADDRSTRLEN];			\
 	if (__sa) {						\
 	  int __rc = getnameinfo(__sa, 				\
@@ -308,14 +317,14 @@
 			NULL,					\
 			0,					\
-			0);					\
+			flag);					\
 	  if (__rc)						\
-	  	__str = (char *)gai_strerror(__rc);		\
+	  	fd_log_debug((char *)gai_strerror(__rc));	\
 	  else							\
-	  	__str = &__addrbuf[0];				\
+	  	fd_log_debug(&__addrbuf[0]);			\
 	} else {						\
-		__str = "(NULL / ANY)";				\
+		fd_log_debug("(NULL / ANY)");			\
 	}							\
-	TRACE_DEBUG(level, text "%s", __str);			\
 }
+/* if needed, add sSA_DUMP_SERVICE */
 
 /* The sockaddr length of a sSS structure */
@@ -2275,53 +2284,53 @@
 
 /*============================================================*/
-/*                    MESSAGE QUEUES                          */
+/*                     QUEUES                                 */
 /*============================================================*/
 
-/* Management of queues of messages */
-
-/* A message queue is an opaque object */
-struct mqueue;
-
-/*
- * FUNCTION:	fd_mq_new
- *
- * PARAMETERS:
- *  queue	: Upon success, a pointer to the new message queue is saved here.
- *
- * DESCRIPTION: 
- *  Create a new empty message queue.
+/* Management of FIFO queues of elements */
+
+/* A queue is an opaque object */
+struct fifo;
+
+/*
+ * FUNCTION:	fd_fifo_new
+ *
+ * PARAMETERS:
+ *  queue	: Upon success, a pointer to the new queue is saved here.
+ *
+ * DESCRIPTION: 
+ *  Create a new empty queue.
  *
  * RETURN VALUE :
- *  0		: The message queue has been initialized successfully.
+ *  0		: The queue has been initialized successfully.
  *  EINVAL 	: The parameter is invalid.
  *  ENOMEM	: Not enough memory to complete the creation.  
  */
-int fd_mq_new ( struct mqueue ** queue );
-
-/*
- * FUNCTION:	fd_mq_del
- *
- * PARAMETERS:
- *  queue	: Pointer to an empty message queue to delete.
- *
- * DESCRIPTION: 
- *  Destroys a message queue. This is only possible if no thread is waiting for a message,
+int fd_fifo_new ( struct fifo ** queue );
+
+/*
+ * FUNCTION:	fd_fifo_del
+ *
+ * PARAMETERS:
+ *  queue	: Pointer to an empty queue to delete.
+ *
+ * DESCRIPTION: 
+ *  Destroys a queue. This is only possible if no thread is waiting for an element,
  * and the queue is empty.
  *
  * RETURN VALUE:
- *  0		: The message queue has been destroyed successfully.
+ *  0		: The queue has been destroyed successfully.
  *  EINVAL 	: The parameter is invalid.
  */
-int fd_mq_del ( struct mqueue  ** queue );
-
-/*
- * FUNCTION:	fd_mq_length
- *
- * PARAMETERS:
- *  queue	: The queue from which to retrieve the length.
- *  length	: Upon success, the current number of messages in the queue is stored here.
- *
- * DESCRIPTION: 
- *  Retrieve the number of messages pending in a queue.
+int fd_fifo_del ( struct fifo  ** queue );
+
+/*
+ * FUNCTION:	fd_fifo_length
+ *
+ * PARAMETERS:
+ *  queue	: The queue from which to retrieve the number of elements.
+ *  length	: Upon success, the current number of elements in the queue is stored here.
+ *
+ * DESCRIPTION: 
+ *  Retrieve the number of elements in a queue.
  *
  * RETURN VALUE:
@@ -2329,9 +2338,9 @@
  *  EINVAL 	: A parameter is invalid.
  */
-int fd_mq_length ( struct mqueue * queue, int * length );
-int fd_mq_length_noerr ( struct mqueue * queue ); /* alternate with no error checking */
-
-/*
- * FUNCTION:	fd_mq_setthrhd
+int fd_fifo_length ( struct fifo * queue, int * length );
+int fd_fifo_length_noerr ( struct fifo * queue ); /* no error checking version */
+
+/*
+ * FUNCTION:	fd_fifo_setthrhd
  *
  * PARAMETERS:
@@ -2345,11 +2354,11 @@
  * DESCRIPTION: 
  *  This function allows to adjust the number of producer / consumer threads of a queue.
- * If the consumer are slower than the producers, the number of messages in the queue increase.
+ * If the consumer are slower than the producers, the number of elements in the queue increase.
  * By setting a "high" value, we allow a callback to be called when this number is too high.
  * The typical use would be to create an additional consumer thread in this callback.
  * If the queue continues to grow, the callback will be called again when the length is 2 * high, then 3*high, ... N * high
- * (the callback itself may implement a limit on the number of consumers that can be created)
+ * (the callback itself should implement a limit on the number of consumers that can be created)
  * When the queue starts to decrease, and the number of elements go under ((N - 1) * high + low, the l_cb callback is called
- * and would typially stop one of the consumer threads. If the queue continue to reduce, l_cb is again called at (N-2)*high + low,
+ * and would typially stop one of the consumer threads. If the queue continues to reduce, l_cb is again called at (N-2)*high + low,
  * and so on.
  *
@@ -2357,5 +2366,5 @@
  * l_cb when the length of the queue is becoming < low.
  *
- * Note that the callbacks are called synchronously, during fd_mq_post or fd_mq_get. Their operation should be quick.
+ * Note that the callbacks are called synchronously, during fd_fifo_post or fd_fifo_get. Their operation should be quick.
  *
  * RETURN VALUE:
@@ -2363,79 +2372,87 @@
  *  EINVAL 	: A parameter is invalid.
  */
-int fd_mq_setthrhd ( struct mqueue * queue, void * data, uint16_t high, void (*h_cb)(struct mqueue *, void **), uint16_t low, void (*l_cb)(struct mqueue *, void **) );
-
-/*
- * FUNCTION:	fd_mq_post
- *
- * PARAMETERS:
- *  queue	: The queue in which the message must be posted.
- *  msg		: The message that is put in the queue.
- *
- * DESCRIPTION: 
- *  A message is added in a queue. Messages are retrieved from the queue (in FIFO order)
- *  with the fd_mq_get, fd_mq_tryget, or fd_mq_timedget functions.
- *
- * RETURN VALUE:
- *  0		: The message is queued.
+int fd_fifo_setthrhd ( struct fifo * queue, void * data, uint16_t high, void (*h_cb)(struct fifo *, void **), uint16_t low, void (*l_cb)(struct fifo *, void **) );
+
+/*
+ * FUNCTION:	fd_fifo_post
+ *
+ * PARAMETERS:
+ *  queue	: The queue in which the element must be posted.
+ *  item	: The element that is put in the queue.
+ *
+ * DESCRIPTION: 
+ *  An element is added in a queue. Elements are retrieved from the queue in FIFO order
+ *  with the fd_fifo_get, fd_fifo_tryget, or fd_fifo_timedget functions.
+ *
+ * RETURN VALUE:
+ *  0		: The element is queued.
  *  EINVAL 	: A parameter is invalid.
  *  ENOMEM 	: Not enough memory to complete the operation.
  */
-int fd_mq_post ( struct mqueue * queue, struct msg ** msg );
-
-/*
- * FUNCTION:	fd_mq_get
- *
- * PARAMETERS:
- *  queue	: The queue from which the message must be retrieved.
- *  msg		: On return, the first message of the queue is stored here.
- *
- * DESCRIPTION: 
- *  This function retrieves a message from a queue. If the queue is empty, the function will block the 
- * thread until a new message is posted to the queue, or until the thread is canceled (in which case the 
+int fd_fifo_post_int ( struct fifo * queue, void ** item );
+#define fd_fifo_post(queue, item) \
+	fd_fifo_post_int((queue), (void *)(item))
+
+/*
+ * FUNCTION:	fd_fifo_get
+ *
+ * PARAMETERS:
+ *  queue	: The queue from which the first element must be retrieved.
+ *  item	: On return, the first element of the queue is stored here.
+ *
+ * DESCRIPTION: 
+ *  This function retrieves the first element from a queue. If the queue is empty, the function will block the 
+ * thread until a new element is posted to the queue, or until the thread is canceled (in which case the 
  * function does not return).
  *
  * RETURN VALUE:
- *  0		: A new message has been retrieved.
- *  EINVAL 	: A parameter is invalid.
- */
-int fd_mq_get ( struct mqueue * queue, struct msg ** msg );
-
-/*
- * FUNCTION:	fd_mq_tryget
- *
- * PARAMETERS:
- *  queue	: The queue from which the message must be retrieved.
+ *  0		: A new element has been retrieved.
+ *  EINVAL 	: A parameter is invalid.
+ */
+int fd_fifo_get_int ( struct fifo * queue, void ** item );
+#define fd_fifo_get(queue, item) \
+	fd_fifo_get_int((queue), (void *)(item))
+
+/*
+ * FUNCTION:	fd_fifo_tryget
+ *
+ * PARAMETERS:
+ *  queue	: The queue from which the element must be retrieved.
  *  msg		: On return, the message is stored here.
  *
  * DESCRIPTION: 
- *  This function is similar to fd_mq_get, except that it will not block if 
+ *  This function is similar to fd_fifo_get, except that it will not block if 
  * the queue is empty, but return EWOULDBLOCK instead.
  *
  * RETURN VALUE:
- *  0		: A new message has been retrieved.
+ *  0		: A new element has been retrieved.
  *  EINVAL 	: A parameter is invalid.
  *  EWOULDBLOCK : The queue was empty.
  */
-int fd_mq_tryget ( struct mqueue * queue, struct msg ** msg );
-
-/*
- * FUNCTION:	fd_mq_timedget
- *
- * PARAMETERS:
- *  queue	: The queue from which the message must be retrieved.
- *  msg		: On return, the message is stored here.
- *  abstime	: the absolute time until which we allow waiting for a message.
- *
- * DESCRIPTION: 
- *  This function is similar to fd_mq_get, except that it will block if the queue is empty 
+int fd_fifo_tryget_int ( struct fifo * queue, void ** item );
+#define fd_fifo_tryget(queue, item) \
+	fd_fifo_tryget_int((queue), (void *)(item))
+
+/*
+ * FUNCTION:	fd_fifo_timedget
+ *
+ * PARAMETERS:
+ *  queue	: The queue from which the element must be retrieved.
+ *  item	: On return, the element is stored here.
+ *  abstime	: the absolute time until which we allow waiting for an item.
+ *
+ * DESCRIPTION: 
+ *  This function is similar to fd_fifo_get, except that it will block if the queue is empty 
  * only until the absolute time abstime (see pthread_cond_timedwait for + info).
  * If the queue is still empty when the time expires, the function returns ETIMEDOUT
  *
  * RETURN VALUE:
- *  0		: A new message has been retrieved.
- *  EINVAL 	: A parameter is invalid.
- *  ETIMEDOUT   : The time out has passed and no message has been received.
- */
-int fd_mq_timedget ( struct mqueue * queue, struct msg ** msg, const struct timespec *abstime );
+ *  0		: A new item has been retrieved.
+ *  EINVAL 	: A parameter is invalid.
+ *  ETIMEDOUT   : The time out has passed and no item has been received.
+ */
+int fd_fifo_timedget_int ( struct fifo * queue, void ** item, const struct timespec *abstime );
+#define fd_fifo_timedget(queue, item, abstime) \
+	fd_fifo_timedget_int((queue), (void *)(item), (abstime))
 
 #endif /* _LIBFREEDIAMETER_H */
