changeset 316:2b15c02bd2c2

Automated merge with ssh://thedoc@morbier.koganei.wide.ad.jp//var/hg/repos/waaad/
author Sebastien Decugis <sdecugis@nict.go.jp>
date Wed, 25 Feb 2009 16:49:21 +0900
parents 192f0c2e0bdf (current diff) 3cebe1c677ab (diff)
children 987cea8b1e37
files Makefile.am configure.ac extensions/Makefile.am extensions/app_test/Makefile.am extensions/app_test/atst_gram.y extensions/app_test/atst_tok.l extensions/rt_any/Makefile.am extensions/rt_debug/Makefile.am extensions/rt_default/Makefile.am extensions/rt_default/rtd_gram.y extensions/rt_default/rtd_tok.l extensions/sample/Makefile.am extensions/sec_nosec/Makefile.am extensions/sec_nosec/sns_gram.y extensions/sec_nosec/sns_token.l extensions/sec_tls_gnutls/Makefile.am m4/README m4/acx_pthread.m4 waaad/Makefile.am waaad/conf-gram.y waaad/conf-token.l waaad/tests/Makefile.am
diffstat 58 files changed, 2683 insertions(+), 2958 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Feb 25 11:27:53 2009 +0900
+++ b/.hgignore	Wed Feb 25 16:49:21 2009 +0900
@@ -5,15 +5,5 @@
 *.log
 *.sum
 .hg
-bld-aux
 build
-autom4te.cache
-stamp-*
-libtool
-Makefile.in
-config.h.in
-configure
-aclocal.m4
-m4/libtool.m4
-m4/lt*.m4
 
--- a/BUGS	Wed Feb 25 11:27:53 2009 +0900
+++ b/BUGS	Wed Feb 25 16:49:21 2009 +0900
@@ -2,10 +2,8 @@
 
 ---- BUILD SYSTEM ----
 To regenerate the package from Mercurial, you'll need at least the following tools:
-- autoconf, automake
-- libtool
+- cmake
+- 
 - flex, bison
 
-Otherwise the "autoreconf -i" or "./configure" or "make" will fail with strange errors.
-
 ---- 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CMakeLists.txt	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,35 @@
+# Build description file for use with cmake (cmake.org)
+
+# Name of the project, and language
+PROJECT("WIDE Diameter AAA daemon" C)
+
+# Some subfolder have tests
+ENABLE_TESTING()
+
+# CMake version
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+# Location of additional CMake modules
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
+
+# Location for the include files
+INCLUDE_DIRECTORIES(include)
+
+# waaad daemon, and some extensions, use yacc and lex parsers
+SET(BISON_GENERATE_DEFINES TRUE)
+SET(BISON_PREFIX_OUTPUTS TRUE)
+INCLUDE(CMakeUserUseBison)
+SET(FLEX_PREFIX_OUTPUTS TRUE)
+INCLUDE(CMakeUserUseFlex)
+IF( NOT BISON_EXECUTABLE OR NOT FLEX_EXECUTABLE )
+  MESSAGE( SEND_ERROR "Bison and Flex are required" )
+ENDIF( NOT BISON_EXECUTABLE OR NOT FLEX_EXECUTABLE )
+
+# Location for the waaad source code
+SUBDIRS(waaad)
+
+# Do we build the extensions?
+OPTION(NoExtensions "Ignore the extensions completly?")
+IF(NOT NoExtensions)
+	SUBDIRS(extensions)
+ENDIF(NOT NoExtensions)
--- a/INSTALL	Wed Feb 25 11:27:53 2009 +0900
+++ b/INSTALL	Wed Feb 25 16:49:21 2009 +0900
@@ -1,29 +1,41 @@
-In order to build this package you need to do the following:
+This package now uses CMake (cmake.org) to handle the build burden. You'll need the cmake tool in order 
+to generate the Makefiles for your platform. You can also select which extensions must be built.
 
-autoreconf -i
-configure
+Building in a separate directory is recommended:
+mkdir build
+cd build
+cmake ../
 make
 
-The build system uses standard GNU tools.
+You can enable the unary tests by doing:
+cmake -DSkip_Tests:BOOL=OFF ../
+make
+make tests
 
-Note that there are dependencies on some external tools that may not be enforced by the configure script:
-flex, bison, autoconf, automake, libtool ...
+Note: instead of passing options on the command line, you can edit the CCmakeCache.txt file
+or use a CMake front-end (cmake-gui)
+
+Note that there are dependencies on some external tools that may not be enforced by the configure script.
 On Ubuntu Intrepid, the following packages were required:
- gcc make flex bison libtool libsctp1 libsctp-dev libgnutls26 libgnutls-dev
+ gcc make flex bison libsctp1 libsctp-dev cmake
 
 make install would probably install some files in your system but... at your own risks!
-(this will be improved later!)
-
-To clean almost all generated files, use: make maintainer-clean
-(you must have configured with --enable-maintainer-mode ?)
+(never tested yet!)
 
 
-Building in separate directory is supported (RECOMMENDED FOR DEVELOPERS!):
-autoreconf -i
-mkdir build
-cd build
-../configure srcdir=..
-make
+You can also configure which extensions to build with CMake:
+NoExtensions:BOOL=OFF    (or the following are ignored)
+BUILD_APP_TEST:BOOL=ON
+BUILD_RT_ANY:BOOL=ON
+BUILD_RT_DEBUG:BOOL=ON
+BUILD_RT_DEFAULT:BOOL=ON
+BUILD_SAMPLE:BOOL=ON
+BUILD_SEC_NOSEC:BOOL=ON
+BUILD_SEC_TLS_GNUTLS:BOOL=OFF
 
