Module: sip-router
Branch: master
Commit: 178b21cc1f7f7f7a3fa10b6937755f6b72ec84b3
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=178b21c…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sun Aug 14 22:59:53 2011 +0200
core: new core event for received datagrams
- event type defined as SREV_NET_DGRAM_IN
- allow modules to get a callback when a udp datagram is received
- offers the possibility to handle different content sent via datagram,
such as HEP from Homer project, without invading the core with new
code
---
events.c | 11 +++++++++++
events.h | 2 ++
udp_server.c | 12 ++++++++++++
3 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/events.c b/events.c
index fccfd1c..048cb45 100644
--- a/events.c
+++ b/events.c
@@ -81,6 +81,11 @@ int sr_event_register_cb(int type, sr_event_cb_f f)
_sr_events_list.pkg_set_real_used = f;
else return -1;
break;
+ case SREV_NET_DGRAM_IN:
+ if(_sr_events_list.net_dgram_in==0)
+ _sr_events_list.net_dgram_in = f;
+ else return -1;
+ break;
default:
return -1;
}
@@ -154,6 +159,12 @@ int sr_event_exec(int type, void *data)
ret = _sr_events_list.pkg_set_real_used(data);
return ret;
} else return 1;
+ case SREV_NET_DGRAM_IN:
+ if(unlikely(_sr_events_list.net_dgram_in!=0))
+ {
+ ret = _sr_events_list.net_dgram_in(data);
+ return ret;
+ } else return 1;
default:
return -1;
}
diff --git a/events.h b/events.h
index fdbcb45..465976f 100644
--- a/events.h
+++ b/events.h
@@ -29,6 +29,7 @@
#define SREV_CFG_RUN_ACTION 4
#define SREV_PKG_SET_USED 5
#define SREV_PKG_SET_REAL_USED 6
+#define SREV_NET_DGRAM_IN 7
typedef int (*sr_event_cb_f)(void *data);
@@ -39,6 +40,7 @@ typedef struct sr_event_cb {
sr_event_cb_f run_action;
sr_event_cb_f pkg_set_used;
sr_event_cb_f pkg_set_real_used;
+ sr_event_cb_f net_dgram_in;
} sr_event_cb_t;
void sr_event_cb_init(void);
diff --git a/udp_server.c b/udp_server.c
index c2c45bb..3889a65 100644
--- a/udp_server.c
+++ b/udp_server.c
@@ -75,6 +75,7 @@
#include "mem/mem.h"
#include "ip_addr.h"
#include "cfg/cfg_struct.h"
+#include "events.h"
#ifdef USE_RAW_SOCKS
#include "raw_sock.h"
#endif /* USE_RAW_SOCKS */
@@ -475,6 +476,17 @@ int udp_rcv_loop()
su2ip_addr(&ri.src_ip, from);
ri.src_port=su_getport(from);
+ if(unlikely(sr_event_enabled(SREV_NET_DGRAM_IN)))
+ {
+ void *sredp[3];
+ sredp[0] = (void*)buf;
+ sredp[1] = (void*)(&len);
+ sredp[2] = (void*)(&ri);
+ if(sr_event_exec(SREV_NET_DGRAM_IN, (void*)sredp)<0) {
+ /* data handled by callback - continue to next packet */
+ continue;
+ }
+ }
#ifndef NO_ZERO_CHECKS
#ifdef USE_STUN
/* STUN support can be switched off even if it's compiled */