changeset 36:c90483949e69

Added the dispatch API
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 24 Jun 2008 15:02:46 +0900
parents f35a9404cbef
children a8723c5ada52
files include/waaad/conf-api.h include/waaad/dictionary-api.h include/waaad/dispatch-api.h include/waaad/log-api.h include/waaad/message-api.h include/waaad/peer-api.h include/waaad/routing-api.h include/waaad/session-api.h include/waaad/waaad.h waaad/Makefile.am waaad/dispatch.c waaad/dispatch.h waaad/extensions.c waaad/main.c waaad/waaad-internal.h
diffstat 15 files changed, 494 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/include/waaad/conf-api.h	Mon Jun 23 17:53:53 2008 +0900
+++ b/include/waaad/conf-api.h	Tue Jun 24 15:02:46 2008 +0900
@@ -66,7 +66,7 @@
 
 /* From within the extensions, we access to conf through this structure */
 #ifdef DECLARE_API_POINTERS
-api_conf_t * g_api_conf;
+api_conf_t * g_api_conf=NULL;
 #else /* DECLARE_API_POINTERS */
 extern api_conf_t * g_api_conf;
 #endif /* DECLARE_API_POINTERS */
--- a/include/waaad/dictionary-api.h	Mon Jun 23 17:53:53 2008 +0900
+++ b/include/waaad/dictionary-api.h	Tue Jun 24 15:02:46 2008 +0900
@@ -151,7 +151,7 @@
 
 /* From within the extensions, we register callbacks in the following global structure */
 #ifdef DECLARE_API_POINTERS
-api_dict_t * g_api_dict;
+api_dict_t * g_api_dict=NULL;
 #else /* DECLARE_API_POINTERS */
 extern api_dict_t * g_api_dict;
 #endif /* DECLARE_API_POINTERS */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/waaad/dispatch-api.h	Tue Jun 24 15:02:46 2008 +0900
