changeset 1301:50fb308e84f7

Added a new hook to allow extensions act on the error messages being returned in case of parsing error (e.g. if some mandatory AVP are expected in error messages)
author Sebastien Decugis <sdecugis@freediameter.net>
date Sun, 30 Aug 2015 01:58:21 +0800
parents 3f1e79e1273e
children d8c998e7c535
files extensions/dbg_msg_dumps/dbg_msg_dumps.c include/freeDiameter/libfdcore.h libfdcore/hooks.c libfdcore/routing_dispatch.c
diffstat 4 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/dbg_msg_dumps/dbg_msg_dumps.c	Sun Aug 30 01:11:55 2015 +0800
+++ b/extensions/dbg_msg_dumps/dbg_msg_dumps.c	Sun Aug 30 01:58:21 2015 +0800
@@ -104,6 +104,10 @@
 			LOG_E("PARSING ERROR: %zdB msg from '%s': %s", rcv_data->length, peer_name, buf);
 		}
 		break;
+	case HOOK_MESSAGE_PARSING_ERROR2:
+		LOG_E("PARSING ERROR, returning:");
+		LOG_SPLIT(FD_LOG_ERROR, "     ", buf, NULL);
+		break;
 	case HOOK_MESSAGE_ROUTING_ERROR:
 		LOG_E("ROUTING ERROR '%s' for: ", (char *)other);
 		LOG_SPLIT(FD_LOG_ERROR, "     ", buf, NULL);
@@ -197,6 +201,9 @@
 			LOG_E("PARSING ERROR: %zdB msg from '%s': %s", rcv_data->length, peer_name, buf);
 		}
 		break;
+	case HOOK_MESSAGE_PARSING_ERROR2:
+		LOG_E("PARSING ERROR, returning: %s", buf);
+		break;
 	case HOOK_MESSAGE_ROUTING_ERROR:
 		LOG_E("ROUTING ERROR '%s' for: %s", (char *)other, buf);
 		break;
@@ -279,6 +286,9 @@
 			LOG_E("PARSING ERROR: %zdB msg from '%s': %s", rcv_data->length, peer_name, buf);
 		}
 		break;
+	case HOOK_MESSAGE_PARSING_ERROR2:
+		LOG_E("PARSING ERROR, returning: %s", buf);
+		break;
 	case HOOK_MESSAGE_ROUTING_ERROR:
 		LOG_E("ROUTING ERROR '%s' for: %s", (char *)other, buf);
 		break;
@@ -350,7 +360,7 @@
 			return EINVAL; });
 	}
 	
-	mask_errors = HOOK_MASK( HOOK_MESSAGE_FAILOVER, HOOK_MESSAGE_PARSING_ERROR, HOOK_MESSAGE_ROUTING_ERROR, HOOK_MESSAGE_DROPPED  );
+	mask_errors = HOOK_MASK( HOOK_MESSAGE_FAILOVER, HOOK_MESSAGE_PARSING_ERROR, HOOK_MESSAGE_PARSING_ERROR2, HOOK_MESSAGE_ROUTING_ERROR, HOOK_MESSAGE_DROPPED  );
 	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/include/freeDiameter/libfdcore.h	Sun Aug 30 01:11:55 2015 +0800
+++ b/include/freeDiameter/libfdcore.h	Sun Aug 30 01:58:21 2015 +0800
@@ -1002,7 +1002,7 @@
 		 - {other} is a char * pointer to the error message (human-readable) if {msg} is not NULL, a pointer to struct fd_cnx_rcvdata containing the received buffer otherwise.
 		 - {permsgdata} points to existing structure associated with this message (or new structure if no previous hook was registered). 
 		 */
-	
+		 
 	HOOK_MESSAGE_ROUTING_ERROR,
 		/* Hook called when a message being processed by the routing thread meets an error such as no remaining available peer for sending, based on routing callbacks decisions (maybe after retries).
 		 - {msg} points to the message. Again, the objects may not have been dictionary resolved. If you
@@ -1058,7 +1058,16 @@
 		 - {permsgdata} is always NULL for this hook.
 		 */
 	
-#define HOOK_LAST	HOOK_PEER_CONNECT_SUCCESS
+	HOOK_MESSAGE_PARSING_ERROR2,
+		/* Hook called after an error message has been generated due to a dictionary parsing error.
+		 - {msg} points to the error message that has been generated.
+		 - {peer} is NULL. You can still retrieve the source from the message itself.
+		 - {other} is NULL
+		 - {permsgdata} points to existing structure associated with this message (or new structure if no previous hook was registered). 
+		 Use this hook if you need to populate more data in the error being returned, from the error message. 
+		 (e.g. some AVP need to be added to replies even if error case.
+		 */
+#define HOOK_LAST	HOOK_MESSAGE_PARSING_ERROR2
 };
 
 
--- a/libfdcore/hooks.c	Sun Aug 30 01:11:55 2015 +0800
+++ b/libfdcore/hooks.c	Sun Aug 30 01:58:21 2015 +0800
@@ -382,6 +382,14 @@
 				break;
 			}
 			
+			case HOOK_MESSAGE_PARSING_ERROR2: {
+				CHECK_MALLOC_DO(fd_msg_dump_treeview(&hook_default_buf, &hook_default_len, NULL, msg, NULL, 0, 1), break);
+
+				LOG_E("Returning following message after parsing error:");
+				LOG_SPLIT(FD_LOG_ERROR, "   ", hook_default_buf, NULL);
+				break;
+			}
+			
 			case HOOK_MESSAGE_ROUTING_ERROR: {
 				CHECK_MALLOC_DO(fd_msg_dump_treeview(&hook_default_buf, &hook_default_len, NULL, msg, NULL, 0, 1), break);
 				LOG_E("Routing error: '%s' for the following message:", (char *)other);
--- a/libfdcore/routing_dispatch.c	Sun Aug 30 01:11:55 2015 +0800
+++ b/libfdcore/routing_dispatch.c	Sun Aug 30 01:58:21 2015 +0800
@@ -453,6 +453,7 @@
 				fd_msg_free(msgptr);
 			} else {
 				if (!msgptr) {
+					fd_hook_call(HOOK_MESSAGE_PARSING_ERROR2, error, NULL, NULL, fd_msg_pmdl_get(error));
 					/* error now contains the answer message to send back */
 					CHECK_FCT( fd_fifo_post(fd_g_outgoing, &error) );
 				} else if (!error) {
"Welcome to our mercurial repository"