-Remark: you may use something like:
-../configure --with-conf=/root/sources/waaad/doc/waaad.conf.sample --enable-maintainer-mode
+You can enable early debug messages in waaad (before command line is parsed) with:
+Waaad_Early_Debug:BOOL=ON
+
+You can change the default configuration file name:
+DEFAULT_CONF_FILE:STRING=/path/to/some/waaad.conf
+
--- a/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-# Note:
-# where_PRIMARY = targets
-# targets should be built as:
-# _PROGRAMS, _LIBRARIES, _LTLIBRARIES (libtool), _HEADERS, SCRIPTS, _DATA
-# in: bin_, lib_, ...
-#     custom_ is also OK but $(customdir) must be defined
-#     noinst_ : not installed target
-#     check_  : built by make check
-#  optional: dist_ , nodist_ : distribute targets / don't
-
-# To tell aclocal to use the package's m4 macros in autoconf and automake:
-ACLOCAL_AMFLAGS = -I m4
-
-# Nothing to compile there, but we want it distributed also :
-EXTRA_DIST = include
-
-# Subdirectories to compile:
-SUBDIRS = waaad extensions
-
-# Update libtool if required -- how to use this???
-libtool: $(LIBTOOL_DEPS)
-	$(SHELL) ./config.status --recheck
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/Modules/CMakeUserUseBison.cmake	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,71 @@
+# - Look for GNU Bison, the parser generator
+# Based off a news post from Andy Cedilnik at Kitware
+# Defines the following:
+#  BISON_EXECUTABLE - path to the bison executable
+#  BISON_FILE - parse a file with bison
+#  BISON_PREFIX_OUTPUTS - Set to true to make BISON_FILE produce prefixed
+#                         symbols in the generated output based on filename.
+#                         So for ${filename}.y, you'll get ${filename}parse(), etc.
+#                         instead of yyparse().
+#  BISON_GENERATE_DEFINES - Set to true to make BISON_FILE output the matching
+#                           .h file for a .c file. You want this if you're using
+#                           flex.
+
+IF(NOT DEFINED BISON_PREFIX_OUTPUTS)
+ SET(BISON_PREFIX_OUTPUTS FALSE)
+ENDIF(NOT DEFINED BISON_PREFIX_OUTPUTS)
+
+IF(NOT DEFINED BISON_GENERATE_DEFINES)
+ SET(BISON_GENERATE_DEFINES FALSE)
+ENDIF(NOT DEFINED BISON_GENERATE_DEFINES)
+
+IF(NOT BISON_EXECUTABLE)
+ MESSAGE(STATUS "Looking for bison")
+ FIND_PROGRAM(BISON_EXECUTABLE bison)
+ IF(BISON_EXECUTABLE)
+   MESSAGE(STATUS "Looking for bison -- ${BISON_EXECUTABLE}")
+ ENDIF(BISON_EXECUTABLE)
+ENDIF(NOT BISON_EXECUTABLE)
+
+IF(BISON_EXECUTABLE)
+ MACRO(BISON_FILE FILENAME)
+   GET_FILENAME_COMPONENT(PATH "${FILENAME}" PATH)
+   IF("${PATH}" STREQUAL "")
+     SET(PATH_OPT "")
+   ELSE("${PATH}" STREQUAL "")
+     SET(PATH_OPT "/${PATH}")
+   ENDIF("${PATH}" STREQUAL "")
+   GET_FILENAME_COMPONENT(HEAD "${FILENAME}" NAME_WE)
+   IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
+     FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
+   ENDIF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
+   IF(BISON_PREFIX_OUTPUTS)
+     SET(PREFIX "${HEAD}")
+   ELSE(BISON_PREFIX_OUTPUTS)
+     SET(PREFIX "yy")
+   ENDIF(BISON_PREFIX_OUTPUTS)
+   SET(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/${HEAD}.tab.c")
+   IF(BISON_GENERATE_DEFINES)
+     SET(HEADER "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/${HEAD}.tab.h")
+     ADD_CUSTOM_COMMAND(
+       OUTPUT "${OUTFILE}" "${HEADER}"
+       COMMAND "${BISON_EXECUTABLE}"
+       ARGS "--name-prefix=${PREFIX}"
+       "--defines"
+       "--output-file=${OUTFILE}"
+       "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
+       DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
+     SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" "${HEADER}" PROPERTIES GENERATED TRUE)
+     SET_SOURCE_FILES_PROPERTIES("${HEADER}" PROPERTIES HEADER_FILE_ONLY TRUE)
+   ELSE(BISON_GENERATE_DEFINES)
+     ADD_CUSTOM_COMMAND(
+       OUTPUT "${OUTFILE}"
+       COMMAND "${BISON_EXECUTABLE}"
+       ARGS "--name-prefix=${PREFIX}"
+       "--output-file=${OUTFILE}"
+       "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
+       DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
+     SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" PROPERTIES GENERATED TRUE)
+   ENDIF(BISON_GENERATE_DEFINES)
+ ENDMACRO(BISON_FILE) 
+ENDIF(BISON_EXECUTABLE)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/Modules/CMakeUserUseFlex.cmake	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,46 @@
+# - Look for GNU flex, the lexer generator.
+# Defines the following:
+#  FLEX_EXECUTABLE - path to the flex executable
+#  FLEX_FILE - parse a file with flex
+#  FLEX_PREFIX_OUTPUTS - Set to true to make FLEX_FILE produce outputs of
+#                        lex.${filename}.c, not lex.yy.c . Passes -P to flex. 
+
+IF(NOT DEFINED FLEX_PREFIX_OUTPUTS)
+  SET(FLEX_PREFIX_OUTPUTS FALSE)
+ENDIF(NOT DEFINED FLEX_PREFIX_OUTPUTS) 
+
+IF(NOT FLEX_EXECUTABLE)
+  MESSAGE(STATUS "Looking for flex")
+  FIND_PROGRAM(FLEX_EXECUTABLE flex)
+  IF(FLEX_EXECUTABLE)
+    MESSAGE(STATUS "Looking for flex -- ${FLEX_EXECUTABLE}")
+  ENDIF(FLEX_EXECUTABLE)
+ENDIF(NOT FLEX_EXECUTABLE) 
+
+IF(FLEX_EXECUTABLE)
+  MACRO(FLEX_FILE FILENAME)
+    GET_FILENAME_COMPONENT(PATH "${FILENAME}" PATH)
+    IF("${PATH}" STREQUAL "")
+      SET(PATH_OPT "")
+    ELSE("${PATH}" STREQUAL "")
+      SET(PATH_OPT "/${PATH}")
+    ENDIF("${PATH}" STREQUAL "")
+    IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
+      FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
+    ENDIF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
+    IF(FLEX_PREFIX_OUTPUTS)
+      GET_FILENAME_COMPONENT(PREFIX "${FILENAME}" NAME_WE)
+    ELSE(FLEX_PREFIX_OUTPUTS)
+      SET(PREFIX "yy")
+    ENDIF(FLEX_PREFIX_OUTPUTS)
+    SET(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/lex.${PREFIX}.c")
+    ADD_CUSTOM_COMMAND(
+      OUTPUT "${OUTFILE}"
+      COMMAND "${FLEX_EXECUTABLE}"
+      ARGS "--prefix=${PREFIX}"
+      "--outfile=${OUTFILE}"
+      "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
+      DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
+    SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" PROPERTIES GENERATED TRUE)
+  ENDMACRO(FLEX_FILE)
+ENDIF(FLEX_EXECUTABLE)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/Modules/FindSCTP.cmake	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,28 @@
+# Will set the required definitions for SCTP:
+#  SCTP_FOUND
+#  SCTP_LIBRARIES
+
+INCLUDE (CheckSymbolExists) 
+
+SET(SCTP_FOUND FALSE)
+
+# Search compile information
+CHECK_SYMBOL_EXISTS(IPPROTO_SCTP "sys/socket.h;netinet/in.h;netinet/sctp.h" HAVE_IPPROTO_SCTP)
+IF ( NOT HAVE_IPPROTO_SCTP )
+   MESSAGE( SEND_ERROR "Symbol IPPROTO_SCTP was not found in standard headers." )
+ENDIF ( NOT HAVE_IPPROTO_SCTP )
+
+# Search link information
+CHECK_FUNCTION_EXISTS (sctp_getladdrs HAVE_SCTP_GETLADDRS)
+IF (HAVE_SCTP_GETLADDRS)
+   SET(SCTP_LIBRARIES "")
+ELSE (HAVE_SCTP_GETLADDRS)
+   CHECK_LIBRARY_EXISTS (sctp sctp_getladdrs "" HAVE_LIBSCTP)
+   IF (HAVE_LIBSCTP)
+     SET(SCTP_LIBRARIES "-lsctp")
+   ELSE (HAVE_LIBSCTP)
+     MESSAGE( SEND_ERROR "Function sctp_getladdrs was not found, please install libsctp." )
+   ENDIF (HAVE_LIBSCTP)
+ENDIF (HAVE_SCTP_GETLADDRS)
+
+SET(SCTP_FOUND TRUE)
--- a/configure.ac	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,264 +0,0 @@
-#######################
-# Prelude
-
-# Package name.
-AC_INIT([WIDE Diameter AAA daemon], [0.1], [sdecugis@nict.go.jp], [waaad])
-
-# Require minimum Autoconf version 
-AC_PREREQ([2.61])
-
-# Copyright notice
-AC_COPYRIGHT([Copyright (c) 2008, WIDE Project and NICT])
-AC_DEFINE([PACKAGE_COPYRIGHT],
-	["Copyright (c) 2008, WIDE Project and NICT"], 
-	[Copyright to show in waaad --version])
-
-# safety check to ensure configure is run in the proper directory
-AC_CONFIG_SRCDIR([waaad/main.c])
-
-# Place for auxiliary scripts
-AC_CONFIG_AUX_DIR([bld-aux])
-
-# Location for additional m4 macros
-AC_CONFIG_MACRO_DIR([m4])
-
-# Initialize automake tool
-AM_INIT_AUTOMAKE([-Wall -Werror foreign])
-
-# Include the macro definition to check the pthread availability
-sinclude(acx_pthread.m4)
-
-# Test the version of the sources
-AS_IF( [test -d $srcdir/.hg], [hgstr=`cd $srcdir && hg log -r tip --template '{rev}'`],
-	      [hgstr='No Mercurial'])
-AC_DEFINE_UNQUOTED([PACKAGE_HG_REVISION], ["$hgstr"], [Mercurial version of package at configure time])
-
-
-#######################
-# Checks for programs
-
-AC_PROG_CC
-
-AC_PROG_YACC
-AM_PROG_LEX
-
-# For libraries
-# AC_PROG_RANLIB
-# We use libtool for handling shared libraries
-AC_DISABLE_STATIC
-AC_LIBTOOL_DLOPEN
-# LT_INIT([dlopen])
-AC_PROG_LIBTOOL
-
-# Handle update of libtool script
-AC_SUBST([LIBTOOL_DEPS])
-
-# AC_PROGS( VAR, PROGS, [VAL-IF-NOT-FOUND])
-#  define VAR to the first PROGS found, or to VAL-IF-NOT-FOUND otherwise
-#  ex: AC_CHECK_PROGS([TAR], [tar gtar], [:])
-#then: if test "$TAR" = :; then
-#        AC_MSG_ERROR([This package needs tar.])
-#      fi
-
-# Note:
-#  AC_MSG_ERROR( ERROR-DESCRIPTION, [EXIT-STATUS])
-#  AC_MSG_WARN( ERROR-DESCRIPTION )
-
-# Note:
-#  AC_DEFINE(VARIABLE, VALUE, DESCRIPTION)
-# will put in config.h:
-#  /* DESCRIPTION */
-#  #define VARIABLE VALUE
-
-# Note:
-#  AC_SUBST(VARIABLE, VALUE)
-# defines $(VARIABLE) as VALUE in Makefile
-
-# Note:
-#  AM_CONDITIONAL(NAME, CONDITION)
-#   NAME will be true if the condition is true.
-#  The NAME can be used for optional compilation in Makefiles:
-#   if NAME
-#    foo_SOURCES += bar.h
-#   endif
-#  Example:
-#   AC_CHECK_HEADER([bar.h], [use_bar=yes])
-#   AM_CONDITIONAL([WANT_BAR], [test "$use_bar" = yes])
-
-
-
-#######################
-# Checks for libraries
-
-# Note:
-# AC_CHECK_LIB ( LIBRARY, FUNCT, [ACT-IF-FOUND], [ACT-IF-NOT])
-#  Check if LIBRARY exists and contains FUNCT.
-#  If ACT-IF-FOUND is not defined, this is done automatically:
-#   LIBS="-lLIBRARY $LIBS"  (automatically used by automake)
-#   #define HAVE_LIBLIBRARY
-#
-#  Example: AC_CHECK_LIB([efence], [malloc], [EFENCELIB=-lefence])
-#           AC_SUBST([EFENCELIB]), then we will use $(EFENCELIB) in the link rule
-
-# Save the LIBS value
-backup_LIBS=${LIBS}
-
-# Test for libdl
-AC_HAVE_LIBRARY([-ldl], ,[AC_MSG_ERROR([This package needs libdl.])])
-
-# Save the value and restore the LIBS var
-AC_SUBST([dl_LIBS], [${LIBS}])
-LIBS=${backup_LIBS}
-
-# This is a POSIX function but sometimes in separate libraries
-AC_SEARCH_LIBS([clock_gettime], [rt posix4], , [AC_MSG_ERROR([This package needs clock_gettime.])])
-
-# Save and restore
-AC_SUBST([clock_LIBS], [${LIBS}])
-LIBS=${backup_LIBS}
-
-# Needed to retrieve the set of local addresses in SCTP associations
-AC_SEARCH_LIBS([sctp_getladdrs], [sctp], , [AC_MSG_ERROR([This package needs sctp_getladdrs.])])
-
-# Save and restore
-AC_SUBST([sctp_LIBS], [${LIBS}])
-LIBS=${backup_LIBS}
-
-# threads library. We apply this to any extension and subprograms for safety
-ACX_PTHREAD(, [AC_MSG_ERROR([Unable to find a suitable POSIX thread library.])])
-LIBS="$PTHREAD_LIBS $LIBS"
-CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-CC="$PTHREAD_CC"
-
-
-#######################
-# Checks for header files
-
-# Note:
-# AC_CHECK_HEADERS(HEADERS...)
-#  Check for headers and #define HAVE_/HEADER/_H for each header found
-# ex:
-#  AC_CHECK_HEADERS([sys/param.h unistd.h])
-#  AC_CHECK_HEADERS([wchar.h])
-#  may #define HAVE_SYS_PARAM_H, HAVE_UNISTD_H and HAVE_WCHAR_H
-# then in source file:
-#  #if HAVE_UNISTD_H
-#  # include <unistd.h>
-#  #endif
-#
-# AC_CHECK_HEADER(HEADER, [ACT_IF_FOUND], [ACT_IF_NOT])
-#  Check only one header
-#
-AC_CHECK_HEADERS([sys/socket.h netinet/in.h netinet/sctp.h])
-
-#######################
-# Checks for typedefs, structures, and compiler caracteristics
-
-AC_CHECK_DECL(
-	[IPPROTO_SCTP], 
-	, 
-	[AC_MSG_ERROR([This package needs IPPROTO_SCTP definition. Please update the configure.ac to support non-standard paths.])],
-	[
-	  [#ifdef HAVE_SYS_SOCKET_H]
-	  [#include <sys/socket.h>]
-	  [#endif]
-	  [#ifdef HAVE_NETINET_IN_H]
-	  [#include <netinet/in.h>]
-	  [#endif]
-	  [#ifdef HAVE_NETINET_SCTP_H]
-	  [# include <netinet/sctp.h>]
-	  [#endif]
-	])
-
-AC_CHECK_DECL(
-	[__BYTE_ORDER],
-	,
-	[AC_MSG_ERROR([This package needs __BYTE_ORDER definition. Please update the configure.ac to support non-standard paths.])],
-	[
-	  [#include <sys/param.h>]
-	])
-	
-
-#######################
-# Checks for library functions.
-
-AC_CHECK_FUNC([getopt_long], ,[AC_MSG_ERROR([This package needs getopt_long.])])
-# AC_CHECK_FUNC([getrrsetbyname], ,[AC_MSG_ERROR([This package needs getrrsetbyname.])])
-
-# Some POSIX systems may not have the read-write lock support?
-AC_CHECK_FUNC([pthread_rwlock_init], ,[AC_MSG_ERROR([This package needs a pthread implementation with read-write locks support.])])
-
-# When this is not provided by host, we provide a replacement function in the daemon.
-AC_CHECK_FUNC([ntohll], [AC_DEFINE([HAVE_NTOHLL], [1], [Defined if the ntohll function or macro is defined])])
-
-#######################
-# Checks for system services
-
-
-#######################
-# Configurable options
-
-AC_ARG_ENABLE([debug],
-            [AS_HELP_STRING([--disable-debug],
-               [Remove all debug messages.])],
-            [AC_SUBST([WAAAD_DEBUG], [-DTRACE_LEVEL=NONE])],
-            [AC_SUBST([WAAAD_DEBUG], [-DTRACE_LEVEL=INFO])])
-
-AC_ARG_WITH([conf],
-            [AS_HELP_STRING([--with-conf=<file>],
-               [Change default location of configuration file ($(sysconfdir)/waaad/waaad.conf)])],
-            [AC_SUBST([defconffile], [$withval])],
-            [AC_SUBST([defconffile], [${sysconfdir}/waaad/waaad.conf])])
-
-AC_ARG_WITH([gnutls],
-            [AS_HELP_STRING([--with-gnutls=<path>],
-               [Provide an alternative path to the gnutls library (NOT SUPPORTED YET).])])
-AC_ARG_WITH([gnutls],
-            [AS_HELP_STRING([--without-gnutls],
-               [Do not compile extension that uses the GNU TLS library.])],
-            [],
-            [with_gnutls=default])
-
-AM_CONDITIONAL([NOGNUTLS], [test x$with_gnutls = xno])
-
-LIBGNUTLS=
-# We may use the libgnutls-config --libs and --cflags helper program here...
-AS_IF( [test x$with_gnutls = xno], [],
-       [test x$with_gnutls = xdefault], 
-       		[AC_HAVE_LIBRARY([-lgnutls], 
-				 [AC_SUBST([LIBGNUTLS], ["-lgnutls"])],
-				 [AC_MSG_ERROR([This package needs libgnutls.])])
-		 AC_CHECK_HEADER([gnutls/gnutls.h],
-		                  ,
-				 [AC_MSG_ERROR([This package requires the gnutls library header file (see --without-gnutls for workaround).])]) ],
-       [AC_MSG_ERROR([The --with-gnutls=<path> option is not yet supported in the configure.ac file.])])
-        
-
-#######################
-# Output files.
-
-# Since we are in early development, let's be in maintainer mode
-AM_MAINTAINER_MODE
-CPPFLAGS="$CPPFLAGS -Wall -Werror"
-
-AC_CONFIG_HEADERS([waaad/config.h])
-# Create config.h from config.h.in (created by autoheader)
-# Contains all definitions made with AC_DEFINE
-
-AC_CONFIG_FILES([Makefile])
-AC_CONFIG_FILES([waaad/Makefile])
-AC_CONFIG_FILES([waaad/tests/Makefile])
-AC_CONFIG_FILES([extensions/Makefile])
-AC_CONFIG_FILES([extensions/sample/Makefile])
-AC_CONFIG_FILES([extensions/sec_nosec/Makefile])
-AC_CONFIG_FILES([extensions/sec_tls_gnutls/Makefile])
-AC_CONFIG_FILES([extensions/rt_debug/Makefile])
-AC_CONFIG_FILES([extensions/rt_any/Makefile])
-AC_CONFIG_FILES([extensions/rt_default/Makefile])
-AC_CONFIG_FILES([extensions/app_test/Makefile])
-# Create these files from these files.in (created by automake from .am if any)
-# Contains all definitions made with AC_SUBST
-# AC_SUBST([XYZ]) are replaced into @XYZ@ in the files.
-# Can also process files that are not Makefiles (for examples script.sh.in)
-
-AC_OUTPUT
--- a/doc/waaad.conf.sample	Wed Feb 25 11:27:53 2009 +0900
+++ b/doc/waaad.conf.sample	Wed Feb 25 16:49:21 2009 +0900
@@ -88,7 +88,7 @@
 #};
 #
 "sec_nosec" = {
-	filename="/root/sources/waaad/build/extensions/sec_nosec/.libs/sec_nosec.so";
+	filename="/root/sources/waaad-cmake-bld/extensions/libsec_nosec.so";
 	conffile="/root/sources/waaad/doc/sec_nosec.conf.sample";
 };
 #"sec_tls" = {
@@ -97,7 +97,7 @@
 #};
 
 "rt_default" = {
-	filename="/root/sources/waaad/build/extensions/rt_default/.libs/rt_default.so";
+	filename="/root/sources/waaad-cmake-bld/extensions/librt_default.so";
 	conffile="/root/sources/waaad/doc/rt_default.conf.sample";
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/CMakeLists.txt	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,59 @@
+# This is the rules to make extensions for waaad.
+PROJECT("waaad extensions" C)
+
+# Set destination for extensions
+SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
+
+
+###########################
+# Extensions section
+
+####
+# Diameter applications
+
+
+####
+# Routing extensions
+
+OPTION(BUILD_RT_DEFAULT "Build rt_default? (Routing extension using Destination-Host, Destination-Realm, and static configuration)" ON)
+	IF (BUILD_RT_DEFAULT)
+	   SUBDIRS(rt_default)
+	ENDIF (BUILD_RT_DEFAULT)
+
+
+####
+# Security extensions
+
+OPTION(BUILD_SEC_NOSEC "Build sec_nosec? (Security extension allowing direct connections without encryption to specified peers)" ON)
+	IF (BUILD_SEC_NOSEC)
+	   SUBDIRS(sec_nosec)
+	ENDIF (BUILD_SEC_NOSEC)
+
+OPTION(BUILD_SEC_TLS_GNUTLS "Build sec_tls_gnutls? (Security extension for TLS connections, using libgnutls (LGPL))" OFF) # OFF yet because code is incomplete
+	IF (BUILD_SEC_TLS_GNUTLS)
+	   SUBDIRS(sec_tls_gnutls)
+	ENDIF (BUILD_SEC_TLS_GNUTLS)
+
+
+####
+# Debug / development extensions
+
+OPTION(BUILD_SAMPLE "Build sample? (Simple extension to demonstrate extension mechanism, for developpers only)" OFF)
+	IF (BUILD_SAMPLE)
+	   SUBDIRS(sample)
+	ENDIF (BUILD_SAMPLE)
+
+OPTION(BUILD_RT_ANY "Build rt_any? (Routing extension sending message to any peer available, for testing purpose only)" OFF)
+	IF (BUILD_RT_ANY)
+	   SUBDIRS(rt_any)
+	ENDIF (BUILD_RT_ANY)
+
+OPTION(BUILD_RT_DEBUG "Build rt_debug? (Routing extension tracing routing list, for debug purpose only)" OFF)
+	IF (BUILD_RT_DEBUG)
+	   SUBDIRS(rt_debug)
+	ENDIF (BUILD_RT_DEBUG)
+
+OPTION(BUILD_APP_TEST "Build app_test? (Testing application to send dummy message to another peer, for testing purpose only)" OFF)
+	IF (BUILD_APP_TEST)
+	   SUBDIRS(app_test)
+	ENDIF (BUILD_APP_TEST)
--- a/extensions/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-# Subdirectories to compile:
-
-################################
-# Sample - for developers only #
-################################
-SUBDIRS = sample
-
-
-
-#######################
-# Security extensions #
-#######################
-SUBDIRS += sec_nosec
-
-if !NOGNUTLS
-SUBDIRS += sec_tls_gnutls
-endif
-
-
-#######################
-# Routing  extensions #
-#######################
-SUBDIRS += rt_debug
-SUBDIRS += rt_any
-SUBDIRS += rt_default
-
-
-#########################
-# Diameter Applications #
-#########################
-SUBDIRS += app_test
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/app_test/CMakeLists.txt	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,23 @@
+# The app_test extension
+PROJECT("Test application waaad extension" C)
+
+# Parser files
+BISON_FILE(atst_conf.y)
+FLEX_FILE(atst_conf.l)
+SET_SOURCE_FILES_PROPERTIES(lex.atst_conf.c atst_conf.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}")
+
+# List of source files
+SET( APP_TEST_SRC
+	app_test.c
+	app_test.h
+	lex.atst_conf.c
+	atst_conf.tab.c
+	atst_conf.tab.h
+	atst_sig.c
+	atst_dict.c
+	atst_serv.c
+	atst_cli.c
+)
+
+# Compile these files as a module
+ADD_LIBRARY(app_test MODULE ${APP_TEST_SRC})
--- a/extensions/app_test/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-# Compile the "app_test" Diameter application extension for waaad.
-
-# Location of the API headers:
-AM_CPPFLAGS = -I$(srcdir)/../../include
-
-# For bison
-AM_YFLAGS = -d
-BUILT_SOURCES = atst_gram.h
-
-# The extension to build
-pkglib_LTLIBRARIES = app_test.la
-
-# Linker flags (for libtool)
-app_test_la_LDFLAGS = -module
-
-# Source files
-app_test_la_SOURCES = 	app_test.c 	\
-			app_test.h 	\
-			atst_gram.y 	\
-			atst_tok.l	\
-			atst_sig.c	\
-			atst_dict.c	\
-			atst_serv.c	\
-			atst_cli.c
--- a/extensions/app_test/app_test.c	Wed Feb 25 11:27:53 2009 +0900
+++ b/extensions/app_test/app_test.c	Wed Feb 25 16:49:21 2009 +0900
@@ -86,7 +86,7 @@
 	
 	/* Parse configuration file */
 	if (conffile != NULL) {
-		CHECK( conf_parse(conffile) );
+		CHECK( atst_conf_handle(conffile) );
 	}
 	conf_dump();
 	
--- a/extensions/app_test/app_test.h	Wed Feb 25 11:27:53 2009 +0900
+++ b/extensions/app_test/app_test.h	Wed Feb 25 16:49:21 2009 +0900
@@ -69,7 +69,7 @@
 
 
 /* Parse the configuration file */
-int conf_parse(char * conffile);
+int atst_conf_handle(char * conffile);
 
 /* Start or stop the signal handler */
 int sig_init(void (*cb)(void));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/app_test/atst_conf.l	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,161 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+/* Lex extension's configuration parser.
+ *
+ * The configuration file contains a default priority, and a list of peers with optional overwite priority.
+ * -- see the app_test.conf.sample file for more detail.
+ */
+
+%{
+#include "app_test.h"
+/* Include yacc tokens definitions */
+#include "atst_conf.tab.h"
+
+/* Update the column information */
+#define YY_USER_ACTION { 						\
+	yylloc->first_column = yylloc->last_column + 1; 		\
+	yylloc->last_column = yylloc->first_column + yyleng - 1;	\
+}
+
+/* Avoid warning with newer flex */
+#define YY_NO_INPUT
+
+%}
+
+%option bison-bridge bison-locations
+%option noyywrap
+%option nounput
+
+%%
+
+	/* Update the line count */
+\n			{
+				yylloc->first_line++; 
+				yylloc->last_line++; 
+				yylloc->last_column=0; 
+			}
+	 
+	/* Eat all spaces but not new lines */
+([[:space:]]{-}[\n])+	;
+	/* Eat all comments */
+#.*$			;
+
+	/* Recognize any integer */
+[-]?[[:digit:]]+		{
+				/* Convert this to an integer value */
+				int ret=0;
+				ret = sscanf(yytext, "%i", &yylval->integer);
+				if (ret != 1) {
+					/* No matching: an error occurred */
+					log_error("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno));
+					return LEX_ERROR; /* trig an error in yacc parser */
+					/* Maybe we could REJECT instead of failing here? */
+				}
+				return INTEGER;
+			}
+
+	/* Recognize quoted strings */
+\"[[:alnum:].-]+\"	{
+				/* Match a string. expected only ASCII characters, '-' and '.'. The validation is done in yacc */
+				yylval->string = strdup(yytext+1);
+				if (!yylval->string) {
+					log_error("Unable to copy the string '%s': %s\n", yytext, strerror(errno));
+					TRACE_DEBUG(INFO, "strdup failed");
+					return LEX_ERROR; /* trig an error in yacc parser */
+				}
+				yylval->string[strlen(yytext) - 2] = '\0';
+				return QSTRING;
+			}
+			
+	/* Recognize the tokens */	
+(?i:"vendor-id")	{
+				return VENDOR_ID;
+			}
+
+(?i:"appli-id")		{
+				return APPLI_ID;
+			}
+
+(?i:"cmd-id")		{
+				return CMD_ID;
+			}
+
+(?i:"avp-id")		{
+				return AVP_ID;
+			}
+
+(?i:"mode")		{
+				return MODE;
+			}
+
+(?i:"server")		{
+				yylval->integer = MODE_SERV;
+				return INTEGER;
+			}
+
+(?i:"client")		{
+				yylval->integer = MODE_CLI;
+				return INTEGER;
+			}
+
+(?i:"both")		{
+				yylval->integer = MODE_SERV | MODE_CLI;
+				return INTEGER;
+			}
+
+(?i:"dest-realm")	{
+				return DEST_REALM;
+			}
+
+(?i:"dest-host")	{
+				return DEST_HOST;
+			}
+
+(?i:"Signal")		{
+				return SIGNAL;
+			}
+
+			
+	/* Valid single characters for yyparse */
+[=;]			{ return yytext[0]; }
+
+	/* Unrecognized sequence, if it did not match any previous pattern */
+[^[:space:]"*=>;\n]+	{ 
+				log_error("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext);
+			 	return LEX_ERROR; 
+			}
+
+%%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/app_test/atst_conf.y	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,200 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+/* Yacc extension's configuration parser.
+ * See doc/rt_default.conf.sample for configuration file format
+ */
+
+/* For development only : */
+%debug 
+%error-verbose
+
+/* The parser receives the configuration file filename as parameter */
+%parse-param {char * conffile}
+
+/* Keep track of location */
+%locations 
+%pure-parser
+
+%{
+#include "app_test.h"
+#include "atst_conf.tab.h"	/* bison is not smart enough to define the YYLTYPE before including this code, so... */
+
+#include <string.h>
+#include <errno.h>
+
+/* Forward declaration */
+int yyparse(char * conffile);
+
+/* Parse the configuration file */
+int atst_conf_handle(char * conffile)
+{
+	extern FILE * atst_confin;
+	int ret;
+	
+	TRACE_ENTRY("%p", conffile);
+	
+	TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
+	
+	atst_confin = fopen(conffile, "r");
+	if (atst_confin == NULL) {
+		ret = errno;
+		log_error("Unable to open extension configuration file %s for reading: %s\n", conffile, strerror(ret));
+		TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
+		return ret;
+	}
+
+	ret = yyparse(conffile);
+
+	fclose(atst_confin);
+
+	if (ret != 0) {
+		TRACE_DEBUG (INFO, "Unable to parse the configuration file.");
+		return EINVAL;
+	}
+	
+	return 0;
+}
+
+/* The Lex parser prototype */
+int atst_conflex(YYSTYPE *lvalp, YYLTYPE *llocp);
+
+/* Function to report the errors */
+void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
+{
+	TRACE_DEBUG(INFO, "Error in configuration parsing");
+	
+	if (ploc->first_line != ploc->last_line)
+		log_error("%s:%d.%d-%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
+	else if (ploc->first_column != ploc->last_column)
+		log_error("%s:%d.%d-%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
+	else
+		log_error("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s);
+}
+
+%}
+
+/* Values returned by lex for token */
+%union {
+	char 		*string;	/* The string is allocated by strdup in lex.*/
+	int		 integer;	/* Store integer values */
+}
+
+/* In case of error in the lexical analysis */
+%token 		LEX_ERROR
+
+/* Key words */
+%token 		VENDOR_ID
+%token 		APPLI_ID
+%token 		CMD_ID
+%token 		AVP_ID
+%token 		MODE
+%token 		DEST_REALM
+%token 		DEST_HOST
+%token 		SIGNAL
+
+/* Tokens and types for routing table definition */
+/* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
+%token <string>	QSTRING
+
+/* An integer value */
+%token <integer> INTEGER
+
+
+
+/* -------------------------------------- */
+%%
+
+	/* The grammar definition */
+conffile:		/* empty grammar is OK */
+			| conffile vendor
+			| conffile appli
+			| conffile cmd
+			| conffile avp
+			| conffile mode
+			| conffile dstrealm
+			| conffile dsthost
+			| conffile signal
+			;
+
+vendor:			VENDOR_ID '=' INTEGER ';'
+			{
+				atst_conf->vendor_id = $3;
+			}
+			;
+
+appli:			APPLI_ID '=' INTEGER ';'
+			{
+				atst_conf->appli_id = $3;
+			}
+			;
+
+cmd:			CMD_ID '=' INTEGER ';'
+			{
+				atst_conf->cmd_id = $3;
+			}
+			;
+
+avp:			AVP_ID '=' INTEGER ';'
+			{
+				atst_conf->avp_id = $3;
+			}
+			;
+
+mode:			MODE '=' INTEGER ';'
+			{
+				atst_conf->mode = $3;
+			}
+			;
+
+dstrealm:		DEST_REALM '=' QSTRING ';'
+			{
+				free(atst_conf->dest_realm);
+				atst_conf->dest_realm = $3;
+			}
+			;
+
+dsthost:		DEST_HOST '=' QSTRING ';'
+			{
+				free(atst_conf->dest_host);
+				atst_conf->dest_host = $3;
+			}
+			;
+
+signal:			SIGNAL '=' INTEGER ';'
+			{
+				atst_conf->signal = $3;
+			}
+			;
--- a/extensions/app_test/atst_gram.y	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,200 +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.								 *
-*********************************************************************************************************/
-
-/* Yacc extension's configuration parser.
- * See doc/rt_default.conf.sample for configuration file format
- */
-
-/* For development only : */
-%debug 
-%error-verbose
-
-/* The parser receives the configuration file filename as parameter */
-%parse-param {char * conffile}
-
-/* Keep track of location */
-%locations 
-%pure-parser
-
-%{
-#include "app_test.h"
-#include "atst_gram.h"	/* bison is not smart enough to define the YYLTYPE before including this code, so... */
-
-#include <string.h>
-#include <errno.h>
-
-/* Forward declaration */
-int yyparse(char * conffile);
-
-/* Parse the configuration file */
-int conf_parse(char * conffile)
-{
-	extern FILE * yyin;
-	int ret;
-	
-	TRACE_ENTRY("%p", conffile);
-	
-	TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
-	
-	yyin = fopen(conffile, "r");
-	if (yyin == NULL) {
-		ret = errno;
-		log_error("Unable to open extension configuration file %s for reading: %s\n", conffile, strerror(ret));
-		TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
-		return ret;
-	}
-
-	ret = yyparse(conffile);
-
-	fclose(yyin);
-
-	if (ret != 0) {
-		TRACE_DEBUG (INFO, "Unable to parse the configuration file.");
-		return EINVAL;
-	}
-	
-	return 0;
-}
-
-/* The Lex parser prototype */
-int yylex(YYSTYPE *lvalp, YYLTYPE *llocp);
-
-/* Function to report the errors */
-void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
-{
-	TRACE_DEBUG(INFO, "Error in configuration parsing");
-	
-	if (ploc->first_line != ploc->last_line)
-		log_error("%s:%d.%d-%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
-	else if (ploc->first_column != ploc->last_column)
-		log_error("%s:%d.%d-%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
-	else
-		log_error("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s);
-}
-
-%}
-
-/* Values returned by lex for token */
-%union {
-	char 		*string;	/* The string is allocated by strdup in lex.*/
-	int		 integer;	/* Store integer values */
-}
-
-/* In case of error in the lexical analysis */
-%token 		LEX_ERROR
-
-/* Key words */
-%token 		VENDOR_ID
-%token 		APPLI_ID
-%token 		CMD_ID
-%token 		AVP_ID
-%token 		MODE
-%token 		DEST_REALM
-%token 		DEST_HOST
-%token 		SIGNAL
-
-/* Tokens and types for routing table definition */
-/* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
-%token <string>	QSTRING
-
-/* An integer value */
-%token <integer> INTEGER
-
-
-
-/* -------------------------------------- */
-%%
-
-	/* The grammar definition */
-conffile:		/* empty grammar is OK */
-			| conffile vendor
-			| conffile appli
-			| conffile cmd
-			| conffile avp
-			| conffile mode
-			| conffile dstrealm
-			| conffile dsthost
-			| conffile signal
-			;
-
-vendor:			VENDOR_ID '=' INTEGER ';'
-			{
-				atst_conf->vendor_id = $3;
-			}
-			;
-
-appli:			APPLI_ID '=' INTEGER ';'
-			{
-				atst_conf->appli_id = $3;
-			}
-			;
-
-cmd:			CMD_ID '=' INTEGER ';'
-			{
-				atst_conf->cmd_id = $3;
-			}
-			;
-
-avp:			AVP_ID '=' INTEGER ';'
-			{
-				atst_conf->avp_id = $3;
-			}
-			;
-
-mode:			MODE '=' INTEGER ';'
-			{
-				atst_conf->mode = $3;
-			}
-			;
-
-dstrealm:		DEST_REALM '=' QSTRING ';'
-			{
-				free(atst_conf->dest_realm);
-				atst_conf->dest_realm = $3;
-			}
-			;
-
-dsthost:		DEST_HOST '=' QSTRING ';'
-			{
-				free(atst_conf->dest_host);
-				atst_conf->dest_host = $3;
-			}
-			;
-
-signal:			SIGNAL '=' INTEGER ';'
-			{
-				atst_conf->signal = $3;
-			}
-			;
--- a/extensions/app_test/atst_tok.l	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,161 +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.								 *
-*********************************************************************************************************/
-
-/* Lex extension's configuration parser.
- *
- * The configuration file contains a default priority, and a list of peers with optional overwite priority.
- * -- see the app_test.conf.sample file for more detail.
- */
-
-%{
-#include "app_test.h"
-/* Include yacc tokens definitions */
-#include "atst_gram.h"
-
-/* Update the column information */
-#define YY_USER_ACTION { 						\
-	yylloc->first_column = yylloc->last_column + 1; 		\
-	yylloc->last_column = yylloc->first_column + yyleng - 1;	\
-}
-
-/* Avoid warning with newer flex */
-#define YY_NO_INPUT
-
-%}
-
-%option bison-bridge bison-locations
-%option noyywrap
-%option nounput
-
-%%
-
-	/* Update the line count */
-\n			{
-				yylloc->first_line++; 
-				yylloc->last_line++; 
-				yylloc->last_column=0; 
-			}
-	 
-	/* Eat all spaces but not new lines */
-([[:space:]]{-}[\n])+	;
-	/* Eat all comments */
-#.*$			;
-
-	/* Recognize any integer */
-[-]?[[:digit:]]+		{
-				/* Convert this to an integer value */
-				int ret=0;
-				ret = sscanf(yytext, "%i", &yylval->integer);
-				if (ret != 1) {
-					/* No matching: an error occurred */
-					log_error("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno));
-					return LEX_ERROR; /* trig an error in yacc parser */
-					/* Maybe we could REJECT instead of failing here? */
-				}
-				return INTEGER;
-			}
-
-	/* Recognize quoted strings */
-\"[[:alnum:].-]+\"	{
-				/* Match a string. expected only ASCII characters, '-' and '.'. The validation is done in yacc */
-				yylval->string = strdup(yytext+1);
-				if (!yylval->string) {
-					log_error("Unable to copy the string '%s': %s\n", yytext, strerror(errno));
-					TRACE_DEBUG(INFO, "strdup failed");
-					return LEX_ERROR; /* trig an error in yacc parser */
-				}
-				yylval->string[strlen(yytext) - 2] = '\0';
-				return QSTRING;
-			}
-			
-	/* Recognize the tokens */	
-(?i:"vendor-id")	{
-				return VENDOR_ID;
-			}
-
-(?i:"appli-id")		{
-				return APPLI_ID;
-			}
-
-(?i:"cmd-id")		{
-				return CMD_ID;
-			}
-
-(?i:"avp-id")		{
-				return AVP_ID;
-			}
-
-(?i:"mode")		{
-				return MODE;
-			}
-
-(?i:"server")		{
-				yylval->integer = MODE_SERV;
-				return INTEGER;
-			}
-
-(?i:"client")		{
-				yylval->integer = MODE_CLI;
-				return INTEGER;
-			}
-
-(?i:"both")		{
-				yylval->integer = MODE_SERV | MODE_CLI;
-				return INTEGER;
-			}
-
-(?i:"dest-realm")	{
-				return DEST_REALM;
-			}
-
-(?i:"dest-host")	{
-				return DEST_HOST;
-			}
-
-(?i:"Signal")		{
-				return SIGNAL;
-			}
-
-			
-	/* Valid single characters for yyparse */
-[=;]			{ return yytext[0]; }
-
-	/* Unrecognized sequence, if it did not match any previous pattern */
-[^[:space:]"*=>;\n]+	{ 
-				log_error("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext);
-			 	return LEX_ERROR; 
-			}
-
-%%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/rt_any/CMakeLists.txt	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,5 @@
+# The rt_any extension
+PROJECT("Force routing to random peer waaad extension" C)
+
+# Compile as a module
+ADD_LIBRARY(rt_any MODULE rt_any.c)
--- a/extensions/rt_any/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-
-pkglib_LTLIBRARIES = rt_any.la
-rt_any_la_SOURCES = rt_any.c 
-rt_any_la_LDFLAGS = -module
-
-# Location of the API headers:
-AM_CPPFLAGS = -I$(srcdir)/../../include
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/rt_debug/CMakeLists.txt	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,5 @@
+# The rt_debug extension
+PROJECT("Routing trace waaad extension" C)
+
+# Compile as a module
+ADD_LIBRARY(rt_debug MODULE rt_debug.c)
--- a/extensions/rt_debug/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-
-pkglib_LTLIBRARIES = rt_debug.la
-rt_debug_la_SOURCES = rt_debug.c 
-rt_debug_la_LDFLAGS = -module
-
-# Location of the API headers:
-AM_CPPFLAGS = -I$(srcdir)/../../include
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/rt_default/CMakeLists.txt	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,20 @@
+# The rt_default extension
+PROJECT("Default routing waaad extension" C)
+
+# Parser files
+BISON_FILE(rtd_conf.y)
+FLEX_FILE(rtd_conf.l)
+SET_SOURCE_FILES_PROPERTIES(lex.rtd_conf.c rtd_conf.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}")
+
+# List of source files
+SET( RT_DEFAULT_SRC
+	rt_default.c
+	rt_default.h
+	lex.rtd_conf.c
+	rtd_conf.tab.c
+	rtd_conf.tab.h
+	rtd_table.c
+)
+
+# Compile these files as a module
+ADD_LIBRARY(rt_default MODULE ${RT_DEFAULT_SRC})
--- a/extensions/rt_default/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-# Compile the "default" routing extension for waaad.
-
-# Location of the API headers:
-AM_CPPFLAGS = -I$(srcdir)/../../include
-
-# For bison
-AM_YFLAGS = -d
-BUILT_SOURCES = rtd_gram.h
-
-# The extension to build
-pkglib_LTLIBRARIES = rt_default.la
-
-# Linker flags (for libtool)
-rt_default_la_LDFLAGS = -module
-
-# Source files
-rt_default_la_SOURCES = rt_default.c 	\
-			rtd_gram.y 	\
-			rtd_tok.l	\
-			rtd_table.c
-
--- a/extensions/rt_default/rt_default.c	Wed Feb 25 11:27:53 2009 +0900
+++ b/extensions/rt_default/rt_default.c	Wed Feb 25 16:49:21 2009 +0900
@@ -228,7 +228,7 @@
 	}
 	
 	if (conffile != NULL) {
-		ret = conf_parse(conffile);
+		ret = rtd_conf_handle(conffile);
 		if (ret != 0) {
 			log_error("Error parsing extension configuration: %s\n", strerror(ret));
 			return ret;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/rt_default/rtd_conf.l	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,153 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+/* Lex sec_nosec extension's configuration parser.
+ *
+ * The configuration file contains a default priority, and a list of peers with optional overwite priority.
+ * -- see the sec_nosec.conf.sample file for more detail.
+ */
+
+%{
+#include "rt_default.h"
+/* Include yacc tokens definitions */
+#include "rtd_conf.tab.h"
+
+/* Update the column information */
+#define YY_USER_ACTION { 						\
+	yylloc->first_column = yylloc->last_column + 1; 		\
+	yylloc->last_column = yylloc->first_column + yyleng - 1;	\
+}
+
+/* Avoid warning with newer flex */
+#define YY_NO_INPUT
+
+%}
+
+%option bison-bridge bison-locations
+%option noyywrap
+%option nounput
+
+%%
+
+	/* Update the line count */
+\n			{
+				yylloc->first_line++; 
+				yylloc->last_line++; 
+				yylloc->last_column=0; 
+			}
+	 
+	/* Eat all spaces but not new lines */
+([[:space:]]{-}[\n])+	;
+	/* Eat all comments */
+#.*$			;
+
+	/* Recognize any integer */
+[-]?[[:digit:]]+		{
+				/* Convert this to an integer value */
+				int ret=0;
+				ret = sscanf(yytext, "%i", &yylval->integer);
+				if (ret != 1) {
+					/* No matching: an error occurred */
+					log_error("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno));
+					return LEX_ERROR; /* trig an error in yacc parser */
+					/* Maybe we could REJECT instead of failing here? */
+				}
+				return INTEGER;
+			}
+
+	/* Recognize quoted strings */
+\"[[:alnum:].-]+\"	{
+				/* Match a string. expected only ASCII characters, '-' and '.'. The validation is done in yacc */
+				yylval->string = strdup(yytext+1);
+				if (!yylval->string) {
+					log_error("Unable to copy the string '%s': %s\n", yytext, strerror(errno));
+					TRACE_DEBUG(INFO, "strdup failed");
+					return LEX_ERROR; /* trig an error in yacc parser */
+				}
+				yylval->string[strlen(yytext) - 2] = '\0';
+				return QSTRING;
+			}
+			
+	/* Recognize the verbosity string */	
+(?i:"Verbosity")	{
+				return VERBOSITY;
+			}
+	/* Idem for other tokens */
+(?i:"handle_dest_host")	{
+				return HANDLE_DESTINATION_HOST;
+			}
+			
+(?i:"handle_dest_realm") {
+				return HANDLE_DESTINATION_REALM;
+			}
+			
+(?i:"score_dest_host") 	{
+				return SCORE_DESTINATION_HOST;
+			}
+			
+(?i:"score_dest_realm")	{
+				return SCORE_DESTINATION_REALM;
+			}
+			
+(?i:"score_no_info") 	{
+				return SCORE_NO_INFO;
+			}
+			
+(?i:"score_def") 	{
+				return SCORE_DEFAULT_PEER;
+			}
+			
+(?i:"score_def_pref") 	{
+				return SCORE_DEFAULT_PEER_PREF;
+			}
+			
+(?i:"score_realm") 	{
+				return SCORE_REALM;
+			}
+			
+(?i:"score_realm_pref") {
+				return SCORE_REALM_PREF;
+			}
+			
+	/* Valid single characters for yyparse */
+[*=>;]			{ return yytext[0]; }
+
+	/* Unrecognized sequence, if it did not match any previous pattern */
+[^[:space:]"*=>;\n]+	{ 
+				log_error("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext);
+			 	return LEX_ERROR; 
+			}
+
+%%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/rt_default/rtd_conf.y	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,288 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+/* Yacc extension's configuration parser.
+ * See doc/rt_default.conf.sample for configuration file format
+ */
+
+/* For development only : */
+%debug 
+%error-verbose
+
+/* The parser receives the configuration file filename as parameter */
+%parse-param {char * conffile}
+
+/* Keep track of location */
+%locations 
+%pure-parser
+
+%{
+#include "rt_default.h"
+#include "rtd_conf.tab.h"	/* bison is not smart enough to define the YYLTYPE before including this code, so... */
+
+#include <string.h>
+#include <errno.h>
+
+/* Forward declaration */
+int yyparse(char * conffile);
+
+/* Parse the configuration file */
+int rtd_conf_handle(char * conffile)
+{
+	extern FILE * rtd_confin;
+	int ret;
+	
+	TRACE_ENTRY("%p", conffile);
+	
+	TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
+	
+	rtd_confin = fopen(conffile, "r");
+	if (rtd_confin == NULL) {
+		ret = errno;
+		log_error("Unable to open extension configuration file %s for reading: %s\n", conffile, strerror(ret));
+		TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
+		return ret;
+	}
+
+	ret = rtd_confparse(conffile);
+
+	fclose(rtd_confin);
+
+	if (ret != 0) {
+		TRACE_DEBUG (INFO, "Unable to parse the configuration file.");
+		return EINVAL;
+	}
+	
+	return 0;
+}
+
+/* The Lex parser prototype */
+int rtd_conflex(YYSTYPE *lvalp, YYLTYPE *llocp);
+
+/* This function checks a string value can be a DiameterId (== a fqdn) */
+static int is_valid_fqdn( char * candidate ) 
+{
+	/* We first search for a '.' */
+	if (!strchr(candidate, '.')) {
+		log_error("The string '%s' is not a valid fully-qualified domain name (fqdn).\n", candidate);
+		return 0;
+	}
+	
+	/* We may do additional checking here */
+	
+	/* Ok this candidate is valid */
+	return 1;
+}
+
+/* This function checks a string value can be a Realm */
+static int is_valid_realm( char * candidate ) 
+{
+	/* What are the constraints? i18n and so on... See for this another time... */
+	
+	/* Ok this candidate is valid */
+	return 1;
+}
+
+/* Function to report the errors */
+void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
+{
+	TRACE_DEBUG(INFO, "Error in configuration parsing");
+	
+	if (ploc->first_line != ploc->last_line)
+		log_error("%s:%d.%d-%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
+	else if (ploc->first_column != ploc->last_column)
+		log_error("%s:%d.%d-%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
+	else
+		log_error("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s);
+}
+
+/* Global var to simplify reporting prefered route */
+int pref;
+
+%}
+
+/* Values returned by lex for token */
+%union {
+	char 		*string;	/* The string is allocated by strdup in lex.*/
+	int		 integer;	/* Store integer values */
+}
+
+/* In case of error in the lexical analysis */
+%token 		LEX_ERROR
+
+/* The debug level token */
+%token 		VERBOSITY
+
+/* Tokens to overwrite default configuration */
+%token 		HANDLE_DESTINATION_HOST
+%token 		HANDLE_DESTINATION_REALM
+%token 		SCORE_DESTINATION_HOST
+%token 		SCORE_DESTINATION_REALM
+%token 		SCORE_NO_INFO
+%token 		SCORE_DEFAULT_PEER
+%token 		SCORE_DEFAULT_PEER_PREF
+%token 		SCORE_REALM
+%token 		SCORE_REALM_PREF
+
+/* Tokens and types for routing table definition */
+/* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
+%token <string>	QSTRING
+/* used in these subtypes */
+%type <string>	FQDN		/* This is a fqdn. We check that the syntax is correct. */
+%type <string>	REALM		/* This is a realm. */
+%type <string>	ROUTE		/* A realm or NULL for default realm */
+%type <string>	DEST		/* the FQDN, and the "pref" global var is defined */
+
+/* An integer value */
+%token <integer> INTEGER
+
+
+
+/* -------------------------------------- */
+%%
+
+	/* The grammar definition */
+conffile:		/* empty grammar is OK */
+			| conffile verbosity
+			| conffile confhdl
+			| conffile confscore
+			| conffile peerdef
+			;
+
+	/* Defining the extension debug verbosity level */
+verbosity:		VERBOSITY '=' INTEGER ';'
+			{
+				rtd_conf->verbosity = $3;
+			}
+			;
+			
+	/* Overwrite some default configuration values */
+confhdl:		HANDLE_DESTINATION_HOST '=' INTEGER ';'
+			{
+				rtd_conf->do_dest_host = $3;
+			}
+			| HANDLE_DESTINATION_REALM '=' INTEGER ';'
+			{
+				rtd_conf->do_dest_realm = $3;
+			}
+			;
+
+confscore:		SCORE_DESTINATION_HOST '=' INTEGER ';'
+			{
+				rtd_conf->sc_dest_host = $3;
+			}
+			| SCORE_DESTINATION_REALM '=' INTEGER ';'
+			{
+				rtd_conf->sc_dest_realm = $3;
+			}
+			| SCORE_NO_INFO '=' INTEGER ';'
+			{
+				rtd_conf->sc_no_info = $3;
+			}
+			| SCORE_DEFAULT_PEER '=' INTEGER ';'
+			{
+				rtd_conf->sc_all = $3;
+			}
+			| SCORE_DEFAULT_PEER_PREF '=' INTEGER ';'
+			{
+				rtd_conf->sc_all_pref = $3;
+			}
+			| SCORE_REALM '=' INTEGER ';'
+			{
+				rtd_conf->sc_rlm = $3;
+			}
+			| SCORE_REALM_PREF '=' INTEGER ';'
+			{
+				rtd_conf->sc_rlm_pref = $3;
+			}
+			;
+
+	/* Definitions for the routing table */
+peerdef:		ROUTE '=' '>' DEST ';'
+			{
+				if (rtd_add( $1, $4, pref ) != 0) {
+					yyerror (&yylloc, conffile, "An error occurred while adding a route definition, aborting...");
+					YYERROR;
+				}
+				/* We don't free the strings here, they will be freed by the rtd_fini function */
+			}
+			;
+			
+ROUTE:			REALM
+			{
+				$$ = $1;
+			}
+			| '*'
+			{
+				$$ = NULL;
+			}
+			;
+			
+DEST:			FQDN
+			{
+				pref = 0;
+				$$ = $1;
+			}
+			| FQDN '*'
+			{
+				pref = 1;
+				$$ = $1;
+			}
+			;
+
+	/* Validating a FQDN: */
+FQDN:			QSTRING
+			{
+				/* Verify this is a valid FQDN */
+				if (!is_valid_fqdn($1)) {
+					yyerror (&yylloc, conffile, "An error was detected on a fqdn, aborting...");
+					YYERROR;
+				}
+				$$ = $1;
+			}
+			;
+			
+	/* Validating a REALM: */
+REALM:			QSTRING
+			{
+				/* Verify this is a valid FQDN */
+				if (!is_valid_realm($1)) {
+					yyerror (&yylloc, conffile, "An error was detected on a fqdn, aborting...");
+					YYERROR;
+				}
+				$$ = $1;
+			}
+			;
+	
--- a/extensions/rt_default/rtd_gram.y	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,288 +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.								 *
-*********************************************************************************************************/
-
-/* Yacc extension's configuration parser.
- * See doc/rt_default.conf.sample for configuration file format
- */
-
-/* For development only : */
-%debug 
-%error-verbose
-
-/* The parser receives the configuration file filename as parameter */
-%parse-param {char * conffile}
-
-/* Keep track of location */
-%locations 
-%pure-parser
-
-%{
-#include "rt_default.h"
-#include "rtd_gram.h"	/* bison is not smart enough to define the YYLTYPE before including this code, so... */
-
-#include <string.h>
-#include <errno.h>
-
-/* Forward declaration */
-int yyparse(char * conffile);
-
-/* Parse the configuration file */
-int conf_parse(char * conffile)
-{
-	extern FILE * yyin;
-	int ret;
-	
-	TRACE_ENTRY("%p", conffile);
-	
-	TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
-	
-	yyin = fopen(conffile, "r");
-	if (yyin == NULL) {
-		ret = errno;
-		log_error("Unable to open extension configuration file %s for reading: %s\n", conffile, strerror(ret));
-		TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
-		return ret;
-	}
-
-	ret = yyparse(conffile);
-
-	fclose(yyin);
-
-	if (ret != 0) {
-		TRACE_DEBUG (INFO, "Unable to parse the configuration file.");
-		return EINVAL;
-	}
-	
-	return 0;
-}
-
-/* The Lex parser prototype */
-int yylex(YYSTYPE *lvalp, YYLTYPE *llocp);
-
-/* This function checks a string value can be a DiameterId (== a fqdn) */
-static int is_valid_fqdn( char * candidate ) 
-{
-	/* We first search for a '.' */
-	if (!strchr(candidate, '.')) {
-		log_error("The string '%s' is not a valid fully-qualified domain name (fqdn).\n", candidate);
-		return 0;
-	}
-	
-	/* We may do additional checking here */
-	
-	/* Ok this candidate is valid */
-	return 1;
-}
-
-/* This function checks a string value can be a Realm */
-static int is_valid_realm( char * candidate ) 
-{
-	/* What are the constraints? i18n and so on... See for this another time... */
-	
-	/* Ok this candidate is valid */
-	return 1;
-}
-
-/* Function to report the errors */
-void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
-{
-	TRACE_DEBUG(INFO, "Error in configuration parsing");
-	
-	if (ploc->first_line != ploc->last_line)
-		log_error("%s:%d.%d-%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
-	else if (ploc->first_column != ploc->last_column)
-		log_error("%s:%d.%d-%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
-	else
-		log_error("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s);
-}
-
-/* Global var to simplify reporting prefered route */
-int pref;
-
-%}
-
-/* Values returned by lex for token */
-%union {
-	char 		*string;	/* The string is allocated by strdup in lex.*/
-	int		 integer;	/* Store integer values */
-}
-
-/* In case of error in the lexical analysis */
-%token 		LEX_ERROR
-
-/* The debug level token */
-%token 		VERBOSITY
-
-/* Tokens to overwrite default configuration */
-%token 		HANDLE_DESTINATION_HOST
-%token 		HANDLE_DESTINATION_REALM
-%token 		SCORE_DESTINATION_HOST
-%token 		SCORE_DESTINATION_REALM
-%token 		SCORE_NO_INFO
-%token 		SCORE_DEFAULT_PEER
-%token 		SCORE_DEFAULT_PEER_PREF
-%token 		SCORE_REALM
-%token 		SCORE_REALM_PREF
-
-/* Tokens and types for routing table definition */
-/* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
-%token <string>	QSTRING
-/* used in these subtypes */
-%type <string>	FQDN		/* This is a fqdn. We check that the syntax is correct. */
-%type <string>	REALM		/* This is a realm. */
-%type <string>	ROUTE		/* A realm or NULL for default realm */
-%type <string>	DEST		/* the FQDN, and the "pref" global var is defined */
-
-/* An integer value */
-%token <integer> INTEGER
-
-
-
-/* -------------------------------------- */
-%%
-
-	/* The grammar definition */
-conffile:		/* empty grammar is OK */
-			| conffile verbosity
-			| conffile confhdl
-			| conffile confscore
-			| conffile peerdef
-			;
-
-	/* Defining the extension debug verbosity level */
-verbosity:		VERBOSITY '=' INTEGER ';'
-			{
-				rtd_conf->verbosity = $3;
-			}
-			;
-			
-	/* Overwrite some default configuration values */
-confhdl:		HANDLE_DESTINATION_HOST '=' INTEGER ';'
-			{
-				rtd_conf->do_dest_host = $3;
-			}
-			| HANDLE_DESTINATION_REALM '=' INTEGER ';'
-			{
-				rtd_conf->do_dest_realm = $3;
-			}
-			;
-
-confscore:		SCORE_DESTINATION_HOST '=' INTEGER ';'
-			{
-				rtd_conf->sc_dest_host = $3;
-			}
-			| SCORE_DESTINATION_REALM '=' INTEGER ';'
-			{
-				rtd_conf->sc_dest_realm = $3;
-			}
-			| SCORE_NO_INFO '=' INTEGER ';'
-			{
-				rtd_conf->sc_no_info = $3;
-			}
-			| SCORE_DEFAULT_PEER '=' INTEGER ';'
-			{
-				rtd_conf->sc_all = $3;
-			}
-			| SCORE_DEFAULT_PEER_PREF '=' INTEGER ';'
-			{
-				rtd_conf->sc_all_pref = $3;
-			}
-			| SCORE_REALM '=' INTEGER ';'
-			{
-				rtd_conf->sc_rlm = $3;
-			}
-			| SCORE_REALM_PREF '=' INTEGER ';'
-			{
-				rtd_conf->sc_rlm_pref = $3;
-			}
-			;
-
-	/* Definitions for the routing table */
-peerdef:		ROUTE '=' '>' DEST ';'
-			{
-				if (rtd_add( $1, $4, pref ) != 0) {
-					yyerror (&yylloc, conffile, "An error occurred while adding a route definition, aborting...");
-					YYERROR;
-				}
-				/* We don't free the strings here, they will be freed by the rtd_fini function */
-			}
-			;
-			
-ROUTE:			REALM
-			{
-				$$ = $1;
-			}
-			| '*'
-			{
-				$$ = NULL;
-			}
-			;
-			
-DEST:			FQDN
-			{
-				pref = 0;
-				$$ = $1;
-			}
-			| FQDN '*'
-			{
-				pref = 1;
-				$$ = $1;
-			}
-			;
-
-	/* Validating a FQDN: */
-FQDN:			QSTRING
-			{
-				/* Verify this is a valid FQDN */
-				if (!is_valid_fqdn($1)) {
-					yyerror (&yylloc, conffile, "An error was detected on a fqdn, aborting...");
-					YYERROR;
-				}
-				$$ = $1;
-			}
-			;
-			
-	/* Validating a REALM: */
-REALM:			QSTRING
-			{
-				/* Verify this is a valid FQDN */
-				if (!is_valid_realm($1)) {
-					yyerror (&yylloc, conffile, "An error was detected on a fqdn, aborting...");
-					YYERROR;
-				}
-				$$ = $1;
-			}
-			;
-	
--- a/extensions/rt_default/rtd_tok.l	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,153 +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.								 *
-*********************************************************************************************************/
-
-/* Lex sec_nosec extension's configuration parser.
- *
- * The configuration file contains a default priority, and a list of peers with optional overwite priority.
- * -- see the sec_nosec.conf.sample file for more detail.
- */
-
-%{
-#include "rt_default.h"
-/* Include yacc tokens definitions */
-#include "rtd_gram.h"
-
-/* Update the column information */
-#define YY_USER_ACTION { 						\
-	yylloc->first_column = yylloc->last_column + 1; 		\
-	yylloc->last_column = yylloc->first_column + yyleng - 1;	\
-}
-
-/* Avoid warning with newer flex */
-#define YY_NO_INPUT
-
-%}
-
-%option bison-bridge bison-locations
-%option noyywrap
-%option nounput
-
-%%
-
-	/* Update the line count */
-\n			{
-				yylloc->first_line++; 
-				yylloc->last_line++; 
-				yylloc->last_column=0; 
-			}
-	 
-	/* Eat all spaces but not new lines */
-([[:space:]]{-}[\n])+	;
-	/* Eat all comments */
-#.*$			;
-
-	/* Recognize any integer */
-[-]?[[:digit:]]+		{
-				/* Convert this to an integer value */
-				int ret=0;
-				ret = sscanf(yytext, "%i", &yylval->integer);
-				if (ret != 1) {
-					/* No matching: an error occurred */
-					log_error("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno));
-					return LEX_ERROR; /* trig an error in yacc parser */
-					/* Maybe we could REJECT instead of failing here? */
-				}
-				return INTEGER;
-			}
-
-	/* Recognize quoted strings */
-\"[[:alnum:].-]+\"	{
-				/* Match a string. expected only ASCII characters, '-' and '.'. The validation is done in yacc */
-				yylval->string = strdup(yytext+1);
-				if (!yylval->string) {
-					log_error("Unable to copy the string '%s': %s\n", yytext, strerror(errno));
-					TRACE_DEBUG(INFO, "strdup failed");
-					return LEX_ERROR; /* trig an error in yacc parser */
-				}
-				yylval->string[strlen(yytext) - 2] = '\0';
-				return QSTRING;
-			}
-			
-	/* Recognize the verbosity string */	
-(?i:"Verbosity")	{
-				return VERBOSITY;
-			}
-	/* Idem for other tokens */
-(?i:"handle_dest_host")	{
-				return HANDLE_DESTINATION_HOST;
-			}
-			
-(?i:"handle_dest_realm") {
-				return HANDLE_DESTINATION_REALM;
-			}
-			
-(?i:"score_dest_host") 	{
-				return SCORE_DESTINATION_HOST;
-			}
-			
-(?i:"score_dest_realm")	{
-				return SCORE_DESTINATION_REALM;
-			}
-			
-(?i:"score_no_info") 	{
-				return SCORE_NO_INFO;
-			}
-			
-(?i:"score_def") 	{
-				return SCORE_DEFAULT_PEER;
-			}
-			
-(?i:"score_def_pref") 	{
-				return SCORE_DEFAULT_PEER_PREF;
-			}
-			
-(?i:"score_realm") 	{
-				return SCORE_REALM;
-			}
-			
-(?i:"score_realm_pref") {
-				return SCORE_REALM_PREF;
-			}
-			
-	/* Valid single characters for yyparse */
-[*=>;]			{ return yytext[0]; }
-
-	/* Unrecognized sequence, if it did not match any previous pattern */
-[^[:space:]"*=>;\n]+	{ 
-				log_error("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext);
-			 	return LEX_ERROR; 
-			}
-
-%%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/sample/CMakeLists.txt	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,5 @@
+# The sample extension
+PROJECT("Sample waaad extension" C)
+
+# Compile as a module
+ADD_LIBRARY(sample MODULE sample.c fini.c)
--- a/extensions/sample/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-# Compile the sample extension.
-
-# noinst_LTLIBRARIES = sample.la
-pkglib_LTLIBRARIES = sample.la
-sample_la_SOURCES = sample.c fini.c
-sample_la_LDFLAGS = -module
-
-# Location of the API headers:
-AM_CPPFLAGS = -I$(srcdir)/../../include
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/sec_nosec/CMakeLists.txt	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,25 @@
+# The sec_nosec extension
+PROJECT("Filtered no encryption security waaad extension" C)
+
+# Parser files
+BISON_FILE(sns_conf.y)
+FLEX_FILE(sns_conf.l)
+SET_SOURCE_FILES_PROPERTIES(lex.sns_conf.c sns_conf.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}")
+
+# List of source files
+SET( SEC_NOSEC_SRC
+	sec_nosec.c
+	sec_nosec.h
+	lex.sns_conf.c
+	sns_conf.tab.c
+	sns_conf.tab.h
+	sns_is_supported_peer.c
+	sns_parse.c
+	sns_peers.c
+	sns_recv_unprotect.c
+	sns_send_protect.c
+	sns_state_change.c
+)
+
+# Compile these files as a module
+ADD_LIBRARY(sec_nosec MODULE ${SEC_NOSEC_SRC})
--- a/extensions/sec_nosec/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-# Compile the nosec extension.
-
-# Location of the API headers:
-AM_CPPFLAGS = -I$(srcdir)/../../include
-
-# For bison
-AM_YFLAGS = -d
-BUILT_SOURCES = sns_gram.h
-
-pkglib_LTLIBRARIES = sec_nosec.la
-sec_nosec_la_LDFLAGS = -module
-
-sec_nosec_la_SOURCES =  sec_nosec.c 		\
-			sns_state_change.c 	\
-			sns_send_protect.c 	\
-			sns_recv_unprotect.c 	\
-			sns_is_supported_peer.c	\
-			sns_peers.c		\
-			sns_parse.c		\
-			sns_gram.y		\
-			sns_token.l
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/sec_nosec/sns_conf.l	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,122 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+/* Lex sec_nosec extension's configuration parser.
+ *
+ * The configuration file contains a default priority, and a list of peers with optional overwite priority.
+ * -- see the sec_nosec.conf.sample file for more detail.
+ */
+
+%{
+/* Include the daemon's header files */
+#include "sec_nosec.h"
+/* Include yacc tokens definitions */
+#include "sns_conf.tab.h"
+
+/* Update the column information */
+#define YY_USER_ACTION { 					\
+	yylloc->first_column = yylloc->last_column + 1; 	\
+	yylloc->last_column = yylloc->first_column + yyleng - 1;\
+}
+
+/* Avoid warning with newer flex */
+#define YY_NO_INPUT
+
+%}
+
+%option bison-bridge bison-locations
+%option noyywrap
+%option nounput
+
+%%
+
+	/* Update the line count */
+\n			{
+				yylloc->first_line++; 
+				yylloc->last_line++; 
+				yylloc->last_column=0; 
+			}
+	 
+	/* Eat all spaces but not new lines */
+([[:space:]]{-}[\n])+	;
+	/* Eat all comments */
+#.*$			;
+
+	/* Recognize any integer */
+[[:digit:]]+		{
+				/* Convert this to an integer value */
+				int ret=0;
+				ret = sscanf(yytext, "%i", &yylval->integer);
+				if (ret != 1) {
+					/* No matching: an error occurred */
+					log_error("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno));
+					return LEX_ERROR; /* trig an error in yacc parser */
+					/* Maybe we could REJECT instead of failing here? */
+				}
+				return INTEGER;
+			}
+
+	/* Recognize the verbosity string */	
+(?i:"Debug_Verbosity")	{
+				return VERBOSITY;
+			}
+
+	/* Recognize the default_priority string */	
+(?i:"Default_Priority")	{
+				return DEF_PRIO; 
+			}
+
+	/* Any other string is considered as a fqdn, if the pattern is valid */
+[[:alnum:].-]+		{
+				/* Match a fqdn string. expected only ASCII characters, '-' and '.'. The validation of fqdn is done in yacc */
+				yylval->string = strdup(yytext);
+				if (!yylval->string) {
+					log_error("Unable to copy the string '%s': %s\n", yytext, strerror(errno));
+					TRACE_DEBUG(INFO, "strdup failed");
+					return LEX_ERROR; /* trig an error in yacc parser */
+				}
+				return STRING;
+			}
+
+	/* Valid single characters for yyparse */
+[=,;]			{ return yytext[0]; }
+
+	/* Unrecognized sequence */
+[^[:space:]=,;\n]+	{ 
+				log_error("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext);
+			 	return LEX_ERROR; 
+			}
+
+%%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/sec_nosec/sns_conf.y	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,174 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+/* Yacc sec_nosec extension's configuration parser.
+ */
+
+/* For development only : */
+%debug 
+%error-verbose
+
+/* The parser receives the configuration file filename as parameter */
+%parse-param {char * conffile}
+
+/* Keep track of location */
+%locations 
+%pure-parser
+
+%{
+#include "sec_nosec.h"
+#include "sns_conf.tab.h"	/* bison is not smart enough to define the YYLTYPE before including this code, so... */
+
+#include <string.h>
+#include <errno.h>
+
+/* The Lex parser prototype */
+int sns_conflex(YYSTYPE *lvalp, YYLTYPE *llocp);
+
+/* This function checks a string value can be a DiameterId (== a fqdn) */
+static int is_valid_fqdn( char * candidate ) 
+{
+	/* We first search for a '.' */
+	if (!strchr(candidate, '.')) {
+		log_error("The string '%s' is not a valid fully-qualified domain name (fqdn).\n", candidate);
+		return 0;
+	}
+	
+	/* We may do additional checking here */
+	
+	/* Ok this candidate is valid */
+	return 1;
+}
+
+/* Function to report the errors */
+void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
+{
+	TRACE_DEBUG(INFO, "Error in configuration parsing");
+	
+	if (ploc->first_line != ploc->last_line)
+		log_error("%s:%d.%d-%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
+	else if (ploc->first_column != ploc->last_column)
+		log_error("%s:%d.%d-%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
+	else
+		log_error("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s);
+}
+
+/* Global variable to store the default priority */
+static int def_prio = 1;
+
+%}
+
+/* Values returned by lex for token */
+%union {
+	char 		*string;	/* The string is allocated by strdup in lex.*/
+	int		 integer;	/* Store integer values */
+}
+
+/* In case of error in the lexical analysis */
+%token 		LEX_ERROR
+
+/* A string (malloc'd in lex parser; it must be freed after use) */
+%token <string>	STRING
+/* Strings subtypes */
+%type <string>	FQDN		/* This is a fqdn. We check that the syntax is correct. */
+
+/* An integer value */
+%token <integer> INTEGER
+
+/* The default priority token */
+%token 		DEF_PRIO
+
+/* The debug level token */
+%token 		VERBOSITY
+
+/* -------------------------------------- */
+%%
+
+	/* The grammar definition */
+conffile:		/* empty grammar is OK */
+			| conffile verbosity
+			| conffile def_prio
+			| conffile peer
+			;
+
+	/* Defining the extension debug verbosity level */
+verbosity:		VERBOSITY '=' INTEGER ';'
+			{
+				verbosity = $3;
+			}
+			;
+
+	/* Defining the default peers priority */
+def_prio:		DEF_PRIO '=' INTEGER ';'
+			{
+				def_prio = $3;
+			}
+			;
+
+	/* Validating a FQDN: */
+FQDN:			STRING
+			{
+				/* Verify this is a valid FQDN */
+				if (!is_valid_fqdn($1)) {
+					yyerror (&yylloc, conffile, "An error was detected on a fqdn, aborting...");
+					YYERROR;
+				}
+				$$ = $1;
+			}
+			;
+	
+	/* A peer definition */
+peer:			FQDN ';'
+			{
+				int ret = 0;
+				ret = sns_addpeer( $1, def_prio );
+				if (ret != 0) {
+					log_error("An error occurred while saving peer '%s': %s\n", $1, strerror(ret));
+					YYERROR;
+				}
+				free( $1 );
+			}
+			| FQDN ',' INTEGER ';'
+			{
+				int ret = 0;
+				ret = sns_addpeer( $1, $3 );
+				if (ret != 0) {
+					log_error("An error occurred while saving peer '%s': %s\n", $1, strerror(ret));
+					YYERROR;
+				}
+				free( $1 );
+			}
+			;
+				
--- a/extensions/sec_nosec/sns_gram.y	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,174 +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.								 *
-*********************************************************************************************************/
-
-/* Yacc sec_nosec extension's configuration parser.
- */
-
-/* For development only : */
-%debug 
-%error-verbose
-
-/* The parser receives the configuration file filename as parameter */
-%parse-param {char * conffile}
-
-/* Keep track of location */
-%locations 
-%pure-parser
-
-%{
-#include "sec_nosec.h"
-#include "sns_gram.h"	/* bison is not smart enough to define the YYLTYPE before including this code, so... */
-
-#include <string.h>
-#include <errno.h>
-
-/* The Lex parser prototype */
-int yylex(YYSTYPE *lvalp, YYLTYPE *llocp);
-
-/* This function checks a string value can be a DiameterId (== a fqdn) */
-static int is_valid_fqdn( char * candidate ) 
-{
-	/* We first search for a '.' */
-	if (!strchr(candidate, '.')) {
-		log_error("The string '%s' is not a valid fully-qualified domain name (fqdn).\n", candidate);
-		return 0;
-	}
-	
-	/* We may do additional checking here */
-	
-	/* Ok this candidate is valid */
-	return 1;
-}
-
-/* Function to report the errors */
-void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
-{
-	TRACE_DEBUG(INFO, "Error in configuration parsing");
-	
-	if (ploc->first_line != ploc->last_line)
-		log_error("%s:%d.%d-%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
-	else if (ploc->first_column != ploc->last_column)
-		log_error("%s:%d.%d-%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
-	else
-		log_error("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s);
-}
-
-/* Global variable to store the default priority */
-static int def_prio = 1;
-
-%}
-
-/* Values returned by lex for token */
-%union {
-	char 		*string;	/* The string is allocated by strdup in lex.*/
-	int		 integer;	/* Store integer values */
-}
-
-/* In case of error in the lexical analysis */
-%token 		LEX_ERROR
-
-/* A string (malloc'd in lex parser; it must be freed after use) */
-%token <string>	STRING
-/* Strings subtypes */
-%type <string>	FQDN		/* This is a fqdn. We check that the syntax is correct. */
-
-/* An integer value */
-%token <integer> INTEGER
-
-/* The default priority token */
-%token 		DEF_PRIO
-
-/* The debug level token */
-%token 		VERBOSITY
-
-/* -------------------------------------- */
-%%
-
-	/* The grammar definition */
-conffile:		/* empty grammar is OK */
-			| conffile verbosity
-			| conffile def_prio
-			| conffile peer
-			;
-
-	/* Defining the extension debug verbosity level */
-verbosity:		VERBOSITY '=' INTEGER ';'
-			{
-				verbosity = $3;
-			}
-			;
-
-	/* Defining the default peers priority */
-def_prio:		DEF_PRIO '=' INTEGER ';'
-			{
-				def_prio = $3;
-			}
-			;
-
-	/* Validating a FQDN: */
-FQDN:			STRING
-			{
-				/* Verify this is a valid FQDN */
-				if (!is_valid_fqdn($1)) {
-					yyerror (&yylloc, conffile, "An error was detected on a fqdn, aborting...");
-					YYERROR;
-				}
-				$$ = $1;
-			}
-			;
-	
-	/* A peer definition */
-peer:			FQDN ';'
-			{
-				int ret = 0;
-				ret = sns_addpeer( $1, def_prio );
-				if (ret != 0) {
-					log_error("An error occurred while saving peer '%s': %s\n", $1, strerror(ret));
-					YYERROR;
-				}
-				free( $1 );
-			}
-			| FQDN ',' INTEGER ';'
-			{
-				int ret = 0;
-				ret = sns_addpeer( $1, $3 );
-				if (ret != 0) {
-					log_error("An error occurred while saving peer '%s': %s\n", $1, strerror(ret));
-					YYERROR;
-				}
-				free( $1 );
-			}
-			;
-				
--- a/extensions/sec_nosec/sns_parse.c	Wed Feb 25 11:27:53 2009 +0900
+++ b/extensions/sec_nosec/sns_parse.c	Wed Feb 25 16:49:21 2009 +0900
@@ -36,29 +36,29 @@
 #include "sec_nosec.h"
 
 /* Yacc parser prototype */
-int yyparse(char * conffile);
+int sns_confparse(char * conffile);
 
 /* Parse the configuration file */
 int sns_parse(char * conffile)
 {
-	extern FILE * yyin;
+	extern FILE * sns_confin;
 	int ret;
 	
 	TRACE_ENTRY("%p", conffile);
 	
 	TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
 	
-	yyin = fopen(conffile, "r");
-	if (yyin == NULL) {
+	sns_confin = fopen(conffile, "r");
+	if (sns_confin == NULL) {
 		ret = errno;
 		log_error("Unable to open extension configuration file %s for reading: %s\n", conffile, strerror(ret));
 		TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
 		return ret;
 	}
 
-	ret = yyparse(conffile);
+	ret = sns_confparse(conffile);
 
-	fclose(yyin);
+	fclose(sns_confin);
 
 	if (ret != 0) {
 		TRACE_DEBUG (INFO, "Unable to parse the configuration file.");
--- a/extensions/sec_nosec/sns_token.l	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,122 +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.								 *
-*********************************************************************************************************/
-
-/* Lex sec_nosec extension's configuration parser.
- *
- * The configuration file contains a default priority, and a list of peers with optional overwite priority.
- * -- see the sec_nosec.conf.sample file for more detail.
- */
-
-%{
-/* Include the daemon's header files */
-#include "sec_nosec.h"
-/* Include yacc tokens definitions */
-#include "sns_gram.h"
-
-/* Update the column information */
-#define YY_USER_ACTION { 					\
-	yylloc->first_column = yylloc->last_column + 1; 	\
-	yylloc->last_column = yylloc->first_column + yyleng - 1;\
-}
-
-/* Avoid warning with newer flex */
-#define YY_NO_INPUT
-
-%}
-
-%option bison-bridge bison-locations
-%option noyywrap
-%option nounput
-
-%%
-
-	/* Update the line count */
-\n			{
-				yylloc->first_line++; 
-				yylloc->last_line++; 
-				yylloc->last_column=0; 
-			}
-	 
-	/* Eat all spaces but not new lines */
-([[:space:]]{-}[\n])+	;
-	/* Eat all comments */
-#.*$			;
-
-	/* Recognize any integer */
-[[:digit:]]+		{
-				/* Convert this to an integer value */
-				int ret=0;
-				ret = sscanf(yytext, "%i", &yylval->integer);
-				if (ret != 1) {
-					/* No matching: an error occurred */
-					log_error("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno));
-					return LEX_ERROR; /* trig an error in yacc parser */
-					/* Maybe we could REJECT instead of failing here? */
-				}
-				return INTEGER;
-			}
-
-	/* Recognize the verbosity string */	
-(?i:"Debug_Verbosity")	{
-				return VERBOSITY;
-			}
-
-	/* Recognize the default_priority string */	
-(?i:"Default_Priority")	{
-				return DEF_PRIO; 
-			}
-
-	/* Any other string is considered as a fqdn, if the pattern is valid */
-[[:alnum:].-]+		{
-				/* Match a fqdn string. expected only ASCII characters, '-' and '.'. The validation of fqdn is done in yacc */
-				yylval->string = strdup(yytext);
-				if (!yylval->string) {
-					log_error("Unable to copy the string '%s': %s\n", yytext, strerror(errno));
-					TRACE_DEBUG(INFO, "strdup failed");
-					return LEX_ERROR; /* trig an error in yacc parser */
-				}
-				return STRING;
-			}
-
-	/* Valid single characters for yyparse */
-[=,;]			{ return yytext[0]; }
-
-	/* Unrecognized sequence */
-[^[:space:]=,;\n]+	{ 
-				log_error("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext);
-			 	return LEX_ERROR; 
-			}
-
-%%
--- a/extensions/sec_tls_gnutls/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-# Compile the tls_gnutls extension.
-
-# Location of the API headers:
-AM_CPPFLAGS = -I$(srcdir)/../../include
-
-pkglib_LTLIBRARIES = sec_tls_gnutls.la
-sec_tls_gnutls_la_LDFLAGS = -module $(LIBGNUTLS)
-
-sec_tls_gnutls_la_SOURCES = sec_tls_gnutls.c	\
-				gnutls_sctp_wrapper.c \
-				todo.c
--- a/m4/README	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-This folder contains waaad-specific autoconf / automake macros.
-
-Will probably be necessary for testing SCTP availability on the system.
-
--- a/m4/acx_pthread.m4	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,275 +0,0 @@
-# ===========================================================================
-#              http://autoconf-archive.cryp.to/acx_pthread.html
-# ===========================================================================
-#
-# SYNOPSIS
-#
-#   ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
-#
-# DESCRIPTION
-#
-#   This macro figures out how to build C programs using POSIX threads. It
-#   sets the PTHREAD_LIBS output variable to the threads library and linker
-#   flags, and the PTHREAD_CFLAGS output variable to any special C compiler
-#   flags that are needed. (The user can also force certain compiler
-#   flags/libs to be tested by setting these environment variables.)
-#
-#   Also sets PTHREAD_CC to any special C compiler that is needed for
-#   multi-threaded programs (defaults to the value of CC otherwise). (This
-#   is necessary on AIX to use the special cc_r compiler alias.)
-#
-#   NOTE: You are assumed to not only compile your program with these flags,
-#   but also link it with them as well. e.g. you should link with
-#   $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
-#
-#   If you are only building threads programs, you may wish to use these
-#   variables in your default LIBS, CFLAGS, and CC:
-#
-#          LIBS="$PTHREAD_LIBS $LIBS"
-#          CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-#          CC="$PTHREAD_CC"
-#
-#   In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
-#   has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name
-#   (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
-#
-#   ACTION-IF-FOUND is a list of shell commands to run if a threads library
-#   is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
-#   is not found. If ACTION-IF-FOUND is not specified, the default action
-#   will define HAVE_PTHREAD.
-#
-#   Please let the authors know if this macro fails on any platform, or if
-#   you have any other suggestions or comments. This macro was based on work
-#   by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
-#   from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
-#   Alejandro Forero Cuervo to the autoconf macro repository. We are also
-#   grateful for the helpful feedback of numerous users.
-#
-# LAST MODIFICATION
-#
-#   2008-04-12
-#
-# COPYLEFT
-#
-#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
-#
-#   This program is free software: you can redistribute it and/or modify it
-#   under the terms of the GNU General Public License as published by the
-#   Free Software Foundation, either version 3 of the License, or (at your
-#   option) any later version.
-#
-#   This program is distributed in the hope that it will be useful, but
-#   WITHOUT ANY WARRANTY; without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-#   Public License for more details.
-#
-#   You should have received a copy of the GNU General Public License along
-#   with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-#   As a special exception, the respective Autoconf Macro's copyright owner
-#   gives unlimited permission to copy, distribute and modify the configure
-#   scripts that are the output of Autoconf when processing the Macro. You
-#   need not follow the terms of the GNU General Public License when using
-#   or distributing such scripts, even though portions of the text of the
-#   Macro appear in them. The GNU General Public License (GPL) does govern
-#   all other use of the material that constitutes the Autoconf Macro.
-#
-#   This special exception to the GPL applies to versions of the Autoconf
-#   Macro released by the Autoconf Macro Archive. When you make and
-#   distribute a modified version of the Autoconf Macro, you may extend this
-#   special exception to the GPL to apply to your modified version as well.
-
-AC_DEFUN([ACX_PTHREAD], [
-AC_REQUIRE([AC_CANONICAL_HOST])
-AC_LANG_SAVE
-AC_LANG_C
-acx_pthread_ok=no
-
-# We used to check for pthread.h first, but this fails if pthread.h
-# requires special compiler flags (e.g. on True64 or Sequent).
-# It gets checked for in the link test anyway.
-
-# First of all, check if the user has set any of the PTHREAD_LIBS,
-# etcetera environment variables, and if threads linking works using
-# them:
-if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
-        save_CFLAGS="$CFLAGS"
-        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-        save_LIBS="$LIBS"
-        LIBS="$PTHREAD_LIBS $LIBS"
-        AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
-        AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
-        AC_MSG_RESULT($acx_pthread_ok)
-        if test x"$acx_pthread_ok" = xno; then
-                PTHREAD_LIBS=""
-                PTHREAD_CFLAGS=""
-        fi
-        LIBS="$save_LIBS"
-        CFLAGS="$save_CFLAGS"
-fi
-
-# We must check for the threads library under a number of different
-# names; the ordering is very important because some systems
-# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
-# libraries is broken (non-POSIX).
-
-# Create a list of thread flags to try.  Items starting with a "-" are
-# C compiler flags, and other items are library names, except for "none"
-# which indicates that we try without any flags at all, and "pthread-config"
-# which is a program returning the flags for the Pth emulation library.
-
-acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
-
-# The ordering *is* (sometimes) important.  Some notes on the
-# individual items follow:
-
-# pthreads: AIX (must check this before -lpthread)
-# none: in case threads are in libc; should be tried before -Kthread and
-#       other compiler flags to prevent continual compiler warnings
-# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
-# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
-# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
-# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
-# -pthreads: Solaris/gcc
-# -mthreads: Mingw32/gcc, Lynx/gcc
-# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
-#      doesn't hurt to check since this sometimes defines pthreads too;
-#      also defines -D_REENTRANT)
-#      ... -mt is also the pthreads flag for HP/aCC
-# pthread: Linux, etcetera
-# --thread-safe: KAI C++
-# pthread-config: use pthread-config program (for GNU Pth library)
-
-case "${host_cpu}-${host_os}" in
-        *solaris*)
-
-        # On Solaris (at least, for some versions), libc contains stubbed
-        # (non-functional) versions of the pthreads routines, so link-based
-        # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
-        # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
-        # a function called by this macro, so we could check for that, but
-        # who knows whether they'll stub that too in a future libc.)  So,
-        # we'll just look for -pthreads and -lpthread first:
-
-        acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
-        ;;
-esac
-
-if test x"$acx_pthread_ok" = xno; then
-for flag in $acx_pthread_flags; do
-
-        case $flag in
-                none)
-                AC_MSG_CHECKING([whether pthreads work without any flags])
-                ;;
-
-                -*)
-                AC_MSG_CHECKING([whether pthreads work with $flag])
-                PTHREAD_CFLAGS="$flag"
-                ;;
-
-		pthread-config)
-		AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
-		if test x"$acx_pthread_config" = xno; then continue; fi
-		PTHREAD_CFLAGS="`pthread-config --cflags`"
-		PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
-		;;
-
-                *)
-                AC_MSG_CHECKING([for the pthreads library -l$flag])
-                PTHREAD_LIBS="-l$flag"
-                ;;
-        esac
-
-        save_LIBS="$LIBS"
-        save_CFLAGS="$CFLAGS"
-        LIBS="$PTHREAD_LIBS $LIBS"
-        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-
-        # Check for various functions.  We must include pthread.h,
-        # since some functions may be macros.  (On the Sequent, we
-        # need a special flag -Kthread to make this header compile.)
-        # We check for pthread_join because it is in -lpthread on IRIX
-        # while pthread_create is in libc.  We check for pthread_attr_init
-        # due to DEC craziness with -lpthreads.  We check for
-        # pthread_cleanup_push because it is one of the few pthread
-        # functions on Solaris that doesn't have a non-functional libc stub.
-        # We try pthread_create on general principles.
-        AC_TRY_LINK([#include <pthread.h>],
-                    [pthread_t th; pthread_join(th, 0);
-                     pthread_attr_init(0); pthread_cleanup_push(0, 0);
-                     pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
-                    [acx_pthread_ok=yes])
-
-        LIBS="$save_LIBS"
-        CFLAGS="$save_CFLAGS"
-
-        AC_MSG_RESULT($acx_pthread_ok)
-        if test "x$acx_pthread_ok" = xyes; then
-                break;
-        fi
-
-        PTHREAD_LIBS=""
-        PTHREAD_CFLAGS=""
-done
-fi
-
-# Various other checks:
-if test "x$acx_pthread_ok" = xyes; then
-        save_LIBS="$LIBS"
-        LIBS="$PTHREAD_LIBS $LIBS"
-        save_CFLAGS="$CFLAGS"
-        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-
-        # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
-	AC_MSG_CHECKING([for joinable pthread attribute])
-	attr_name=unknown
-	for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
-	    AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
-                        [attr_name=$attr; break])
-	done
-        AC_MSG_RESULT($attr_name)
-        if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
-            AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
-                               [Define to necessary symbol if this constant
-                                uses a non-standard name on your system.])
-        fi
-
-        AC_MSG_CHECKING([if more special flags are required for pthreads])
-        flag=no
-        case "${host_cpu}-${host_os}" in
-            *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
-            *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
-        esac
-        AC_MSG_RESULT(${flag})
-        if test "x$flag" != xno; then
-            PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
-        fi
-
-        LIBS="$save_LIBS"
-        CFLAGS="$save_CFLAGS"
-
-        # More AIX lossage: must compile with xlc_r or cc_r
-	if test x"$GCC" != xyes; then
-          AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
-        else
-          PTHREAD_CC=$CC
-	fi
-else
-        PTHREAD_CC="$CC"
-fi
-
-AC_SUBST(PTHREAD_LIBS)
-AC_SUBST(PTHREAD_CFLAGS)
-AC_SUBST(PTHREAD_CC)
-
-# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
-if test x"$acx_pthread_ok" = xyes; then
-        ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
-        :
-else
-        acx_pthread_ok=no
-        $2
-fi
-AC_LANG_RESTORE
-])dnl ACX_PTHREAD
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/waaad/CMakeLists.txt	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,151 @@
+#CMake configuration for waaad source code
+
+Project("waaad" C)
+
+SET(PROJECT_VERSION 0.1)
+SET(PROJECT_COPYRIGHT "Copyright (c) 2008-2009, WIDE Project (www.wide.ad.jp) and NICT (www.nict.go.jp)")
+
+########################
+# Configurable parameters
+
+OPTION(Waaad_Early_Debug "Enable waaad early debugging (before option parsing)?")
+
+# No sure if we can actually pass strings to options, but it works in CMakeCache.txt file at least. 
+OPTION(DEFAULT_CONF_FILE "Default path to configuration file?" OFF)
+
+########################
+# System checks 
+
+INCLUDE (CheckLibraryExists)
+INCLUDE (CheckFunctionExists)
+INCLUDE (CheckIncludeFiles)
+INCLUDE (CheckSymbolExists) 
+
+# We use dlopen and dlclose
+SET(WAAAD_LIBS ${WAAAD_LIBS} ${CMAKE_DL_LIBS})
+
+# We need the threads library (pthread)
+INCLUDE(FindThreads)
+SET(WAAAD_LIBS ${WAAAD_LIBS} ${CMAKE_THREAD_LIBS_INIT})
+
+# We need the clock_gettime function ( -lrt, -lposix4 )
+CHECK_FUNCTION_EXISTS (clock_gettime HAVE_CLOCK_GETTIME)
+IF (HAVE_CLOCK_GETTIME)
+   SET(CLOCK_GETTIME_LIBS "")
+ELSE (HAVE_CLOCK_GETTIME)
+   CHECK_LIBRARY_EXISTS (rt clock_gettime "" HAVE_LIBRT)
+   IF (HAVE_LIBRT)
+     SET(CLOCK_GETTIME_LIBS "-lrt")
+   ELSE (HAVE_LIBRT)
+     CHECK_LIBRARY_EXISTS (posix4 clock_gettime "" HAVE_LIBPOSIX4)
+     IF (HAVE_LIBPOSIX4)
+       SET(CLOCK_GETTIME_LIBS "-lposix4")
+     ENDIF (HAVE_LIBPOSIX4)
+   ENDIF (HAVE_LIBRT)
+ENDIF (HAVE_CLOCK_GETTIME)
+SET(WAAAD_LIBS ${WAAAD_LIBS} ${CLOCK_GETTIME_LIBS})
+
+
+# We need the sctp_getladdrs function ( -lsctp )
+# We need the IPPROTO_SCTP symbol from sys/socket.h, netinet/in.h or netinet/sctp.h
+INCLUDE(FindSCTP)
+SET(WAAAD_LIBS ${WAAAD_LIBS} ${SCTP_LIBRARIES})
+
+
+# We need the __BYTE_ORDER definition ( sys/param.h )
+CHECK_SYMBOL_EXISTS(__BYTE_ORDER "sys/param.h" HAVE___BYTE_ORDER)
+IF (NOT HAVE___BYTE_ORDER)
+   MESSAGE(SEND_ERROR "The __BYTE_ORDER is not found, please hack the code to fix this")
+ENDIF (NOT HAVE___BYTE_ORDER)
+
+
+# We need the getopt_long function
+CHECK_FUNCTION_EXISTS (getopt_long HAVE_LONG_OPTIONS)
+IF (NOT HAVE_LONG_OPTIONS)
+   MESSAGE(SEND_ERROR "The getopt_long function is not found, please add needed library in build system")
+ENDIF (NOT HAVE_LONG_OPTIONS)
+
+
+# Check if ntohll is provided on the system
+CHECK_SYMBOL_EXISTS(ntohll "" HAVE_NTOHLL)
+
+
+# malloc.h ?
+CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
+
+##########################
+# Building waaad
+
+# Parse configurable options
+IF(Waaad_Early_Debug)
+	ADD_DEFINITIONS(-DTRACE_LEVEL=FULL)
+ELSE(Waaad_Early_Debug)
+	ADD_DEFINITIONS(-DTRACE_LEVEL=NONE)
+ENDIF(Waaad_Early_Debug)
+
+IF (NOT DEFAULT_CONF_FILE)
+   SET(DEFAULT_CONF_FILE "waaad.conf")
+ENDIF (NOT DEFAULT_CONF_FILE)
+
+# Generate the config-waaad.h file
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/waaad-host.h.in ${CMAKE_CURRENT_BINARY_DIR}/waaad-host.h)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+
+# Declare the lex and yacc files, so that they can be compiled properly
+BISON_FILE(waaad.y)
+FLEX_FILE(waaad.l)
+SET_SOURCE_FILES_PROPERTIES(lex.waaad.c waaad.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}")
+
+# Source files common to daemon and tests
+SET(WAAAD_COMMON_SRC
+		waaad-internal.h waaad-host.h
+		utils.h utils.c
+		conf.h conf.c 
+		log.h log.c
+		extensions.h extensions.c
+		dictionary.h dictionary.c
+		dict-base.h dict-base.c
+		dict-hardcoded.h
+		peer.h peer-internal.h
+		peer.c peer-struct.c
+		peer-expire.c peer-events.c
+		peer-in.c peer-out.c
+		peer-secini.c
+		peer-sctp.c peer-tcp.c
+		peer-server.c peer-client.c
+		peer-cer_cea.c
+		peer-dwr_dwa.c
+		peer-dpr_dpa.c
+		peer-psm.c
+		peer-failover.c
+		message.h message.c
+		queues.h queues.c
+		routing.h routing.c
+		session.h session.c
+		dispatch.h dispatch.c
+		security.h security.c
+	)
+SET(WAAAD_COMMON_GEN_SRC
+		lex.waaad.c
+		waaad.tab.c
+		waaad.tab.h
+	)
+
+# Source files for the daemon
+SET(WAAAD_SRC
+	${WAAAD_COMMON_SRC}
+	${WAAAD_COMMON_GEN_SRC}
+	main.c 
+	)
+
+# Create the binary for waaad
+ADD_EXECUTABLE(waaad ${WAAAD_SRC})
+
+# Link parameters
+TARGET_LINK_LIBRARIES(waaad ${WAAAD_LIBS})
+
+# Add the tests
+OPTION(Skip_Tests "Skip compilation of the tests?" ON)
+IF ( NOT Skip_Tests )
+	SUBDIRS(tests)
+ENDIF ( NOT Skip_Tests )
--- a/waaad/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-# Tests subdirectory
-SUBDIRS = tests
-
-# Location of the API headers:
-AM_CPPFLAGS = -I$(srcdir)/../include
-
-# Debug level :
-AM_CPPFLAGS += $(WAAAD_DEBUG)
-
-# Location of the default daemon's configuration file :
-AM_CPPFLAGS += -DDEFAULT_CONF_FILE='"$(defconffile)"'
-
-# Flag to pass to have verbose SCTP operations, for development of this part
-# AM_CPPFLAGS += -DDEBUG_SCTP
-
-# bison outputs a .h file. Also useful to change automake behavior.
-AM_YFLAGS = -d
-
-# The lex file need bison to output the header file before compiling:
-BUILT_SOURCES = conf-gram.h hgversion.h
-
-# We are building the "waaad" program :
-bin_PROGRAMS = waaad
-
-# This program needs the following libraries
-waaad_LDFLAGS = $(pthread_LIBS) $(dl_LIBS) $(clock_LIBS) $(sctp_LIBS)
-
-# This is the list of sources for "waaad" :
-waaad_SOURCES = waaad-internal.h main.c \
-		utils.h utils.c \
-		conf.h conf.c conf-gram.y conf-token.l \
-		hgversion.h log.h log.c \
-		extensions.h extensions.c \
-		dictionary.h dictionary.c \
-		dict-base.h dict-base.c \
-		dict-hardcoded.h \
-		peer.h peer-internal.h \
-		peer.c peer-struct.c \
-		peer-expire.c peer-events.c\
-		peer-in.c peer-out.c \
-		peer-secini.c \
-		peer-sctp.c peer-tcp.c \
-		peer-server.c peer-client.c \
-		peer-cer_cea.c \
-		peer-dwr_dwa.c \
-		peer-dpr_dpa.c \
-		peer-psm.c \
-		peer-failover.c \
-		message.h message.c \
-		queues.h queues.c \
-		routing.h routing.c \
-		session.h session.c \
-		dispatch.h dispatch.c \
-		security.h security.c
-
-# Rule to make the hgversion.h file
-hgversion.h:	stamp-hg
-	echo "Rebuilding hgversion.h..."
-	echo '/* Mercurial repository information, generated on '`date -R`' */' > hgversion.h
-	if test -d $(srcdir)/../.hg; \
-	then echo '#define HG_HASH "'`cd $(srcdir)/.. && hg log -r tip --template '{node|short}'`'"' >> hgversion.h; \
-	     echo '#define HG_REVISION "'`cd $(srcdir)/.. && hg log -r tip --template '{rev}'`'"' >> hgversion.h; \
-	     echo '#define HG_VERSION  HG_REVISION ":" HG_HASH' >> hgversion.h; \
-	else echo '/* No Mercurial repository found */' >> hgversion.h; \
-	fi
-
-stamp-hg: stamp-hg.cur
-
-# Currently, this is executed twice... it could be improved.
-stamp-hg.cur:
-	if test -d $(srcdir)/../.hg; \
-	then echo `cd $(srcdir)/.. && hg log -r tip --template '{rev}:{node|short}'` > stamp-hg.cur; \
-	else echo 0 > stamp-hg.cur; \
-	fi
-	if test -e stamp-hg && diff -q stamp-hg stamp-hg.cur ; \
-	then rm stamp-hg.cur; \
-	else mv -f stamp-hg.cur stamp-hg; \
-	fi
-
-.PHONY: stamp-hg.cur
-.SILENT: stamp-hg.cur hgversion.h
-
-clean-local:
-	rm -f hgversion.h
--- a/waaad/conf-gram.y	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,732 +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.								 *
-*********************************************************************************************************/
-
-/* Yacc configuration parser.
- *
- * This file defines the grammar for parsing the configuration file of waaad.
- * Note that each extension has a separate independant configuration file.
- *
- * Note : This module is NOT thread-safe. All processing must be done from one thread only.
- */
-
-/* For development only : */
-
-%debug 
-%error-verbose
-
-
-/* The parser receives a configuration pointer as parameter */
-%parse-param {waaad_conf_t * pconfig}
-
-/* Keep track of location */
-%locations 
-%pure-parser
-
-%{
-#include "waaad-internal.h"
-#include "conf-gram.h"	/* bison is not smart enough to define the YYLTYPE before including this code, so... */
-
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-
-/* The Lex parser prototype */
-int yylex(YYSTYPE *lvalp, YYLTYPE *llocp);
-
-/* This function checks a string value is a valid network locator */
-static int is_valid_locator( char * candidate, sSS *ss, waaad_conf_t * pconfig ) 
-{
-	int ret=0;
-	struct addrinfo *ai = NULL, hint;
-	
-	memset(&hint, 0, sizeof(hint));
-	
-	hint.ai_family = AF_UNSPEC;
-	
-	if (pconfig->pub.disable_inet6)
-		hint.ai_family = AF_INET;
-	if (pconfig->pub.disable_inet4)
-		hint.ai_family = AF_INET6;
-		
-	/* TRACE_DEBUG(FULL, "Resolving '%s'...", candidate); */
-	ret = getaddrinfo(candidate, NULL, &hint, &ai);
-	if (ai) {
-		/*
-		TRACE_DEBUG(FULL, "Result:");
-		TRACE_DEBUG(FULL, "  ai_flags    : %x", ai->ai_flags);
-		TRACE_DEBUG(FULL, "  ai_family   : %d", ai->ai_family);
-		TRACE_DEBUG(FULL, "  ai_socktype : %d", ai->ai_socktype);
-		TRACE_DEBUG(FULL, "  ai_protocol : %d", ai->ai_protocol);
-		TRACE_DEBUG(FULL, "  ai_addrlen  : %d", ai->ai_addrlen);
-		TRACE_DEBUG(FULL, "  ai_addr     : .sa_family = %d (%s)", ai->ai_addr->sa_family, ai->ai_addr->sa_family == AF_INET ? "AF_INET" :
-													ai->ai_addr->sa_family == AF_INET6 ? "AF_INET6" :
-														"???");
-		TRACE_DEBUG(FULL, "  ai_canonname: %s", ai->ai_canonname ? ai->ai_canonname:"(null)");
-		TRACE_DEBUG(FULL, "  ai_next     : %p", ai->ai_next);
-		*/
-		if (ss) {
-			memset(ss, 0, sizeof(sSS));
-			memcpy(ss, ai->ai_addr, ai->ai_addrlen);
-		}
-		freeaddrinfo(ai);
-	}
-	if (ret != 0) {
-		log_error("Error resolving network locator '%s': %s.\n", candidate, gai_strerror(ret));
-		return 0;
-	}
-
-	/* Ok this candidate is valid */
-	return 1;
-}
-
-/* This function checks a string value can be a DiameterId (== a fqdn) */
-static int is_valid_fqdn( char * candidate, sSS *ss, waaad_conf_t * pconfig ) 
-{
-	/* What is a valid FQDN? 
-	   Difficult question... maybe use getaddrinfo with flag AI_CANONNAME ?
-	   Let's be permissive here and trust administrators to configure properly their Diameter daemon ^^'
-	 */
-	
-	/* We search for a '.' to reject some aliases and local names */
-	if (!strchr(candidate, '.')) {
-		log_error("The string '%s' is not a valid fully-qualified domain name (fqdn).\n", candidate);
-		return 0;
-	}
-	
-	/* Ok now check this is a valid network locator */
-	return is_valid_locator(candidate, ss, pconfig);
-}
-
-/* This function checks a string value is a valid filename */
-static int is_valid_file( char * candidate ) 
-{
-	int ret;
-	struct stat buffer;
-	
-	ret = stat(candidate, &buffer);
-	if (ret != 0) {
-		log_error("Error on file '%s': %s.\n", candidate, strerror(errno));
-		return 0;
-	}
-
-	/* Ok this candidate is valid */
-	return 1;
-}
-
-/* Global variable to store a sockaddr checked by is_valid_addr or fqdn */
-static sSS _ss;
-
-static int have_ip4 = 0; /* have some ip4 been added already? */
-static int have_ip6 = 0; /* have some ip6 been added already? */
-
-/* This function converts a string into an IP or IPv6 address */
-static int is_valid_addr( char * candidate, waaad_conf_t * pconfig) 
-{
-	int ret=0;
-	
-	/* Clean the storage area */
-	memset(&_ss, 0, sizeof(_ss));
-	
-	/* Search for a ":" in the string */
-	if (!strchr(candidate, ':')) {
-		sSA4 * sin = (sSA4 *) &_ss;
-		/* Assume this is IPv4 */
-		CHECK_SYS_DO(  ret = inet_pton(AF_INET, candidate, &sin->sin_addr.s_addr), return 0 );
-		if (ret == 1) {
-			if (pconfig->pub.disable_inet4) {
-				log_error("Cannot use the address '%s' since NO_IP4 was defined\n", candidate);
-				return 0;
-			}
-			have_ip4++;
-			sin->sin_family = AF_INET;
-			sin->sin_port = htons(pconfig->pub.local_port);
-			return 1; /* the IP is valid */
-		} else {
-			log_error("Error on IP address '%s': unrecognized.\n", candidate);
-		}
-	} else {
-		sSA6 * sin6 = (sSA6 *)&_ss;
-		/* Assume this is IPv6 */
-		CHECK_SYS_DO(  ret = inet_pton(AF_INET6, candidate, &sin6->sin6_addr.s6_addr), return 0 );
-		if (ret == 1) {
-			if (pconfig->pub.disable_inet6) {
-				log_error("Cannot use the address '%s' since NO_IP6 was defined\n", candidate);
-				return 0;
-			}
-			have_ip6++;
-			sin6->sin6_family = AF_INET6;
-			sin6->sin6_port = htons(pconfig->pub.local_port);
-			return 1; /* the IPv6 is valid */
-		} else {
-			log_error("Error on IPv6 address '%s': unrecognized.\n", candidate);
-		}
-	}
-
-	/* This candidate is not valid */
-	return 0;
-}
-
-/* This function extends the list of addresses and stores the new value of _ss inside */
-static int queue_ss( sSS ** plist )
-{
-	sSS * new;
-	
-	if (*plist == NULL) {
-		/* If the array has not been alloc'd yet */
-		CHECK_MALLOC(  *plist = malloc( sizeof (sSS) * 2 )  );
-		new = *plist;
-	} else {
-		/* otherwise, we need to resize the array to add the new element */
-		int cnt = 0;
-		new = *plist;
-		while (new->ss_family != 0)
-			cnt++, new++;
-		CHECK_MALLOC(  *plist = realloc(*plist, sizeof(sSS) * (cnt + 2))  );
-		new = (*plist) + cnt;
-	}
-	
-	/* Now, new points to the beginning of the location where the _ss must be stored */
-	memcpy(new, &_ss, sizeof(sSS));
-	memset(new+1, 0,  sizeof(sSS));
-	return 0;
-}
-
-/* Function to report the errors */
-void yyerror (YYLTYPE *ploc, waaad_conf_t * pconfig, char const *s)
-{
-	if (ploc->first_line != ploc->last_line)
-		log_error("%s:%d.%d-%d.%d : %s\n", pconfig->filepath, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
-	else if (ploc->first_column != ploc->last_column)
-		log_error("%s:%d.%d-%d : %s\n", pconfig->filepath, ploc->first_line, ploc->first_column, ploc->last_column, s);
-	else
-		log_error("%s:%d.%d : %s\n", pconfig->filepath, ploc->first_line, ploc->first_column, s);
-}
-
-/* Global variable to store temporarily extension information */
-static struct _ext_detail {
-	char * fname;
-	char * cname;
-} ext_detail={NULL, NULL};
-
-/* Global variable to store temporarily peer information */
-static struct {
-	char   * locator;
-	sSS	 peerss;
-	uint16_t port;
-	uint16_t sctp_streams;
-	char     flags;
-} peer_detail = {.locator = NULL};
-
-/* Flags values; 0 is default behavior */
-#define PEER_NO_SEC	0x1
-#define PEER_TCP	0x2
-
-%}
-
-/* Values returned by lex for token */
-%union {
-	char 		*string;	/* The string is allocated by strdup in lex.*/
-	uint16_t	 u16;		/* Store small values such as TCP port or timers */
-	int		 integer;	/* Store integer values */
-}
-
-/* In case of error in the lexical analysis */
-%token 		LEX_ERROR
-
-/* A quoted string */
-%token <string>	QSTRING
-/* Strings subtypes */
-%type <string>	FQDN		/* This is a fqdn. We check that the syntax is correct. */
-%type <string>	FILENAME	/* This is a filename. existence of the file is checked. */
-%type <string>  IPADDRESS	/* This is an IP. the numerical value is stored in _ss. */
-
-/* An integer value */
-%token <integer> INTEGER
-
-/* In the "general" section */
-%token 		SECTION_GENERAL
-%token		GEN_LOG
-%type	<u16>	gen_log_type
-%token		GEN_LOG_CONSOLE
-%token		GEN_LOG_SYSLOG
-%token		GEN_DIAMID
-%token		GEN_PORT
-%type	<u16>	gen_port_val
-%token		GEN_TCTIMER
-%token		GEN_TWTIMER
-%token		GEN_DISABLERELAY
-%token		GEN_DISABLETCP
-%token		GEN_DISABLEIP4
-%token		GEN_DISABLEIP6
-%token		GEN_PRIMARY
-%token		GEN_SECONDARY
-%token		GEN_SCTP_STREAMS
-%type	<u16>	gen_sctp_streams_val
-
-/* In the "extension" section */
-%token 		SECTION_EXTENSION
-%token <string>	EXT_NAME
-%token		EXT_FILENAME
-%token		EXT_CONFFILE
-
-/* In the "peer" section */
-%token 		SECTION_PEER
-%token		PEER_URI
-%token		PEER_SCHEME_SEC
-%token		PEER_SCHEME_NOSEC
-%token <string>	PEER_LOCATOR
-%token <u16>	PEER_PORT
-%token 		PEER_TRANS_SCTP
-%token 		PEER_TRANS_TCP
-
-/* -------------------------------------- */
-%%
-
-	/* The grammar definition - Sections blocs. */
-conffile:		  general_section extensions_section peers_section
-			| general_section peers_section extensions_section
-			;
-
-	/* These types are used several times: */
-FQDN:			QSTRING
-			{
-				/* Verify this is a valid FQDN */
-				if (!is_valid_fqdn($1, &_ss, pconfig)) {
-					yyerror (&yylloc, pconfig, "An error was detected on a fqdn, aborting...");
-					YYERROR;
-				}
-				$$ = $1;
-			}
-			;
-				
-FILENAME:		QSTRING
-			{
-				/* Verify this is a valid file */
-				if (!is_valid_file($1)) {
-					yyerror (&yylloc, pconfig, "An error was detected on a file name, aborting...");
-					YYERROR;
-				}
-				$$ = $1;
-			}
-			;
-				
-IPADDRESS:		QSTRING
-			{
-				/* Verify this is a valid IP */
-				if (!is_valid_addr($1, pconfig)) {
-					yyerror (&yylloc, pconfig, "An error was detected on an IP address, aborting...");
-					YYERROR;
-				}
-				/* _ss is set with the IP numerical value during the check */
-				/* Return the string anyway, to be freed */
-				$$ = $1;
-			}
-			;
-				
-
-	/* Define the [general] section grammar */
-general_section:	SECTION_GENERAL general_content
-			;
-
-general_content:	/* empty is allowed */
-			| general_content gen_log 
-			| general_content gen_diamid
-			| general_content gen_port
-			| general_content gen_sctp_streams
-			| general_content gen_tctimer
-			| general_content gen_twtimer
-			| general_content gen_disablerelay
-			| general_content gen_disabletcp
-			| general_content gen_disableip4
-			| general_content gen_disableip6
-			| general_content gen_primary
-			| general_content gen_secondary
-			;
-
-gen_log:		GEN_LOG '=' gen_log_type ';'
-			{
-				/* Save the new log type in the configuration. We'll set it only after conf file is parsed */
-				pconfig->log_to = (int) $3;
-			}
-			;
-
-gen_log_type:		/* Terminals rules */
-			  GEN_LOG_SYSLOG
-			{
-				/* Save the syslog flag */
-				$$ = LOG_TO_SYSLOG;
-			}
-			| GEN_LOG_CONSOLE
-			{
-				/* Save the console flag */
-				$$ = LOG_TO_CONSOLE;
-			}
-			/* Recursive rules */
-			| gen_log_type ',' GEN_LOG_SYSLOG
-			{
-				/* Add the syslog flag */
-				$$ = $1 | LOG_TO_SYSLOG;
-			}
-			| gen_log_type ',' GEN_LOG_CONSOLE
-			{
-				/* Add the console flag */
-				$$ = $1 | LOG_TO_CONSOLE;
-			}
-			;
-
-gen_diamid:		GEN_DIAMID '=' FQDN ';'
-			{
-				/* Save this string as the peer diameter id */
-				if (pconfig->pub.diameter_identity) {
-					free(pconfig->pub.diameter_identity);
-					pconfig->pub.diameter_identity = NULL;
-				}
-				pconfig->pub.diameter_identity = $3;
-			}
-			| GEN_DIAMID '=' error ';'
-			{
-				log_error("A Diameter-Id MUST be a fqdn. Exiting...\n");
-				YYERROR;
-			}
-			;
-
-gen_port:		GEN_PORT '=' gen_port_val ';'
-			{
-				pconfig->pub.local_port = $3;
-			}
-			;
-			
-gen_port_val:		INTEGER
-			{
-				if (( $1 <= 0) || ($1 > 65535)) {
-					log_error("The LocalPort value (%d) is invalid. Exiting...\n", $1);
-					YYERROR;
-				}
-				$$ = (uint16_t) $1 ;
-			}
-			;
-
-gen_sctp_streams:	GEN_SCTP_STREAMS '=' gen_sctp_streams_val ';'
-			{
-				pconfig->pub.sctp_streams = $3;
-			}
-			;
-			
-gen_sctp_streams_val:	INTEGER
-			{
-				if (( $1 <= 0) || ($1 > 65535)) {
-					log_error("The sctp_streams value (%d) is invalid. Exiting...\n", $1);
-					YYERROR;
-				}
-				$$ = (uint16_t) $1 ;
-			}
-			;
-
-gen_tctimer:		GEN_TCTIMER '=' INTEGER ';'
-			{
-				pconfig->pub.tctimer = $3;
-			}
-			;
-
-gen_twtimer:		GEN_TWTIMER '=' INTEGER ';'
-			{
-				if ($3 >= 6) {
-					pconfig->pub.twtimer = $3;
-				} else {
-					log_error("The TwTimer value (%d) is invalid. It must be >= 6. Exiting...\n", $3);
-					YYERROR;
-				}
-			}
-			;
-
-gen_disablerelay:	GEN_DISABLERELAY '=' INTEGER ';'
-			{
-				pconfig->pub.disable_relay = $3;
-			}
-			;
-
-gen_disabletcp:		GEN_DISABLETCP ';'
-			{
-				pconfig->pub.disable_tcp = 1;
-			}
-			;
-
-gen_disableip4:		GEN_DISABLEIP4 ';'
-			{
-				if (pconfig->pub.disable_inet6) {
-					yyerror (&yylloc, pconfig, "NO_IP6 and NO_IP4 can not be used together.");
-					YYERROR;
-				}
-				if (have_ip4) {
-					yyerror (&yylloc, pconfig, "A primary or secondary IP address was defined, but NO_IP4 appears.");
-					YYERROR;
-				}
-				pconfig->pub.disable_inet4 = 1;
-			}
-			;
-
-gen_disableip6:		GEN_DISABLEIP6 ';'
-			{
-				if (pconfig->pub.disable_inet4) {
-					yyerror (&yylloc, pconfig, "NO_IP4 and NO_IP6 can not be used together.");
-					YYERROR;
-				}
-				if (have_ip6) {
-					yyerror (&yylloc, pconfig, "A primary or secondary IPv6 address was defined, but NO_IP6 appears.");
-					YYERROR;
-				}
-				pconfig->pub.disable_inet6 = 1;
-			}
-			;
-			
-gen_primary:		GEN_PRIMARY '=' IPADDRESS ';'
-			{
-				/* queue the sa in _ss into pconfig->pub.local_addr_pri_sa */
-				if (queue_ss(&pconfig->pub.local_addr_pri_sa) != 0) {
-					yyerror (&yylloc, pconfig, "An error occurred while saving an address, aborting...");
-					YYERROR;
-				}
-				
-				
-				/* we don't need the string anymore */
-				free($3);
-			}
-			;
-
-gen_secondary:		GEN_SECONDARY '=' IPADDRESS ';'
-			{
-				/* queue the sa in _ss into pconfig->pub.local_addr_sec_sa */
-				if (queue_ss(&pconfig->pub.local_addr_sec_sa) != 0) {
-					yyerror (&yylloc, pconfig, "An error occurred while saving an address, aborting...");
-					YYERROR;
-				}
-				
-				/* we don't need the string anymore */
-				free($3);
-			}
-			;
-
-
-	/* Define the [extensions] section grammar */
-extensions_section:	SECTION_EXTENSION extensions_content
-			;
-
-extensions_content:	/* empty is allowed */
-			| extensions_content extension_detail
-			;
-
-extension_detail:	{
-				/* Reset the ext_detail global before processing the rule */
-				if (ext_detail.fname) { free(ext_detail.fname); ext_detail.fname = NULL; }
-				if (ext_detail.cname) { free(ext_detail.cname); ext_detail.cname = NULL; }
-			}
-			QSTRING '=' '{' extension_params '}' ';'
-			{
-				int ret = 0;
-				
-				/* Add this extension */
-				ret = ext_register( ext_detail.fname, ext_detail.cname );
-				
-				/* Free the strings */
-				if (ext_detail.fname) { free(ext_detail.fname); ext_detail.fname = NULL; }
-				if (ext_detail.cname) { free(ext_detail.cname); ext_detail.cname = NULL; }
-				
-				/* Check error */
-				if (ret != 0) {
-					log_error("Failed to register extension %s: %s\n", $2, strerror(ret));
-					YYERROR;
-				}
-			}
-			;
-
-extension_params:	extension_confname extension_filename extension_confname	/* confname appears twice on purpose, to allow any order */
-			;
-
-extension_filename:	EXT_FILENAME '=' FILENAME ';'
-			{
-				if (ext_detail.fname) { free(ext_detail.fname); ext_detail.fname = NULL; }
-				ext_detail.fname = $3;
-			}
-			| EXT_FILENAME '=' error ';'
-			{
-				log_error("You must provide a valid filename for extension.\n");
-				YYERROR;
-			}
-			;
-
-extension_confname:	/* This one is optional */
-			| EXT_CONFFILE '=' FILENAME ';'
-			{
-				if (ext_detail.cname) { free(ext_detail.cname); ext_detail.cname = NULL; }
-				ext_detail.cname = $3;
-			}
-			| EXT_CONFFILE '=' error ';'
-			{
-				log_error("If you provide a configuration file for the extension, it must be a valid file.\n"
-					  " Note that you may remove the 'conffile' directive if your extension has no configuration.\n");
-				YYERROR;
-			}
-			;
-
-	/* Define the [peers] section grammar */
-peers_section:		SECTION_PEER peers_content
-			;
-
-peers_content:		/* empty is allowed */
-			| peers_content peer_detail
-			;
-
-peer_detail:		{
-				/* Initialize the peer details */
-				if (peer_detail.locator ) { free(peer_detail.locator); }
-				memset(&peer_detail, 0, sizeof(peer_detail));
-				peer_detail.port = 3868;
-				peer_detail.sctp_streams = pconfig->pub.sctp_streams;
-			}
-			FQDN '=' '{' peer_content '}' ';'
-			{
-				int ret = 0;
-				peer_add_t data;
-				
-				memset(&data, 0, sizeof(peer_add_t));
-				
-				/* Copy information from peer_detail */
-				
-				/* The "no sec" flag */
-				if (peer_detail.flags & PEER_NO_SEC)
-					data.pa_flags = PA_NOSEC;
-				
-				/* The peers declared in the configuration file do not expire */
-				
-				/* Now fill the connection information */
-				if (peer_detail.flags & PEER_TCP) {
-					data.pa_proto = IPPROTO_TCP;
-				} else {
-					data.pa_proto = IPPROTO_SCTP;
-				}
-				
-				/* the SA information was resolved in peerss during the "peer_locator" rule, or fqdn */
-				if (peer_detail.locator)
-					memcpy(&data.pa_ss, &peer_detail.peerss, sizeof(sSS));
-				else
-					memcpy(&data.pa_ss, &_ss, sizeof(sSS));
-					
-				switch (data.pa_ss.ss_family) {
-					case AF_INET:
-						{
-							sSA4 * sin = (sSA4 *)&data.pa_ss;
-							sin->sin_port = htons(peer_detail.port);
-						}
-						break;
-					case AF_INET6:
-						{
-							sSA6 * sin6 = (sSA6 *)&data.pa_ss;
-							sin6->sin6_port = htons(peer_detail.port);
-						}
-						break;
-					default:
-						TRACE_DEBUG(INFO, "Unknown AF: %d", data.pa_ss.ss_family);
-						yyerror(&yylloc, pconfig, "Resolved peer to unknown address family...");
-						YYERROR;
-				}
-				
-				/* Save the number of streams */
-				data.pa_streams = peer_detail.sctp_streams;
-				
-				/* Now add the peer with its information */
-				ret = peer_add($2, strlen($2), &data);
-				if (ret != 0) {
-					yyerror(&yylloc, pconfig, "An error occurred while adding a peer, aborting...");
-					YYERROR;
-				}
-				
-				free($2);
-				if (peer_detail.locator ) { free(peer_detail.locator); peer_detail.locator=NULL; }
-			}
-			;
-			
-peer_content:		/* empty is allowed */
-			| peer_content peer_uri
-			| peer_content peer_sctp_streams
-			;
-
-peer_uri:		PEER_URI '=' '"' peer_scheme peer_locator peer_port peer_transport '"' ';'
-			;
-
-peer_scheme:		PEER_SCHEME_SEC 
-			| PEER_SCHEME_NOSEC
-			{
-				peer_detail.flags |= PEER_NO_SEC;
-			}
-			;
-
-peer_locator:		PEER_LOCATOR
-			{
-				/* Check the locator is valid */
-				if (!is_valid_locator($1, &peer_detail.peerss, pconfig)) {
-					yyerror (&yylloc, pconfig, "An error was detected on a locator, aborting...");
-					YYERROR;
-				}
-				if (peer_detail.locator) 
-					free(peer_detail.locator);
-				peer_detail.locator = $1;
-			}
-			;
-			
-peer_port:		/* empty */
-			| PEER_PORT
-			{
-				peer_detail.port = $1;
-			}
-			;
-			
-peer_transport:		/* empty */
-			| PEER_TRANS_SCTP
-			| PEER_TRANS_TCP
-			{
-				if (pconfig->pub.disable_tcp) {
-					yyerror(&yylloc, pconfig, "Transport is set to TCP but this protocol is disabled in general section.");
-					YYERROR;
-				}
-				peer_detail.flags |= PEER_TCP;
-			}
-			;
-
-peer_sctp_streams:	GEN_SCTP_STREAMS '=' gen_sctp_streams_val ';'
-			{
-				peer_detail.sctp_streams = $3;
-			}
-			;
--- a/waaad/conf-token.l	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,195 +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.								 *
-*********************************************************************************************************/
-
-/* Lex configuration parser.
- *
- * This file defines the token for parsing the configuration file of waaad.
- * Note that each extension has a separate independant configuration file.
- *
- * Note : This module is NOT thread-safe. All processing must be done from one thread only.
- */
-
-%{
-/* Include the daemon's header files */
-#include "waaad-internal.h"
-/* Include yacc tokens definitions */
-#include "conf-gram.h"
-
-/* Update the column information */
-#ifdef DEBUG_LEX
-#define YY_USER_ACTION { 						\
-	yylloc->first_column = yylloc->last_column + 1; 		\
-	yylloc->last_column = yylloc->first_column + yyleng - 1;	\
-	TRACE_DEBUG(FULL, 						\
-		"(%d:%d-%d:%d) matched rule %d, length=%d, txt='%s'\n",	\
-		yylloc->first_line, yylloc->first_column, 		\
-		yylloc->last_line, yylloc->last_column, 		\
-		yy_act, yyleng, yytext); 				\
-}
-#else /* DEBUG_LEX */
-#define YY_USER_ACTION { 						\
-	yylloc->first_column = yylloc->last_column + 1; 		\
-	yylloc->last_column = yylloc->first_column + yyleng - 1;	\
-}
-#endif
-
-/* %option noinput ? */
-#define YY_NO_INPUT
-%}
-
-%option bison-bridge bison-locations
-%option noyywrap
-%option nounput
-
-/* Use the following start condition to parse an URI */
-%x	EXPECT_URI
-%x	IN_URI
-
-/* Quoted string. Multilines do not match. */
-qstring		\"[^\"\n]*\"
-
-%%
-
-<*>\n			{ 
-				/* Update the line count */
-				yylloc->first_line++; 
-				yylloc->last_line++; 
-				yylloc->last_column=0; 
-			} 
-
-<*>([[:space:]]{-}[\n])+	; /* Eat all spaces, not new lines */
-<*>#.*$			; /* Eat all comments */
-
-{qstring}		{
-				/* First copy the string without the quotes for use in the yacc parser */
-				CHECK_MALLOC_DO(	yylval->string = strdup(yytext+1), /* This allocates one useless tail char but... it's easier :D */ 
-							return LEX_ERROR  );/* on error, trig an error in yacc parser */
-
-				yylval->string[yyleng-2] = '\0';
-				
-				/* the yacc parser will check the string is valid */
-				return QSTRING;
-			}
-			
-[[:digit:]]+		{
-				/* Convert this to an integer value */
-				int ret = sscanf(yytext, "%i", &yylval->integer);
-				if (ret != 1) {
-					/* No matching: an error occurred */
-					log_error("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno));
-					return LEX_ERROR; /* trig an error in yacc parser */
-					/* Maybe we could REJECT instead of failing here? */
-				}
-				return INTEGER;
-			}
-				
-
-	/* The GENERAL section tokens */
-(?i:"[general]")	{ return SECTION_GENERAL; 			} /* enter the General section */
-
-(?i:"Log")		{ return GEN_LOG; 				} /* How to specify the logging facility */
-(?i:"console")		{ return GEN_LOG_CONSOLE; 			} /* Log messages to console */
-(?i:"syslog")		{ return GEN_LOG_SYSLOG; 			} /* Log messages to syslog */
-
-(?i:"TcTimer")		{ return GEN_TCTIMER;				} /* Specify the Tc timer value */
-(?i:"TwTimer")		{ return GEN_TWTIMER;				} /* Specify the Tw timer value */
-(?i:"DisableRelay")	{ return GEN_DISABLERELAY;			} /* Is relaying disabled? */
-
-(?i:"Diameter-Id")	{ return GEN_DIAMID;				} /* How to specify the Diameter Identity of the local peer */
-(?i:"LocalPort")	{ return GEN_PORT;				} /* The port the local peer is listening on */
-(?i:"sctp_streams")	{ return GEN_SCTP_STREAMS;			} /* The maximum number of SCTP streams per assoc */
-(?i:"no_tcp")		{ return GEN_DISABLETCP;			} /* Is TCP disabled? */
-(?i:"no_ip4")		{ return GEN_DISABLEIP4;			} /* Is IP disabled? */
-(?i:"no_ip6")		{ return GEN_DISABLEIP6;			} /* Is IPv6 disabled? */
-(?i:"primary")		{ return GEN_PRIMARY;				} /* An address to listen to TCP and SCTP connections */
-(?i:"secondary")	{ return GEN_SECONDARY;				} /* An address to use in SCTP multihoming (+ all primaries) */
-
-	/* The EXTENSION section tokens */
-(?i:"[extensions]")	{ return SECTION_EXTENSION; 			} /* enter the Extension section */
-
-(?i:"filename")		{ return EXT_FILENAME;				}
-(?i:"conffile")		{ return EXT_CONFFILE; 				}
-
-	/* The PEERS section tokens */
-(?i:"[peers]")		{ return SECTION_PEER;				} /* enter the Peers section */
-
-(?i:"uri")		{ BEGIN(EXPECT_URI); return PEER_URI;		} /* We are now expecting an URI, we do not consider QSTRINGS anymore. */
-<EXPECT_URI>"\""	{ BEGIN(IN_URI);     return '"';		} /* Enter the string describing the URI */
-<IN_URI>"\""		{ BEGIN(INITIAL);    return '"';		} /* Exit the string describing the URI */
-<IN_URI>"aaa://"	{ return PEER_SCHEME_NOSEC;			}
-<IN_URI>"aaas://"	{ return PEER_SCHEME_SEC;			}
-<IN_URI>[[][[:xdigit:]]*:[[:xdigit:]]*:[[:xdigit:].:]*[]]	{
-				/* This matches a protected IPv6 or mapped ipv4 between [ ]. In this case, we remove the [ ] */
-				CHECK_MALLOC_DO( yylval->string = strdup(yytext+1), /* This allocates one useless tail char but... it's easier :D */ 
-						return LEX_ERROR  ); /* on error, trig an error in yacc parser */
-				yylval->string[yyleng-2] = '\0';
-				
-				/* the yacc parser will check the string is valid */
-				return PEER_LOCATOR;
-			}
-<IN_URI>":"[[:digit:]]+	{ 
-				/* Check this is a valid port number */
-				int ret=0;
-				ret = sscanf(yytext, ":%hu", &yylval->u16);
-				if (ret != 1) {
-					/* No matching: an error occurred */
-					log_error("Unable to convert the value '%s' to a valid port number: %s\n", yytext, strerror(errno));
-					return LEX_ERROR; /* trig an error in yacc parser */
-				}
-				return PEER_PORT;
-			}
-<IN_URI>(?i:";transport=sctp") 	{ return PEER_TRANS_SCTP;		}
-<IN_URI>(?i:";transport=tcp") 	{ return PEER_TRANS_TCP;		}
-<IN_URI>[[:alnum:].-]+	{
-				/* Any string that did not match one of the previous IN_URI rules is treated as a locator */
-				CHECK_MALLOC_DO( yylval->string = strdup(yytext),
-						return LEX_ERROR  ); /* on error, trig an error in yacc parser */
-				
-				/* the yacc parser will check the string is valid */
-				return PEER_LOCATOR;
-			}
-	
-	/* Valid single characters for yyparse */
-<*>[=,;{}]		{ return yytext[0]; }
-
-	/* Unrecognized token */
-<*>[[:alnum:]]+		|	/* This rule is only useful to print a complete token in error messages */
-	/* Unrecognized character */
-<*>.			{ 
-				log_error("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext);
-			 	return LEX_ERROR; 
-			}
-
-%%
--- a/waaad/conf.c	Wed Feb 25 11:27:53 2009 +0900
+++ b/waaad/conf.c	Wed Feb 25 16:49:21 2009 +0900
@@ -57,7 +57,7 @@
 static waaad_conf_t waaad_config;
 
 /* The Yacc parser prototype */
-int yyparse (waaad_conf_t * pconfig);
+int waaadparse (waaad_conf_t * pconfig);
 
 /* Set the default values in a configuration structure */
 static int conf_setdefaults(waaad_conf_t * conf)
@@ -148,15 +148,15 @@
 /* Parse the configuration file (using the yacc parser) */
 int conf_parse ( void )
 {
-	extern FILE * yyin;
+	extern FILE * waaadin;
 	int ret;
 	
 	CHECK_PARAMS( g_conf );
 
 	TRACE_DEBUG (FULL, "Parsing configuration file: %s...", g_conf->filepath);
 	
-	yyin = fopen(g_conf->filepath, "r");
-	if (yyin == NULL) {
+	waaadin = fopen(g_conf->filepath, "r");
+	if (waaadin == NULL) {
 		ret = errno;
 		log_error("Unable to open configuration file %s for reading: %s\n", g_conf->filepath, strerror(ret));
 		TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
@@ -164,10 +164,10 @@
 	}
 	
 	/* call yacc parser */
-	CHECK_FCT(  yyparse(g_conf)  );
+	CHECK_FCT(  waaadparse(g_conf)  );
 
 	/* close the file */
-	fclose(yyin);
+	fclose(waaadin);
 	
 	/* resolve the diameter-id, store result in local_addr_diamid */
 	{
--- a/waaad/main.c	Wed Feb 25 11:27:53 2009 +0900
+++ b/waaad/main.c	Wed Feb 25 16:49:21 2009 +0900
@@ -42,7 +42,6 @@
  */
 
 #include "waaad-internal.h"
-#include "hgversion.h"
 
 #include <signal.h>
 #include <getopt.h>
@@ -59,7 +58,7 @@
 		")"
 #endif /* HG_VERSION */
 		"\n", 
-		PACKAGE_NAME, PACKAGE_TARNAME, PACKAGE_VERSION
+		CMAKE_PROJECT_NAME, PROJECT_NAME, PROJECT_VERSION
 #ifdef HG_VERSION
 		, HG_VERSION
 #ifdef PACKAGE_HG_REVISION
@@ -73,8 +72,8 @@
 static void main_version(void)
 {
 	main_version_core();
-	printf( "\n%s\n", PACKAGE_COPYRIGHT);
-	printf( "\nSee " PACKAGE_TARNAME " homepage at http://aaa.koganei.wide.ad.jp/\n"
+	printf( "\n%s\n", PROJECT_COPYRIGHT);
+	printf( "\nSee " CMAKE_PROJECT_NAME " homepage at http://aaa.koganei.wide.ad.jp/\n"
 		" for information, updates and bug reports on this software.\n");
 }
 
@@ -83,7 +82,7 @@
 {
 	main_version_core();
 	printf("\nThis daemon is an implementation of the Diameter protocol.\n");
-	printf("\nUsage: " PACKAGE_TARNAME " [OPTIONS]...\n");
+	printf("\nUsage: " PROJECT_NAME " [OPTIONS]...\n");
 	printf( "  -h, --help             Print help and exit\n"
   		"  -V, --version          Print version and exit\n"
   		"  -c, --config=filename  Read configuration from this file instead of the \n"
--- a/waaad/peer-cer_cea.c	Wed Feb 25 11:27:53 2009 +0900
+++ b/waaad/peer-cer_cea.c	Wed Feb 25 16:49:21 2009 +0900
@@ -43,7 +43,6 @@
 
 #include "waaad-internal.h"
 #include "peer-internal.h"
-#include "hgversion.h"
 
 /* Dictionary objects for PSM */
 static dict_object_t * dict_CER = NULL;
@@ -191,8 +190,8 @@
 		
 		/* Set its value */
 		memset(&val, 0, sizeof(val));
-		val.os.data = (unsigned char *)PACKAGE_TARNAME;
-		val.os.len = strlen(PACKAGE_TARNAME);
+		val.os.data = (unsigned char *)CMAKE_PROJECT_NAME;
+		val.os.len = strlen(CMAKE_PROJECT_NAME);
 		CHECK_FCT( msg_avp_setvalue( avp, &val ) );
 
 		/* Add it to the message */
@@ -210,7 +209,7 @@
 		#ifdef HG_REVISION
 		val.u32 = (uint32_t)atol(HG_REVISION);
 		#else /* HG_REVISION */
-		val.u32 = (uint32_t)atol(PACKAGE_VERSION); /* Will convert only the major of the version... */
+		val.u32 = (uint32_t)atol(PROJECT_VERSION); /* Will convert only the major of the version... */
 		#endif /* HG_REVISION */
 
 		CHECK_FCT( msg_avp_setvalue( avp, &val ) );
@@ -718,8 +717,8 @@
 		
 		/* Set its value */
 		memset(&val, 0, sizeof(val));
-		val.os.data = (unsigned char *)PACKAGE_TARNAME;
-		val.os.len = strlen(PACKAGE_TARNAME);
+		val.os.data = (unsigned char *)CMAKE_PROJECT_NAME;
+		val.os.len = strlen(CMAKE_PROJECT_NAME);
 		CHECK_FCT( msg_avp_setvalue( avp, &val ) );
 
 		/* Add it to the message */
@@ -737,7 +736,7 @@
 		#ifdef HG_REVISION
 		val.u32 = (uint32_t)atol(HG_REVISION);
 		#else /* HG_REVISION */
-		val.u32 = (uint32_t)atol(PACKAGE_VERSION); /* Will convert only the major of the version... */
+		val.u32 = (uint32_t)atol(PROJECT_VERSION); /* Will convert only the major of the version... */
 		#endif /* HG_REVISION */
 
 		CHECK_FCT( msg_avp_setvalue( avp, &val ) );
--- a/waaad/peer-psm.c	Wed Feb 25 11:27:53 2009 +0900
+++ b/waaad/peer-psm.c	Wed Feb 25 16:49:21 2009 +0900
@@ -1509,6 +1509,7 @@
 			
 		case -1:
 		default:
+			TRACE_DEBUG(FULL, "Killing PSM %p", peer->p_psm);
 			return _thread_term(&peer->p_psm);
 	}
 	
--- a/waaad/peer-server.c	Wed Feb 25 11:27:53 2009 +0900
+++ b/waaad/peer-server.c	Wed Feb 25 16:49:21 2009 +0900
@@ -370,10 +370,6 @@
 	
 	si->started = 1;
 	
-	/* Initialize the list of clients */
-	uti_list_init ( &si->clients, si );
-	CHECK_POSIX_DO(  pthread_mutex_init(&si->climtx, NULL),  goto error  );
-	
 	/* Listen, to enable remote peers to connect */
 	CHECK_SYS_DO(  listen(si->sock, 5), { TRACE_DEBUG(FULL, "Error on socket %d", si->sock); goto error; }  );
 	
@@ -458,7 +454,7 @@
 /* Code to start listening */
 int _peer_server_start()
 {
-	int i   = 1;
+	int i = 0;
 	
 	TRACE_ENTRY( );
 	
@@ -468,10 +464,17 @@
 	/* Allocate the _psi array */
 	CHECK_MALLOC( _psi = calloc(_psi_cnt, sizeof(_peer_servinfo_t)) );
 	
+	/* calloc sets the memory to 0 */
+	for (i=0; i<_psi_cnt; i++) {
+		uti_list_init(&_psi[i].clients, &_psi[i]);
+		CHECK_POSIX(pthread_mutex_init(&_psi[i].climtx, NULL));
+	}
+	
 	/* The first element is the SCTP server, create this one already */
 	_psi[0].proto = IPPROTO_SCTP;
 	CHECK_FCT(  _peer_sctp_create_server( &_psi[0].sock )  );
 	snprintf( &(_psi[0].servname[0]), DEBUG_NAME_LEN, "SCTP.Srv(%d)", _psi[0].sock);
+	i = 1;
 	
 	/* Now create the TCP servers */
 	if ( ! g_pconf->disable_tcp ) {
@@ -563,6 +566,8 @@
 		/* loop in the list, kill the threads (clients and server) if any, close the sockets */
 		for (i = 0; i < _psi_cnt; i++) {
 			
+			TRACE_DEBUG(FULL, "Stopping server %d (%s)", i, _psi[i].servname);
+			
 			/* First, stop the server thread so that no new client is accepted */
 			CHECK_FCT_DO( _thread_term( &(_psi[i].listen) ), /* continue */ );
 
@@ -580,7 +585,9 @@
 				CHECK_FCT_DO( _thread_term( &cli->thr ),  /* continue */);
 				
 				/* Close the socket */
-				CHECK_SYS_DO(  shutdown(cli->sock, SHUT_RDWR),  /* continue */);
+				if (cli->sock) {
+					CHECK_SYS_DO(  shutdown(cli->sock, SHUT_RDWR),  /* continue */);
+				}
 				
 				/* free this client information */
 				free(cli);
@@ -591,7 +598,9 @@
 			CHECK_POSIX_DO(  pthread_mutex_destroy( &(_psi[i].climtx) ), /* continue */ );
 			
 			/* Now shutdown the server socket */
-			CHECK_SYS_DO(  shutdown(_psi[i].sock, SHUT_RDWR),  /* continue */);
+			if (_psi[i].sock) {
+				CHECK_SYS_DO(  shutdown(_psi[i].sock, SHUT_RDWR),  /* continue */);
+			}
 		}
 		
 		/* then free the object */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/waaad/tests/CMakeLists.txt	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,56 @@
+# Test directory
+PROJECT("waaad tests" C)
+
+#############################
+# List the test cases
+SET(TEST_LIST
+	testdict
+	testmesg
+	testmeq
+	testsess
+	testsec
+	testpeer
+	testrt
+	testdisp
+)
+
+#############################
+# Some parameters for the tests
+# Work with a smaller hash table to augment collisions
+ADD_DEFINITIONS(-D_PEER_HASH_SIZE=2)
+
+# Define a flag to allow exporting some of the functions to tests 
+ADD_DEFINITIONS(-DIN_WAAAD_TEST)
+
+# Add this flag to add some debug information in the tests themselves
+ADD_DEFINITIONS(-DTEST_DEBUG)
+
+#############################
+# Compilation rules
+
+# Part of the source files are in upper directory
+INCLUDE_DIRECTORIES(..)
+
+# All tests uses the waaad core files (defined in upper CMakeList.txt file)
+BISON_FILE(../waaad.y)
+FLEX_FILE(../waaad.l)
+
+SET(TEST_COMMON_SRC "")
+
+FOREACH( SRC_FILE ${WAAAD_COMMON_SRC})
+   SET(TEST_COMMON_SRC ${TEST_COMMON_SRC} "../${SRC_FILE}")
+ENDFOREACH(SRC_FILE)
+
+FOREACH( SRC_FILE ${WAAAD_COMMON_GEN_SRC})
+   SET(TEST_COMMON_SRC ${TEST_COMMON_SRC} "${CMAKE_CURRENT_BINARY_DIR}/../${SRC_FILE}")
+ENDFOREACH(SRC_FILE)
+
+# Create an archive of all the daemon common files
+ADD_LIBRARY(waaadcore STATIC ${TEST_COMMON_SRC})
+
+# Compile each test
+FOREACH( TEST ${TEST_LIST} )
+   ADD_EXECUTABLE(${TEST} ${TEST}.c tests.h)
+   TARGET_LINK_LIBRARIES(${TEST} waaadcore ${WAAAD_LIBS})
+   ADD_TEST(${TEST} ${EXECUTABLE_OUTPUT_PATH}/${TEST})
+ENDFOREACH( TEST )
--- a/waaad/tests/Makefile.am	Wed Feb 25 11:27:53 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-# Testsuite directory.
-
-# find the API and daemon headers
-AM_CPPFLAGS = -I$(srcdir)/../../include -I$(srcdir)/..
-
-# Also use the same flags as parent directory
-AM_CPPFLAGS += -DTRACE_LEVEL=NONE -DDEFAULT_CONF_FILE='"$(defconffile)"'
-# Remark: the tests are run by default with TRACE_LEVEL = NONE.
-# Anyway, youcan run the test directly with the "-ddd" flags to turn on the debug without recompiling.
-# example: $ waaad/test/testmesg -ddd
-
-# We also use the same LD flags
-AM_LDFLAGS = $(pthread_LIBS) $(dl_LIBS) $(clock_LIBS) $(sctp_LIBS)
-
-# Work with a smaller hash table to augment collisions */
-AM_CPPFLAGS += -D_PEER_HASH_SIZE=2
-
-# Define a flag to allow exporting some of the functions to tests 
-AM_CPPFLAGS += -DIN_WAAAD_TEST
-
-# Add this flag to add some debug information in the tests themselves
-AM_CPPFLAGS += -DTEST_DEBUG
-
-
-# List of daemon's source files, without the "main" function
-# WAAADSOURCES = $(filter-out ../main.c, $(subst $(srcdir)/,,$(shell echo $(srcdir)/../*.c)))
-# ... does not work :( It would have to be understood by Automake, not make...
-
-WAAADSOURCES =  ../conf.c ../conf-gram.y ../conf.h ../conf-token.l \
-		../dict-base.c ../dict-base.h ../dict-hardcoded.h \
-		../dictionary.c ../dictionary.h \
-		../dispatch.h ../dispatch.c \
-		../extensions.h ../extensions.c \
-		../log.h ../log.c ../hgversion.h \
-		../message.h ../message.c \
-		../peer.h ../peer.c \
-		../peer-cer_cea.c ../peer-client.c ../peer-dpr_dpa.c ../peer-dwr_dwa.c \
-		../peer-events.c ../peer-expire.c ../peer-failover.c \
-		../peer-in.c ../peer-internal.h ../peer-out.c ../peer-psm.c \
-		../peer-sctp.c ../peer-secini.c ../peer-server.c \
-		../peer-struct.c ../peer-tcp.c \
-		../queues.h ../queues.c \
-		../routing.h ../routing.c \
-		../security.h ../security.c \
-		../session.h ../session.c \
-		../utils.h ../utils.c \
-		../waaad-internal.h
-
-# Testing the dictionary:
-testdict_SOURCES = testdict.c tests.h $(WAAADSOURCES)
-
-# Testing the messages:
-testmesg_SOURCES = testmesg.c tests.h $(WAAADSOURCES)
-
-# Testing the queues:
-testmeq_SOURCES = testmeq.c tests.h $(WAAADSOURCES)
-
-# Testing the sessions:
-testsess_SOURCES = testsess.c tests.h $(WAAADSOURCES)
-
-# Testing the security:
-testsec_SOURCES = testsec.c tests.h $(WAAADSOURCES)
-
-# Testing the peer:
-testpeer_SOURCES = testpeer.c tests.h $(WAAADSOURCES)
-
-# Testing the routing:
-testrt_SOURCES = testrt.c tests.h $(WAAADSOURCES)
-
-# Testing the dispatching:
-testdisp_SOURCES = testdisp.c tests.h $(WAAADSOURCES)
-
-check_PROGRAMS = testdict testmesg testmeq testsess testsec testpeer testrt testdisp
-
-TESTS = $(check_PROGRAMS)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/waaad/waaad-host.h.in	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,49 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+/* Configuration from compile-time */
+#ifndef _WAAAD_HOST_H
+#define _WAAAD_HOST_H
+
+#cmakedefine HAVE_NTOHLL
+
+#cmakedefine PROJECT_NAME "@PROJECT_NAME@"
+#cmakedefine CMAKE_PROJECT_NAME "@CMAKE_PROJECT_NAME@"
+#cmakedefine PROJECT_VERSION "@PROJECT_VERSION@"
+#cmakedefine PROJECT_COPYRIGHT "@PROJECT_COPYRIGHT@"
+
+#cmakedefine DEFAULT_CONF_FILE "@DEFAULT_CONF_FILE@"
+
+#endif /* _WAAAD_HOST_H */
--- a/waaad/waaad-internal.h	Wed Feb 25 11:27:53 2009 +0900
+++ b/waaad/waaad-internal.h	Wed Feb 25 16:49:21 2009 +0900
@@ -41,6 +41,10 @@
 #ifndef _WAAAD_INTERNAL_H
 #define _WAAAD_INTERNAL_H
 
+/* Configuration generated by the configure script. Contains host-specific environment information */
+#include "waaad-host.h"
+
+
 /* Some standard headers used in most files */
 #include <pthread.h>
 #include <errno.h>
@@ -50,9 +54,6 @@
 #include <stdlib.h>
 
 
-/* Configuration generated by the configure script. Contains host-specific environment information */
-#include "config.h"
-
 /* The logging facility. 
 All daemon messages are sent to this module after initialization.
 Extensions may also choose to send their messages to this module, or handle their own logging mechanism.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/waaad/waaad.l	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,195 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+/* Lex configuration parser.
+ *
+ * This file defines the token for parsing the configuration file of waaad.
+ * Note that each extension has a separate independant configuration file.
+ *
+ * Note : This module is NOT thread-safe. All processing must be done from one thread only.
+ */
+
+%{
+/* Include the daemon's header files */
+#include "waaad-internal.h"
+/* Include yacc tokens definitions */
+#include "waaad.tab.h"
+
+/* Update the column information */
+#ifdef DEBUG_LEX
+#define YY_USER_ACTION { 						\
+	yylloc->first_column = yylloc->last_column + 1; 		\
+	yylloc->last_column = yylloc->first_column + yyleng - 1;	\
+	TRACE_DEBUG(FULL, 						\
+		"(%d:%d-%d:%d) matched rule %d, length=%d, txt='%s'\n",	\
+		yylloc->first_line, yylloc->first_column, 		\
+		yylloc->last_line, yylloc->last_column, 		\
+		yy_act, yyleng, yytext); 				\
+}
+#else /* DEBUG_LEX */
+#define YY_USER_ACTION { 						\
+	yylloc->first_column = yylloc->last_column + 1; 		\
+	yylloc->last_column = yylloc->first_column + yyleng - 1;	\
+}
+#endif
+
+/* %option noinput ? */
+#define YY_NO_INPUT
+%}
+
+%option bison-bridge bison-locations
+%option noyywrap
+%option nounput
+
+/* Use the following start condition to parse an URI */
+%x	EXPECT_URI
+%x	IN_URI
+
+/* Quoted string. Multilines do not match. */
+qstring		\"[^\"\n]*\"
+
+%%
+
+<*>\n			{ 
+				/* Update the line count */
+				yylloc->first_line++; 
+				yylloc->last_line++; 
+				yylloc->last_column=0; 
+			} 
+
+<*>([[:space:]]{-}[\n])+	; /* Eat all spaces, not new lines */
+<*>#.*$			; /* Eat all comments */
+
+{qstring}		{
+				/* First copy the string without the quotes for use in the yacc parser */
+				CHECK_MALLOC_DO(	yylval->string = strdup(yytext+1), /* This allocates one useless tail char but... it's easier :D */ 
+							return LEX_ERROR  );/* on error, trig an error in yacc parser */
+
+				yylval->string[yyleng-2] = '\0';
+				
+				/* the yacc parser will check the string is valid */
+				return QSTRING;
+			}
+			
+[[:digit:]]+		{
+				/* Convert this to an integer value */
+				int ret = sscanf(yytext, "%i", &yylval->integer);
+				if (ret != 1) {
+					/* No matching: an error occurred */
+					log_error("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno));
+					return LEX_ERROR; /* trig an error in yacc parser */
+					/* Maybe we could REJECT instead of failing here? */
+				}
+				return INTEGER;
+			}
+				
+
+	/* The GENERAL section tokens */
+(?i:"[general]")	{ return SECTION_GENERAL; 			} /* enter the General section */
+
+(?i:"Log")		{ return GEN_LOG; 				} /* How to specify the logging facility */
+(?i:"console")		{ return GEN_LOG_CONSOLE; 			} /* Log messages to console */
+(?i:"syslog")		{ return GEN_LOG_SYSLOG; 			} /* Log messages to syslog */
+
+(?i:"TcTimer")		{ return GEN_TCTIMER;				} /* Specify the Tc timer value */
+(?i:"TwTimer")		{ return GEN_TWTIMER;				} /* Specify the Tw timer value */
+(?i:"DisableRelay")	{ return GEN_DISABLERELAY;			} /* Is relaying disabled? */
+
+(?i:"Diameter-Id")	{ return GEN_DIAMID;				} /* How to specify the Diameter Identity of the local peer */
+(?i:"LocalPort")	{ return GEN_PORT;				} /* The port the local peer is listening on */
+(?i:"sctp_streams")	{ return GEN_SCTP_STREAMS;			} /* The maximum number of SCTP streams per assoc */
+(?i:"no_tcp")		{ return GEN_DISABLETCP;			} /* Is TCP disabled? */
+(?i:"no_ip4")		{ return GEN_DISABLEIP4;			} /* Is IP disabled? */
+(?i:"no_ip6")		{ return GEN_DISABLEIP6;			} /* Is IPv6 disabled? */
+(?i:"primary")		{ return GEN_PRIMARY;				} /* An address to listen to TCP and SCTP connections */
+(?i:"secondary")	{ return GEN_SECONDARY;				} /* An address to use in SCTP multihoming (+ all primaries) */
+
+	/* The EXTENSION section tokens */
+(?i:"[extensions]")	{ return SECTION_EXTENSION; 			} /* enter the Extension section */
+
+(?i:"filename")		{ return EXT_FILENAME;				}
+(?i:"conffile")		{ return EXT_CONFFILE; 				}
+
+	/* The PEERS section tokens */
+(?i:"[peers]")		{ return SECTION_PEER;				} /* enter the Peers section */
+
+(?i:"uri")		{ BEGIN(EXPECT_URI); return PEER_URI;		} /* We are now expecting an URI, we do not consider QSTRINGS anymore. */
+<EXPECT_URI>"\""	{ BEGIN(IN_URI);     return '"';		} /* Enter the string describing the URI */
+<IN_URI>"\""		{ BEGIN(INITIAL);    return '"';		} /* Exit the string describing the URI */
+<IN_URI>"aaa://"	{ return PEER_SCHEME_NOSEC;			}
+<IN_URI>"aaas://"	{ return PEER_SCHEME_SEC;			}
+<IN_URI>[[][[:xdigit:]]*:[[:xdigit:]]*:[[:xdigit:].:]*[]]	{
+				/* This matches a protected IPv6 or mapped ipv4 between [ ]. In this case, we remove the [ ] */
+				CHECK_MALLOC_DO( yylval->string = strdup(yytext+1), /* This allocates one useless tail char but... it's easier :D */ 
+						return LEX_ERROR  ); /* on error, trig an error in yacc parser */
+				yylval->string[yyleng-2] = '\0';
+				
+				/* the yacc parser will check the string is valid */
+				return PEER_LOCATOR;
+			}
+<IN_URI>":"[[:digit:]]+	{ 
+				/* Check this is a valid port number */
+				int ret=0;
+				ret = sscanf(yytext, ":%hu", &yylval->u16);
+				if (ret != 1) {
+					/* No matching: an error occurred */
+					log_error("Unable to convert the value '%s' to a valid port number: %s\n", yytext, strerror(errno));
+					return LEX_ERROR; /* trig an error in yacc parser */
+				}
+				return PEER_PORT;
+			}
+<IN_URI>(?i:";transport=sctp") 	{ return PEER_TRANS_SCTP;		}
+<IN_URI>(?i:";transport=tcp") 	{ return PEER_TRANS_TCP;		}
+<IN_URI>[[:alnum:].-]+	{
+				/* Any string that did not match one of the previous IN_URI rules is treated as a locator */
+				CHECK_MALLOC_DO( yylval->string = strdup(yytext),
+						return LEX_ERROR  ); /* on error, trig an error in yacc parser */
+				
+				/* the yacc parser will check the string is valid */
+				return PEER_LOCATOR;
+			}
+	
+	/* Valid single characters for yyparse */
+<*>[=,;{}]		{ return yytext[0]; }
+
+	/* Unrecognized token */
+<*>[[:alnum:]]+		|	/* This rule is only useful to print a complete token in error messages */
+	/* Unrecognized character */
+<*>.			{ 
+				log_error("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext);
+			 	return LEX_ERROR; 
+			}
+
+%%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/waaad/waaad.y	Wed Feb 25 16:49:21 2009 +0900
@@ -0,0 +1,731 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+/* Yacc configuration parser.
+ *
+ * This file defines the grammar for parsing the configuration file of waaad.
+ * Note that each extension has a separate independant configuration file.
+ *
+ * Note : This module is NOT thread-safe. All processing must be done from one thread only.
+ */
+
+/* For development only : */
+
+%debug 
+%error-verbose
+
+/* The parser receives a configuration pointer as parameter */
+%parse-param {waaad_conf_t * pconfig}
+
+/* Keep track of location */
+%locations 
+%pure-parser
+
+%{
+#include "waaad-internal.h"
+#include "waaad.tab.h"	/* bison is not smart enough to define the YYLTYPE before including this code, so... */
+
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+/* The Lex parser prototype */
+int waaadlex(YYSTYPE *lvalp, YYLTYPE *llocp);
+
+/* This function checks a string value is a valid network locator */
+static int is_valid_locator( char * candidate, sSS *ss, waaad_conf_t * pconfig ) 
+{
+	int ret=0;
+	struct addrinfo *ai = NULL, hint;
+	
+	memset(&hint, 0, sizeof(hint));
+	
+	hint.ai_family = AF_UNSPEC;
+	
+	if (pconfig->pub.disable_inet6)
+		hint.ai_family = AF_INET;
+	if (pconfig->pub.disable_inet4)
+		hint.ai_family = AF_INET6;
+		
+	/* TRACE_DEBUG(FULL, "Resolving '%s'...", candidate); */
+	ret = getaddrinfo(candidate, NULL, &hint, &ai);
+	if (ai) {
+		/*
+		TRACE_DEBUG(FULL, "Result:");
+		TRACE_DEBUG(FULL, "  ai_flags    : %x", ai->ai_flags);
+		TRACE_DEBUG(FULL, "  ai_family   : %d", ai->ai_family);
+		TRACE_DEBUG(FULL, "  ai_socktype : %d", ai->ai_socktype);
+		TRACE_DEBUG(FULL, "  ai_protocol : %d", ai->ai_protocol);
+		TRACE_DEBUG(FULL, "  ai_addrlen  : %d", ai->ai_addrlen);
+		TRACE_DEBUG(FULL, "  ai_addr     : .sa_family = %d (%s)", ai->ai_addr->sa_family, ai->ai_addr->sa_family == AF_INET ? "AF_INET" :
+													ai->ai_addr->sa_family == AF_INET6 ? "AF_INET6" :
+														"???");
+		TRACE_DEBUG(FULL, "  ai_canonname: %s", ai->ai_canonname ? ai->ai_canonname:"(null)");
+		TRACE_DEBUG(FULL, "  ai_next     : %p", ai->ai_next);
+		*/
+		if (ss) {
+			memset(ss, 0, sizeof(sSS));
+			memcpy(ss, ai->ai_addr, ai->ai_addrlen);
+		}
+		freeaddrinfo(ai);
+	}
+	if (ret != 0) {
+		log_error("Error resolving network locator '%s': %s.\n", candidate, gai_strerror(ret));
+		return 0;
+	}
+
+	/* Ok this candidate is valid */
+	return 1;
+}
+
+/* This function checks a string value can be a DiameterId (== a fqdn) */
+static int is_valid_fqdn( char * candidate, sSS *ss, waaad_conf_t * pconfig ) 
+{
+	/* What is a valid FQDN? 
+	   Difficult question... maybe use getaddrinfo with flag AI_CANONNAME ?
+	   Let's be permissive here and trust administrators to configure properly their Diameter daemon ^^'
+	 */
+	
+	/* We search for a '.' to reject some aliases and local names */
+	if (!strchr(candidate, '.')) {
+		log_error("The string '%s' is not a valid fully-qualified domain name (fqdn).\n", candidate);
+		return 0;
+	}
+	
+	/* Ok now check this is a valid network locator */
+	return is_valid_locator(candidate, ss, pconfig);
+}
+
+/* This function checks a string value is a valid filename */
+static int is_valid_file( char * candidate ) 
+{
+	int ret;
+	struct stat buffer;
+	
+	ret = stat(candidate, &buffer);
+	if (ret != 0) {
+		log_error("Error on file '%s': %s.\n", candidate, strerror(errno));
+		return 0;
+	}
+
+	/* Ok this candidate is valid */
+	return 1;
+}
+
+/* Global variable to store a sockaddr checked by is_valid_addr or fqdn */
+static sSS _ss;
+
+static int have_ip4 = 0; /* have some ip4 been added already? */
+static int have_ip6 = 0; /* have some ip6 been added already? */
+
+/* This function converts a string into an IP or IPv6 address */
+static int is_valid_addr( char * candidate, waaad_conf_t * pconfig) 
+{
+	int ret=0;
+	
+	/* Clean the storage area */
+	memset(&_ss, 0, sizeof(_ss));
+	
+	/* Search for a ":" in the string */
+	if (!strchr(candidate, ':')) {
+		sSA4 * sin = (sSA4 *) &_ss;
+		/* Assume this is IPv4 */
+		CHECK_SYS_DO(  ret = inet_pton(AF_INET, candidate, &sin->sin_addr.s_addr), return 0 );
+		if (ret == 1) {
+			if (pconfig->pub.disable_inet4) {
+				log_error("Cannot use the address '%s' since NO_IP4 was defined\n", candidate);
+				return 0;
+			}
+			have_ip4++;
+			sin->sin_family = AF_INET;
+			sin->sin_port = htons(pconfig->pub.local_port);
+			return 1; /* the IP is valid */
+		} else {
+			log_error("Error on IP address '%s': unrecognized.\n", candidate);
+		}
+	} else {
+		sSA6 * sin6 = (sSA6 *)&_ss;
+		/* Assume this is IPv6 */
+		CHECK_SYS_DO(  ret = inet_pton(AF_INET6, candidate, &sin6->sin6_addr.s6_addr), return 0 );
+		if (ret == 1) {
+			if (pconfig->pub.disable_inet6) {
+				log_error("Cannot use the address '%s' since NO_IP6 was defined\n", candidate);
+				return 0;
+			}
+			have_ip6++;
+			sin6->sin6_family = AF_INET6;
+			sin6->sin6_port = htons(pconfig->pub.local_port);
+			return 1; /* the IPv6 is valid */
+		} else {
+			log_error("Error on IPv6 address '%s': unrecognized.\n", candidate);
+		}
+	}
+
+	/* This candidate is not valid */
+	return 0;
+}
+
+/* This function extends the list of addresses and stores the new value of _ss inside */
+static int queue_ss( sSS ** plist )
+{
+	sSS * new;
+	
+	if (*plist == NULL) {
+		/* If the array has not been alloc'd yet */
+		CHECK_MALLOC(  *plist = malloc( sizeof (sSS) * 2 )  );
+		new = *plist;
+	} else {
+		/* otherwise, we need to resize the array to add the new element */
+		int cnt = 0;
+		new = *plist;
+		while (new->ss_family != 0)
+			cnt++, new++;
+		CHECK_MALLOC(  *plist = realloc(*plist, sizeof(sSS) * (cnt + 2))  );
+		new = (*plist) + cnt;
+	}
+	
+	/* Now, new points to the beginning of the location where the _ss must be stored */
+	memcpy(new, &_ss, sizeof(sSS));
+	memset(new+1, 0,  sizeof(sSS));
+	return 0;
+}
+
+/* Function to report the errors */
+void yyerror (YYLTYPE *ploc, waaad_conf_t * pconfig, char const *s)
+{
+	if (ploc->first_line != ploc->last_line)
+		log_error("%s:%d.%d-%d.%d : %s\n", pconfig->filepath, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
+	else if (ploc->first_column != ploc->last_column)
+		log_error("%s:%d.%d-%d : %s\n", pconfig->filepath, ploc->first_line, ploc->first_column, ploc->last_column, s);
+	else
+		log_error("%s:%d.%d : %s\n", pconfig->filepath, ploc->first_line, ploc->first_column, s);
+}
+
+/* Global variable to store temporarily extension information */
+static struct _ext_detail {
+	char * fname;
+	char * cname;
+} ext_detail={NULL, NULL};
+
+/* Global variable to store temporarily peer information */
+static struct {
+	char   * locator;
+	sSS	 peerss;
+	uint16_t port;
+	uint16_t sctp_streams;
+	char     flags;
+} peer_detail = {.locator = NULL};
+
+/* Flags values; 0 is default behavior */
+#define PEER_NO_SEC	0x1
+#define PEER_TCP	0x2
+
+%}
+
+/* Values returned by lex for token */
+%union {
+	char 		*string;	/* The string is allocated by strdup in lex.*/
+	uint16_t	 u16;		/* Store small values such as TCP port or timers */
+	int		 integer;	/* Store integer values */
+}
+
+/* In case of error in the lexical analysis */
+%token 		LEX_ERROR
+
+/* A quoted string */
+%token <string>	QSTRING
+/* Strings subtypes */
+%type <string>	FQDN		/* This is a fqdn. We check that the syntax is correct. */
+%type <string>	FILENAME	/* This is a filename. existence of the file is checked. */
+%type <string>  IPADDRESS	/* This is an IP. the numerical value is stored in _ss. */
+
+/* An integer value */
+%token <integer> INTEGER
+
+/* In the "general" section */
+%token 		SECTION_GENERAL
+%token		GEN_LOG
+%type	<u16>	gen_log_type
+%token		GEN_LOG_CONSOLE
+%token		GEN_LOG_SYSLOG
+%token		GEN_DIAMID
+%token		GEN_PORT
+%type	<u16>	gen_port_val
+%token		GEN_TCTIMER
+%token		GEN_TWTIMER
+%token		GEN_DISABLERELAY
+%token		GEN_DISABLETCP
+%token		GEN_DISABLEIP4
+%token		GEN_DISABLEIP6
+%token		GEN_PRIMARY
+%token		GEN_SECONDARY
+%token		GEN_SCTP_STREAMS
+%type	<u16>	gen_sctp_streams_val
+
+/* In the "extension" section */
+%token 		SECTION_EXTENSION
+%token <string>	EXT_NAME
+%token		EXT_FILENAME
+%token		EXT_CONFFILE
+
+/* In the "peer" section */
+%token 		SECTION_PEER
+%token		PEER_URI
+%token		PEER_SCHEME_SEC
+%token		PEER_SCHEME_NOSEC
+%token <string>	PEER_LOCATOR
+%token <u16>	PEER_PORT
+%token 		PEER_TRANS_SCTP
+%token 		PEER_TRANS_TCP
+
+/* -------------------------------------- */
+%%
+
+	/* The grammar definition - Sections blocs. */
+conffile:		  general_section extensions_section peers_section
+			| general_section peers_section extensions_section
+			;
+
+	/* These types are used several times: */
+FQDN:			QSTRING
+			{
+				/* Verify this is a valid FQDN */
+				if (!is_valid_fqdn($1, &_ss, pconfig)) {
+					yyerror (&yylloc, pconfig, "An error was detected on a fqdn, aborting...");
+					YYERROR;
+				}
+				$$ = $1;
+			}
+			;
+				
+FILENAME:		QSTRING
+			{
+				/* Verify this is a valid file */
+				if (!is_valid_file($1)) {
+					yyerror (&yylloc, pconfig, "An error was detected on a file name, aborting...");
+					YYERROR;
+				}
+				$$ = $1;
+			}
+			;
+				
+IPADDRESS:		QSTRING
+			{
+				/* Verify this is a valid IP */
+				if (!is_valid_addr($1, pconfig)) {
+					yyerror (&yylloc, pconfig, "An error was detected on an IP address, aborting...");
+					YYERROR;
+				}
+				/* _ss is set with the IP numerical value during the check */
+				/* Return the string anyway, to be freed */
+				$$ = $1;
+			}
+			;
+				
+
+	/* Define the [general] section grammar */
+general_section:	SECTION_GENERAL general_content
+			;
+
+general_content:	/* empty is allowed */
+			| general_content gen_log 
+			| general_content gen_diamid
+			| general_content gen_port
+			| general_content gen_sctp_streams
+			| general_content gen_tctimer
+			| general_content gen_twtimer
+			| general_content gen_disablerelay
+			| general_content gen_disabletcp
+			| general_content gen_disableip4
+			| general_content gen_disableip6
+			| general_content gen_primary
+			| general_content gen_secondary
+			;
+
+gen_log:		GEN_LOG '=' gen_log_type ';'
+			{
+				/* Save the new log type in the configuration. We'll set it only after conf file is parsed */
+				pconfig->log_to = (int) $3;
+			}
+			;
+
+gen_log_type:		/* Terminals rules */
+			  GEN_LOG_SYSLOG
+			{
+				/* Save the syslog flag */
+				$$ = LOG_TO_SYSLOG;
+			}
+			| GEN_LOG_CONSOLE
+			{
+				/* Save the console flag */
+				$$ = LOG_TO_CONSOLE;
+			}
+			/* Recursive rules */
+			| gen_log_type ',' GEN_LOG_SYSLOG
+			{
+				/* Add the syslog flag */
+				$$ = $1 | LOG_TO_SYSLOG;
+			}
+			| gen_log_type ',' GEN_LOG_CONSOLE
+			{
+				/* Add the console flag */
+				$$ = $1 | LOG_TO_CONSOLE;
+			}
+			;
+
+gen_diamid:		GEN_DIAMID '=' FQDN ';'
+			{
+				/* Save this string as the peer diameter id */
+				if (pconfig->pub.diameter_identity) {
+					free(pconfig->pub.diameter_identity);
+					pconfig->pub.diameter_identity = NULL;
+				}
+				pconfig->pub.diameter_identity = $3;
+			}
+			| GEN_DIAMID '=' error ';'
+			{
+				log_error("A Diameter-Id MUST be a fqdn. Exiting...\n");
+				YYERROR;
+			}
+			;
+
+gen_port:		GEN_PORT '=' gen_port_val ';'
+			{
+				pconfig->pub.local_port = $3;
+			}
+			;
+			
+gen_port_val:		INTEGER
+			{
+				if (( $1 <= 0) || ($1 > 65535)) {
+					log_error("The LocalPort value (%d) is invalid. Exiting...\n", $1);
+					YYERROR;
+				}
+				$$ = (uint16_t) $1 ;
+			}
+			;
+
+gen_sctp_streams:	GEN_SCTP_STREAMS '=' gen_sctp_streams_val ';'
+			{
+				pconfig->pub.sctp_streams = $3;
+			}
+			;
+			
+gen_sctp_streams_val:	INTEGER
+			{
+				if (( $1 <= 0) || ($1 > 65535)) {
+					log_error("The sctp_streams value (%d) is invalid. Exiting...\n", $1);
+					YYERROR;
+				}
+				$$ = (uint16_t) $1 ;
+			}
+			;
+
+gen_tctimer:		GEN_TCTIMER '=' INTEGER ';'
+			{
+				pconfig->pub.tctimer = $3;
+			}
+			;
+
+gen_twtimer:		GEN_TWTIMER '=' INTEGER ';'
+			{
+				if ($3 >= 6) {
+					pconfig->pub.twtimer = $3;
+				} else {
+					log_error("The TwTimer value (%d) is invalid. It must be >= 6. Exiting...\n", $3);
+					YYERROR;
+				}
+			}
+			;
+
+gen_disablerelay:	GEN_DISABLERELAY '=' INTEGER ';'
+			{
+				pconfig->pub.disable_relay = $3;
+			}
+			;
+
+gen_disabletcp:		GEN_DISABLETCP ';'
+			{
+				pconfig->pub.disable_tcp = 1;
+			}
+			;
+
+gen_disableip4:		GEN_DISABLEIP4 ';'
+			{
+				if (pconfig->pub.disable_inet6) {
+					yyerror (&yylloc, pconfig, "NO_IP6 and NO_IP4 can not be used together.");
+					YYERROR;
+				}
+				if (have_ip4) {
+					yyerror (&yylloc, pconfig, "A primary or secondary IP address was defined, but NO_IP4 appears.");
+					YYERROR;
+				}
+				pconfig->pub.disable_inet4 = 1;
+			}
+			;
+
+gen_disableip6:		GEN_DISABLEIP6 ';'
+			{
+				if (pconfig->pub.disable_inet4) {
+					yyerror (&yylloc, pconfig, "NO_IP4 and NO_IP6 can not be used together.");
+					YYERROR;
+				}
+				if (have_ip6) {
+					yyerror (&yylloc, pconfig, "A primary or secondary IPv6 address was defined, but NO_IP6 appears.");
+					YYERROR;
+				}
+				pconfig->pub.disable_inet6 = 1;
+			}
+			;
+			
+gen_primary:		GEN_PRIMARY '=' IPADDRESS ';'
+			{
+				/* queue the sa in _ss into pconfig->pub.local_addr_pri_sa */
+				if (queue_ss(&pconfig->pub.local_addr_pri_sa) != 0) {
+					yyerror (&yylloc, pconfig, "An error occurred while saving an address, aborting...");
+					YYERROR;
+				}
+				
+				
+				/* we don't need the string anymore */
+				free($3);
+			}
+			;
+
+gen_secondary:		GEN_SECONDARY '=' IPADDRESS ';'
+			{
+				/* queue the sa in _ss into pconfig->pub.local_addr_sec_sa */
+				if (queue_ss(&pconfig->pub.local_addr_sec_sa) != 0) {
+					yyerror (&yylloc, pconfig, "An error occurred while saving an address, aborting...");
+					YYERROR;
+				}
+				
+				/* we don't need the string anymore */
+				free($3);
+			}
+			;
+
+
+	/* Define the [extensions] section grammar */
+extensions_section:	SECTION_EXTENSION extensions_content
+			;
+
+extensions_content:	/* empty is allowed */
+			| extensions_content extension_detail
+			;
+
+extension_detail:	{
+				/* Reset the ext_detail global before processing the rule */
+				if (ext_detail.fname) { free(ext_detail.fname); ext_detail.fname = NULL; }
+				if (ext_detail.cname) { free(ext_detail.cname); ext_detail.cname = NULL; }
+			}
+			QSTRING '=' '{' extension_params '}' ';'
+			{
+				int ret = 0;
+				
+				/* Add this extension */
+				ret = ext_register( ext_detail.fname, ext_detail.cname );
+				
+				/* Free the strings */
+				if (ext_detail.fname) { free(ext_detail.fname); ext_detail.fname = NULL; }
+				if (ext_detail.cname) { free(ext_detail.cname); ext_detail.cname = NULL; }
+				
+				/* Check error */
+				if (ret != 0) {
+					log_error("Failed to register extension %s: %s\n", $2, strerror(ret));
+					YYERROR;
+				}
+			}
+			;
+
+extension_params:	extension_confname extension_filename extension_confname	/* confname appears twice on purpose, to allow any order */
+			;
+
+extension_filename:	EXT_FILENAME '=' FILENAME ';'
+			{
+				if (ext_detail.fname) { free(ext_detail.fname); ext_detail.fname = NULL; }
+				ext_detail.fname = $3;
+			}
+			| EXT_FILENAME '=' error ';'
+			{
+				log_error("You must provide a valid filename for extension.\n");
+				YYERROR;
+			}
+			;
+
+extension_confname:	/* This one is optional */
+			| EXT_CONFFILE '=' FILENAME ';'
+			{
+				if (ext_detail.cname) { free(ext_detail.cname); ext_detail.cname = NULL; }
+				ext_detail.cname = $3;
+			}
+			| EXT_CONFFILE '=' error ';'
+			{
+				log_error("If you provide a configuration file for the extension, it must be a valid file.\n"
+					  " Note that you may remove the 'conffile' directive if your extension has no configuration.\n");
+				YYERROR;
+			}
+			;
+
+	/* Define the [peers] section grammar */
+peers_section:		SECTION_PEER peers_content
+			;
+
+peers_content:		/* empty is allowed */
+			| peers_content peer_detail
+			;
+
+peer_detail:		{
+				/* Initialize the peer details */
+				if (peer_detail.locator ) { free(peer_detail.locator); }
+				memset(&peer_detail, 0, sizeof(peer_detail));
+				peer_detail.port = 3868;
+				peer_detail.sctp_streams = pconfig->pub.sctp_streams;
+			}
+			FQDN '=' '{' peer_content '}' ';'
+			{
+				int ret = 0;
+				peer_add_t data;
+				
+				memset(&data, 0, sizeof(peer_add_t));
+				
+				/* Copy information from peer_detail */
+				
+				/* The "no sec" flag */
+				if (peer_detail.flags & PEER_NO_SEC)
+					data.pa_flags = PA_NOSEC;
+				
+				/* The peers declared in the configuration file do not expire */
+				
+				/* Now fill the connection information */
+				if (peer_detail.flags & PEER_TCP) {
+					data.pa_proto = IPPROTO_TCP;
+				} else {
+					data.pa_proto = IPPROTO_SCTP;
+				}
+				
+				/* the SA information was resolved in peerss during the "peer_locator" rule, or fqdn */
+				if (peer_detail.locator)
+					memcpy(&data.pa_ss, &peer_detail.peerss, sizeof(sSS));
+				else
+					memcpy(&data.pa_ss, &_ss, sizeof(sSS));
+					
+				switch (data.pa_ss.ss_family) {
+					case AF_INET:
+						{
+							sSA4 * sin = (sSA4 *)&data.pa_ss;
+							sin->sin_port = htons(peer_detail.port);
+						}
+						break;
+					case AF_INET6:
+						{
+							sSA6 * sin6 = (sSA6 *)&data.pa_ss;
+							sin6->sin6_port = htons(peer_detail.port);
+						}
+						break;
+					default:
+						TRACE_DEBUG(INFO, "Unknown AF: %d", data.pa_ss.ss_family);
+						yyerror(&yylloc, pconfig, "Resolved peer to unknown address family...");
+						YYERROR;
+				}
+				
+				/* Save the number of streams */
+				data.pa_streams = peer_detail.sctp_streams;
+				
+				/* Now add the peer with its information */
+				ret = peer_add($2, strlen($2), &data);
+				if (ret != 0) {
+					yyerror(&yylloc, pconfig, "An error occurred while adding a peer, aborting...");
+					YYERROR;
+				}
+				
+				free($2);
+				if (peer_detail.locator ) { free(peer_detail.locator); peer_detail.locator=NULL; }
+			}
+			;
+			
+peer_content:		/* empty is allowed */
+			| peer_content peer_uri
+			| peer_content peer_sctp_streams
+			;
+
+peer_uri:		PEER_URI '=' '"' peer_scheme peer_locator peer_port peer_transport '"' ';'
+			;
+
+peer_scheme:		PEER_SCHEME_SEC 
+			| PEER_SCHEME_NOSEC
+			{
+				peer_detail.flags |= PEER_NO_SEC;
+			}
+			;
+
+peer_locator:		PEER_LOCATOR
+			{
+				/* Check the locator is valid */
+				if (!is_valid_locator($1, &peer_detail.peerss, pconfig)) {
+					yyerror (&yylloc, pconfig, "An error was detected on a locator, aborting...");
+					YYERROR;
+				}
+				if (peer_detail.locator) 
+					free(peer_detail.locator);
+				peer_detail.locator = $1;
+			}
+			;
+			
+peer_port:		/* empty */
+			| PEER_PORT
+			{
+				peer_detail.port = $1;
+			}
+			;
+			
+peer_transport:		/* empty */
+			| PEER_TRANS_SCTP
+			| PEER_TRANS_TCP
+			{
+				if (pconfig->pub.disable_tcp) {
+					yyerror(&yylloc, pconfig, "Transport is set to TCP but this protocol is disabled in general section.");
+					YYERROR;
+				}
+				peer_detail.flags |= PEER_TCP;
+			}
+			;
+
+peer_sctp_streams:	GEN_SCTP_STREAMS '=' gen_sctp_streams_val ';'
+			{
+				peer_detail.sctp_streams = $3;
+			}
+			;
"Welcome to our mercurial repository"