@@ -0,0 +1,291 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
+*													 *
+* Copyright (c) 2008, WIDE Project and NICT								 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the WIDE Project or NICT nor the 						 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of WIDE Project and 						 *
+*   NICT.												 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+
+/* This file contains the definitions of types and functions related to the dispatch module
+ * and that can be called by extensions. 
+ */
+
+/* The dispatch module has two main roles:
+ *  - help determine if a message can be handled locally (during the routing process)
+ *  - pass the message to the callback(s) that will handle it (during the dispatch process)
+ *
+ * This module consists in registering callbacks that will be called when a message is received.
+ * The decision whether a callback must be called depends on the content of the message and
+ * how the callback was registered.
+ * 
+ * These are the possibilities for registering a callback:
+ *
+ * -> by AVP value.
+ *  This callback will be called when a message is received and contains a certain AVP with a specified value.
+ *
+ * -> by AVP.
+ *  This callback will be called when the received message contains a certain AVP.
+ *
+ * -> by command-code.
+ *  This callback will be called when the message is a specific command.
+ *
+ * -> by application.
+ *  This callback will be called when the message has a specific application-id.
+ *
+ * ( by vendor: would this be useful? it may be added later)
+ *
+ * In order to advertise the support for a given application in the CER/CEA messages, 
+ * at least one callback must be registered on this application.
+ *
+ * Note that several criteria may be selected at the same time, for example command-code AND application id.
+ *
+ * When a callback is called, it receives the message as parameter, and eventually a pointer to 
+ * the AVP in the message when this is appropriate.
+ *
+ * The callback must process the message, and then return a value with the following meaning:
+ *  (negative): -errno, if an error occurred.
+ *  (positive): one of the disp_cb_ret_t values. See the definition for more information.
+ *
+ * At least one of the registered callbacks must return a value of DIST_CBRET_HANDLED_* on the message, or
+ * a default handler will be called with the effect of requeuing the message for forwarding on the network to 
+ * another peer (for requests), or discarding the message (for answers).
+ */
+
+#ifndef _DISPATCH_API_H
+#define _DISPATCH_API_H
+
+#include <waaad/message-api.h>
+
+/* The values that must be returned by a callback, when no error occurred: */
+typedef enum {
+	DISP_CBRET_CONTINUE = 0,	/* The callback has completed its process without error. 
+					   Next callback can be called.
+					   This value is typically returned by non-final callbacks (for example cb registered on AVPs) */
+	DISP_CBRET_HANDLED_CONTINUE,	/* The callback has processed the message (for example answered a request or 
+					   taken action from an answer). Remaining callbacks may be called, if any. */
+	DISP_CBRET_HANDLED_STOP		/* The callback has processed the message (for example generated an error answer or forwarded the 
+					   message to another peer). No additional handler should be called on this message. */
+} disp_cb_ret_t;
+
+/* The allowed methods for registering a callback. */
+typedef enum {
+	DISP_REG_ANY = 1,		/* The callback is called on any message. This should be only used for debug. */
+	DISP_REG_APPID,			/* The callback is called for any message with the specified application-id */
+	DISP_REG_CC,			/* The callback is called for message of the specified command-code (requests & answers). App id may be specified. */
+	DISP_REG_CC_FLAG,		/* The callback is called for message of the specified command-code and flag (request, answer, or error). App id may be specified. */
+	DISP_REG_AVP,			/* The callback is called for messages containing a specific AVP. Command-code and App id may be specified. */
+	DISP_REG_AVP_ENUMVAL		/* The callback is called for messages containing a specific AVP with a specific enumerated value. Command-code and App id may be specified. */
+} disp_reg_t;
+
+/* Note on the order of callbacks calls:
+  This is the priority of the calls (first in the list = first called).
+  If several callbacks are registered with the same disp_reg_t, their order is unspecified.
+  
+  DISP_REG_ANY
+  DISP_REG_AVP_ENUMVAL
+  DISP_REG_AVP
+  DISP_REG_CC_FLAG
+  DISP_REG_CC
+  DISP_REG_APPID
+*/
+
+/* Explanation follow */
+typedef struct {
+	dict_object_t *	app_id;
+	dict_object_t *	command;
+	uint8_t		flag_mask;
+	uint8_t		flag_val;
+	dict_object_t *	avp;
+	dict_object_t *	value;
+} disp_reg_val_t;
+
+/* When a callback is registered, a "when" argument is passed in addition to the disp_reg_t value 
+ * to specify which values the criteria must match.
+ *
+ * Here is the details on the "when" argument, depending on the disp_reg_t value.
+ *
+ * DISP_REG_ANY.
+ *  In this case, "when" must be NULL.
+ *
+ * In any other case (yet), the "when" parameter points to a disp_reg_val_t structure. Detail is given bellow.
+ *
+ * DISP_REG_APPID.
+ *  Only the "app_id" field must be set, other fields are ignored. It points to a dictionary object of type DICT_APPLICATION.
+ *
+ * DISP_REG_CC.
+ *  The "command" field must be defined and point to a dictionary object of type DICT_COMMAND (it may be the request or the answer object).
+ *  The "app_id" may be also set. In the case it is set, it restricts the callback to be called only with this command-code and app id.
+ *  The other fields are ignored.
+ *
+ * DISP_REG_CC_FLAG.
+ *  The "command" code must be set as previously. The "app_id" field may be set as previously.
+ *  In addition, the flag_mask and flag_val must be set.
+ *  The flag_mask specifies the bit mask of the message that must be checked.
+ *  The flag_val specifies the values of the flags that must be matched.
+ *  The other fields are ignored.
+ *
+ * DISP_REG_AVP.
+ *  The "avp" field of the structure must be set and point to a dictionary object of type DICT_AVP.
+ *  The "app_id" field may be set to restrict the messages matching to a specific app id.
+ *  The "command" field may also be set to a valid DICT_COMMAND object.
+ *  The flags may be set also as previously.
+ *  The content of the "value" field is ignored.
+ *
+ * DISP_REG_AVP_ENUMVAL.
+ *  All fields have the same constraints and meaning as in DISP_REG_AVP. In addition, the "value" field must be set
+ *  and points to a valid DICT_TYPE_ENUM object. 
+ *
+ * Here is a sumary of the fields: ( M : must be set; m : may be set, or NULL/0 to ignore; 0 : ignored )
+ *
+ *  field:     app_id    command   flag_mask    avp    value
+ * APPID :       M          0          0         0       0
+ * CC    :       m          M          0         0       0
+ * CC_FLA:       m          M          M         0       0
+ * AVP   :       m          m          m         M       0
+ * AVP_EN:       m          m          m         M       M
+ */
+ 
+
+/* Here is the prototype of callback functions that will be called */
+/*
+ * CALLBACK:	disp_cb_t
+ *
+ * PARAMETERS:
+ *  msg     : The message that trigged the callback call.
+ *  avp     : for callbacks registered with DISP_REG_AVP or DISP_REG_AVP_ENUMVAL, this points to the triggering AVP. NULL otherwise.
+ *  handled : (boolean) a previous handler has returned DISP_CBRET_HANDLED_CONTINUE already?
+ *
+ * DESCRIPTION: 
+ *   This is the prototype of the callback functions that are registered with dicp_cb_reg function.
+ *  See introduction and previous comments for more information on how this callback is called.
+ *
+ * RETURN VALUE:
+ *  < 0 			: An error occurred (ex: -EINVAL = invalid parameter; -ENOMEM: not enough memory, ...).
+ *  DISP_CBRET_CONTINUE		: The next callback can be called, no action has been taken yet.
+ *  DISP_CBRET_HANDLED_CONTINUE : Action has been taken, next callback can be called (used in normal condition)
+ *  DISP_CBRET_HANDLED_STOP	: Action has been taken, no more callback must be called (used in error conditions)
+ */
+typedef int (*disp_cb_t) ( msg_t * msg, msg_avp_t * avp, int handled );
+
+/* The following opaque type represents a handler to a registered callback. This allows to remove a registered callback. */
+typedef void disp_cb_hdl_t;
+
+#ifndef IN_EXTENSION
+
+/*
+ * FUNCTION:	disp_register
+ *
+ * PARAMETERS:
+ *  cb 		  : The callback function to register.
+ *  how	  	  : How the callback must be registered.
+ *  when          : Values that must match, depending on the how argument.
+ *  handle        : On success, a handler to the registered callback is stored here. 
+ *		   This handler will be used to unregister the cb.
+ *
+ * DESCRIPTION: 
+ *   Register a new callback to handle messages delivered locally.
+ *  When a callback is registered for DISP_REG_APPID, it also have the effect of advertising 
+ *  this application support in the CER/CEA messages.
+ *
+ * RETURN VALUE:
+ *  0      	: The callback is registered.
+ *  EINVAL 	: A parameter is invalid.
+ *  ENOMEM	: Not enough memory to complete the operation
+ */
+int disp_register ( disp_cb_t cb, disp_reg_t how, void * when, disp_cb_hdl_t ** handle );
+
+
+/*
+ * FUNCTION:	disp_unregister
+ *
+ * PARAMETERS:
+ *  handler       : The callback that must be unregistered.
+ *
+ * DESCRIPTION: 
+ *   Removes a callback from the list of registered callbacks.
+ *
+ * RETURN VALUE:
+ *  0      	: The callback is unregistered.
+ *  EINVAL 	: A parameter is invalid.
+ */
+int disp_unregister ( disp_cb_hdl_t * handle );
+
+#endif /* ! IN_EXTENSION */
+
+/******************************************************************/
+
+/* The version of this API, to check binary compatibility -- increment each time a change is made in api_disp_t */
+#define WAAAD_API_DISP_VER	1
+
+/* Now define the type of the structure that contains the callback to pass to extensions */
+typedef struct {
+	/* The header is common to all sub-API pieces */
+	size_t	length;		/* The size of this structure, may be useful for extensions not using the facility */
+	int	version;	/* The version of this API/ABI, must be WAAAD_API_DISP_VER */
+	
+	/* the remaining is dispatching-specific */
+	int (*disp_register)    ( disp_cb_t cb, disp_reg_t how, void * when, disp_cb_hdl_t ** handle );
+	int (*disp_unregister)  ( disp_cb_hdl_t * handle );
+} api_disp_t;
+
+#ifdef IN_EXTENSION
+
+/* From within the extensions, we register callbacks in the following global structure */
+#ifdef DECLARE_API_POINTERS
+api_disp_t * g_api_disp=NULL;
+#else /* DECLARE_API_POINTERS */
+extern api_disp_t * g_api_disp;
+#endif /* DECLARE_API_POINTERS */
+
+/* These defines allow to call functions from extension in the same way as in waaad */
+#define disp_register		g_api_disp->disp_register
+#define disp_unregister		g_api_disp->disp_unregister
+
+#else /* IN_EXTENSION */
+
+/* From the daemon, we must initialize the API object, in extension.c */
+# define MY_WAAAD_API_DISP_VER 1
+# if MY_WAAAD_API_DISP_VER != WAAAD_API_DISP_VER
+#  error "You must update API_INIT_DISP also"
+# endif
+
+#define API_INIT_DISP( api_disp ) 				\
+{								\
+	(api_disp).length           = sizeof(api_disp_t);	\
+	(api_disp).version          = WAAAD_API_DISP_VER;	\
+	(api_disp).disp_register    = disp_register;		\
+	(api_disp).disp_unregister  = disp_unregister;		\
+}							
+
+#endif /* IN_EXTENSION */
+
+#endif /* _DISPATCH_API_H */
+
+
--- a/include/waaad/log-api.h	Mon Jun 23 17:53:53 2008 +0900
+++ b/include/waaad/log-api.h	Tue Jun 24 15:02:46 2008 +0900
@@ -120,7 +120,7 @@
 
 /* From within the extensions, we register callbacks in the following global structure */
 #ifdef DECLARE_API_POINTERS
