changeset 1216:581bbd48524a

Change prototype of rt_out callbacks to allow disposal of messages
author Sebastien Decugis <sdecugis@freediameter.net>
date Wed, 19 Jun 2013 16:03:24 +0200
parents 65c6460f60f2
children 3f7c74ef3787 152466ff49f8
files extensions/dbg_rt/dbg_rt.c extensions/rt_default/rt_default.c extensions/rt_ereg/rtereg.c extensions/rt_load_balance/rt_load_balance.c extensions/rt_redirect/redir_out.c extensions/rt_redirect/rt_redir.h extensions/test_rt_any/test_rt_any.c include/freeDiameter/libfdcore.h libfdcore/routing_dispatch.c
diffstat 9 files changed, 25 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/dbg_rt/dbg_rt.c	Wed Jun 19 10:20:47 2013 +0800
+++ b/extensions/dbg_rt/dbg_rt.c	Wed Jun 19 16:03:24 2013 +0200
@@ -58,9 +58,10 @@
 }
 
 /* Path selection debug callback */
-static int dbgrt_out_cb(void * cbdata, struct msg * msg, struct fd_list * candidates)
+static int dbgrt_out_cb(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
 {
 	struct fd_list * li;
+	struct msg * msg = *pmsg;
 	char * buf = NULL; size_t buflen;
 	
 	TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
--- a/extensions/rt_default/rt_default.c	Wed Jun 19 10:20:47 2013 +0800
+++ b/extensions/rt_default/rt_default.c	Wed Jun 19 16:03:24 2013 +0200
@@ -40,8 +40,9 @@
 #include "rt_default.h"
 
 /* The callback called on new messages */
-static int rtd_out(void * cbdata, struct msg * msg, struct fd_list * candidates)
+static int rtd_out(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
 {
+	struct msg * msg = *pmsg;
 	TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
 	
 	CHECK_PARAMS(msg && candidates);
--- a/extensions/rt_ereg/rtereg.c	Wed Jun 19 10:20:47 2013 +0800
+++ b/extensions/rt_ereg/rtereg.c	Wed Jun 19 16:03:24 2013 +0200
@@ -125,8 +125,9 @@
 }
 
 /* The callback called on new messages */
-static int rtereg_out(void * cbdata, struct msg * msg, struct fd_list * candidates)
+static int rtereg_out(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
 {
+	struct msg * msg = *pmsg;
 	struct avp * avp = NULL;
 	
 	TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
--- a/extensions/rt_load_balance/rt_load_balance.c	Wed Jun 19 10:20:47 2013 +0800
+++ b/extensions/rt_load_balance/rt_load_balance.c	Wed Jun 19 16:03:24 2013 +0200
@@ -36,9 +36,10 @@
  */
 
 /* The callback for load balancing the requests across the peers */
-static int rt_load_balancing(void * cbdata, struct msg * msg, struct fd_list * candidates)
+static int rt_load_balancing(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
 {
 	struct fd_list *lic;
+	struct msg * msg = *pmsg;
 	
 	TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
 	
--- a/extensions/rt_redirect/redir_out.c	Wed Jun 19 10:20:47 2013 +0800
+++ b/extensions/rt_redirect/redir_out.c	Wed Jun 19 16:03:24 2013 +0200
@@ -37,7 +37,7 @@
 
 
 /* Find the data pertinent to a type in the input data */
-static int get_data_to_match(enum redir_h_u type, struct msg * msg, union matchdata * data, int * nodata)
+static int get_data_to_match(enum redir_h_u type, struct msg *msg, union matchdata * data, int * nodata)
 {
 	TRACE_ENTRY("%d %p %p %p", type, msg, data, nodata);
 	
@@ -219,9 +219,10 @@
 
 
 /* OUT callback */
-int redir_out_cb(void * cbdata, struct msg * msg, struct fd_list * candidates)
+int redir_out_cb(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
 {
 	int i, ret = 0;
+	struct msg * msg = *pmsg;
 	
 	TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
 	
--- a/extensions/rt_redirect/rt_redir.h	Wed Jun 19 10:20:47 2013 +0800
+++ b/extensions/rt_redirect/rt_redir.h	Wed Jun 19 16:03:24 2013 +0200
@@ -170,4 +170,4 @@
 int redir_fwd_cb(void * cbdata, struct msg ** msg);
 
 /* Out callback */
-int redir_out_cb(void * cbdata, struct msg * msg, struct fd_list * candidates);
+int redir_out_cb(void * cbdata, struct msg ** pmsg, struct fd_list * candidates);
--- a/extensions/test_rt_any/test_rt_any.c	Wed Jun 19 10:20:47 2013 +0800
+++ b/extensions/test_rt_any/test_rt_any.c	Wed Jun 19 16:03:24 2013 +0200
@@ -40,8 +40,9 @@
 #include <stdlib.h>
 
 /* The callback */
-static int tra_out_cb(void * cbdata, struct msg * msg, struct fd_list * candidates)
+static int tra_out_cb(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
 {
+	struct msg * msg = *pmsg;
 	struct fd_list * li;
 	
 	TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
--- a/include/freeDiameter/libfdcore.h	Wed Jun 19 10:20:47 2013 +0800
+++ b/include/freeDiameter/libfdcore.h	Wed Jun 19 16:03:24 2013 +0200
@@ -762,13 +762,13 @@
  *  EINVAL 	: A parameter is invalid.
  *  ENOMEM	: Not enough memory to complete the operation
  */
-int fd_rt_out_register ( int (*rt_out_cb)(void * cbdata, struct msg * msg, struct fd_list * candidates), void * cbdata, int priority, struct fd_rt_out_hdl ** handler );
+int fd_rt_out_register ( int (*rt_out_cb)(void * cbdata, struct msg ** pmsg, struct fd_list * candidates), void * cbdata, int priority, struct fd_rt_out_hdl ** handler );
 /*
  * CALLBACK:	rt_out_cb
  *
  * PARAMETERS:
  *  cbdata	: pointer to some data that was registered with the callback.
- *  msg 	: The message that must be sent.
+ *  pmsg 	: pointer to the message that must be sent. upon return if *msg is NULL, the processing stops and the message is not sent.
  *  list        : The list of peers to which the message may be sent to, as returned by fd_rtd_candidate_extract
  *
  * DESCRIPTION: 
--- a/libfdcore/routing_dispatch.c	Wed Jun 19 10:20:47 2013 +0800
+++ b/libfdcore/routing_dispatch.c	Wed Jun 19 16:03:24 2013 +0200
@@ -57,7 +57,7 @@
 	};
 	union {
 		int (*rt_fwd_cb)(void * cbdata, struct msg ** msg);
-		int (*rt_out_cb)(void * cbdata, struct msg * msg, struct fd_list * candidates);
+		int (*rt_out_cb)(void * cbdata, struct msg ** msg, struct fd_list * candidates);
 	};
 };	
 
@@ -134,7 +134,7 @@
 }
 
 /* Register a new OUT callback */
-int fd_rt_out_register ( int (*rt_out_cb)(void * cbdata, struct msg * msg, struct fd_list * candidates), void * cbdata, int priority, struct fd_rt_out_hdl ** handler )
+int fd_rt_out_register ( int (*rt_out_cb)(void * cbdata, struct msg ** pmsg, struct fd_list * candidates), void * cbdata, int priority, struct fd_rt_out_hdl ** handler )
 {
 	struct rt_hdl * new;
 	
@@ -188,8 +188,9 @@
 /********************************************************************************/
 
 /* Prevent sending to peers that do not support the message application */
-static int dont_send_if_no_common_app(void * cbdata, struct msg * msg, struct fd_list * candidates)
+static int dont_send_if_no_common_app(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
 {
+	struct msg * msg = *pmsg;
 	struct fd_list * li;
 	struct msg_hdr * hdr;
 	
@@ -220,8 +221,9 @@
 }
 
 /* Detect if the Destination-Host and Destination-Realm match the peer */
-static int score_destination_avp(void * cbdata, struct msg * msg, struct fd_list * candidates)
+static int score_destination_avp(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
 {
+	struct msg * msg = *pmsg;
 	struct fd_list * li;
 	struct avp * avp;
 	union avp_value *dh = NULL, *dr = NULL;
@@ -958,11 +960,11 @@
 		pthread_cleanup_push( fd_cleanup_rwlock, &rt_out_lock );
 
 		/* We call the cb by reverse priority order */
-		for (	li = rt_out_list.prev ; li != &rt_out_list ; li = li->prev ) {
+		for (	li = rt_out_list.prev ; (msgptr != NULL) && (li != &rt_out_list) ; li = li->prev ) {
 			struct rt_hdl * rh = (struct rt_hdl *)li;
 
 			TRACE_DEBUG(ANNOYING, "Calling next OUT callback on %p : %p (prio %d)", msgptr, rh->rt_out_cb, rh->prio);
-			CHECK_FCT_DO( ret = (*rh->rt_out_cb)(rh->cbdata, msgptr, candidates),
+			CHECK_FCT_DO( ret = (*rh->rt_out_cb)(rh->cbdata, &msgptr, candidates),
 				{
 					char buf[256];
 					snprintf(buf, sizeof(buf), "An OUT routing callback returned an error: %s", strerror(ret));
@@ -970,17 +972,14 @@
 					fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr));
 					fd_msg_free(msgptr);
 					msgptr = NULL;
-					break;
 				} );
 		}
 
 		pthread_cleanup_pop(0);
 		CHECK_FCT( pthread_rwlock_unlock( &rt_out_lock ) );
 
-		/* If an error occurred, skip to the next message */
+		/* If an error occurred or the callback disposed of the message, go to next message */
 		if (! msgptr) {
-			if (rtd)
-				fd_rtd_free(&rtd);
 			return 0;
 		}
 	}
"Welcome to our mercurial repository"