Browse Source

tm: Trigger local-request event for ACK on negative replies

Xenofon Karamanos 1 month ago
parent
commit
8cf1dbf7a4
2 changed files with 30 additions and 3 deletions
  1. 8 2
      src/modules/tm/config.h
  2. 22 1
      src/modules/tm/t_reply.c

+ 8 - 2
src/modules/tm/config.h

@@ -88,8 +88,14 @@
 #define CANCEL_DONE "ok -- no more pending branches"
 #define CANCELED "Request canceled"
 
-/* execute event_route[tm:local-request] for hop-by-hop CANCEL */
-#define TM_EVLREQ_CANCEL_HBH 1
+/* execute event_route[tm:local-request] for hop-by-hop messages
+1 = execute for Cancel
+2 = execute for ACK
+3 = execute for both
+*/
+#define TM_EVLREQ_CANCEL_HBH (1 << 0)
+#define TM_EVLREQ_ACK_HBH (1 << 1)
+#define TM_EVLREQ_BOTH_HBH (TM_EVLREQ_CANCEL_HBH | TM_EVLREQ_ACK_HBH) // 3
 
 /* to-tag separator for stateful processing */
 #define TM_TAG_SEPARATOR '-'

+ 22 - 1
src/modules/tm/t_reply.c

@@ -100,6 +100,7 @@ static int goto_on_reply = 0;
 /* where to go on receipt of reply without transaction context */
 int goto_on_sl_reply = 0;
 extern str on_sl_reply_name;
+extern int _tm_evlreq_mode;
 
 extern str _tm_event_callback_lres_sent;
 
@@ -2460,6 +2461,26 @@ int reply_received(struct sip_msg *p_msg)
 							run_trans_callbacks_off_params(
 									TMCB_REQUEST_SENT, t, &onsend_params);
 						}
+/* trigger tm:local-request event route for negative reply ACK --- */
+#ifdef WITH_EVENT_LOCAL_REQUEST
+						if(goto_on_local_req >= 0
+								&& (_tm_evlreq_mode & TM_EVLREQ_ACK_HBH)) {
+							struct sip_msg ack_msg;
+							memset(&ack_msg, 0, sizeof(struct sip_msg));
+							if(build_sip_msg_from_buf(
+									   &ack_msg, ack, ack_len, inc_msg_no())
+									== 0) {
+								run_top_route(event_rt.rlist[goto_on_local_req],
+										&ack_msg, 0);
+								free_sip_msg(&ack_msg);
+							} else {
+								LM_ERR("failed to build sip msg structure for "
+									   "negative reply ACK event route\n");
+							}
+						}
+#endif /* WITH_EVENT_LOCAL_REQUEST */
+
+						/* trigger tm:local-request event route for negative reply ACK --- */
 					}
 					shm_free(ack);
 				}
@@ -2773,7 +2794,7 @@ int reply_received(struct sip_msg *p_msg)
 #endif
 		restart_rb_fr(&uac->request, t->fr_inv_timeout);
 		uac->request.flags |= F_RB_FR_INV; /* mark fr_inv */
-	}									   /* provisional replies */
+	} /* provisional replies */
 
 done:
 	if(unlikely(replies_locked)) {