-api_log_t * g_api_log;
+api_log_t * g_api_log=NULL;
 #else /* DECLARE_API_POINTERS */
 extern api_log_t * g_api_log;
 #endif /* DECLARE_API_POINTERS */
--- a/include/waaad/message-api.h	Mon Jun 23 17:53:53 2008 +0900
+++ b/include/waaad/message-api.h	Tue Jun 24 15:02:46 2008 +0900
@@ -379,7 +379,7 @@
 
 /* From within the extensions, we register callbacks in the following global structure */
 #ifdef DECLARE_API_POINTERS
-api_msg_t * g_api_msg;
+api_msg_t * g_api_msg=NULL;
 #else /* DECLARE_API_POINTERS */
 extern api_msg_t * g_api_msg;
 #endif /* DECLARE_API_POINTERS */
--- a/include/waaad/peer-api.h	Mon Jun 23 17:53:53 2008 +0900
+++ b/include/waaad/peer-api.h	Tue Jun 24 15:02:46 2008 +0900
@@ -156,7 +156,7 @@
 
 /* From within the extensions, we register callbacks in the following global structure */
 #ifdef DECLARE_API_POINTERS
-api_peer_t * g_api_peer;
+api_peer_t * g_api_peer=NULL;
 #else /* DECLARE_API_POINTERS */
 extern api_peer_t * g_api_peer;
 #endif /* DECLARE_API_POINTERS */
