Module: kamailio
Branch: master
Commit: 5856d9848345a429c0a7bd91a6d9eccf45d067d3
URL: 
https://github.com/kamailio/kamailio/commit/5856d9848345a429c0a7bd91a6d9eccf45d067d3

Author: Armen Babikyan <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2016-01-04T23:06:52+01:00

tcpops: framework to execute event_route[tcp:closed]

---

Modified: modules/tcpops/tcpops.c
Modified: modules/tcpops/tcpops.h
Modified: modules/tcpops/tcpops_mod.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/5856d9848345a429c0a7bd91a6d9eccf45d067d3.diff
Patch: 
https://github.com/kamailio/kamailio/commit/5856d9848345a429c0a7bd91a6d9eccf45d067d3.patch

---

diff --git a/modules/tcpops/tcpops.c b/modules/tcpops/tcpops.c
index 037a8cb..d89e01a 100644
--- a/modules/tcpops/tcpops.c
+++ b/modules/tcpops/tcpops.c
@@ -31,6 +31,7 @@
 #include "../../globals.h"
 #include "../../pass_fd.h"
 #include "../../timer.h"
+#include "../../sr_module.h"
 
 /**
  * gets the fd of the current message source connection
@@ -185,3 +186,46 @@ int tcpops_set_connection_lifetime(struct tcp_connection* 
con, int time) {
        LM_DBG("new connection lifetime for conid=%d: %d\n", con->id, 
con->timeout);
        return 1;
 }
+
+static void tcpops_tcp_closed_run_route(struct tcp_connection *con)
+{
+       int rt, backup_rt;
+       struct run_act_ctx ctx;
+       sip_msg_t *fmsg;
+       LM_DBG("tcp_closed_run_route event_route[tcp:closed]\n");
+
+       rt = route_get(&event_rt, "tcp:closed");
+       if (rt < 0 || event_rt.rlist[rt] == NULL)
+       {
+               LM_DBG("route does not exist");
+               return;
+       }
+
+       if (faked_msg_init() < 0)
+       {
+               LM_ERR("faked_msg_init() failed\n");
+               return;
+       }
+       fmsg = faked_msg_next();
+       fmsg->rcv = con->rcv;
+
+       backup_rt = get_route_type();
+       set_route_type(EVENT_ROUTE);
+       init_run_actions_ctx(&ctx);
+       run_top_route(event_rt.rlist[rt], fmsg, 0);
+       set_route_type(backup_rt);
+}
+
+int tcpops_handle_tcp_closed(void *data)
+{
+       tcp_event_info_t *tev = (tcp_event_info_t *) data;
+
+       if (tev == NULL || tev->con == NULL) {
+               LM_WARN("received bad TCP closed event\n");
+               return -1;
+       }
+
+       tcpops_tcp_closed_run_route(tev->con);
+
+       return 0;
+}
diff --git a/modules/tcpops/tcpops.h b/modules/tcpops/tcpops.h
index c9a0771..771516f 100644
--- a/modules/tcpops/tcpops.h
+++ b/modules/tcpops/tcpops.h
@@ -25,11 +25,13 @@
 #define TCP_KEEPALIVE_H_
 
 #include "../../tcp_conn.h"
+#include "../../events.h"
 
 int tcpops_get_current_fd(int conid, int *fd);
 int tcpops_acquire_fd_from_tcpmain(int conid, int *fd);
 int tcpops_keepalive_enable(int fd, int idle, int count, int interval, int 
closefd);
 int tcpops_keepalive_disable(int fd, int closefd);
 int tcpops_set_connection_lifetime(struct tcp_connection* con, int time);
+int tcpops_handle_tcp_closed(void *data);
 
 #endif /* TCP_KEEPALIVE_H_ */
diff --git a/modules/tcpops/tcpops_mod.c b/modules/tcpops/tcpops_mod.c
index c400020..0de40c7 100644
--- a/modules/tcpops/tcpops_mod.c
+++ b/modules/tcpops/tcpops_mod.c
@@ -35,6 +35,7 @@
 #include "../../tcp_options.h"
 #include "../../dprint.h"
 #include "../../mod_fix.h"
+#include "../../events.h"
 
 #include "tcpops.h"
 
@@ -101,6 +102,11 @@ static int mod_init(void)
 {
        LM_DBG("TCP keepalive module loaded.\n");
 
+       if (sr_event_register_cb(SREV_TCP_CLOSED, tcpops_handle_tcp_closed) != 
0) {
+               LM_ERR("problem registering tcpops_handle_tcp_closed 
call-back\n");
+               return -1;
+       }
+
        return 0;
 }
 


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to