Module: kamailio
Branch: master
Commit: 858fab6bbf0c26f22bb9411e9385c10d654a6da5
URL: 
https://github.com/kamailio/kamailio/commit/858fab6bbf0c26f22bb9411e9385c10d654a6da5

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2021-03-31T21:59:51+02:00

topos: ability to execute event routes when messages

---

Modified: src/modules/topos/topos_mod.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/858fab6bbf0c26f22bb9411e9385c10d654a6da5.diff
Patch: 
https://github.com/kamailio/kamailio/commit/858fab6bbf0c26f22bb9411e9385c10d654a6da5.patch

---

diff --git a/src/modules/topos/topos_mod.c b/src/modules/topos/topos_mod.c
index 15f9678560..dd2741a126 100644
--- a/src/modules/topos/topos_mod.c
+++ b/src/modules/topos/topos_mod.c
@@ -89,12 +89,20 @@ int _tps_clean_interval = 60;
 
 #define TPS_EVENTRT_OUTGOING 1
 #define TPS_EVENTRT_SENDING  2
-static int _tps_eventrt_mode = TPS_EVENTRT_OUTGOING | TPS_EVENTRT_SENDING;
+#define TPS_EVENTRT_INCOMING  4
+#define TPS_EVENTRT_RECEIVING 8
+static int _tps_eventrt_mode = TPS_EVENTRT_OUTGOING | TPS_EVENTRT_SENDING
+                               | TPS_EVENTRT_INCOMING | TPS_EVENTRT_RECEIVING;
 static int _tps_eventrt_outgoing = -1;
 static str _tps_eventrt_callback = STR_NULL;
 static str _tps_eventrt_outgoing_name = str_init("topos:msg-outgoing");
 static int _tps_eventrt_sending = -1;
 static str _tps_eventrt_sending_name = str_init("topos:msg-sending");
+static int _tps_eventrt_incoming = -1;
+static str _tps_eventrt_incoming_name = str_init("topos:msg-incoming");
+static int _tps_eventrt_receiving = -1;
+static str _tps_eventrt_receiving_name = str_init("topos:msg-receiving");
+
 str _tps_contact_host = str_init("");
 int _tps_contact_mode = 0;
 str _tps_contact_host_avp = str_init("");
@@ -130,7 +138,8 @@ int bind_topos(topos_api_t *api);
 
 static cmd_export_t cmds[]={
        {"tps_set_context", (cmd_function)w_tps_set_context,
-               1, fixup_spve_null, fixup_free_spve_null, ANY_ROUTE},
+               1, fixup_spve_null, fixup_free_spve_null,
+               ANY_ROUTE},
 
        {"bind_topos",  (cmd_function)bind_topos,  0,
                0, 0, 0},
@@ -189,6 +198,16 @@ static int mod_init(void)
                        || event_rt.rlist[_tps_eventrt_sending]==NULL) {
                _tps_eventrt_sending = -1;
        }
+       _tps_eventrt_incoming = route_lookup(&event_rt, 
_tps_eventrt_incoming_name.s);
+       if(_tps_eventrt_incoming<0
+                       || event_rt.rlist[_tps_eventrt_incoming]==NULL) {
+               _tps_eventrt_incoming = -1;
+       }
+       _tps_eventrt_receiving = route_lookup(&event_rt, 
_tps_eventrt_receiving_name.s);
+       if(_tps_eventrt_receiving<0
+                       || event_rt.rlist[_tps_eventrt_receiving]==NULL) {
+               _tps_eventrt_receiving = -1;
+       }
 
        if(faked_msg_init()<0) {
                LM_ERR("failed to init fmsg\n");
@@ -436,6 +455,12 @@ int tps_msg_received(sr_event_param_t *evp)
        int ret;
 
        obuf = (str*)evp->data;
+
+       if(tps_execute_event_route(NULL, evp, TPS_EVENTRT_INCOMING,
+                               _tps_eventrt_incoming, 
&_tps_eventrt_incoming_name)==1) {
+               return 0;
+       }
+
        memset(&msg, 0, sizeof(sip_msg_t));
        msg.buf = obuf->s;
        msg.len = obuf->len;
@@ -449,6 +474,11 @@ int tps_msg_received(sr_event_param_t *evp)
                goto done;
        }
 
+       if(tps_execute_event_route(&msg, evp, TPS_EVENTRT_RECEIVING,
+                               _tps_eventrt_receiving, 
&_tps_eventrt_receiving_name)==1) {
+               goto done;
+       }
+
        if(msg.first_line.type==SIP_REQUEST) {
                if(_tps_sanity_checks!=0) {
                        if(scb.check_defaults(&msg)<1) {


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to