--- a/include/waaad/routing-api.h	Mon Jun 23 17:53:53 2008 +0900
+++ b/include/waaad/routing-api.h	Tue Jun 24 15:02:46 2008 +0900
@@ -278,7 +278,7 @@
 
 /* From within the extensions, we register callbacks in the following global structure */
 #ifdef DECLARE_API_POINTERS
-api_rt_t * g_api_rt;
+api_rt_t * g_api_rt=NULL;
 #else /* DECLARE_API_POINTERS */
 extern api_rt_t * g_api_rt;
 #endif /* DECLARE_API_POINTERS */
--- a/include/waaad/session-api.h	Mon Jun 23 17:53:53 2008 +0900
+++ b/include/waaad/session-api.h	Tue Jun 24 15:02:46 2008 +0900
@@ -322,7 +322,7 @@
 
 /* From within the extensions, we register callbacks in the following global structure */
 #ifdef DECLARE_API_POINTERS
-api_sess_t * g_api_session;
+api_sess_t * g_api_session=NULL;
 #else /* DECLARE_API_POINTERS */
 extern api_sess_t * g_api_session;
 #endif /* DECLARE_API_POINTERS */
--- a/include/waaad/waaad.h	Mon Jun 23 17:53:53 2008 +0900
+++ b/include/waaad/waaad.h	Tue Jun 24 15:02:46 2008 +0900
@@ -74,6 +74,7 @@
 #include <waaad/message-api.h>
 #include <waaad/routing-api.h>
 #include <waaad/session-api.h>
