changeset 353:6ca21598562a

Unified TRACE_DEBUG handling between daemon and extensions + some progress on radius gateway
author Sebastien Decugis <sdecugis@nict.go.jp>
date Thu, 14 May 2009 15:58:30 +0900
parents 6d22078428a5
children e8f36f5342d1
files .hgignore doc/app_test.conf.sample doc/sec_nosec.conf.sample extensions/app_test/app_test.c extensions/app_test/app_test.h extensions/app_test/atst_conf.l extensions/app_test/atst_conf.y extensions/radius_gw/CMakeLists.txt extensions/radius_gw/radius_gw.c extensions/radius_gw/radius_gw.h extensions/radius_gw/radius_gw.y extensions/radius_gw/radius_gw_internal.h extensions/radius_gw/radius_msg.c extensions/radius_gw/rgw_clients.c extensions/radius_gw/rgw_extensions.c extensions/radius_gw/rgw_msg.c extensions/radius_gw/rgw_servers.c extensions/radius_gw/rgw_utils.c extensions/rt_default/rt_default.c extensions/rt_default/rt_default.h extensions/rt_default/rtd_conf.y extensions/sec_nosec/sec_nosec.c extensions/sec_nosec/sec_nosec.h extensions/sec_nosec/sns_conf.y extensions/sec_tls_gnutls/sec_tls_gnutls.c extensions/sec_tls_gnutls/sec_tls_gnutls.h include/waaad/log-api.h waaad/conf.h waaad/dictionary.c waaad/log.c waaad/log.h waaad/main.c waaad/message.c waaad/peer-struct.c waaad/tests/tests.h waaad/utils.h
diffstat 36 files changed, 661 insertions(+), 342 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri May 08 18:28:41 2009 +0900
+++ b/.hgignore	Thu May 14 15:58:30 2009 +0900
@@ -5,5 +5,5 @@
 *.log
 *.sum
 .hg
-build
+build*
 
--- a/doc/app_test.conf.sample	Fri May 08 18:28:41 2009 +0900
+++ b/doc/app_test.conf.sample	Thu May 14 15:58:30 2009 +0900
@@ -40,6 +40,10 @@
 # - both: acts as client and server
 # mode = both;
 
+# Verbosity level
+# Increase this value to have more extension debug messages.
+# verbosity = 0;
+
 #######################
 # Client-specific configuration
 
--- a/doc/sec_nosec.conf.sample	Fri May 08 18:28:41 2009 +0900
+++ b/doc/sec_nosec.conf.sample	Thu May 14 15:58:30 2009 +0900
@@ -1,10 +1,9 @@
 # This is a sample configuration file for the sec_nosec waaad extension.
 
 # For debug purpose, use this parameter to change the debug verbosity of the extension.
-# 0: no debug
-# 1: information only (error conditions)
-# 2: full debug (errors and tracing)
-# Debug_Verbosity = 1;
+# 0: information only (error conditions)
+# 1: full debug (errors and tracing)
+# Debug_Verbosity = 0;
 
 # Specify the default priority given to this extension to handle a peer.
 # The extension with the highest priority will handle a connection.
--- a/extensions/app_test/app_test.c	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/app_test/app_test.c	Thu May 14 15:58:30 2009 +0900
@@ -44,6 +44,9 @@
 atst_conf_t * atst_conf = NULL;
 static atst_conf_t _conf;
 
