# HG changeset patch # User Sebastien Decugis # Date 1440871101 -28800 # Node ID 50fb308e84f776dc1214e12dd0278adeca123693 # Parent 3f1e79e1273ef22f3fa240c716699207b72bbe89 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) diff -r 3f1e79e1273e -r 50fb308e84f7 extensions/dbg_msg_dumps/dbg_msg_dumps.c --- 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 ); diff -r 3f1e79e1273e -r 50fb308e84f7 include/freeDiameter/libfdcore.h --- 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 }; diff -r 3f1e79e1273e -r 50fb308e84f7 libfdcore/hooks.c --- 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); diff -r 3f1e79e1273e -r 50fb308e84f7 libfdcore/routing_dispatch.c --- 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) {