+#include <waaad/dispatch-api.h>
 
 
 
@@ -92,6 +93,7 @@
 	api_msg_t	msg;
 	api_rt_t	rt;
 	api_sess_t	session;
+	api_disp_t	dispatch;
 } waaad_api_t;
 
 /* ********************************** */
@@ -113,6 +115,7 @@
 #define API_MODULE_MSG		0x00000010	/* Load the message API in the extension */
 #define API_MODULE_RT		0x00000020	/* Load the routing API in the extension */
 #define API_MODULE_SESSION	0x00000040	/* Load the session API in the extension */
+#define API_MODULE_DISPATCH	0x00000080	/* Load the dispatch API in the extension */
 
 
 #define EXTENSION_API_INIT(flags, function, name) 								\
@@ -236,6 +239,21 @@
 	hdr = (sub_api_header_t *) &buffer[index];								\
 	index += hdr->length;											\
 														\
+	if ( flags & API_MODULE_DISPATCH) {									\
+		g_api_disp = (api_disp_t *)hdr;									\
+		if (g_api_disp->version != WAAAD_API_DISP_VER) {						\
+			/* Unable to parse this API, do not continue */						\
+			fprintf(stderr, 									\
+				"[%s] Incompatible dispatch API version, please recompile the extension"	\
+				" or update the initialization in extensions.c.\n",				\
+				name);										\
+			return EINVAL;										\
+		}												\
+	}													\
+														\
+	hdr = (sub_api_header_t *) &buffer[index];								\
+	index += hdr->length;											\
+														\
 	/* next module... */											\
 														\
 	return function(conffile);										\
--- a/waaad/Makefile.am	Mon Jun 23 17:53:53 2008 +0900
+++ b/waaad/Makefile.am	Tue Jun 24 15:02:46 2008 +0900
@@ -27,6 +27,7 @@
 		message.h message.c \
 		queues.h queues.c \
 		routing.h routing.c \