+/* Debug level */
+int app_test_verbosity = 0;
+
 static int atst_conf_init(void)
 {
 	atst_conf = &_conf;
--- a/extensions/app_test/app_test.h	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/app_test/app_test.h	Thu May 14 15:58:30 2009 +0900
@@ -41,6 +41,8 @@
  */
  
 #define IN_EXTENSION
+#define DEFINE_DEBUG_MACRO app_test
+
 #include <waaad/waaad.h>
 
 #include <pthread.h>
@@ -101,24 +103,10 @@
 extern dict_object_t * atst_dest_realm;
 extern dict_object_t * atst_res_code;
 
+/* Debug level */
+extern int app_test_verbosity;
 
-/**********************************************************************************
- * Define the TRACE_DEBUG macro to be used similarly as in the daemon (see log.h)
- **********************************************************************************/
-#define NONE 0
-#define INFO 1
-#define FULL 2
-#ifndef TRACE_LEVEL 
-#define TRACE_LEVEL INFO
-#endif /* TRACE_LEVEL */
-static int debug_level = TRACE_LEVEL;
-#define TRACE_DEBUG(level,format,args... ) \
-	{ if ( level <= debug_level ) \
-		log_debug("%-12s:%-4d( %-15s): " format "\n", __FILE__, __LINE__, __FUNCTION__, ## args); }
-#define TRACE_ENTRY(_format,_args... ) \
-	TRACE_DEBUG(FULL, "Entering ext function (parms: " _format ")", ##_args )
-/**************************************************************************************/
-
+/* Some macro */
 #define ASSERT( _x ) assert( _x )
 
 #define CHECK( _call ) {								\
--- a/extensions/app_test/atst_conf.l	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/app_test/atst_conf.l	Thu May 14 15:58:30 2009 +0900
@@ -117,6 +117,10 @@
 				return AVP_ID;
 			}
 
+(?i:"verbosity")	{
+				return VERBOSITY;
+			}
+
 (?i:"mode")		{
 				return MODE;
 			}
--- a/extensions/app_test/atst_conf.y	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/app_test/atst_conf.y	Thu May 14 15:58:30 2009 +0900
@@ -120,6 +120,7 @@
 %token 		APPLI_ID
 %token 		CMD_ID
 %token 		AVP_ID
+%token 		VERBOSITY
 %token 		MODE
 %token 		DEST_REALM
 %token 		DEST_HOST
@@ -143,6 +144,7 @@
 			| conffile appli
 			| conffile cmd
 			| conffile avp
+			| conffile verbo
 			| conffile mode
 			| conffile dstrealm
 			| conffile dsthost
@@ -173,6 +175,12 @@
 			}
 			;
 
+verbo:			VERBOSITY '=' INTEGER ';'
+			{
+				app_test_verbosity = $3;
+			}
+			;
+
 mode:			MODE '=' INTEGER ';'
 			{
 				atst_conf->mode = $3;
--- a/extensions/radius_gw/CMakeLists.txt	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/radius_gw/CMakeLists.txt	Thu May 14 15:58:30 2009 +0900
@@ -12,7 +12,11 @@
 	lex.radius_gw.c
 	radius_gw.tab.c
 	radius_gw.tab.h
-	radius_msg.c
+	rgw_utils.c
+	rgw_clients.c
+	rgw_extensions.c
+	rgw_msg.c
+	rgw_servers.c
 )
 
 SET( RGW_DEFAULT_HEADER
--- a/extensions/radius_gw/radius_gw.c	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/radius_gw/radius_gw.c	Thu May 14 15:58:30 2009 +0900
@@ -41,7 +41,26 @@
 
 static int rgw_init(void)
 {
-	rgw_conf_init();
+	int ret = 0;
+	ret = rgw_servers_init();
+	if (ret != 0) {
+		log_error("Error in servers initialization: %s\n", strerror(ret));
+		return ret;
+	}
+	
+	ret = rgw_clients_init();
+	if (ret != 0) {
+		log_error("Error in clients initialization: %s\n", strerror(ret));
+		return ret;
+	}
+	
+	ret = rgw_extensions_init();
+	if (ret != 0) {
+		log_error("Error in extensions initialization: %s\n", strerror(ret));
+		return ret;
+	}
+	
+	return 0;
 }
 
 static int rgw_entry(char * conffile) 
@@ -59,9 +78,13 @@
 		log_error("Error while parsin the configuration: %s\n", strerror(ret));
 		return ret;
 	}
-	
+		
+	log_normal("-------------------------\n");
+	rgw_servers_dump();
+	rgw_clients_dump();
+	rgw_extensions_dump();
+	log_normal("-------------------------\n");
 	
-	rgw_dump_conf();
 	
 	return ret;
 }
@@ -69,7 +92,9 @@
 /* Unload */
 void waaad_ext_fini(void)
 {
-	;
+	rgw_servers_fini();
+	rgw_extensions_fini();
+	rgw_clients_fini();
 }
 
 EXTENSION_API_INIT( API_MODULE_ALL, rgw_entry, "radius_gw" );
--- a/extensions/radius_gw/radius_gw.h	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/radius_gw/radius_gw.h	Thu May 14 15:58:30 2009 +0900
@@ -43,6 +43,7 @@
 #define IN_EXTENSION
 #include <waaad/waaad.h>
 
+
 /* This type is used for all lists in this extension */
 struct rgw_list {
 	struct rgw_list *next;
@@ -128,7 +129,11 @@
 
 /* List management */
 
-/* and so on ... */
+void rgw_list_init(struct rgw_list * plist);
+int rgw_list_is_empty(struct rgw_list * plist);
+void rgw_list_insert_after(struct rgw_list * ref, struct rgw_list * item);
+void rgw_list_unlink(struct rgw_list * plist);
+
 
 
 
--- a/extensions/radius_gw/radius_gw.y	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/radius_gw/radius_gw.y	Thu May 14 15:58:30 2009 +0900
@@ -55,9 +55,6 @@
 #include "radius_gw_internal.h"
 #include "radius_gw.tab.h"	/* bison is not smart enough to define the YYLTYPE before including this code, so... */
 
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
@@ -66,17 +63,14 @@
 /* Forward declaration */
 int yyparse(char * conffile);
 
-/* Declare the rgw_servers */
-struct rgw_servs rgw_servers;
-
 /* Parse the configuration file */
 int rgw_conf_handle(char * conffile)
 {
-	extern FILE * rgw_confin;
+	extern FILE * radius_gwin;
 	int ret;
 	
-	rgw_confin = fopen(conffile, "r");
-	if (rgw_confin == NULL) {
+	radius_gwin = fopen(conffile, "r");
+	if (radius_gwin == NULL) {
 		ret = errno;
 		log_error("Unable to open extension configuration file %s for reading: %s\n", conffile, strerror(ret));
 		return ret;
@@ -84,7 +78,7 @@
 
 	ret = radius_gwparse(conffile);
 
-	fclose(rgw_confin);
+	fclose(radius_gwin);
 
 	if (ret != 0) {
 		return EINVAL;
@@ -93,49 +87,6 @@
 	return 0;
 }
 
-void rgw_dump_conf(void)
-{
-	char ipstr[INET6_ADDRSTRLEN];
-	
-	log_normal("-------------------------\n");
-	
-	log_normal(" auth server:\n");
-	log_normal("    disabled..... : %s\n", rgw_servers.auth_serv.disabled ? "TRUE":"false");
-	log_normal("    IP disabled.. : %s\n", rgw_servers.auth_serv.ipv4_disabled ? "TRUE":"false");
-	log_normal("    IPv6 disabled : %s\n", rgw_servers.auth_serv.ipv6_disabled ? "TRUE":"false");
-	log_normal("    port......... : %hu\n", ntohs(rgw_servers.auth_serv.port));
-	inet_ntop(AF_INET, &rgw_servers.auth_serv.ipv4_endpoint,ipstr,sizeof(ipstr));
-	log_normal("    IP bind...... : %s\n", ipstr);
-	inet_ntop(AF_INET6, &rgw_servers.auth_serv.ipv6_endpoint,ipstr,sizeof(ipstr));
-	log_normal("    IPv6 bind.... : %s\n", ipstr);
-
-	log_normal(" acct server:\n");
-	log_normal("    disabled..... : %s\n", rgw_servers.acct_serv.disabled ? "TRUE":"false");
-	log_normal("    IP disabled.. : %s\n", rgw_servers.acct_serv.ipv4_disabled ? "TRUE":"false");
-	log_normal("    IPv6 disabled : %s\n", rgw_servers.acct_serv.ipv6_disabled ? "TRUE":"false");
-	log_normal("    port......... : %hu\n", ntohs(rgw_servers.acct_serv.port));
-	inet_ntop(AF_INET, &rgw_servers.acct_serv.ipv4_endpoint,ipstr,sizeof(ipstr));
-	log_normal("    IP bind...... : %s\n", ipstr);
-	inet_ntop(AF_INET6, &rgw_servers.acct_serv.ipv6_endpoint,ipstr,sizeof(ipstr));
-	log_normal("    IPv6 bind.... : %s\n", ipstr);
-
-	log_normal("-------------------------\n");
-}
-
-void rgw_conf_init(void)
-{
-	memset(&rgw_servers, 0, sizeof(rgw_servers));
-
-	rgw_servers.auth_serv.port = htons(1812);
-	rgw_servers.auth_serv.ipv4_endpoint.s_addr = INADDR_ANY;
-	memcpy(&rgw_servers.auth_serv.ipv6_endpoint, &in6addr_any, sizeof(struct in6_addr));
-	
-	rgw_servers.acct_serv.port = htons(1813);
-	rgw_servers.acct_serv.ipv4_endpoint.s_addr = INADDR_ANY;
-	memcpy(&rgw_servers.acct_serv.ipv6_endpoint, &in6addr_any, sizeof(struct in6_addr));
-}
-
-
 /* The Lex parser prototype */
 int radius_gwlex(YYSTYPE *lvalp, YYLTYPE *llocp);
 
@@ -266,7 +217,7 @@
 			EXT_PREFIX '=' FILENAME extconf extport extcodes ';'
 			{
 				/* Add this extension in the list */
-				if ( rgw_add_extension( $4, $5, $6, buf, buf_sz ) ) {
+				if ( rgw_extensions_add( $4, $5, $6, buf, buf_sz ) ) {
 					yyerror (&yylloc, conffile, "Error parsing / adding extension !");
 					YYERROR;
 				}
@@ -325,7 +276,7 @@
 			CLI_PREFIX '=' IP '/' clisecret_key ';'
 			{
 				/* Add this client */
-				if ( rgw_add_client( $4, buf, buf_sz ) ) {
+				if ( rgw_clients_add( $4, buf, buf_sz ) ) {
 					yyerror (&yylloc, conffile, "Error parsing / adding client !");
 					YYERROR;
 				}
--- a/extensions/radius_gw/radius_gw_internal.h	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/radius_gw/radius_gw_internal.h	Thu May 14 15:58:30 2009 +0900
@@ -40,16 +40,19 @@
 /* include the general stuff */
 #include "radius_gw.h"
 
-
-/* The content of this file is mainly used to declare interfaces 
-    between lex/yacc files and the main extension file. */
+/* Some headers that are useful in many files */
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
 
-#define RGW_EXT_PORT_AUTH	1
-#define RGW_EXT_PORT_ACCT	2
-int rgw_add_extension( char * extfile, char * conffile, int port, unsigned char * codes_array, size_t codes_sz );
+#include <assert.h>
+#ifndef ASSERT
+#define ASSERT(x) assert(x)
+#endif /* ASSERT */
 
-int rgw_add_client( struct sockaddr * ip_port, unsigned char * key, size_t keylen );
 
+    
+/* The RADIUS server(s) interface */
 struct rgw_serv {
 	unsigned	disabled	:1;
 	unsigned	ipv4_disabled	:1;
@@ -67,12 +70,30 @@
 	struct rgw_serv	acct_serv;
 } rgw_servers;
 
-void rgw_conf_init(void);
+int rgw_servers_init(void);
+int rgw_servers_start(void);
+void rgw_servers_dump(void);
+void rgw_servers_fini(void);
+
+
+/* The clients allowed to connect to these servers */
+int rgw_clients_init(void);
+int rgw_clients_add( struct sockaddr * ip_port, unsigned char * key, size_t keylen );
+void rgw_clients_dump(void);
+void rgw_clients_fini(void);
+
+
+/* The sub-extensions that provide functions to support RADIUS messages and attributes (see also radius_gw.h) */
+#define RGW_EXT_PORT_AUTH	1
+#define RGW_EXT_PORT_ACCT	2
+int rgw_extensions_init(void);
+int rgw_extensions_add( char * extfile, char * conffile, int port, unsigned char * codes_array, size_t codes_sz );
+void rgw_extensions_dump(void);
+void rgw_extensions_fini(void);
+
+/* The function to parse the configuration file */
 int rgw_conf_handle(char * conffile);
 
-void rgw_dump_conf(void);
-void rgw_dump_extensions(void);
-void rgw_dump_clients(void);
 
 #endif /* _RADIUS_GW_INTERNAL_H */
   
--- a/extensions/radius_gw/radius_msg.c	Fri May 08 18:28:41 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-/*********************************************************************************************************
-* Software License Agreement (BSD License)                                                               *
-* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
-*													 *
-* Copyright (c) 2008, 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.								 *
-*********************************************************************************************************/
-/* Note on copyright: Some parts of this header have been copied from the Hostap project.
- Files from this project are dual-licensed GPL2 and BSD. 
- Credits go to the original authors for these parts.
- */
-
-/* This file contains all support functions to parse, create, and manipulate RADIUS messages. Other 
-modules do not need to "know" the actual representation of RADIUS messages on the network. They only 
-receive the logical view as exposed in the radius_gw.h file. */
-
-#include "radius_gw_internal.h"
-
-/* To ensure packed structures with some common compilers */
-#ifdef __GNUC__
-#define STRUCT_PACKED __attribute__ ((packed))
-#else
-#define STRUCT_PACKED
-#endif
-#ifdef _MSC_VER
-#pragma pack(push, 1)
-#endif /* _MSC_VER */
-
-struct radius_hdr {
-	uint8_t code;
-	uint8_t identifier;
-	uint16_t length; /* including this header */
-	uint8_t authenticator[16];
-	/* followed by length-20 octets of attributes */
-} STRUCT_PACKED;
-
-struct radius_attr_hdr {
-	uint8_t type;
-	uint8_t length; /* including this header */
-	/* followed by length-2 octets of attribute value */
-} STRUCT_PACKED;
-
-struct radius_attr_vendor {
-	uint8_t vendor_type;
-	uint8_t vendor_length;
-} STRUCT_PACKED;
-
-#ifdef _MSC_VER
-#pragma pack(pop)
-#endif /* _MSC_VER */
-
-/* Default size to be allocated for new RADIUS messages */
-#define RADIUS_DEFAULT_MSG_SIZE 1024
-
-/* Default size to be allocated for attribute array */
-#define RADIUS_DEFAULT_ATTR_COUNT 16
-
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/radius_gw/rgw_clients.c	Thu May 14 15:58:30 2009 +0900
@@ -0,0 +1,56 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
+*													 *
+* Copyright (c) 2008, 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.								 *
+*********************************************************************************************************/
+
+/* Manage the list of RADIUS clients, along with their shared secrets. */
+
+#include "radius_gw_internal.h"
+
+int rgw_clients_init(void)
+{
+	return 0;
+}
+
+int rgw_clients_add( struct sockaddr * ip_port, unsigned char * key, size_t keylen )
+{
+	return ENOTSUP;
+}
+
+void rgw_clients_dump(void)
+{
+}
+void rgw_clients_fini(void)
+{
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/radius_gw/rgw_extensions.c	Thu May 14 15:58:30 2009 +0900
@@ -0,0 +1,56 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
+*													 *
+* Copyright (c) 2008, 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.								 *
+*********************************************************************************************************/
+
+/* Manage the list of sub-extensions that provide handlers for RADIUS messages / attributes */
+
+#include "radius_gw_internal.h"
+
+int rgw_extensions_init(void)
+{
+	return 0;
+}
+
+int rgw_extensions_add( char * extfile, char * conffile, int port, unsigned char * codes_array, size_t codes_sz )
+{
+	return ENOTSUP;
+}
+
+void rgw_extensions_dump(void)
+{
+}
+
+void rgw_extensions_fini(void)
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/radius_gw/rgw_msg.c	Thu May 14 15:58:30 2009 +0900
@@ -0,0 +1,82 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
+*													 *
+* Copyright (c) 2008, 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.								 *
+*********************************************************************************************************/
+
+/* This file contains all support functions to parse, create, and manipulate RADIUS messages. Other 
+modules do not need to "know" the actual representation of RADIUS messages on the network. They only 
+receive the logical view as exposed in the radius_gw.h file. */
+
+#include "radius_gw_internal.h"
+
+/* To ensure packed structures with some common compilers */
+#ifdef __GNUC__
+#define STRUCT_PACKED __attribute__ ((packed))
+#else
+#define STRUCT_PACKED
+#endif
+#ifdef _MSC_VER
+#pragma pack(push, 1)
+#endif /* _MSC_VER */
+
+struct radius_hdr {
+	uint8_t code;
+	uint8_t identifier;
+	uint16_t length; /* including this header */
+	uint8_t authenticator[16];
+	/* followed by length-20 octets of attributes */
+} STRUCT_PACKED;
+
+struct radius_attr_hdr {
+	uint8_t type;
+	uint8_t length; /* including this header */
+	/* followed by length-2 octets of attribute value */
+} STRUCT_PACKED;
+
+struct radius_attr_vendor {
+	uint8_t vendor_type;
+	uint8_t vendor_length;
+} STRUCT_PACKED;
+
+#ifdef _MSC_VER
+#pragma pack(pop)
+#endif /* _MSC_VER */
+
+/* Default size to be allocated for new RADIUS messages */
+#define RADIUS_DEFAULT_MSG_SIZE 1024
+
+/* Default size to be allocated for attribute array */
+#define RADIUS_DEFAULT_ATTR_COUNT 16
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/radius_gw/rgw_servers.c	Thu May 14 15:58:30 2009 +0900
@@ -0,0 +1,94 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
+*													 *
+* Copyright (c) 2008, 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.								 *
+*********************************************************************************************************/
+
+/* Manage the server(s): opening sockets, receiving messages, ... */
+
+#include "radius_gw_internal.h"
+
+/* Declare the rgw_servers */
+struct rgw_servs rgw_servers;
+
+int rgw_servers_init(void)
+{
+	memset(&rgw_servers, 0, sizeof(rgw_servers));
+
+	rgw_servers.auth_serv.port = htons(1812);
+	rgw_servers.auth_serv.ipv4_endpoint.s_addr = INADDR_ANY;
+	memcpy(&rgw_servers.auth_serv.ipv6_endpoint, &in6addr_any, sizeof(struct in6_addr));
+	
+	rgw_servers.acct_serv.port = htons(1813);
+	rgw_servers.acct_serv.ipv4_endpoint.s_addr = INADDR_ANY;
+	memcpy(&rgw_servers.acct_serv.ipv6_endpoint, &in6addr_any, sizeof(struct in6_addr));
+	
+	return 0;
+}
+
+void rgw_servers_dump(void)
+{
+	char ipstr[INET6_ADDRSTRLEN];
+	
+	log_normal(" auth server:\n");
+	log_normal("    disabled..... : %s\n", rgw_servers.auth_serv.disabled ? "TRUE":"false");
+	log_normal("    IP disabled.. : %s\n", rgw_servers.auth_serv.ipv4_disabled ? "TRUE":"false");
+	log_normal("    IPv6 disabled : %s\n", rgw_servers.auth_serv.ipv6_disabled ? "TRUE":"false");
+	log_normal("    port......... : %hu\n", ntohs(rgw_servers.auth_serv.port));
+	inet_ntop(AF_INET, &rgw_servers.auth_serv.ipv4_endpoint,ipstr,sizeof(ipstr));
+	log_normal("    IP bind...... : %s\n", ipstr);
+	inet_ntop(AF_INET6, &rgw_servers.auth_serv.ipv6_endpoint,ipstr,sizeof(ipstr));
+	log_normal("    IPv6 bind.... : %s\n", ipstr);
+
+	log_normal(" acct server:\n");
+	log_normal("    disabled..... : %s\n", rgw_servers.acct_serv.disabled ? "TRUE":"false");
+	log_normal("    IP disabled.. : %s\n", rgw_servers.acct_serv.ipv4_disabled ? "TRUE":"false");
+	log_normal("    IPv6 disabled : %s\n", rgw_servers.acct_serv.ipv6_disabled ? "TRUE":"false");
+	log_normal("    port......... : %hu\n", ntohs(rgw_servers.acct_serv.port));
+	inet_ntop(AF_INET, &rgw_servers.acct_serv.ipv4_endpoint,ipstr,sizeof(ipstr));
+	log_normal("    IP bind...... : %s\n", ipstr);
+	inet_ntop(AF_INET6, &rgw_servers.acct_serv.ipv6_endpoint,ipstr,sizeof(ipstr));
+	log_normal("    IPv6 bind.... : %s\n", ipstr);
+
+}
+
+int rgw_servers_start(void)
+{
+	return ENOTSUP;
+}
+
+void rgw_servers_fini(void)
+{
+	
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/radius_gw/rgw_utils.c	Thu May 14 15:58:30 2009 +0900
@@ -0,0 +1,76 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
+*													 *
+* Copyright (c) 2008, 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.								 *
+*********************************************************************************************************/
+
+/* Some useful functions */
+
+#include "radius_gw_internal.h"
+
+void rgw_list_init(struct rgw_list * plist)
+{
+	ASSERT(plist != NULL);
+	plist->next = plist;
+	plist->prev = plist;
+	plist->head = plist;
+}
+
+int rgw_list_is_empty(struct rgw_list * plist)
+{
+	ASSERT(plist != NULL);
+	return plist == plist->next;
+}
+
+void rgw_list_insert_after(struct rgw_list * ref, struct rgw_list * item)
+{
+	ASSERT(ref != NULL);
+	ASSERT(item != NULL);
+	ASSERT(rgw_list_is_empty(item));
+	item->next = ref->next;
+	item->prev = ref;
+	item->head = ref->head;
+	ref->next->prev = item;
+	ref->next = item;
+}
+
+void rgw_list_unlink(struct rgw_list * plist)
+{
+	ASSERT(plist != NULL);
+	if (plist->head == plist)
+		return;
+	plist->next->prev = plist->prev;
+	plist->prev->next = plist->next;
+	plist->next = plist;
+	plist->prev = plist;
+	plist->head = plist;
+}
--- a/extensions/rt_default/rt_default.c	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/rt_default/rt_default.c	Thu May 14 15:58:30 2009 +0900
@@ -43,6 +43,8 @@
 static dict_object_t * dict_avp_DH  = NULL; /* Destination-Host */
 static dict_object_t * dict_avp_DR  = NULL; /* Destination-Realm */
 
+int rt_default_verbosity = 0;
+
 /* Analyze a message content to find Destination-Realm and Destination-Host */
 static int find_avps(msg_t * msg, avp_value_t ** dr, avp_value_t ** dh)
 {
@@ -181,16 +183,27 @@
 
 static void conf_dump(void)
 {
-	TRACE_DEBUG(FULL, " Verbosity...........: %d", rtd_conf->verbosity);
-	TRACE_DEBUG(FULL, " Handle Dest Host....: %d", rtd_conf->do_dest_host);
-	TRACE_DEBUG(FULL, " Handle Dest Realm...: %d", rtd_conf->do_dest_realm);
-	TRACE_DEBUG(FULL, " Score Dest Host.....: %d", rtd_conf->sc_dest_host);
-	TRACE_DEBUG(FULL, " Score Dest Realm....: %d", rtd_conf->sc_dest_realm);
-	TRACE_DEBUG(FULL, " Score no info.......: %d", rtd_conf->sc_no_info);
-	TRACE_DEBUG(FULL, " Score default route.: %d", rtd_conf->sc_all);
-	TRACE_DEBUG(FULL, " Score default pref..: %d", rtd_conf->sc_all_pref);
-	TRACE_DEBUG(FULL, " Score realm.........: %d", rtd_conf->sc_rlm);
-	TRACE_DEBUG(FULL, " Score realm pref....: %d", rtd_conf->sc_rlm_pref);
+	TRACE_DEBUG(FULL, "rt_default configuration dump:\n"
+			  " Verbosity...........: %d\n"
+			  " Handle Dest Host....: %d\n"
+			  " Handle Dest Realm...: %d\n"
+			  " Score Dest Host.....: %d\n"
+			  " Score Dest Realm....: %d\n"
+			  " Score no info.......: %d\n"
+			  " Score default route.: %d\n"
+			  " Score default pref..: %d\n"
+			  " Score realm.........: %d\n"
+			  " Score realm pref....: %d",
+			  		  rt_default_verbosity,
+					  rtd_conf->do_dest_host,
+					  rtd_conf->do_dest_realm,
+					  rtd_conf->sc_dest_host,
+					  rtd_conf->sc_dest_realm,
+					  rtd_conf->sc_no_info,
+					  rtd_conf->sc_all,
+					  rtd_conf->sc_all_pref,
+					  rtd_conf->sc_rlm,
+					  rtd_conf->sc_rlm_pref);
 }
 
 /* handler */
--- a/extensions/rt_default/rt_default.h	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/rt_default/rt_default.h	Thu May 14 15:58:30 2009 +0900
@@ -45,17 +45,18 @@
  */
  
 #define IN_EXTENSION
+#define DEFINE_DEBUG_MACRO  rt_default
 #include <waaad/waaad.h>
 
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
 
+/* debug level */
+extern int rt_default_verbosity;	/* default: 0 */
+	
 /* The module configuration */
 typedef struct {
-	/* debug level */
-	int 	verbosity;	/* default: 0 */
-	
 	/* Destination-Host management? */
 	int	do_dest_host;	/* default: 1 */
 	int	do_dest_realm;	/* default: 1 */
@@ -92,20 +93,3 @@
 
 /* For debug: dump the table */
 void rtd_dump(void);
-
-/**********************************************************************************
- * Define the TRACE_DEBUG macro to be used similarly as in the daemon (see log.h)
- **********************************************************************************/
-#define NONE 0
-#define INFO 1
-#define FULL 2
-#ifndef TRACE_LEVEL 
-#define TRACE_LEVEL INFO
-#endif /* TRACE_LEVEL */
-static int debug_level = TRACE_LEVEL;
-#define TRACE_DEBUG(level,format,args... ) \
-	{ if ( level <= debug_level + (rtd_conf ? rtd_conf->verbosity : 0) ) \
-		log_debug("%-12s:%-4d( %-15s): " format "\n", __FILE__, __LINE__, __FUNCTION__, ## args); }
-#define TRACE_ENTRY(_format,_args... ) \
-	TRACE_DEBUG(FULL, "Entering ext function (parms: " _format ")", ##_args )
-/**************************************************************************************/
--- a/extensions/rt_default/rtd_conf.y	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/rt_default/rtd_conf.y	Thu May 14 15:58:30 2009 +0900
@@ -184,7 +184,7 @@
 	/* Defining the extension debug verbosity level */
 verbosity:		VERBOSITY '=' INTEGER ';'
 			{
-				rtd_conf->verbosity = $3;
+				rt_default_verbosity = $3;
 			}
 			;
 			
--- a/extensions/sec_nosec/sec_nosec.c	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/sec_nosec/sec_nosec.c	Thu May 14 15:58:30 2009 +0900
@@ -48,7 +48,7 @@
 
 static sec_module_t sns_mod;
 static sec_mod_hdl_t * sns_hdl;
-int sns_verbosity;
+int sec_nosec_verbosity = 0;
 
 /* The main entry point of the extension, called when the extension is loaded, after API initialization */
 static int sec_nosec_main(char * conffile)
@@ -57,8 +57,6 @@
 	
 	TRACE_ENTRY("%p", conffile);
 	
-	sns_verbosity = 0;
-	
 	/* The configuration file is mandatory */
 	if (!conffile) {
 		TRACE_DEBUG(INFO, "Missing configuration file");
--- a/extensions/sec_nosec/sec_nosec.h	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/sec_nosec/sec_nosec.h	Thu May 14 15:58:30 2009 +0900
@@ -48,6 +48,7 @@
  */
  
 #define IN_EXTENSION
+#define DEFINE_DEBUG_MACRO	sec_nosec
 #include <waaad/waaad.h>
 
 #include <pthread.h>
@@ -63,6 +64,8 @@
 #define DIAMETER_MSG_SIZE_MAX	65536
 #endif /* DIAMETER_MSG_SIZE_MAX */
 
+extern int sec_nosec_verbosity;
+
 
 /**************************************************************************
  * The functions that are provided back to the daemon, as a security module. 
@@ -93,22 +96,3 @@
 
 /* Destroy the table and free all data */
 int sns_fini(void);
-
-
-/**********************************************************************************
- * Define the TRACE_DEBUG macro to be used similarly as in the daemon (see log.h)
- **********************************************************************************/
-#define NONE 0
-#define INFO 1
-#define FULL 2
-#ifndef TRACE_LEVEL 
-#define TRACE_LEVEL INFO
-#endif /* TRACE_LEVEL */
-static int debug_level = TRACE_LEVEL;
-extern int sns_verbosity;
-#define TRACE_DEBUG(level,format,args... ) \
-	{ if ( level <= debug_level + sns_verbosity ) \
-		log_debug("%-12s:%-4d( %-15s): " format "\n", __FILE__, __LINE__, __FUNCTION__, ## args); }
-#define TRACE_ENTRY(_format,_args... ) \
-	TRACE_DEBUG(FULL, "Entering ext function (parms: " _format ")", ##_args )
-/**************************************************************************************/
--- a/extensions/sec_nosec/sns_conf.y	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/sec_nosec/sns_conf.y	Thu May 14 15:58:30 2009 +0900
@@ -126,7 +126,7 @@
 	/* Defining the extension debug verbosity level */
 verbosity:		VERBOSITY '=' INTEGER ';'
 			{
-				sns_verbosity = $3;
+				sec_nosec_verbosity = $3;
 			}
 			;
 
--- a/extensions/sec_tls_gnutls/sec_tls_gnutls.c	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/sec_tls_gnutls/sec_tls_gnutls.c	Thu May 14 15:58:30 2009 +0900
@@ -48,7 +48,7 @@
 
 static sec_module_t 	tls_mod;
 static sec_mod_hdl_t  * tls_hdl;
-int ext_verbose;
+int sec_gnutls_verbosity = 0;
 
 /* The main entry point of the extension, called when the extension is loaded, after API initialization */
 static int tls_main(char * conffile)
@@ -57,8 +57,6 @@
 	
 	TRACE_ENTRY("%p", conffile);
 
-	ext_verbose = 0; /* Get verbosity from somewhere else ? */
-	
 	/* Initialize the extension */
 	ret = tls_init();
 	if (ret != 0) {
--- a/extensions/sec_tls_gnutls/sec_tls_gnutls.h	Fri May 08 18:28:41 2009 +0900
+++ b/extensions/sec_tls_gnutls/sec_tls_gnutls.h	Thu May 14 15:58:30 2009 +0900
@@ -41,6 +41,7 @@
  */
  
 #define IN_EXTENSION
+#define DEFINE_DEBUG_MACRO	sec_gnutls
 #include <waaad/waaad.h>
 
 #include <string.h>
@@ -68,22 +69,5 @@
 /* Destroy the table and free all data */
 int tls_fini(void);
 
-
-/**********************************************************************************
- * Define the TRACE_DEBUG macro to be used similarly as in the daemon (see log.h)
- **********************************************************************************/
-extern int ext_verbose;
-
-#define NONE 0
-#define INFO 1
-#define FULL 2
-#ifndef TRACE_LEVEL 
-#define TRACE_LEVEL INFO
-#endif /* TRACE_LEVEL */
-static int debug_level = TRACE_LEVEL;
-#define TRACE_DEBUG(level,format,args... ) \
-	{ if ( level <= debug_level + ext_verbose ) \
-		log_debug("%-12s:%-4d( %-15s): " format "\n", __FILE__, __LINE__, __FUNCTION__, ## args); }
-#define TRACE_ENTRY(_format,_args... ) \
-	TRACE_DEBUG(FULL, "Entering ext function (parms: " _format ")", ##_args )
-/**************************************************************************************/
+/* verbosity configuration */
+extern int sec_gnutls_verbosity;
--- a/include/waaad/log-api.h	Fri May 08 18:28:41 2009 +0900
+++ b/include/waaad/log-api.h	Thu May 14 15:58:30 2009 +0900
@@ -39,6 +39,7 @@
 #ifndef _LOG_API_H
 #define _LOG_API_H
 
+#include <pthread.h>
 #include <stddef.h>
 
 /*
@@ -99,10 +100,44 @@
  */
 void log_debug ( char * format, ... );
 
+/*
+ * FUNCTION:	log_time
+ *
+ * PARAMETERS:
+ *  format 	: Same format string as in the printf function
+ *  ...		: Same list as printf
+ *
+ * DESCRIPTION: 
+ *  Log internal information for use of developpers only. 
+ *
+ * RETURN VALUE:
+ *  None.
+ */
+char * log_time ( char * buf, size_t len );
+
+/*
+ * FUNCTION:	log_set_thread_name
+ *
+ * PARAMETERS:
+ *  name 	: A name identifying the calling thread
+ *  cat		: Optional categorization. Should for example contain the extension name.
+ *
+ * DESCRIPTION: 
+ *  Get a string describing current time
+ *
+ * RETURN VALUE:
+ *  None.
+ */
+void log_set_thread_name ( char * name, char * cat );
+
+/* The name of the current thread */
+extern pthread_key_t thread_name;
+
+
 #endif /* ! IN_EXTENSION */
 
 /* The version of this API, to check binary compatibility -- increment each time a change is made in api_log_t */
-#define WAAAD_API_LOG_VER	1
+#define WAAAD_API_LOG_VER	2
 
 /* Now define the type of the structure that contains the callback to pass to extensions */
 typedef struct {
@@ -111,9 +146,12 @@
 	int	version;	/* The version of this API/ABI, must be WAAAD_API_LOG_VER */
 	
 	/* the remaining is log-specific */
-	void (*log_error)  ( char * format, ... );
-	void (*log_normal) ( char * format, ... );
-	void (*log_debug)  ( char * format, ... );
+	void  (*log_error)  ( char * format, ... );
+	void  (*log_normal) ( char * format, ... );
+	void  (*log_debug)  ( char * format, ... );
+	char *(*log_time)   ( char * buf, size_t len );
+	void  (*log_set_thread_name) (char * name, char * cat);
+	pthread_key_t (*thread_name);
 } api_log_t;
 
 #ifdef IN_EXTENSION
@@ -129,25 +167,89 @@
 #define log_error	g_api_log->log_error
 #define log_normal	g_api_log->log_normal
 #define log_debug	g_api_log->log_debug
+#define log_time	g_api_log->log_time
+#define log_set_thread_name	g_api_log->log_set_thread_name
+#define thread_name	*g_api_log->thread_name
 
 
 #else /* IN_EXTENSION */
 
 /* From the daemon, we must initialize the API object, in extension.c */
-# define MY_WAAAD_API_LOG_VER 1
+# define MY_WAAAD_API_LOG_VER 2
 # if MY_WAAAD_API_LOG_VER != WAAAD_API_LOG_VER
 #  error "You must update API_INIT_LOG also"
 # endif
 
-#define API_INIT_LOG( api_log ) 			\
-{							\
-	(api_log).length     = sizeof(api_log_t);	\
-	(api_log).version    = WAAAD_API_LOG_VER;	\
-	(api_log).log_error  = log_error;		\
-	(api_log).log_normal = log_normal;		\
-	(api_log).log_debug  = log_debug;		\
+#define API_INIT_LOG( api_log ) 				\
+{								\
+	(api_log).length      = sizeof(api_log_t);		\
+	(api_log).version     = WAAAD_API_LOG_VER;		\
+	(api_log).log_error   = log_error;			\
+	(api_log).log_normal  = log_normal;			\
+	(api_log).log_debug   = log_debug;			\
+	(api_log).log_time    = log_time;			\
+	(api_log).log_set_thread_name  = log_set_thread_name;	\
+	(api_log).thread_name = &thread_name;			\
 }							
 
 #endif /* IN_EXTENSION */
 
+/************************/
+/* Some macro for debug */
+/************************/
+#ifdef DEFINE_DEBUG_MACRO
+
+/* helpers */
+#define __str( arg )  #arg
+#define _stringize( arg ) __str( arg )
+#define __agr( arg1, arg2 ) arg1 ## arg2
+#define _aggregate( arg1, arg2 ) __agr( arg1, arg2 )
+
+/* Macro to set the current thread name, useful for multi-threaded environments */
+#define THREAD_NAME( name )		\
+	log_set_thread_name( (name), _stringize(DEFINE_DEBUG_MACRO) );
+
+/* Boolean for tracing at a certain level, for custom dump functions for example */
+#define TRACE_BOOL(level) ( level <= local_debug_level + _aggregate(DEFINE_DEBUG_MACRO, _verbosity) )
+
+/* The general debug macro, each call results in two lines of debug messages */
+#define TRACE_DEBUG(level,format,args... ) {										\
+	if ( TRACE_BOOL(level) ) {											\
+		char __buf[25];												\
+		char * __thn = ((char *)pthread_getspecific(thread_name) ?: "unnamed");					\
+		log_debug("\t |%-30s\t%s\tin %s@%s:%d\n"								\
+				"\t%s|%*s" format "\n",  								\
+						__thn, log_time(__buf, sizeof(__buf)), __FUNCTION__, __FILE__, __LINE__,\
+						(level < FULL)?"@":" ",level, "", ## args); 				\
+	}														\
+}
+
+/* Helper for function entry */
+#define TRACE_ENTRY(_format,_args... ) \
+	TRACE_DEBUG(FCTS, "->%s (" #_args ") = (" _format ") >", __FUNCTION__, ##_args );
+
+/* Helper for debugging by adding traces */
+#define TRACE_HERE()	\
+	TRACE_DEBUG(INFO, " -- debug checkpoint -- ");
+
+/* levels definitions */
+#define NONE 0	/* Display no debug message */
+#define INFO 1	/* Display errors only */
+#define FULL 2  /* Display additional information to follow code execution */
+#define ANNOYING 4 /* Very verbose, for example in loops */
+#define FCTS 6  /* Display entry parameters of most functions */
+#define CALL 9  /* Display calls to most functions (with CHECK macros) */
+
+/* Default level is INFO */
+#ifndef TRACE_LEVEL 
+#define TRACE_LEVEL INFO
+#endif /* TRACE_LEVEL */
+
+/* The level of the file being compiled */
+static int local_debug_level = TRACE_LEVEL;
+/* We use an run-time variable to be able to change the level on-the-fly with a debugger */
+
+#endif /* DEFINE_DEBUG_MACRO */
+
+
 #endif /* ! _LOG_API_H */
--- a/waaad/conf.h	Fri May 08 18:28:41 2009 +0900
+++ b/waaad/conf.h	Thu May 14 15:58:30 2009 +0900
@@ -49,7 +49,6 @@
 /* This type defines the configuration information */
 typedef struct {
 	int		 log_to;		/* combination of LOG_TO_* flags from log.h */
-	int		 log_verbose;		/* overwrite verbosity mode */
 
 	char		*filepath;		/* Location of the configuration file to parse */
 	
--- a/waaad/dictionary.c	Fri May 08 18:28:41 2009 +0900
+++ b/waaad/dictionary.c	Thu May 14 15:58:30 2009 +0900
@@ -331,11 +331,16 @@
 			&& (obj->typeyec == dict_obj_info[obj->type].eyecatcher),
 		{
 			if (obj) {
-				TRACE_DEBUG(INFO, "Invalid object : %p\n", obj);
-				TRACE_DEBUG(INFO, "obj->objeyec : %x / %x\n", obj->objeyec, OBJECT_EYECATCHER);
-				TRACE_DEBUG(INFO, "obj->type    : %d\n", obj->type);
-				TRACE_DEBUG(INFO, "obj->objeyec : %x / %x\n", obj->objeyec, OBJECT_EYECATCHER);
-				TRACE_DEBUG(INFO, "obj->typeyec : %x / %x\n", obj->typeyec, _OBINFO(obj).eyecatcher);
+				TRACE_DEBUG(FULL, "Invalid object : %p\n"
+						  "     obj->objeyec : %x / %x\n"
+						  "     obj->type    : %d\n"
+						  "     obj->objeyec : %x / %x\n"
+						  "     obj->typeyec : %x / %x", 
+						obj,
+						obj->objeyec, OBJECT_EYECATCHER,
+						obj->type,
+						obj->objeyec, OBJECT_EYECATCHER,
+						obj->typeyec, _OBINFO(obj).eyecatcher);
 			}
 			return 0;
 		}  );
--- a/waaad/log.c	Fri May 08 18:28:41 2009 +0900
+++ b/waaad/log.c	Thu May 14 15:58:30 2009 +0900
@@ -54,6 +54,7 @@
 /* Save the facilities where the logs must be sent */
 static int log_to = 0;
 pthread_key_t thread_name;
+int waaad_verbosity = 0;;
 
 /* Mutex to protect concurrent accesses to the logs */
 pthread_mutex_t log_mtx = PTHREAD_MUTEX_INITIALIZER;
@@ -423,7 +424,7 @@
 	va_list ap;
 	
 	/* If "quiet" has been specified, do not issue debug */
-	if (g_conf->log_verbose < 0)
+	if (waaad_verbosity < 0)
 		return;
 	
 	ret = pthread_mutex_lock(&log_mtx);
--- a/waaad/log.h	Fri May 08 18:28:41 2009 +0900
+++ b/waaad/log.h	Thu May 14 15:58:30 2009 +0900
@@ -51,15 +51,19 @@
 #define _LOG_H_
 
 /* Logs */
+#ifndef DEFINE_DEBUG_MACRO
+#define DEFINE_DEBUG_MACRO 	waaad
+#endif /* DEFINE_DEBUG_MACRO */
 #include <waaad/log-api.h> /* define the log_* functions */
 
-#include "conf.h" /* for the g_conf definition */
 /* The following additional functions are needed inside the daemon */
 
 #define LOG_TO_SYSLOG 	0x1
 #define LOG_TO_CONSOLE	0x2
 #define LOG_TO_FILE	0x4
 
+extern int waaad_verbosity;
+
 /*
  * FUNCTION:	log_init
  *
@@ -107,58 +111,4 @@
 int log_fini ( void );
 
 
-
-/* The remaining of the file is dedicated to debug facility */
-
-/* levels definitions */
-#define NONE 0	/* Display no debug message */
-#define INFO 1	/* Display errors only */
-#define FULL 2  /* Display additional information to follow code execution */
-#define ANNOYING 4 /* Very verbose, for example in loops */
-#define FCTS 6  /* Display entry parameters of most functions */
-#define CALL 9  /* Display calls to most functions (with CHECK macros) */
-
-/* Default level is INFO */
-#ifndef TRACE_LEVEL 
-#define TRACE_LEVEL INFO
-#endif /* TRACE_LEVEL */
-
-/* The level of the module being compiled */
-static int debug_level = TRACE_LEVEL;
-/* We use an run-time variable to be able to change the level on-the-fly with a debugger */
-
-/* The name of the current thread */
-extern pthread_key_t thread_name;
-void log_set_thread_name(char * name, char * cat);
-
-/* Get a string describing current time */
-char * log_time(char * buf, size_t len);
-
-/* Macro to assign current thread name */
-#define THREAD_NAME( name )		\
-	log_set_thread_name( (name), NULL );
-
-/* Macro to log debug */
-#define TRACE_DEBUG(level,format,args... ) {										\
-	if ( level <= debug_level + g_conf->log_verbose ) {								\
-		char __buf[25];												\
-		char * __thn = ((char *)pthread_getspecific(thread_name) ?: "unnamed");					\
-		log_debug("\t |*%-30s\t%s\tin %s@%s:%d\n"								\
-				"\t%s|%*s" format "\n",  								\
-						__thn, log_time(__buf, sizeof(__buf)), __FUNCTION__, __FILE__, __LINE__,\
-						(level < FULL)?"@":" ",level, "", ## args); 				\
-	}														\
-}
-		
-#define TRACE_ENTRY(_format,_args... ) \
-	TRACE_DEBUG(FCTS, "->%s (" #_args ") = (" _format ") >", __FUNCTION__, ##_args );
-	
-#define TRACE_HERE()	\
-	TRACE_DEBUG(INFO, " -- debug checkpoint -- ");
-	
-#define TRACE_DEBUG_ALL( str ) 	\
-	TRACE_DEBUG(CALL, str );
-
-
-
 #endif /* _LOG_H_ */
--- a/waaad/main.c	Fri May 08 18:28:41 2009 +0900
+++ b/waaad/main.c	Thu May 14 15:58:30 2009 +0900
@@ -139,11 +139,11 @@
 				break;
 
 			case 'd':	/* Increase verbosity of debug messages.  */
-				g_conf->log_verbose++;
+				waaad_verbosity++;
 				break;
 				
 			case 'q':	/* Decrease verbosity then remove debug messages.  */
-				g_conf->log_verbose--;
+				waaad_verbosity--;
 				break;
 
 			case '?':	/* Invalid option.  */
--- a/waaad/message.c	Fri May 08 18:28:41 2009 +0900
+++ b/waaad/message.c	Thu May 14 15:58:30 2009 +0900
@@ -669,7 +669,7 @@
 static void msg_dump_intern ( int level, void * obj, int indent )
 {
 	/* Log only if we are at least at level */
-	if (level > debug_level + g_conf->log_verbose)
+	if ( ! TRACE_BOOL(level) )
 		return;
 	
 	/* Check the object */
--- a/waaad/peer-struct.c	Fri May 08 18:28:41 2009 +0900
+++ b/waaad/peer-struct.c	Thu May 14 15:58:30 2009 +0900
@@ -590,7 +590,7 @@
 {
 	_peer_t * p = _P(peer);
 	
-	if (my_debug_level > g_conf->log_verbose)
+	if ( ! TRACE_BOOL(my_debug_level) )
 		return;
 	
 	if (!VALIDATE_PEER( p )) {
@@ -637,25 +637,25 @@
 {
 	int cnt = 0, i;
 	
-	if (my_debug_level <= g_conf->log_verbose)
+	if (TRACE_BOOL(my_debug_level))
 		log_debug("=============== HASH dump ==============================\n");
 	
 	for (i = 0; i < sizeof(_peer_hash) / sizeof(_peer_hash[0]); i++) {
 		uti_list_t * next;
 		
-		if (my_debug_level <= g_conf->log_verbose)
+		if (TRACE_BOOL(my_debug_level))
 			log_debug("==== line %d (%d)\n", i, _peer_hash[i].count);
 		
 		CHECK_POSIX(  pthread_mutex_lock(&_peer_hash[i].lock)  );
 		
 		for (next = _peer_hash[i].all.next; next != &_peer_hash[i].all; next = next->next) {
 			cnt ++;
-			peer_dump(next->o, my_debug_level,g_conf->log_verbose <= FULL ? 0 : 1);
+			peer_dump(next->o, my_debug_level, waaad_verbosity <= FULL ? 0 : 1);
 		}
 		
 		CHECK_POSIX(  pthread_mutex_unlock(&_peer_hash[i].lock)  );
 	}
-	if (my_debug_level <= g_conf->log_verbose)
+	if (TRACE_BOOL(my_debug_level))
 		log_debug("=============== /HASH dump ==============================\n");
 	
 	return cnt;
--- a/waaad/tests/tests.h	Fri May 08 18:28:41 2009 +0900
+++ b/waaad/tests/tests.h	Thu May 14 15:58:30 2009 +0900
@@ -44,6 +44,9 @@
 #include <pthread.h>
 #include <errno.h>
 
+#define DEFINE_DEBUG_MACRO 	test
+static int test_verbosity = 0;
+
 /* The waaad API */
 #include <waaad/waaad.h>
 
@@ -59,6 +62,7 @@
 # include <unistd.h>
 #endif /* HAVE_UNISTD_H */
 #include <time.h>
+#include <libgen.h>
 
 /* Define the return code values */
 #define PASS	0
@@ -79,7 +83,7 @@
 
 /* Define the standard check routines */
 #define CHECK( _val, _assert ){				\
-	if (g_conf && g_conf->log_verbose) {		\
+	if (test_verbosity > 0) {			\
 		fprintf(stderr,				\
 			"%s:%-4d: CHECK( " #_assert " == "\
 				#_val " )\n",		\
@@ -111,7 +115,7 @@
 	CHECK( 0, disp_init()			);	\
 	CHECK( 0, sec_init()			);	\
 	parse_cmdline(argc, argv);			\
-	THREAD_NAME("test");				\
+	THREAD_NAME(basename(__FILE__));		\
 }
 
 #define CONFIG_WAAAD() {					\
@@ -127,11 +131,13 @@
 	while ((c = getopt (argc, argv, "dq")) != -1) {
 		switch (c) {
 			case 'd':	/* Increase verbosity of debug messages.  */
-				g_conf->log_verbose++;
+				waaad_verbosity++;
+				test_verbosity++;
 				break;
 				
 			case 'q':	/* Decrease verbosity then remove debug messages.  */
-				g_conf->log_verbose--;
+				waaad_verbosity--;
+				test_verbosity--;
 				break;
 			
 			default:	/* bug: option not considered.  */
--- a/waaad/utils.h	Fri May 08 18:28:41 2009 +0900
+++ b/waaad/utils.h	Thu May 14 15:58:30 2009 +0900
@@ -60,6 +60,11 @@
 /********************************************************************************************************/
 /* Sets of useful macros */
 
+/* Helper for tracing the CHECK_* macros bellow */
+#define TRACE_DEBUG_ALL( str ) 	\
+	TRACE_DEBUG(CALL, str );
+
+
 /* Macros to check a return value and branch out in case of error.
  * These macro are to be used only when errors are highly improbable, not for expected errors.
  */
"Welcome to our mercurial repository"