Index: freeDiameter/main.c
===================================================================
--- freeDiameter/main.c	(revision 13)
+++ freeDiameter/main.c	(revision 14)
@@ -42,4 +42,6 @@
 static void * sig_hdl(void * arg);
 static int main_cmdline(int argc, char *argv[]);
+static void main_version(void);
+static void main_help( void );
 
 /* The static configuration structure */
@@ -77,8 +79,7 @@
 	
 	/* Initialize other modules */
-	CHECK_FCT(  fd_ext_init()  );
 	CHECK_FCT(  fd_queues_init()  );
 	CHECK_FCT(  fd_msg_init()  );
-	CHECK_FCT(  fd_peer_init()  );
+	CHECK_FCT(  fd_p_expi_init()  );
 	
 	/* Parse the configuration file */
@@ -133,8 +134,91 @@
 	
 	/* cleanups */
-	CHECK_FCT_DO( fd_ext_fini(), /* continue */ );
+	TODO("Stop dispatch thread(s) properly (no cancel yet)");
+	CHECK_FCT_DO( fd_peer_fini(), /* Stop all connections */ );
+	TODO("Stop dispatch & routing threads");
+	CHECK_FCT_DO( fd_ext_fini(), /* Cleaup all extensions */ );
+	TODO("Cleanup queues (dump all remaining messages ?)");
+	
 	CHECK_FCT_DO( fd_thr_term(&sig_th), /* continue */ );
 	
 	return ret;
+}
+
+const char * fd_ev_str(int event)
+{
+	switch (event) {
+	#define case_str( _val )\
+		case _val : return #_val
+		case_str(FDEV_TERMINATE);
+		case_str(FDEV_DUMP_DICT);
+		case_str(FDEV_DUMP_EXT);
+		case_str(FDEV_DUMP_QUEUES);
+		case_str(FDEV_DUMP_CONFIG);
+		case_str(FDEV_DUMP_PEERS);
+		
+		default:
+			TRACE_DEBUG(FULL, "Unknown event : %d", event);
+			return "Unknown event";
+	}
+}
+
+/* Parse the command-line */
+static int main_cmdline(int argc, char *argv[])
+{
+	int c;
+	int option_index = 0;
+	
+      	struct option long_options[] = {
+		{ "help",	0, NULL, 'h' },
+		{ "version",	0, NULL, 'V' },
+		{ "config",	1, NULL, 'c' },
+		{ "debug",	0, NULL, 'd' },
+		{ "quiet",	0, NULL, 'q' },
+		{ NULL,	0, NULL, 0 }
+	};
+	
+	TRACE_ENTRY("%d %p", argc, argv);
+	
+	/* Loop on arguments */
+	while (1) {
+		c = getopt_long (argc, argv, "hVc:dq", long_options, &option_index);
+		if (c == -1) 
+			break;	/* Exit from the loop.  */
+		
+		switch (c) {
+			case 'h':	/* Print help and exit.  */
+				main_help();
+				exit(0);
+
+			case 'V':	/* Print version and exit.  */
+				main_version();
+				exit(0);
+
+			case 'c':	/* Read configuration from this file instead of the default location..  */
+				CHECK_PARAMS( optarg );
+				fd_g_config->cnf_file = optarg;
+				break;
+
+			case 'd':	/* Increase verbosity of debug messages.  */
+				fd_g_debug_lvl++;
+				break;
+				
+			case 'q':	/* Decrease verbosity then remove debug messages.  */
+				fd_g_debug_lvl--;
+				break;
+
+			case '?':	/* Invalid option.  */
+				/* `getopt_long' already printed an error message.  */
+				TRACE_DEBUG(INFO, "getopt_long found an invalid character\n");
+				return EINVAL;
+
+			default:	/* bug: option not considered.  */
+				TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c\n", c);
+				ASSERT(0);
+				return EINVAL;
+		}
+	}
+		
+	return 0;
 }
 
@@ -187,65 +271,4 @@
 }
 
-/* Parse the command-line */
-static int main_cmdline(int argc, char *argv[])
-{
-	int c;
-	int option_index = 0;
-	
-      	struct option long_options[] = {
-		{ "help",	0, NULL, 'h' },
-		{ "version",	0, NULL, 'V' },
-		{ "config",	1, NULL, 'c' },
-		{ "debug",	0, NULL, 'd' },
-		{ "quiet",	0, NULL, 'q' },
-		{ NULL,	0, NULL, 0 }
-	};
-	
-	TRACE_ENTRY("%d %p", argc, argv);
-	
-	/* Loop on arguments */
-	while (1) {
-		c = getopt_long (argc, argv, "hVc:dq", long_options, &option_index);
-		if (c == -1) 
-			break;	/* Exit from the loop.  */
-		
-		switch (c) {
-			case 'h':	/* Print help and exit.  */
-				main_help();
-				exit(0);
-
-			case 'V':	/* Print version and exit.  */
-				main_version();
-				exit(0);
-
-			case 'c':	/* Read configuration from this file instead of the default location..  */
-				CHECK_PARAMS( optarg );
-				fd_g_config->cnf_file = optarg;
-				break;
-
-			case 'd':	/* Increase verbosity of debug messages.  */
-				fd_g_debug_lvl++;
-				break;
-				
-			case 'q':	/* Decrease verbosity then remove debug messages.  */
-				fd_g_debug_lvl--;
-				break;
-
-			case '?':	/* Invalid option.  */
-				/* `getopt_long' already printed an error message.  */
-				TRACE_DEBUG(INFO, "getopt_long found an invalid character\n");
-				return EINVAL;
-
-			default:	/* bug: option not considered.  */
-				TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c\n", c);
-				ASSERT(0);
-				return EINVAL;
-		}
-	}
-		
-	return 0;
-	
-}
-
 #ifdef HAVE_SIGNALENT_H
 const char *const signalstr[] = {
