Module: kamailio
Branch: master
Commit: 2873637af8a58ab5a694a86226d16284a7938460
URL: 
https://github.com/kamailio/kamailio/commit/2873637af8a58ab5a694a86226d16284a7938460

Author: Nikolay Ivanuschak <ivanuschak.niko...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2025-04-25T10:36:22+02:00

core: added support for multiple tcp_closed callbacks

---

Modified: src/core/events.c
Modified: src/core/events.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/2873637af8a58ab5a694a86226d16284a7938460.diff
Patch: 
https://github.com/kamailio/kamailio/commit/2873637af8a58ab5a694a86226d16284a7938460.patch

---

diff --git a/src/core/events.c b/src/core/events.c
index 4274bce58e0..b985bccc6c2 100644
--- a/src/core/events.c
+++ b/src/core/events.c
@@ -209,9 +209,13 @@ int sr_event_register_cb(int type, sr_event_cb_f f)
                                return -1;
                        break;
                case SREV_TCP_CLOSED:
-                       if(_sr_events_list.tcp_closed == 0)
-                               _sr_events_list.tcp_closed = f;
-                       else
+                       for(i = 0; i < SREV_CB_LIST_SIZE; i++) {
+                               if(_sr_events_list.tcp_closed[i] == 0) {
+                                       _sr_events_list.tcp_closed[i] = f;
+                                       break;
+                               }
+                       }
+                       if(i == SREV_CB_LIST_SIZE)
                                return -1;
                        break;
                case SREV_NET_DATA_RECV:
@@ -372,8 +376,13 @@ int sr_event_exec(int type, sr_event_param_t *evp)
                        } else
                                return 1;
                case SREV_TCP_CLOSED:
-                       if(unlikely(_sr_events_list.tcp_closed != 0)) {
-                               ret = _sr_events_list.tcp_closed(evp);
+                       if(unlikely(_sr_events_list.tcp_closed[0] != 0)) {
+                               ret = 0;
+                               for(i = 0;
+                                               i < SREV_CB_LIST_SIZE && 
_sr_events_list.tcp_closed[i];
+                                               i++) {
+                                       ret |= 
_sr_events_list.tcp_closed[i](evp);
+                               }
                                return ret;
                        } else
                                return 1;
@@ -449,7 +458,7 @@ int sr_event_enabled(int type)
                case SREV_RCV_NOSIP:
                        return (_sr_events_list.rcv_nosip != 0) ? 1 : 0;
                case SREV_TCP_CLOSED:
-                       return (_sr_events_list.tcp_closed != 0) ? 1 : 0;
+                       return (_sr_events_list.tcp_closed[0] != 0) ? 1 : 0;
                case SREV_NET_DATA_RECV:
                        return (_sr_events_list.net_data_recv != 0) ? 1 : 0;
                case SREV_NET_DATA_SENT:
diff --git a/src/core/events.h b/src/core/events.h
index cf1ec91d554..297abba798e 100644
--- a/src/core/events.h
+++ b/src/core/events.h
@@ -70,7 +70,7 @@ typedef struct sr_event_cb
        sr_event_cb_f tcp_ws_frame_out;
        sr_event_cb_f stun_in;
        sr_event_cb_f rcv_nosip;
-       sr_event_cb_f tcp_closed;
+       sr_event_cb_f tcp_closed[SREV_CB_LIST_SIZE];
        sr_event_cb_f net_data_recv;
        sr_event_cb_f net_data_sent;
        sr_event_cb_f sip_reply_out[SREV_CB_LIST_SIZE];

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to