Browse code

topos: ability to execute event routes when messages

Daniel-Constantin Mierla authored on 31/03/2021 19:59:51
Showing 1 changed files
... ...
@@ -89,12 +89,20 @@ int _tps_clean_interval = 60;
89 89
 
90 90
 #define TPS_EVENTRT_OUTGOING 1
91 91
 #define TPS_EVENTRT_SENDING  2
92
-static int _tps_eventrt_mode = TPS_EVENTRT_OUTGOING | TPS_EVENTRT_SENDING;
92
+#define TPS_EVENTRT_INCOMING  4
93
+#define TPS_EVENTRT_RECEIVING 8
94
+static int _tps_eventrt_mode = TPS_EVENTRT_OUTGOING | TPS_EVENTRT_SENDING
95
+				| TPS_EVENTRT_INCOMING | TPS_EVENTRT_RECEIVING;
93 96
 static int _tps_eventrt_outgoing = -1;
94 97
 static str _tps_eventrt_callback = STR_NULL;
95 98
 static str _tps_eventrt_outgoing_name = str_init("topos:msg-outgoing");
96 99
 static int _tps_eventrt_sending = -1;
97 100
 static str _tps_eventrt_sending_name = str_init("topos:msg-sending");
101
+static int _tps_eventrt_incoming = -1;
102
+static str _tps_eventrt_incoming_name = str_init("topos:msg-incoming");
103
+static int _tps_eventrt_receiving = -1;
104
+static str _tps_eventrt_receiving_name = str_init("topos:msg-receiving");
105
+
98 106
 str _tps_contact_host = str_init("");
99 107
 int _tps_contact_mode = 0;
100 108
 str _tps_contact_host_avp = str_init("");
... ...
@@ -130,7 +138,8 @@ int bind_topos(topos_api_t *api);
130 138
 
131 139
 static cmd_export_t cmds[]={
132 140
 	{"tps_set_context", (cmd_function)w_tps_set_context,
133
-		1, fixup_spve_null, fixup_free_spve_null, ANY_ROUTE},
141
+		1, fixup_spve_null, fixup_free_spve_null,
142
+		ANY_ROUTE},
134 143
 
135 144
 	{"bind_topos",  (cmd_function)bind_topos,  0,
136 145
 		0, 0, 0},
... ...
@@ -189,6 +198,16 @@ static int mod_init(void)
189 198
 			|| event_rt.rlist[_tps_eventrt_sending]==NULL) {
190 199
 		_tps_eventrt_sending = -1;
191 200
 	}
201
+	_tps_eventrt_incoming = route_lookup(&event_rt, _tps_eventrt_incoming_name.s);
202
+	if(_tps_eventrt_incoming<0
203
+			|| event_rt.rlist[_tps_eventrt_incoming]==NULL) {
204
+		_tps_eventrt_incoming = -1;
205
+	}
206
+	_tps_eventrt_receiving = route_lookup(&event_rt, _tps_eventrt_receiving_name.s);
207
+	if(_tps_eventrt_receiving<0
208
+			|| event_rt.rlist[_tps_eventrt_receiving]==NULL) {
209
+		_tps_eventrt_receiving = -1;
210
+	}
192 211
 
193 212
 	if(faked_msg_init()<0) {
194 213
 		LM_ERR("failed to init fmsg\n");
... ...
@@ -436,6 +455,12 @@ int tps_msg_received(sr_event_param_t *evp)
436 455
 	int ret;
437 456
 
438 457
 	obuf = (str*)evp->data;
458
+
459
+	if(tps_execute_event_route(NULL, evp, TPS_EVENTRT_INCOMING,
460
+				_tps_eventrt_incoming, &_tps_eventrt_incoming_name)==1) {
461
+		return 0;
462
+	}
463
+
439 464
 	memset(&msg, 0, sizeof(sip_msg_t));
440 465
 	msg.buf = obuf->s;
441 466
 	msg.len = obuf->len;
... ...
@@ -449,6 +474,11 @@ int tps_msg_received(sr_event_param_t *evp)
449 474
 		goto done;
450 475
 	}
451 476
 
477
+	if(tps_execute_event_route(&msg, evp, TPS_EVENTRT_RECEIVING,
478
+				_tps_eventrt_receiving, &_tps_eventrt_receiving_name)==1) {
479
+		goto done;
480
+	}
481
+
452 482
 	if(msg.first_line.type==SIP_REQUEST) {
453 483
 		if(_tps_sanity_checks!=0) {
454 484
 			if(scb.check_defaults(&msg)<1) {