changeset 1299:035f489b845b

Added a new hook HOOK_MESSAGE_SENDING
author Sebastien Decugis <sdecugis@freediameter.net>
date Sat, 04 Jul 2015 23:06:37 +0800
parents 0f215b0dda5e
children 3f1e79e1273e
files contrib/debian/changelog extensions/dbg_msg_dumps/dbg_msg_dumps.c extensions/test_app/ta_cli.c include/freeDiameter/libfdcore.h libfdcore/hooks.c libfdcore/p_out.c
diffstat 6 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/debian/changelog	Tue Jun 23 12:12:10 2015 +0800
+++ b/contrib/debian/changelog	Sat Jul 04 23:06:37 2015 +0800
@@ -3,6 +3,8 @@
   * New extension: rt_randomize (load-balancing on possible destinations)
   * New contrib: Gx extension.
   * rt_redirect.fdx and rt_load_balance.fdx improvement: use a hash table. Thanks Thomas.
+  * New hook HOOK_MESSAGE_SENDING to give a last chance to edit messages before they are sent.
+    This will be mostly used for enforcing interoperability constraints on non-compliant peers.
   * Simplified log output. Old output can be recovered with DEBUG_WITH_META build option.
   * Updated the internal counters for finer control on the load.
   * Fixes in message expiry mechanism.
--- a/extensions/dbg_msg_dumps/dbg_msg_dumps.c	Tue Jun 23 12:12:10 2015 +0800
+++ b/extensions/dbg_msg_dumps/dbg_msg_dumps.c	Sat Jul 04 23:06:37 2015 +0800
@@ -118,6 +118,10 @@
 		LOG_N("RCV from '%s':", peer_name);
 		LOG_SPLIT(FD_LOG_NOTICE, "     ", buf, NULL);
 		break;
+	case HOOK_MESSAGE_SENDING:
+		LOG_N("SNDING to '%s':", peer_name);
+		LOG_SPLIT(FD_LOG_NOTICE, "     ", buf, NULL);
+		break;
 	case HOOK_MESSAGE_SENT:
 		LOG_N("SND to '%s':", peer_name);
 		LOG_SPLIT(FD_LOG_NOTICE, "     ", buf, NULL);
@@ -204,6 +208,9 @@
 	case HOOK_MESSAGE_RECEIVED:
 		LOG_N("RCV from '%s': %s", peer_name, buf);
 		break;
+	case HOOK_MESSAGE_SENDING:
+		LOG_N("SNDING to '%s': %s", peer_name, buf);
+		break;
 	case HOOK_MESSAGE_SENT:
 		LOG_N("SND to '%s': %s", peer_name, buf);
 		break;
@@ -283,6 +290,9 @@
 	case HOOK_MESSAGE_RECEIVED:
 		LOG_N("RCV from '%s': %s", peer_name, buf);
 		break;
+	case HOOK_MESSAGE_SENDING:
+		LOG_N("SNDING to '%s': %s", peer_name, buf);
+		break;
 	case HOOK_MESSAGE_SENT:
 		LOG_N("SND to '%s': %s", peer_name, buf);
 		break;
@@ -341,7 +351,7 @@
 	}
 	
 	mask_errors = HOOK_MASK( HOOK_MESSAGE_FAILOVER, HOOK_MESSAGE_PARSING_ERROR, HOOK_MESSAGE_ROUTING_ERROR, HOOK_MESSAGE_DROPPED  );
-	mask_sndrcv = HOOK_MASK( HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_SENT );
+	mask_sndrcv = HOOK_MASK( HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_SENT ); /* We don t access SENDING hook here */
 	mask_routing= HOOK_MASK( HOOK_MESSAGE_LOCAL, HOOK_MESSAGE_ROUTING_FORWARD, HOOK_MESSAGE_ROUTING_LOCAL );
 	mask_peers  = HOOK_MASK( HOOK_PEER_CONNECT_FAILED, HOOK_PEER_CONNECT_SUCCESS );
 	
--- a/extensions/test_app/ta_cli.c	Tue Jun 23 12:12:10 2015 +0800
+++ b/extensions/test_app/ta_cli.c	Sat Jul 04 23:06:37 2015 +0800
@@ -70,7 +70,6 @@
 		ASSERT( new == 0 );
 		
 		CHECK_FCT_DO( fd_sess_state_retrieve( ta_cli_reg, sess, &mi ), return );
-		TRACE_DEBUG( INFO, "%p %p", mi, data);
 		ASSERT( (void *)mi == data );
 	}
 	
--- a/include/freeDiameter/libfdcore.h	Tue Jun 23 12:12:10 2015 +0800
+++ b/include/freeDiameter/libfdcore.h	Sat Jul 04 23:06:37 2015 +0800
@@ -964,6 +964,16 @@
 		 - {permsgdata} points to a new empty structure allocated for this request (cf. fd_hook_data_hdl)
 		 */
 	
+	HOOK_MESSAGE_SENDING,
+		/* Hook called when a message is about to be sent to a peer. The message pointer cannot be modified here, but the content of the message
+		  could still be changed (for example add or remove some AVP. This is the last chance.
+		 - {msg} points to the message. Some objects may not have been dictionary resolved. If you
+		   try to call fd_msg_parse_dict, it will slow down the operation of the instance.
+		 - {peer} is the one the message is being sent to.
+		 - {other} is NULL.
+		 - {permsgdata} points to existing structure if any, or a new structure otherwise. 
+		 */
+	
 	HOOK_MESSAGE_SENT,
 		/* Hook called when a message has been sent to a peer. The message might be freed as soon as the hook function returns,
 		   so it is not safe to store the pointer for asynchronous processing.
--- a/libfdcore/hooks.c	Tue Jun 23 12:12:10 2015 +0800
+++ b/libfdcore/hooks.c	Sat Jul 04 23:06:37 2015 +0800
@@ -344,6 +344,11 @@
 				break;
 			}
 			
+			case HOOK_MESSAGE_SENDING: {
+				LOG_A("SENDING message to '%s'", peer ? peer->p_hdr.info.pi_diamid : "<unknown>");
+				break;
+			}
+			
 			case HOOK_MESSAGE_SENT: {
 				CHECK_MALLOC_DO(fd_msg_dump_summary(&hook_default_buf, &hook_default_len, NULL, msg, NULL, 0, 1), break);
 				LOG_D("SENT to '%s': %s", peer ? peer->p_hdr.info.pi_diamid : "<unknown>", hook_default_buf);
--- a/libfdcore/p_out.c	Tue Jun 23 12:12:10 2015 +0800
+++ b/libfdcore/p_out.c	Sat Jul 04 23:06:37 2015 +0800
@@ -165,6 +165,8 @@
 	
 	TRACE_ENTRY("%p %p %p", msg, cnx, peer);
 	CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx)));
+
+	fd_hook_call(HOOK_MESSAGE_SENDING, *msg, peer, NULL, fd_msg_pmdl_get(*msg));
 	
 	if (update_reqin_cnt && peer) {
 		CHECK_FCT( fd_msg_hdr(*msg, &hdr) );
"Welcome to our mercurial repository"