diff libfreeDiameter/sessions.c @ 639:95a784729cac

Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
author Sebastien Decugis <sdecugis@nict.go.jp>
date Mon, 20 Dec 2010 13:07:06 +0900
parents 85ab58cc427c
children
line wrap: on
line diff
--- a/libfreeDiameter/sessions.c	Fri Dec 17 18:41:19 2010 +0900
+++ b/libfreeDiameter/sessions.c	Mon Dec 20 13:07:06 2010 +0900
@@ -68,7 +68,8 @@
 struct session_handler {
 	int		  eyec;	/* An eye catcher also used to ensure the object is valid, must be SH_EYEC */
 	int		  id;	/* A unique integer to identify this handler */
-	void 		(*cleanup)(session_state *, char *); /* The cleanup function to be called for cleaning a state */
+	void 		(*cleanup)(session_state *, char *, void *); /* The cleanup function to be called for cleaning a state */
+	void             *opaque; /* a value that is passed as is to the cleanup callback */
 };
 
 static int 		hdl_id = 0;				/* A global counter to initialize the id field */
@@ -252,7 +253,7 @@
 }
 
 /* Create a new handler */
-int fd_sess_handler_create_internal ( struct session_handler ** handler, void (*cleanup)(session_state * state, char * sid) )
+int fd_sess_handler_create_internal ( struct session_handler ** handler, void (*cleanup)(session_state * state, char * sid, void * opaque), void * opaque )
 {
 	struct session_handler *new;
 	
@@ -269,6 +270,7 @@
 	
 	new->eyec = SH_EYEC;
 	new->cleanup = cleanup;
+	new->opaque = opaque;
 	
 	*handler = new;
 	return 0;
@@ -276,7 +278,7 @@
 
 /* Destroy a handler, and all states attached to this handler. This operation is very slow but we don't care since it's rarely used. 
  * Note that it's better to call this function after all sessions have been deleted... */
-int fd_sess_handler_destroy ( struct session_handler ** handler )
+int fd_sess_handler_destroy ( struct session_handler ** handler, void ** opaque )
 {
 	struct session_handler * del;
 	/* place to save the list of states to be cleaned up. We do it after finding them to avoid deadlocks. the "o" field becomes a copy of the sid. */
@@ -322,12 +324,15 @@
 	while (!FD_IS_LIST_EMPTY(&deleted_states)) {
 		struct state * st = (struct state *)(deleted_states.next->o);
 		TRACE_DEBUG(FULL, "Calling cleanup handler for session '%s' and data %p", st->sid, st->state);
-		(*del->cleanup)(st->state, st->sid);
+		(*del->cleanup)(st->state, st->sid, del->opaque);
 		free(st->sid);
 		fd_list_unlink(&st->chain);
 		free(st);
 	}
 	
+	if (opaque)
+		*opaque = del->opaque;
+	
 	/* Free the handler */
 	free(del);
 	
@@ -582,7 +587,7 @@
 		struct state * st = (struct state *)(sess->states.next->o);
 		fd_list_unlink(&st->chain);
 		TRACE_DEBUG(FULL, "Calling handler %p cleanup for state registered with session '%s'", st->hdl, sess->sid);
-		(*st->hdl->cleanup)(st->state, sess->sid);
+		(*st->hdl->cleanup)(st->state, sess->sid, st->hdl->opaque);
 		free(st);
 	}
 	
@@ -804,7 +809,7 @@
 	if (!VALIDATE_SH(handler)) {
 		fd_log_debug("\t  %*s  Invalid session handler object\n", level, "");
 	} else {
-		fd_log_debug("\t  %*s  id %d, cleanup %p\n", level, "", handler->id, handler->cleanup);
+		fd_log_debug("\t  %*s  id %d, cleanup %p, opaque %p\n", level, "", handler->id, handler->cleanup, handler->opaque);
 	}
 	fd_log_debug("\t  %*s -- end of handler @%p --\n", level, "", handler);
 }	
"Welcome to our mercurial repository"