-		session.h session.c
+		session.h session.c \
+		dispatch.h dispatch.c
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/waaad/dispatch.c	Tue Jun 24 15:02:46 2008 +0900
@@ -0,0 +1,74 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+/* Dispatch module.
+ * 
+ * See dispatch.h and dispatch-api.h for more information on the functions and types involved.
+ */
+
+#include <errno.h>
+
+#include "waaad-internal.h"
+
+/* Initialize the module */
+int disp_init ( void )
+{
+	TRACE_DEBUG (INFO, "Dispatch module initialized");
+	TRACE_DEBUG (FULL, "@@@ Not implemented yet." );
+	return 0;
+}
+
+/* End of the module */
+int disp_fini ( void )
+{
+	TRACE_DEBUG (FULL, "Unloading dispatch module...");
+	TRACE_DEBUG (FULL, "@@@ Not implemented yet." );
+	return 0;
+}
+
+/* Register a new callback. */
+int disp_register ( disp_cb_t cb, disp_reg_t how, void * when, disp_cb_hdl_t ** handle )
+{
+	TRACE_DEBUG (FULL, "@@@ %s: not implemented yet.", __FUNCTION__ );
+	return ENOTSUP;
+}
+
+/* Remove a registered callback. */
+int disp_unregister ( disp_cb_hdl_t * handle )
+{
+	TRACE_DEBUG (FULL, "@@@ %s: not implemented yet.", __FUNCTION__ );
+	return ENOTSUP;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/waaad/dispatch.h	Tue Jun 24 15:02:46 2008 +0900
@@ -0,0 +1,82 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
+*													 *
+* Copyright (c) 2008, WIDE Project and NICT								 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the WIDE Project or NICT nor the 						 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of WIDE Project and 						 *
+*   NICT.												 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+
+/* Dispatch module.
+ * 
+ * This module provides handles the messages that are handled locally on this peer.
+ * See <waaad/dispatch-api.h> for more information on the available functions, and details on how extensions can
+ * take use the module.
+ */
+ 
+#ifndef _DISPATCH_H
+#define _DISPATCH_H
+
+/* Include the API definitions for the module */
+#include <waaad/dispatch-api.h>
+
+/* The following functions are called only from the daemon */
+
+/*
+ * FUNCTION:	disp_init
+ *
+ * PARAMETERS:
+ *  -
+ *
+ * DESCRIPTION: 
+ *  Initialize the module. 
+ *
+ * RETURN VALUE:
+ *   0	: Application is now ready to use the module.
+ *  !0  : An error occurred. 
+ */
+int disp_init ( void );
+
+/*
+ * FUNCTION:	disp_fini
+ *
+ * PARAMETERS:
+ *  -
+ *
+ * DESCRIPTION: 
+ *  Terminates the module. No disp_* function must be called after this one.
+ *
+ * RETURN VALUE:
+ *   0 : module closed properly.
+ *  !0 : an error occurred (we may ignore it)
+ */
+int disp_fini ( void );
+
+
+#endif /* _DISPATCH_H */
--- a/waaad/extensions.c	Mon Jun 23 17:53:53 2008 +0900
+++ b/waaad/extensions.c	Tue Jun 24 15:02:46 2008 +0900
@@ -78,6 +78,7 @@
 	API_INIT_MSG        ( exported_api.msg        );
 	API_INIT_RT         ( exported_api.rt         );
 	API_INIT_SESSION    ( exported_api.session    );
+	API_INIT_DISP       ( exported_api.dispatch   );
 }
 
 /* Initialize the extensions module */
--- a/waaad/main.c	Mon Jun 23 17:53:53 2008 +0900
+++ b/waaad/main.c	Tue Jun 24 15:02:46 2008 +0900
@@ -198,6 +198,11 @@
 		log_error("An internal error occurred during initialization.\n");
 		goto end;
 	}
+	ret = disp_init();
+	if (ret != 0) {
+		log_error("An internal error occurred during initialization.\n");
+		goto end;
+	}
 	
 	/* Parse the command-line options */
 	ret = main_cmdline(argc, argv);
@@ -218,6 +223,11 @@
 	ext_load();
 
 	/* Allow the peer module to start */
+	ret = peer_start();
+	if (ret != 0) {
+		/* Ignore the error for the moment, until the function is written */
+		;
+	}
 	
 	/* Start listening on Diameter port */
 	
@@ -229,6 +239,8 @@
 end:
 	TRACE_DEBUG(INFO, "Entering 'end' section of main function.");
 	
+	(void)disp_fini();
+	
 	(void)rt_fini();
 	
 	(void)sess_fini();
--- a/waaad/waaad-internal.h	Mon Jun 23 17:53:53 2008 +0900
+++ b/waaad/waaad-internal.h	Tue Jun 24 15:02:46 2008 +0900
@@ -100,4 +100,11 @@
 */
 #include "session.h"
 
+/* The dispatch module.
+Provides functions and threads to handle locally the Diameter messages in extensions.
+disp_* functions.
+*/
+#include "dispatch.h"
+
+
 #endif /* _WAAAD_INTERNAL_H */
"Welcome to our mercurial repository"